Index: ui/aura_shell/shell_unittest.cc |
diff --git a/ui/aura_shell/shell_unittest.cc b/ui/aura_shell/shell_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..903c1c37b3d8160a466433ad26277ef29eb24dfd |
--- /dev/null |
+++ b/ui/aura_shell/shell_unittest.cc |
@@ -0,0 +1,97 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ui/aura/aura_constants.h" |
+#include "ui/aura/desktop.h" |
oshima
2011/11/04 20:40:08
i believe you don't need these two.
xiyuan
2011/11/04 22:40:21
Done.
|
+#include "ui/aura/test/aura_test_base.h" |
+#include "ui/aura/window.h" |
oshima
2011/11/04 20:40:08
you probably don't need this either, although i'm
xiyuan
2011/11/04 22:40:21
We need it because we call on parent() to get cont
|
+#include "ui/aura_shell/shell.h" |
+#include "ui/aura_shell/shell_window_ids.h" |
+#include "views/widget/widget.h" |
+ |
+namespace aura_shell { |
+namespace test { |
+ |
+namespace { |
+ |
+views::Widget* CreateTestWindow(const views::Widget::InitParams& params) { |
+ views::Widget* widget = new views::Widget; |
+ widget->Init(params); |
+ return widget; |
+} |
+ |
+aura::Window* DefaultContainer() { |
oshima
2011/11/04 20:40:08
GetDefaultContainer/GetAlwaysOnTopContainer
xiyuan
2011/11/04 22:40:21
Done.
|
+ return Shell::GetInstance()->GetContainer( |
+ aura_shell::internal::kShellWindowId_DefaultContainer); |
+} |
+ |
+aura::Window* AlwaysOnTopContainer() { |
+ return Shell::GetInstance()->GetContainer( |
+ aura_shell::internal::kShellWindowId_AlwaysOnTopContainer); |
+} |
+ |
+} // namespace |
+ |
+class ShellTest : public aura::test::AuraTestBase { |
+ public: |
+ ShellTest() {} |
+ virtual ~ShellTest() {} |
+ |
+ virtual void SetUp() OVERRIDE { |
+ aura::test::AuraTestBase::SetUp(); |
+ |
+ // Triggers Shell creation and hook with Desktop. |
+ aura_shell::Shell::GetInstance(); |
+ } |
+ |
+private: |
+ DISALLOW_COPY_AND_ASSIGN(ShellTest); |
+}; |
+ |
+TEST_F(ShellTest, CreateAlwaysOnTopWindow) { |
+ // Creates an always-on-top window. |
+ views::Widget::InitParams widget_params( |
+ views::Widget::InitParams::TYPE_WINDOW); |
+ widget_params.keep_on_top = true; |
+ |
+ views::Widget* widget = CreateTestWindow(widget_params); |
+ widget->Show(); |
+ |
+ // It should be put into the always-on-top container. |
+ EXPECT_EQ(AlwaysOnTopContainer(), widget->GetNativeWindow()->parent()); |
+ |
+ widget->Close(); |
+} |
+ |
+TEST_F(ShellTest, ChangeAlwaysOnTop) { |
+ views::Widget::InitParams widget_params( |
+ views::Widget::InitParams::TYPE_WINDOW); |
+ |
+ // Creates a normal window |
+ views::Widget* widget = CreateTestWindow(widget_params); |
+ widget->Show(); |
+ |
+ // It should be in default container. |
+ EXPECT_EQ(DefaultContainer(), widget->GetNativeWindow()->parent()); |
+ |
+ // Flip always-on-top flag. |
+ widget->SetAlwaysOnTop(true); |
+ // And it should in always on top container now. |
+ EXPECT_EQ(AlwaysOnTopContainer(), widget->GetNativeWindow()->parent()); |
+ |
+ // Flip always-on-top flag. |
+ widget->SetAlwaysOnTop(false); |
+ // It should go back to default container. |
+ EXPECT_EQ(DefaultContainer(), widget->GetNativeWindow()->parent()); |
+ |
+ // Set the same always-on-top flag again. |
+ widget->SetAlwaysOnTop(false); |
+ // Should have no effect and we are still in the default container. |
+ EXPECT_EQ(DefaultContainer(), widget->GetNativeWindow()->parent()); |
+ |
+ widget->Close(); |
+} |
+ |
+} // namespace test |
+} // namespace aura_shell |