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

Side by Side Diff: ui/aura_shell/modal_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
« no previous file with comments | « ui/aura_shell/modal_container_layout_manager.cc ('k') | ui/aura_shell/modality_event_filter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/modal_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* GetModalContainer() {
23 return Shell::GetInstance()->GetContainer(
24 aura_shell::internal::kShellWindowId_ModalContainer);
25 }
26
27 aura::Window* GetDefaultContainer() {
28 return Shell::GetInstance()->GetContainer(
29 aura_shell::internal::kShellWindowId_DefaultContainer);
30 }
31
32 class TestWindow : public views::WidgetDelegateView {
33 public:
34 explicit TestWindow(bool modal) : modal_(modal) {}
35 virtual ~TestWindow() {}
36
37 static aura::Window* OpenTestWindow(aura::Window* parent, bool modal) {
38 DCHECK(!modal || modal && parent);
39 views::Widget* widget =
40 views::Widget::CreateWindowWithParent(new TestWindow(modal), parent);
41 widget->Show();
42 return widget->GetNativeView();
43 }
44
45 // Overridden from views::View:
46 virtual gfx::Size GetPreferredSize() OVERRIDE {
47 return gfx::Size(50, 50);
48 }
49
50 // Overridden from views::WidgetDelegate:
51 virtual views::View* GetContentsView() OVERRIDE {
52 return this;
53 }
54 virtual bool IsModal() const OVERRIDE {
55 return modal_;
56 }
57
58 private:
59 bool modal_;
60
61 DISALLOW_COPY_AND_ASSIGN(TestWindow);
62 };
63
64 class TransientWindowObserver : public aura::WindowObserver {
65 public:
66 TransientWindowObserver() : destroyed_(false) {}
67 virtual ~TransientWindowObserver() {}
68
69 bool destroyed() const { return destroyed_; }
70
71 // Overridden from aura::WindowObserver:
72 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE {
73 destroyed_ = true;
74 }
75
76 private:
77 bool destroyed_;
78
79 DISALLOW_COPY_AND_ASSIGN(TransientWindowObserver);
80 };
81
82 } // namespace
83
84 typedef aura_shell::test::AuraShellTestBase ModalContainerLayoutManagerTest;
85
86 TEST_F(ModalContainerLayoutManagerTest, NonModalTransient) {
87 scoped_ptr<aura::Window> parent(TestWindow::OpenTestWindow(NULL, false));
88 aura::Window* transient = TestWindow::OpenTestWindow(parent.get(), false);
89 TransientWindowObserver destruction_observer;
90 transient->AddObserver(&destruction_observer);
91
92 EXPECT_EQ(parent.get(), transient->transient_parent());
93 EXPECT_EQ(GetDefaultContainer(), transient->parent());
94
95 // The transient should be destroyed with its parent.
96 parent.reset();
97 EXPECT_TRUE(destruction_observer.destroyed());
98 }
99
100 TEST_F(ModalContainerLayoutManagerTest, ModalTransient) {
101 scoped_ptr<aura::Window> parent(TestWindow::OpenTestWindow(NULL, false));
102 // parent should be active.
103 EXPECT_EQ(parent.get(), aura::Desktop::GetInstance()->active_window());
104
105 aura::Window* t1 = TestWindow::OpenTestWindow(parent.get(), true);
106 TransientWindowObserver do1;
107 t1->AddObserver(&do1);
108
109 EXPECT_EQ(parent.get(), t1->transient_parent());
110 EXPECT_EQ(GetModalContainer(), t1->parent());
111
112 // t1 should now be active.
113 EXPECT_EQ(t1, aura::Desktop::GetInstance()->active_window());
114
115 // Attempting to click the parent should result in no activation change.
116 aura::test::EventGenerator e1(parent.get());
117 e1.ClickLeftButton();
118 EXPECT_EQ(t1, aura::Desktop::GetInstance()->active_window());
119
120 // Now open another modal transient parented to the original modal transient.
121 aura::Window* t2 = TestWindow::OpenTestWindow(t1, true);
122 TransientWindowObserver do2;
123 t2->AddObserver(&do2);
124
125 EXPECT_EQ(t2, aura::Desktop::GetInstance()->active_window());
126
127 EXPECT_EQ(t1, t2->transient_parent());
128 EXPECT_EQ(GetModalContainer(), t2->parent());
129
130 // t2 should still be active, even after clicking on t1.
131 aura::test::EventGenerator e2(t1);
132 e2.ClickLeftButton();
133 EXPECT_EQ(t2, aura::Desktop::GetInstance()->active_window());
134
135 // Both transients should be destroyed with parent.
136 parent.reset();
137 EXPECT_TRUE(do1.destroyed());
138 EXPECT_TRUE(do2.destroyed());
139 }
140
141 // Tests that we can activate an unrelated window after a modal window is closed
142 // for a window.
143 TEST_F(ModalContainerLayoutManagerTest, CanActivateAfterEndModalSession) {
144 scoped_ptr<aura::Window> unrelated(TestWindow::OpenTestWindow(NULL, false));
145 unrelated->SetBounds(gfx::Rect(100, 100, 50, 50));
146 scoped_ptr<aura::Window> parent(TestWindow::OpenTestWindow(NULL, false));
147 // parent should be active.
148 EXPECT_EQ(parent.get(), aura::Desktop::GetInstance()->active_window());
149
150 scoped_ptr<aura::Window> transient(
151 TestWindow::OpenTestWindow(parent.get(), true));
152 // t1 should now be active.
153 EXPECT_EQ(transient.get(), aura::Desktop::GetInstance()->active_window());
154
155 // Attempting to click the parent should result in no activation change.
156 aura::test::EventGenerator e1(parent.get());
157 e1.ClickLeftButton();
158 EXPECT_EQ(transient.get(), aura::Desktop::GetInstance()->active_window());
159
160 // Now close the transient.
161 transient.reset();
162
163 // parent should now be active again.
164 EXPECT_EQ(parent.get(), aura::Desktop::GetInstance()->active_window());
165
166 // Attempting to click unrelated should activate it.
167 aura::test::EventGenerator e2(unrelated.get());
168 e2.ClickLeftButton();
169 EXPECT_EQ(unrelated.get(), aura::Desktop::GetInstance()->active_window());
170 }
171
172 } // namespace test
173 } // namespace aura_shell
OLDNEW
« no previous file with comments | « ui/aura_shell/modal_container_layout_manager.cc ('k') | ui/aura_shell/modality_event_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698