diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-14 14:58:03 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-14 14:58:03 +0000 |
commit | af4aaba6aa5cbbb5878b5eac51710ff89b8f63f7 (patch) | |
tree | 5b69738a267aa4221369fc683b1935ad8d7b8529 /ui/aura/window_unittest.cc | |
parent | 9f24932a303826ac2279b6e7a261176c0f15b1eb (diff) | |
download | chromium_src-af4aaba6aa5cbbb5878b5eac51710ff89b8f63f7.zip chromium_src-af4aaba6aa5cbbb5878b5eac51710ff89b8f63f7.tar.gz chromium_src-af4aaba6aa5cbbb5878b5eac51710ff89b8f63f7.tar.bz2 |
Attempt 2 at: Makes Window not change focus and send out notifications
when moving to a new parent.
I had to update a couple of test expectations.
BUG=137342
TEST=covered by tests
TBR=ben@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10831297
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151478 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/aura/window_unittest.cc')
-rw-r--r-- | ui/aura/window_unittest.cc | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc index 668abad..cb7ad0e 100644 --- a/ui/aura/window_unittest.cc +++ b/ui/aura/window_unittest.cc @@ -8,6 +8,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" +#include "base/string_number_conversions.h" #include "base/stringprintf.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/aura/client/capture_client.h" @@ -583,7 +584,9 @@ TEST_F(WindowTest, WindowAddedToRootWindowShouldNotifyChildAndNotParent) { AddedToRootWindowObserver parent_observer; AddedToRootWindowObserver child_observer; scoped_ptr<Window> parent_window(CreateTestWindowWithId(1, NULL)); - scoped_ptr<Window> child_window(CreateTestWindowWithId(1, NULL)); + scoped_ptr<Window> child_window(new Window(NULL)); + child_window->Init(ui::LAYER_TEXTURED); + child_window->Show(); parent_window->AddObserver(&parent_observer); child_window->AddObserver(&child_observer); @@ -2461,5 +2464,53 @@ TEST_F(WindowTest, DelegateNotifiedAsBoundsChangeInHiddenLayer) { EXPECT_NE("0,0 100x100", window->bounds().ToString()); } +namespace { + +// Used by AddChildNotifications to track notification counts. +class AddChildNotificationsObserver : public WindowObserver { + public: + AddChildNotificationsObserver() : added_count_(0), removed_count_(0) {} + + std::string CountStringAndReset() { + std::string result = base::IntToString(added_count_) + " " + + base::IntToString(removed_count_); + added_count_ = removed_count_ = 0; + return result; + } + + // WindowObserver overrides: + virtual void OnWindowAddedToRootWindow(Window* window) OVERRIDE { + added_count_++; + } + virtual void OnWindowRemovingFromRootWindow(Window* window) OVERRIDE { + removed_count_++; + } + + private: + int added_count_; + int removed_count_; + + DISALLOW_COPY_AND_ASSIGN(AddChildNotificationsObserver); +}; + +} // namespace + +// Assertions around when root window notifications are sent. +TEST_F(WindowTest, AddChildNotifications) { + AddChildNotificationsObserver observer; + scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); + scoped_ptr<Window> w2(CreateTestWindowWithId(1, NULL)); + w2->AddObserver(&observer); + w2->Focus(); + EXPECT_TRUE(w2->HasFocus()); + + // Move |w2| to be a child of |w1|. + w1->AddChild(w2.get()); + // Sine we moved in the same root, observer shouldn't be notified. + EXPECT_EQ("0 0", observer.CountStringAndReset()); + // |w2| should still have focus after moving. + EXPECT_TRUE(w2->HasFocus()); +} + } // namespace test } // namespace aura |