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

Side by Side Diff: ash/wm/window_modality_controller_unittest.cc

Issue 11316287: Move WindowModalityController to CoreWm. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/wm/window_modality_controller.h" 5 #include "ui/views/corewm/window_modality_controller.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h" 8 #include "ash/test/ash_test_base.h"
9 #include "ash/test/capture_tracking_view.h"
10 #include "ash/test/child_modal_window.h"
11 #include "ash/wm/window_util.h" 9 #include "ash/wm/window_util.h"
12 #include "ui/aura/client/aura_constants.h" 10 #include "ui/aura/client/aura_constants.h"
13 #include "ui/aura/test/event_generator.h" 11 #include "ui/aura/test/event_generator.h"
14 #include "ui/aura/test/test_window_delegate.h" 12 #include "ui/aura/test/test_window_delegate.h"
15 #include "ui/aura/test/test_windows.h" 13 #include "ui/aura/test/test_windows.h"
16 #include "ui/aura/window.h" 14 #include "ui/aura/window.h"
17 #include "ui/base/ui_base_types.h" 15 #include "ui/base/ui_base_types.h"
16 #include "ui/views/test/capture_tracking_view.h"
17 #include "ui/views/test/child_modal_window.h"
18 #include "ui/views/widget/widget.h" 18 #include "ui/views/widget/widget.h"
19 19
20 namespace ash { 20 namespace ash {
21 namespace internal { 21 namespace internal {
22 22
23 typedef test::AshTestBase WindowModalityControllerTest; 23 typedef test::AshTestBase WindowModalityControllerTest;
24 24
25 namespace { 25 namespace {
26 26
27 bool ValidateStacking(aura::Window* parent, int ids[], int count) { 27 bool ValidateStacking(aura::Window* parent, int ids[], int count) {
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 aura::test::TestWindowDelegate d; 212 aura::test::TestWindowDelegate d;
213 scoped_ptr<aura::Window> w1( 213 scoped_ptr<aura::Window> w1(
214 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect())); 214 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect()));
215 scoped_ptr<aura::Window> w11( 215 scoped_ptr<aura::Window> w11(
216 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get())); 216 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get()));
217 scoped_ptr<aura::Window> w2( 217 scoped_ptr<aura::Window> w2(
218 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect())); 218 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect()));
219 w2->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); 219 w2->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
220 220
221 aura::Window* wt; 221 aura::Window* wt;
222 wt = GetModalTransient(w1.get()); 222 wt = views::corewm::GetModalTransient(w1.get());
223 ASSERT_EQ(static_cast<aura::Window*>(NULL), wt); 223 ASSERT_EQ(static_cast<aura::Window*>(NULL), wt);
224 224
225 // Parent w2 to w1. It should get parented to the parent of w1. 225 // Parent w2 to w1. It should get parented to the parent of w1.
226 w1->AddTransientChild(w2.get()); 226 w1->AddTransientChild(w2.get());
227 ASSERT_EQ(2U, w1->parent()->children().size()); 227 ASSERT_EQ(2U, w1->parent()->children().size());
228 EXPECT_EQ(-2, w1->parent()->children().at(1)->id()); 228 EXPECT_EQ(-2, w1->parent()->children().at(1)->id());
229 229
230 // Request the modal transient window for w1, it should be w2. 230 // Request the modal transient window for w1, it should be w2.
231 wt = GetModalTransient(w1.get()); 231 wt = views::corewm::GetModalTransient(w1.get());
232 ASSERT_NE(static_cast<aura::Window*>(NULL), wt); 232 ASSERT_NE(static_cast<aura::Window*>(NULL), wt);
233 EXPECT_EQ(-2, wt->id()); 233 EXPECT_EQ(-2, wt->id());
234 234
235 // Request the modal transient window for w11, it should also be w2. 235 // Request the modal transient window for w11, it should also be w2.
236 wt = GetModalTransient(w11.get()); 236 wt = views::corewm::GetModalTransient(w11.get());
237 ASSERT_NE(static_cast<aura::Window*>(NULL), wt); 237 ASSERT_NE(static_cast<aura::Window*>(NULL), wt);
238 EXPECT_EQ(-2, wt->id()); 238 EXPECT_EQ(-2, wt->id());
239 } 239 }
240 240
241 // Verifies we generate a capture lost when showing a modal window. 241 // Verifies we generate a capture lost when showing a modal window.
242 TEST_F(WindowModalityControllerTest, ChangeCapture) { 242 TEST_F(WindowModalityControllerTest, ChangeCapture) {
243 views::Widget* widget = views::Widget::CreateWindow(NULL); 243 views::Widget* widget = views::Widget::CreateWindow(NULL);
244 scoped_ptr<aura::Window> widget_window(widget->GetNativeView()); 244 scoped_ptr<aura::Window> widget_window(widget->GetNativeView());
245 test::CaptureTrackingView* view = new test::CaptureTrackingView; 245 views::test::CaptureTrackingView* view = new views::test::CaptureTrackingView;
246 widget->client_view()->AddChildView(view); 246 widget->client_view()->AddChildView(view);
247 widget->SetBounds(gfx::Rect(0, 0, 200, 200)); 247 widget->SetBounds(gfx::Rect(0, 0, 200, 200));
248 view->SetBoundsRect(widget->client_view()->GetLocalBounds()); 248 view->SetBoundsRect(widget->client_view()->GetLocalBounds());
249 widget->Show(); 249 widget->Show();
250 250
251 gfx::Point center(view->width() / 2, view->height() / 2); 251 gfx::Point center(view->width() / 2, view->height() / 2);
252 views::View::ConvertPointToScreen(view, &center); 252 views::View::ConvertPointToScreen(view, &center);
253 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), center); 253 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), center);
254 generator.PressLeftButton(); 254 generator.PressLeftButton();
255 EXPECT_TRUE(view->got_press()); 255 EXPECT_TRUE(view->got_press());
256 256
257 views::Widget* modal_widget = 257 views::Widget* modal_widget =
258 views::Widget::CreateWindowWithParent(NULL, widget->GetNativeView()); 258 views::Widget::CreateWindowWithParent(NULL, widget->GetNativeView());
259 scoped_ptr<aura::Window> modal_window(modal_widget->GetNativeView()); 259 scoped_ptr<aura::Window> modal_window(modal_widget->GetNativeView());
260 modal_window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); 260 modal_window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW);
261 test::CaptureTrackingView* modal_view = new test::CaptureTrackingView; 261 views::test::CaptureTrackingView* modal_view =
262 new views::test::CaptureTrackingView;
262 modal_widget->client_view()->AddChildView(modal_view); 263 modal_widget->client_view()->AddChildView(modal_view);
263 modal_widget->SetBounds(gfx::Rect(50, 50, 200, 200)); 264 modal_widget->SetBounds(gfx::Rect(50, 50, 200, 200));
264 modal_view->SetBoundsRect(modal_widget->client_view()->GetLocalBounds()); 265 modal_view->SetBoundsRect(modal_widget->client_view()->GetLocalBounds());
265 modal_widget->Show(); 266 modal_widget->Show();
266 267
267 EXPECT_TRUE(view->got_capture_lost()); 268 EXPECT_TRUE(view->got_capture_lost());
268 generator.ReleaseLeftButton(); 269 generator.ReleaseLeftButton();
269 270
270 view->reset(); 271 view->reset();
271 272
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 // - A |child| window with parent window |parent|, but is modal to 353 // - A |child| window with parent window |parent|, but is modal to
353 // |modal_parent| window. 354 // |modal_parent| window.
354 // Validates: 355 // Validates:
355 // - Clicking on the |modal_parent| should activate the |child| window. 356 // - Clicking on the |modal_parent| should activate the |child| window.
356 // - Clicking on the |parent| window outside of the |modal_parent| bounds should 357 // - Clicking on the |parent| window outside of the |modal_parent| bounds should
357 // activate the |parent| window. 358 // activate the |parent| window.
358 // - Clicking on the |child| while |parent| is active should activate the 359 // - Clicking on the |child| while |parent| is active should activate the
359 // |child| window. 360 // |child| window.
360 // - Focus should follow the active window. 361 // - Focus should follow the active window.
361 TEST_F(WindowModalityControllerTest, ChildModal) { 362 TEST_F(WindowModalityControllerTest, ChildModal) {
362 test::ChildModalParent* delegate = new test::ChildModalParent; 363 views::test::ChildModalParent* delegate = new views::test::ChildModalParent;
363 views::Widget* widget = views::Widget::CreateWindowWithBounds( 364 views::Widget* widget = views::Widget::CreateWindowWithBounds(
364 delegate, gfx::Rect(0, 0, 400, 400)); 365 delegate, gfx::Rect(0, 0, 400, 400));
365 widget->Show(); 366 widget->Show();
366 367
367 aura::Window* parent = widget->GetNativeView(); 368 aura::Window* parent = widget->GetNativeView();
368 EXPECT_TRUE(wm::IsActiveWindow(parent)); 369 EXPECT_TRUE(wm::IsActiveWindow(parent));
369 370
370 aura::Window* modal_parent = delegate->GetModalParent(); 371 aura::Window* modal_parent = delegate->GetModalParent();
371 EXPECT_NE(static_cast<aura::Window*>(NULL), modal_parent); 372 EXPECT_NE(static_cast<aura::Window*>(NULL), modal_parent);
372 EXPECT_NE(parent, modal_parent); 373 EXPECT_NE(parent, modal_parent);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 EXPECT_FALSE(wm::IsActiveWindow(parent)); 412 EXPECT_FALSE(wm::IsActiveWindow(parent));
412 413
413 EXPECT_TRUE(child->HasFocus()); 414 EXPECT_TRUE(child->HasFocus());
414 EXPECT_FALSE(modal_parent->HasFocus()); 415 EXPECT_FALSE(modal_parent->HasFocus());
415 EXPECT_FALSE(parent->HasFocus()); 416 EXPECT_FALSE(parent->HasFocus());
416 } 417 }
417 418
418 // Same as |ChildModal| test, but using |EventGenerator| rather than bypassing 419 // Same as |ChildModal| test, but using |EventGenerator| rather than bypassing
419 // it by calling |ActivateWindow|. 420 // it by calling |ActivateWindow|.
420 TEST_F(WindowModalityControllerTest, ChildModalEventGenerator) { 421 TEST_F(WindowModalityControllerTest, ChildModalEventGenerator) {
421 test::ChildModalParent* delegate = new test::ChildModalParent; 422 views::test::ChildModalParent* delegate = new views::test::ChildModalParent;
422 views::Widget* widget = views::Widget::CreateWindowWithBounds( 423 views::Widget* widget = views::Widget::CreateWindowWithBounds(
423 delegate, gfx::Rect(0, 0, 400, 400)); 424 delegate, gfx::Rect(0, 0, 400, 400));
424 widget->Show(); 425 widget->Show();
425 426
426 aura::Window* parent = widget->GetNativeView(); 427 aura::Window* parent = widget->GetNativeView();
427 EXPECT_TRUE(wm::IsActiveWindow(parent)); 428 EXPECT_TRUE(wm::IsActiveWindow(parent));
428 429
429 aura::Window* modal_parent = delegate->GetModalParent(); 430 aura::Window* modal_parent = delegate->GetModalParent();
430 EXPECT_NE(static_cast<aura::Window*>(NULL), modal_parent); 431 EXPECT_NE(static_cast<aura::Window*>(NULL), modal_parent);
431 EXPECT_NE(parent, modal_parent); 432 EXPECT_NE(parent, modal_parent);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 aura::test::TestWindowDelegate d; 526 aura::test::TestWindowDelegate d;
526 scoped_ptr<aura::Window> w1( 527 scoped_ptr<aura::Window> w1(
527 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect())); 528 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect()));
528 scoped_ptr<aura::Window> w2( 529 scoped_ptr<aura::Window> w2(
529 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get())); 530 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get()));
530 scoped_ptr<aura::Window> w3( 531 scoped_ptr<aura::Window> w3(
531 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w2.get())); 532 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w2.get()));
532 scoped_ptr<aura::Window> w4( 533 scoped_ptr<aura::Window> w4(
533 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect())); 534 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect()));
534 w4->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_CHILD); 535 w4->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_CHILD);
535 SetModalParent(w4.get(), w2.get()); 536 views::corewm::SetModalParent(w4.get(), w2.get());
536 w1->AddTransientChild(w4.get()); 537 w1->AddTransientChild(w4.get());
537 538
538 wm::ActivateWindow(w1.get()); 539 wm::ActivateWindow(w1.get());
539 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); 540 EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
540 541
541 wm::ActivateWindow(w2.get()); 542 wm::ActivateWindow(w2.get());
542 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); 543 EXPECT_TRUE(wm::IsActiveWindow(w4.get()));
543 544
544 wm::ActivateWindow(w3.get()); 545 wm::ActivateWindow(w3.get());
545 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); 546 EXPECT_TRUE(wm::IsActiveWindow(w4.get()));
546 547
547 wm::ActivateWindow(w4.get()); 548 wm::ActivateWindow(w4.get());
548 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); 549 EXPECT_TRUE(wm::IsActiveWindow(w4.get()));
549 } 550 }
550 551
551 } // namespace internal 552 } // namespace internal
552 } // namespace ash 553 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/window_modality_controller.cc ('k') | chrome/browser/ui/views/constrained_window_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698