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

Unified Diff: ui/aura/window_unittest.cc

Issue 8253001: aura: Some changes in Window and Desktop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 2 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
« ui/aura/window.cc ('K') | « 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
diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc
index 1494ba7522a3a10caacd32b2609c30b4a2963a02..b5589319c137592fc78e479bf3e6974bf4cb3a74 100644
--- a/ui/aura/window_unittest.cc
+++ b/ui/aura/window_unittest.cc
@@ -6,6 +6,7 @@
#include "base/compiler_specific.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/desktop.h"
+#include "ui/aura/desktop_observer.h"
#include "ui/aura/event.h"
#include "ui/aura/focus_manager.h"
#include "ui/aura/hit_test.h"
@@ -14,6 +15,7 @@
#include "ui/aura/test/test_desktop_delegate.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/window_delegate.h"
+#include "ui/aura/window_observer.h"
#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/compositor/layer.h"
#include "ui/base/keycodes/keyboard_codes.h"
@@ -760,5 +762,99 @@ TEST_F(WindowTest, Deactivate) {
EXPECT_EQ(w2.get(), parent->children()[1]);
}
+class ObserverTest : public WindowTest,
+ public DesktopObserver,
+ public WindowObserver {
+ public:
+ ObserverTest()
+ : active_(NULL),
+ shown_(NULL),
+ hidden_(NULL) {
+ }
+
+ virtual ~ObserverTest() {}
+
+ Window* active() const { return active_; }
+ Window* shown() const { return shown_; }
+ Window* hidden() const { return hidden_; }
+
+ void Reset() {
+ active_ = NULL;
+ shown_ = NULL;
+ hidden_ = NULL;
+ }
+
+ private:
+ virtual void SetUp() OVERRIDE {
+ WindowTest::SetUp();
+ Desktop::GetInstance()->AddObserver(this);
+ }
+
+ virtual void TearDown() OVERRIDE {
+ Desktop::GetInstance()->RemoveObserver(this);
+ WindowTest::TearDown();
+ }
+
+ virtual void OnActiveWindowChanged(Window* active) OVERRIDE {
+ active_ = active;
+ }
+
+ virtual void OnWindowVisibilityChanged(Window* window) OVERRIDE {
+ if (window->IsVisible())
+ shown_ = window;
+ else
+ hidden_ = window;
+ }
+
+ Window* active_;
+ Window* shown_;
+ Window* hidden_;
+
+ DISALLOW_COPY_AND_ASSIGN(ObserverTest);
+};
+
+TEST_F(ObserverTest, WindowActivationObserve) {
+ scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL));
+ scoped_ptr<Window> w2(CreateTestWindowWithId(2, NULL));
+ scoped_ptr<Window> w3(CreateTestWindowWithId(3, w1.get()));
+
+ EXPECT_EQ(NULL, active());
+
+ w2->Activate();
+ EXPECT_EQ(w2.get(), active());
+
+ w3->Activate();
+ EXPECT_EQ(w2.get(), active());
+
+ w1->Activate();
+ EXPECT_EQ(w1.get(), active());
+}
+
+TEST_F(ObserverTest, WindowVisibilityObserve) {
+ scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL));
+ scoped_ptr<Window> w2(CreateTestWindowWithId(2, NULL));
+ scoped_ptr<Window> w3(CreateTestWindowWithId(3, w1.get()));
+
+ w1->AddObserver(this);
+ w2->AddObserver(this);
+ w3->AddObserver(this);
+
+ Reset();
+ w1->Show();
+ EXPECT_EQ(w1.get(), shown());
+
+ w2->Show();
+ EXPECT_EQ(w2.get(), shown());
+
+ w3->Show();
+ EXPECT_EQ(w3.get(), shown());
+
+ w1->Hide();
+ EXPECT_EQ(w1.get(), hidden());
+
+ w3->Hide();
+ EXPECT_EQ(w3.get(), hidden());
+}
+
} // namespace test
} // namespace aura
« ui/aura/window.cc ('K') | « ui/aura/window_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698