[BUG #7947] Prevent that Widget.contains returns true when parent and child is equal

(cherry picked from commit 02b6787eb16c955f56b7d0c4d6e545bd0c197d45)
[BUG #7947] Add unit tests to ensure that the contains method return false when parent and child are equal

(cherry picked from commit 5d2177c4513b769912805a4a9f6595203cc4fb13)