Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(714)

Unified Diff: ui/aura/window_unittest.cc

Issue 9315015: Adds two new observer methods to allow code to be notified when a Window is added/removed from a ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/aura/window_observer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/aura/window_unittest.cc
===================================================================
--- ui/aura/window_unittest.cc (revision 119986)
+++ ui/aura/window_unittest.cc (working copy)
@@ -1462,5 +1462,98 @@
EXPECT_TRUE(LayerIsAbove(window12.get(), window1.get()));
}
+class RootWindowAttachmentObserver : public WindowObserver {
+ public:
+ RootWindowAttachmentObserver() : added_count_(0), removed_count_(0) {}
+ virtual ~RootWindowAttachmentObserver() {}
+
+ int added_count() const { return added_count_; }
+ int removed_count() const { return removed_count_; }
+
+ void Clear() {
+ added_count_ = 0;
+ removed_count_ = 0;
+ }
+
+ // Overridden from WindowObserver:
+ 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(RootWindowAttachmentObserver);
+};
+
+TEST_F(WindowTest, RootWindowAttachment) {
+ RootWindowAttachmentObserver observer;
+
+ // Test a direct add/remove from the RootWindow.
+ scoped_ptr<Window> w1(new Window(NULL));
+ w1->Init(ui::Layer::LAYER_NOT_DRAWN);
+ w1->AddObserver(&observer);
+
+ w1->SetParent(NULL);
+ EXPECT_EQ(1, observer.added_count());
+ EXPECT_EQ(0, observer.removed_count());
+
+ w1.reset();
+ EXPECT_EQ(1, observer.added_count());
+ EXPECT_EQ(1, observer.removed_count());
+
+ observer.Clear();
+
+ // Test an indirect add/remove from the RootWindow.
+ w1.reset(new Window(NULL));
+ w1->Init(ui::Layer::LAYER_NOT_DRAWN);
+ Window* w11 = new Window(NULL);
+ w11->Init(ui::Layer::LAYER_NOT_DRAWN);
+ w11->AddObserver(&observer);
+ w11->SetParent(w1.get());
+ EXPECT_EQ(0, observer.added_count());
+ EXPECT_EQ(0, observer.removed_count());
+
+ w1->SetParent(NULL);
+ EXPECT_EQ(1, observer.added_count());
+ EXPECT_EQ(0, observer.removed_count());
+
+ w1.reset(); // Deletes w11.
+ w11 = NULL;
+ EXPECT_EQ(1, observer.added_count());
+ EXPECT_EQ(1, observer.removed_count());
+
+ observer.Clear();
+
+ // Test an indirect add/remove with nested observers.
+ w1.reset(new Window(NULL));
+ w1->Init(ui::Layer::LAYER_NOT_DRAWN);
+ w11 = new Window(NULL);
+ w11->Init(ui::Layer::LAYER_NOT_DRAWN);
+ w11->AddObserver(&observer);
+ w11->SetParent(w1.get());
+ Window* w111 = new Window(NULL);
+ w111->Init(ui::Layer::LAYER_NOT_DRAWN);
+ w111->AddObserver(&observer);
+ w111->SetParent(w11);
+
+ EXPECT_EQ(0, observer.added_count());
+ EXPECT_EQ(0, observer.removed_count());
+
+ w1->SetParent(NULL);
+ EXPECT_EQ(2, observer.added_count());
+ EXPECT_EQ(0, observer.removed_count());
+
+ w1.reset(); // Deletes w11 and w111.
+ w11 = NULL;
+ w111 = NULL;
+ EXPECT_EQ(2, observer.added_count());
+ EXPECT_EQ(2, observer.removed_count());
+}
+
} // namespace test
} // namespace aura
« no previous file with comments | « ui/aura/window_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698