| OLD | NEW |
| 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 "ash/wm/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" | 9 #include "ash/test/capture_tracking_view.h" |
| 10 #include "ash/test/child_modal_window.h" | 10 #include "ash/test/child_modal_window.h" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 = wm::GetModalTransient(w1.get()); | 222 wt = 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 = wm::GetModalTransient(w1.get()); | 231 wt = 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 = wm::GetModalTransient(w11.get()); | 236 wt = 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 test::CaptureTrackingView* view = new test::CaptureTrackingView; |
| 246 widget->client_view()->AddChildView(view); | 246 widget->client_view()->AddChildView(view); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 // - A |child| window with parent window |parent|, but is modal to | 352 // - A |child| window with parent window |parent|, but is modal to |
| 353 // |modal_parent| window. | 353 // |modal_parent| window. |
| 354 // Validates: | 354 // Validates: |
| 355 // - Clicking on the |modal_parent| should activate the |child| window. | 355 // - Clicking on the |modal_parent| should activate the |child| window. |
| 356 // - Clicking on the |parent| window outside of the |modal_parent| bounds should | 356 // - Clicking on the |parent| window outside of the |modal_parent| bounds should |
| 357 // activate the |parent| window. | 357 // activate the |parent| window. |
| 358 // - Clicking on the |child| while |parent| is active should activate the | 358 // - Clicking on the |child| while |parent| is active should activate the |
| 359 // |child| window. | 359 // |child| window. |
| 360 // - Focus should follow the active window. | 360 // - Focus should follow the active window. |
| 361 TEST_F(WindowModalityControllerTest, ChildModal) { | 361 TEST_F(WindowModalityControllerTest, ChildModal) { |
| 362 ash::test::ChildModalParent* delegate = new ash::test::ChildModalParent; | 362 test::ChildModalParent* delegate = new test::ChildModalParent; |
| 363 views::Widget* widget = views::Widget::CreateWindowWithBounds( | 363 views::Widget* widget = views::Widget::CreateWindowWithBounds( |
| 364 delegate, gfx::Rect(0, 0, 400, 400)); | 364 delegate, gfx::Rect(0, 0, 400, 400)); |
| 365 widget->Show(); | 365 widget->Show(); |
| 366 | 366 |
| 367 aura::Window* parent = widget->GetNativeView(); | 367 aura::Window* parent = widget->GetNativeView(); |
| 368 EXPECT_TRUE(wm::IsActiveWindow(parent)); | 368 EXPECT_TRUE(wm::IsActiveWindow(parent)); |
| 369 | 369 |
| 370 aura::Window* modal_parent = delegate->GetModalParent(); | 370 aura::Window* modal_parent = delegate->GetModalParent(); |
| 371 EXPECT_NE(static_cast<aura::Window*>(NULL), modal_parent); | 371 EXPECT_NE(static_cast<aura::Window*>(NULL), modal_parent); |
| 372 EXPECT_NE(parent, modal_parent); | 372 EXPECT_NE(parent, modal_parent); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 EXPECT_FALSE(wm::IsActiveWindow(parent)); | 411 EXPECT_FALSE(wm::IsActiveWindow(parent)); |
| 412 | 412 |
| 413 EXPECT_TRUE(child->HasFocus()); | 413 EXPECT_TRUE(child->HasFocus()); |
| 414 EXPECT_FALSE(modal_parent->HasFocus()); | 414 EXPECT_FALSE(modal_parent->HasFocus()); |
| 415 EXPECT_FALSE(parent->HasFocus()); | 415 EXPECT_FALSE(parent->HasFocus()); |
| 416 } | 416 } |
| 417 | 417 |
| 418 // Same as |ChildModal| test, but using |EventGenerator| rather than bypassing | 418 // Same as |ChildModal| test, but using |EventGenerator| rather than bypassing |
| 419 // it by calling |ActivateWindow|. | 419 // it by calling |ActivateWindow|. |
| 420 TEST_F(WindowModalityControllerTest, ChildModalEventGenerator) { | 420 TEST_F(WindowModalityControllerTest, ChildModalEventGenerator) { |
| 421 ash::test::ChildModalParent* delegate = new ash::test::ChildModalParent; | 421 test::ChildModalParent* delegate = new test::ChildModalParent; |
| 422 views::Widget* widget = views::Widget::CreateWindowWithBounds( | 422 views::Widget* widget = views::Widget::CreateWindowWithBounds( |
| 423 delegate, gfx::Rect(0, 0, 400, 400)); | 423 delegate, gfx::Rect(0, 0, 400, 400)); |
| 424 widget->Show(); | 424 widget->Show(); |
| 425 | 425 |
| 426 aura::Window* parent = widget->GetNativeView(); | 426 aura::Window* parent = widget->GetNativeView(); |
| 427 EXPECT_TRUE(wm::IsActiveWindow(parent)); | 427 EXPECT_TRUE(wm::IsActiveWindow(parent)); |
| 428 | 428 |
| 429 aura::Window* modal_parent = delegate->GetModalParent(); | 429 aura::Window* modal_parent = delegate->GetModalParent(); |
| 430 EXPECT_NE(static_cast<aura::Window*>(NULL), modal_parent); | 430 EXPECT_NE(static_cast<aura::Window*>(NULL), modal_parent); |
| 431 EXPECT_NE(parent, modal_parent); | 431 EXPECT_NE(parent, modal_parent); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 aura::test::TestWindowDelegate d; | 525 aura::test::TestWindowDelegate d; |
| 526 scoped_ptr<aura::Window> w1( | 526 scoped_ptr<aura::Window> w1( |
| 527 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect())); | 527 CreateTestWindowInShellWithDelegate(&d, -1, gfx::Rect())); |
| 528 scoped_ptr<aura::Window> w2( | 528 scoped_ptr<aura::Window> w2( |
| 529 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get())); | 529 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w1.get())); |
| 530 scoped_ptr<aura::Window> w3( | 530 scoped_ptr<aura::Window> w3( |
| 531 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w2.get())); | 531 aura::test::CreateTestWindowWithDelegate(&d, -11, gfx::Rect(), w2.get())); |
| 532 scoped_ptr<aura::Window> w4( | 532 scoped_ptr<aura::Window> w4( |
| 533 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect())); | 533 CreateTestWindowInShellWithDelegate(&d, -2, gfx::Rect())); |
| 534 w4->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_CHILD); | 534 w4->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_CHILD); |
| 535 ash::wm::SetModalParent(w4.get(), w2.get()); | 535 SetModalParent(w4.get(), w2.get()); |
| 536 w1->AddTransientChild(w4.get()); | 536 w1->AddTransientChild(w4.get()); |
| 537 | 537 |
| 538 wm::ActivateWindow(w1.get()); | 538 wm::ActivateWindow(w1.get()); |
| 539 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); | 539 EXPECT_TRUE(wm::IsActiveWindow(w1.get())); |
| 540 | 540 |
| 541 wm::ActivateWindow(w2.get()); | 541 wm::ActivateWindow(w2.get()); |
| 542 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); | 542 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); |
| 543 | 543 |
| 544 wm::ActivateWindow(w3.get()); | 544 wm::ActivateWindow(w3.get()); |
| 545 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); | 545 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); |
| 546 | 546 |
| 547 wm::ActivateWindow(w4.get()); | 547 wm::ActivateWindow(w4.get()); |
| 548 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); | 548 EXPECT_TRUE(wm::IsActiveWindow(w4.get())); |
| 549 } | 549 } |
| 550 | 550 |
| 551 } // namespace internal | 551 } // namespace internal |
| 552 } // namespace ash | 552 } // namespace ash |
| OLD | NEW |