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

Side by Side Diff: ui/aura_shell/shell_unittest.cc

Issue 8387043: [Aura] Support always-on-top top level window. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync, move AlwaysOnTonController from Shell to StackingController Created 9 years, 1 month 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
(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 virtual void TearDown() OVERRIDE {
62 // Flush the message loop to finish pending release tasks.
63 FlushMessageLoop();
64
65 // Tear down the shell.
66 aura_shell::Shell::DeleteInstanceForTesting();
67
68 aura::test::AuraTestBase::TearDown();
69 }
70
71 private:
72 DISALLOW_COPY_AND_ASSIGN(ShellTest);
73 };
74
75 TEST_F(ShellTest, CreateWindow) {
76 // Normal window should be created in default container.
77 TestCreateWindow(views::Widget::InitParams::TYPE_WINDOW,
78 false, // always_on_top
79 GetDefaultContainer());
80 TestCreateWindow(views::Widget::InitParams::TYPE_POPUP,
81 false, // always_on_top
82 GetDefaultContainer());
83
84 // Always-on-top window and popup are created in always-on-top container.
85 TestCreateWindow(views::Widget::InitParams::TYPE_WINDOW,
86 true, // always_on_top
87 GetAlwaysOnTopContainer());
88 TestCreateWindow(views::Widget::InitParams::TYPE_POPUP,
89 true, // always_on_top
90 GetAlwaysOnTopContainer());
91 }
92
93 TEST_F(ShellTest, ChangeAlwaysOnTop) {
94 views::Widget::InitParams widget_params(
95 views::Widget::InitParams::TYPE_WINDOW);
96
97 // Creates a normal window
98 views::Widget* widget = CreateTestWindow(widget_params);
99 widget->Show();
100
101 // It should be in default container.
102 EXPECT_EQ(GetDefaultContainer(), widget->GetNativeWindow()->parent());
103
104 // Flip always-on-top flag.
105 widget->SetAlwaysOnTop(true);
106 // And it should in always on top container now.
107 EXPECT_EQ(GetAlwaysOnTopContainer(), widget->GetNativeWindow()->parent());
108
109 // Flip always-on-top flag.
110 widget->SetAlwaysOnTop(false);
111 // It should go back to default container.
112 EXPECT_EQ(GetDefaultContainer(), widget->GetNativeWindow()->parent());
113
114 // Set the same always-on-top flag again.
115 widget->SetAlwaysOnTop(false);
116 // Should have no effect and we are still in the default container.
117 EXPECT_EQ(GetDefaultContainer(), widget->GetNativeWindow()->parent());
118
119 widget->Close();
120 }
121
122 } // namespace test
123 } // namespace aura_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698