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

Side by Side Diff: ui/aura_shell/transient_container_layout_manager_unittest.cc

Issue 8574033: Beginnings of Window Modality support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/aura_shell/transient_container_layout_manager.h"
6
7 #include "base/compiler_specific.h"
8 #include "ui/aura/desktop.h"
9 #include "ui/aura/test/event_generator.h"
10 #include "ui/aura/window.h"
11 #include "ui/aura_shell/shell.h"
12 #include "ui/aura_shell/shell_window_ids.h"
13 #include "ui/aura_shell/test/aura_shell_test_base.h"
14 #include "views/widget/widget.h"
15 #include "views/widget/widget_delegate.h"
16
17 namespace aura_shell {
18 namespace test {
19
20 namespace {
21
22 aura::Window* GetTransientContainer() {
23 return Shell::GetInstance()->GetContainer(
24 aura_shell::internal::kShellWindowId_TransientContainer);
25 }
26
27 class TestWindow : public views::WidgetDelegateView {
28 public:
29 explicit TestWindow(bool modal) : modal_(modal) {}
30 virtual ~TestWindow() {}
31
32 static aura::Window* OpenTestWindow(aura::Window* parent, bool modal) {
33 DCHECK(!modal || modal && parent);
34 views::Widget* widget =
35 views::Widget::CreateWindowWithParent(new TestWindow(modal), parent);
36 widget->Show();
37 return widget->GetNativeView();
38 }
39
40 // Overridden from views::View:
41 virtual gfx::Size GetPreferredSize() OVERRIDE {
42 return gfx::Size(50, 50);
43 }
44
45 // Overridden from views::WidgetDelegate:
46 virtual views::View* GetContentsView() OVERRIDE {
47 return this;
48 }
49 virtual bool IsModal() const OVERRIDE {
50 return modal_;
51 }
52
53 private:
54 bool modal_;
55
56 DISALLOW_COPY_AND_ASSIGN(TestWindow);
57 };
58
59 class TransientWindowObserver : public aura::WindowObserver {
60 public:
61 TransientWindowObserver() : destroyed_(false) {}
62 virtual ~TransientWindowObserver() {}
63
64 bool destroyed() const { return destroyed_; }
65
66 // Overridden from aura::WindowObserver:
67 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE {
68 destroyed_ = true;
69 }
70
71 private:
72 bool destroyed_;
73
74 DISALLOW_COPY_AND_ASSIGN(TransientWindowObserver);
75 };
76
77 } // namespace
78
79 typedef aura_shell::test::AuraShellTestBase TransientContainerLayoutManagerTest;
80
81 TEST_F(TransientContainerLayoutManagerTest, NonModalTransient) {
82 scoped_ptr<aura::Window> parent(TestWindow::OpenTestWindow(NULL, false));
83 aura::Window* transient = TestWindow::OpenTestWindow(parent.get(), false);
84 TransientWindowObserver destruction_observer;
85 transient->AddObserver(&destruction_observer);
86
87 EXPECT_EQ(parent.get(), transient->transient_parent());
88 EXPECT_EQ(GetTransientContainer(), transient->parent());
89
90 // The transient should be destroyed with its parent.
91 parent.reset();
92 EXPECT_TRUE(destruction_observer.destroyed());
93 }
94
95 TEST_F(TransientContainerLayoutManagerTest, ModalTransient) {
96 scoped_ptr<aura::Window> parent(TestWindow::OpenTestWindow(NULL, false));
97 // parent should be active.
98 EXPECT_EQ(parent.get(), aura::Desktop::GetInstance()->active_window());
99
100 aura::Window* t1 = TestWindow::OpenTestWindow(parent.get(), true);
101 TransientWindowObserver do1;
102 t1->AddObserver(&do1);
103
104 EXPECT_EQ(parent.get(), t1->transient_parent());
105 EXPECT_EQ(GetTransientContainer(), t1->parent());
106
107 // t1 should now be active.
108 EXPECT_EQ(t1, aura::Desktop::GetInstance()->active_window());
109
110 // Attempting to click the parent should result in no activation change.
111 aura::test::EventGenerator e1(parent.get());
112 e1.ClickLeftButton();
113 EXPECT_EQ(t1, aura::Desktop::GetInstance()->active_window());
114
115 // Now open another modal transient parented to the original modal transient.
116 aura::Window* t2 = TestWindow::OpenTestWindow(t1, true);
117 TransientWindowObserver do2;
118 t2->AddObserver(&do2);
119
120 EXPECT_EQ(t2, aura::Desktop::GetInstance()->active_window());
121
122 EXPECT_EQ(t1, t2->transient_parent());
123 EXPECT_EQ(GetTransientContainer(), t2->parent());
124
125 // t2 should still be active, even after clicking on t1.
126 aura::test::EventGenerator e2(t1);
127 e2.ClickLeftButton();
128 EXPECT_EQ(t2, aura::Desktop::GetInstance()->active_window());
129
130 // Both transients should be destroyed with parent.
131 parent.reset();
132 EXPECT_TRUE(do1.destroyed());
133 EXPECT_TRUE(do2.destroyed());
134 }
135
136 // Tests that we can activate an unrelated window after a modal window is closed
137 // for a window.
138 TEST_F(TransientContainerLayoutManagerTest, CanActivateAfterEndModalSession) {
139 scoped_ptr<aura::Window> unrelated(TestWindow::OpenTestWindow(NULL, false));
140 unrelated->SetBounds(gfx::Rect(100, 100, 50, 50));
141 scoped_ptr<aura::Window> parent(TestWindow::OpenTestWindow(NULL, false));
142 // parent should be active.
143 EXPECT_EQ(parent.get(), aura::Desktop::GetInstance()->active_window());
144
145 scoped_ptr<aura::Window> transient(
146 TestWindow::OpenTestWindow(parent.get(), true));
147 // t1 should now be active.
148 EXPECT_EQ(transient.get(), aura::Desktop::GetInstance()->active_window());
149
150 // Attempting to click the parent should result in no activation change.
151 aura::test::EventGenerator e1(parent.get());
152 e1.ClickLeftButton();
153 EXPECT_EQ(transient.get(), aura::Desktop::GetInstance()->active_window());
154
155 // Now close the transient.
156 transient.reset();
157
158 // parent should now be active again.
159 EXPECT_EQ(parent.get(), aura::Desktop::GetInstance()->active_window());
160
161 // Attempting to click unrelated should activate it.
162 aura::test::EventGenerator e2(unrelated.get());
163 e2.ClickLeftButton();
164 EXPECT_EQ(unrelated.get(), aura::Desktop::GetInstance()->active_window());
165 }
166
167 } // namespace test
168 } // namespace aura_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698