OLD | NEW |
(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/test/aura_test_base.h" |
| 6 #include "ui/aura/window.h" |
| 7 #include "ui/aura_shell/shell.h" |
| 8 #include "ui/aura_shell/shell_window_ids.h" |
| 9 #include "views/widget/widget.h" |
| 10 |
| 11 namespace aura_shell { |
| 12 namespace test { |
| 13 |
| 14 namespace { |
| 15 |
| 16 views::Widget* CreateTestWindow(const views::Widget::InitParams& params) { |
| 17 views::Widget* widget = new views::Widget; |
| 18 widget->Init(params); |
| 19 return widget; |
| 20 } |
| 21 |
| 22 aura::Window* GetDefaultContainer() { |
| 23 return Shell::GetInstance()->GetContainer( |
| 24 aura_shell::internal::kShellWindowId_DefaultContainer); |
| 25 } |
| 26 |
| 27 aura::Window* GetAlwaysOnTopContainer() { |
| 28 return Shell::GetInstance()->GetContainer( |
| 29 aura_shell::internal::kShellWindowId_AlwaysOnTopContainer); |
| 30 } |
| 31 |
| 32 void TestCreateWindow(views::Widget::InitParams::Type type, |
| 33 bool always_on_top, |
| 34 aura::Window* expected_container) { |
| 35 views::Widget::InitParams widget_params(type); |
| 36 widget_params.keep_on_top = always_on_top; |
| 37 |
| 38 views::Widget* widget = CreateTestWindow(widget_params); |
| 39 widget->Show(); |
| 40 |
| 41 EXPECT_EQ(expected_container, widget->GetNativeWindow()->parent()) << |
| 42 "TestCreateWindow: type=" << type << ", always_on_top=" << always_on_top; |
| 43 |
| 44 widget->Close(); |
| 45 } |
| 46 |
| 47 } // namespace |
| 48 |
| 49 class ShellTest : public aura::test::AuraTestBase { |
| 50 public: |
| 51 ShellTest() {} |
| 52 virtual ~ShellTest() {} |
| 53 |
| 54 virtual void SetUp() OVERRIDE { |
| 55 aura::test::AuraTestBase::SetUp(); |
| 56 |
| 57 // Triggers Shell creation and hook with Desktop. |
| 58 aura_shell::Shell::GetInstance(); |
| 59 } |
| 60 |
| 61 private: |
| 62 DISALLOW_COPY_AND_ASSIGN(ShellTest); |
| 63 }; |
| 64 |
| 65 TEST_F(ShellTest, CreateWindow) { |
| 66 // Normal window should be created in default container. |
| 67 TestCreateWindow(views::Widget::InitParams::TYPE_WINDOW, |
| 68 false, // always_on_top |
| 69 GetDefaultContainer()); |
| 70 TestCreateWindow(views::Widget::InitParams::TYPE_POPUP, |
| 71 false, // always_on_top |
| 72 GetDefaultContainer()); |
| 73 |
| 74 // Always-on-top window and popup are created in always-on-top container. |
| 75 TestCreateWindow(views::Widget::InitParams::TYPE_WINDOW, |
| 76 true, // always_on_top |
| 77 GetAlwaysOnTopContainer()); |
| 78 TestCreateWindow(views::Widget::InitParams::TYPE_POPUP, |
| 79 true, // always_on_top |
| 80 GetAlwaysOnTopContainer()); |
| 81 } |
| 82 |
| 83 TEST_F(ShellTest, ChangeAlwaysOnTop) { |
| 84 views::Widget::InitParams widget_params( |
| 85 views::Widget::InitParams::TYPE_WINDOW); |
| 86 |
| 87 // Creates a normal window |
| 88 views::Widget* widget = CreateTestWindow(widget_params); |
| 89 widget->Show(); |
| 90 |
| 91 // It should be in default container. |
| 92 EXPECT_EQ(GetDefaultContainer(), widget->GetNativeWindow()->parent()); |
| 93 |
| 94 // Flip always-on-top flag. |
| 95 widget->SetAlwaysOnTop(true); |
| 96 // And it should in always on top container now. |
| 97 EXPECT_EQ(GetAlwaysOnTopContainer(), widget->GetNativeWindow()->parent()); |
| 98 |
| 99 // Flip always-on-top flag. |
| 100 widget->SetAlwaysOnTop(false); |
| 101 // It should go back to default container. |
| 102 EXPECT_EQ(GetDefaultContainer(), widget->GetNativeWindow()->parent()); |
| 103 |
| 104 // Set the same always-on-top flag again. |
| 105 widget->SetAlwaysOnTop(false); |
| 106 // Should have no effect and we are still in the default container. |
| 107 EXPECT_EQ(GetDefaultContainer(), widget->GetNativeWindow()->parent()); |
| 108 |
| 109 widget->Close(); |
| 110 } |
| 111 |
| 112 } // namespace test |
| 113 } // namespace aura_shell |
OLD | NEW |