| 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/display/display_controller.h" | 5 #include "ash/display/display_controller.h" |
| 6 #include "ash/display/display_manager.h" | 6 #include "ash/display/display_manager.h" |
| 7 #include "ash/screen_ash.h" | 7 #include "ash/screen_ash.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
| 10 #include "ash/system/tray/system_tray.h" | 10 #include "ash/system/tray/system_tray.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "ui/base/events/event_handler.h" | 26 #include "ui/base/events/event_handler.h" |
| 27 #include "ui/gfx/display.h" | 27 #include "ui/gfx/display.h" |
| 28 #include "ui/gfx/screen.h" | 28 #include "ui/gfx/screen.h" |
| 29 #include "ui/views/controls/textfield/textfield.h" | 29 #include "ui/views/controls/textfield/textfield.h" |
| 30 #include "ui/views/widget/widget.h" | 30 #include "ui/views/widget/widget.h" |
| 31 #include "ui/views/widget/widget_delegate.h" | 31 #include "ui/views/widget/widget_delegate.h" |
| 32 | 32 |
| 33 namespace ash { | 33 namespace ash { |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 views::Widget* CreateTestWidgetWithParent(views::Widget* parent, | |
| 37 const gfx::Rect& bounds, | |
| 38 bool child) { | |
| 39 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | |
| 40 if (parent) | |
| 41 params.parent = parent->GetNativeView(); | |
| 42 params.bounds = bounds; | |
| 43 params.child = child; | |
| 44 views::Widget* widget = new views::Widget; | |
| 45 widget->Init(params); | |
| 46 widget->Show(); | |
| 47 return widget; | |
| 48 } | |
| 49 | |
| 50 views::Widget* CreateTestWidget(const gfx::Rect& bounds) { | |
| 51 return CreateTestWidgetWithParent(NULL, bounds, false); | |
| 52 } | |
| 53 | |
| 54 void SetSecondaryDisplayLayout(DisplayLayout::Position position) { | 36 void SetSecondaryDisplayLayout(DisplayLayout::Position position) { |
| 55 DisplayController* display_controller = | 37 DisplayController* display_controller = |
| 56 Shell::GetInstance()->display_controller(); | 38 Shell::GetInstance()->display_controller(); |
| 57 DisplayLayout layout = display_controller->default_display_layout(); | 39 DisplayLayout layout = display_controller->default_display_layout(); |
| 58 layout.position = position; | 40 layout.position = position; |
| 59 display_controller->SetDefaultDisplayLayout(layout); | 41 display_controller->SetDefaultDisplayLayout(layout); |
| 60 } | 42 } |
| 61 | 43 |
| 62 class ModalWidgetDelegate : public views::WidgetDelegateView { | 44 class ModalWidgetDelegate : public views::WidgetDelegateView { |
| 63 public: | 45 public: |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 root_windows[1]->AddChild(target_); | 79 root_windows[1]->AddChild(target_); |
| 98 } | 80 } |
| 99 } | 81 } |
| 100 | 82 |
| 101 aura::Window* target_; | 83 aura::Window* target_; |
| 102 DISALLOW_COPY_AND_ASSIGN(MoveWindowByClickEventFilter); | 84 DISALLOW_COPY_AND_ASSIGN(MoveWindowByClickEventFilter); |
| 103 }; | 85 }; |
| 104 | 86 |
| 105 } // namespace | 87 } // namespace |
| 106 | 88 |
| 107 typedef test::AshTestBase ExtendedDesktopTest; | 89 class ExtendedDesktopTest : public test::AshTestBase { |
| 90 public: |
| 91 views::Widget* CreateTestWidget(const gfx::Rect& bounds) { |
| 92 return CreateTestWidgetWithParentAndContext( |
| 93 NULL, CurrentContext(), bounds, false); |
| 94 } |
| 95 |
| 96 views::Widget* CreateTestWidgetWithParent(views::Widget* parent, |
| 97 const gfx::Rect& bounds, |
| 98 bool child) { |
| 99 CHECK(parent); |
| 100 return CreateTestWidgetWithParentAndContext(parent, NULL, bounds, child); |
| 101 } |
| 102 |
| 103 views::Widget* CreateTestWidgetWithParentAndContext(views::Widget* parent, |
| 104 gfx::NativeView context, |
| 105 const gfx::Rect& bounds, |
| 106 bool child) { |
| 107 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 108 if (parent) |
| 109 params.parent = parent->GetNativeView(); |
| 110 params.context = context; |
| 111 params.bounds = bounds; |
| 112 params.child = child; |
| 113 views::Widget* widget = new views::Widget; |
| 114 widget->Init(params); |
| 115 widget->Show(); |
| 116 return widget; |
| 117 } |
| 118 }; |
| 108 | 119 |
| 109 // Test conditions that root windows in extended desktop mode | 120 // Test conditions that root windows in extended desktop mode |
| 110 // must satisfy. | 121 // must satisfy. |
| 111 TEST_F(ExtendedDesktopTest, Basic) { | 122 TEST_F(ExtendedDesktopTest, Basic) { |
| 112 UpdateDisplay("1000x600,600x400"); | 123 UpdateDisplay("1000x600,600x400"); |
| 113 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 124 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 114 | 125 |
| 115 // All root windows must have the root window controller. | 126 // All root windows must have the root window controller. |
| 116 ASSERT_EQ(2U, root_windows.size()); | 127 ASSERT_EQ(2U, root_windows.size()); |
| 117 for (Shell::RootWindowList::const_iterator iter = root_windows.begin(); | 128 for (Shell::RootWindowList::const_iterator iter = root_windows.begin(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 TEST_F(ExtendedDesktopTest, SystemModal) { | 174 TEST_F(ExtendedDesktopTest, SystemModal) { |
| 164 UpdateDisplay("1000x600,600x400"); | 175 UpdateDisplay("1000x600,600x400"); |
| 165 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 176 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 166 | 177 |
| 167 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); | 178 views::Widget* widget_on_1st = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
| 168 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView())); | 179 EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView())); |
| 169 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow()); | 180 EXPECT_EQ(root_windows[0], widget_on_1st->GetNativeView()->GetRootWindow()); |
| 170 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow()); | 181 EXPECT_EQ(root_windows[0], Shell::GetActiveRootWindow()); |
| 171 | 182 |
| 172 // Open system modal. Make sure it's on 2nd root window and active. | 183 // Open system modal. Make sure it's on 2nd root window and active. |
| 173 views::Widget* modal_widget = views::Widget::CreateWindowWithBounds( | 184 views::Widget* modal_widget = views::Widget::CreateWindowWithContextAndBounds( |
| 174 new ModalWidgetDelegate(), gfx::Rect(1200, 100, 100, 100)); | 185 new ModalWidgetDelegate(), |
| 186 CurrentContext(), |
| 187 gfx::Rect(1200, 100, 100, 100)); |
| 175 modal_widget->Show(); | 188 modal_widget->Show(); |
| 176 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView())); | 189 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView())); |
| 177 EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow()); | 190 EXPECT_EQ(root_windows[1], modal_widget->GetNativeView()->GetRootWindow()); |
| 178 EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow()); | 191 EXPECT_EQ(root_windows[1], Shell::GetActiveRootWindow()); |
| 179 | 192 |
| 180 // Clicking a widget on widget_on_1st display should not change activation. | 193 // Clicking a widget on widget_on_1st display should not change activation. |
| 181 aura::test::EventGenerator generator_1st(root_windows[0]); | 194 aura::test::EventGenerator generator_1st(root_windows[0]); |
| 182 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView()); | 195 generator_1st.MoveMouseToCenterOf(widget_on_1st->GetNativeView()); |
| 183 generator_1st.ClickLeftButton(); | 196 generator_1st.ClickLeftButton(); |
| 184 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView())); | 197 EXPECT_TRUE(wm::IsActiveWindow(modal_widget->GetNativeView())); |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 | 614 |
| 602 UpdateDisplay("500x600"); | 615 UpdateDisplay("500x600"); |
| 603 EXPECT_FALSE(tray->HasSystemBubble()); | 616 EXPECT_FALSE(tray->HasSystemBubble()); |
| 604 UpdateDisplay("500x600,600x400"); | 617 UpdateDisplay("500x600,600x400"); |
| 605 EXPECT_FALSE(tray->HasSystemBubble()); | 618 EXPECT_FALSE(tray->HasSystemBubble()); |
| 606 } | 619 } |
| 607 | 620 |
| 608 TEST_F(ExtendedDesktopTest, StayInSameRootWindow) { | 621 TEST_F(ExtendedDesktopTest, StayInSameRootWindow) { |
| 609 UpdateDisplay("100x100,200x200"); | 622 UpdateDisplay("100x100,200x200"); |
| 610 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 623 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 611 views::Widget* w1 = CreateTestWidgetWithParent( | 624 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 50, 50)); |
| 612 NULL, gfx::Rect(10, 10, 50, 50), false); | |
| 613 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow()); | 625 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow()); |
| 614 w1->SetBounds(gfx::Rect(150, 10, 50, 50)); | 626 w1->SetBounds(gfx::Rect(150, 10, 50, 50)); |
| 615 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow()); | 627 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow()); |
| 616 | 628 |
| 617 // The widget stays in the same root if kStayInSameRootWindowKey is set to | 629 // The widget stays in the same root if kStayInSameRootWindowKey is set to |
| 618 // true. | 630 // true. |
| 619 w1->GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey, true); | 631 w1->GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey, true); |
| 620 w1->SetBounds(gfx::Rect(10, 10, 50, 50)); | 632 w1->SetBounds(gfx::Rect(10, 10, 50, 50)); |
| 621 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow()); | 633 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow()); |
| 622 | 634 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 | 700 |
| 689 aura::test::EventGenerator generator22(root_windows[1]); | 701 aura::test::EventGenerator generator22(root_windows[1]); |
| 690 generator22.PressKey(ui::VKEY_E, 0); | 702 generator22.PressKey(ui::VKEY_E, 0); |
| 691 generator22.ReleaseKey(ui::VKEY_E, 0); | 703 generator22.ReleaseKey(ui::VKEY_E, 0); |
| 692 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow()); | 704 EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow()); |
| 693 EXPECT_EQ("abcde", UTF16ToASCII(textfield->text())); | 705 EXPECT_EQ("abcde", UTF16ToASCII(textfield->text())); |
| 694 } | 706 } |
| 695 | 707 |
| 696 } // namespace internal | 708 } // namespace internal |
| 697 } // namespace ash | 709 } // namespace ash |
| OLD | NEW |