| 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..a9a18e209a9c4b559f9799853310dc2234575e50
|
| --- /dev/null
|
| +++ b/ui/aura_shell/shell_unittest.cc
|
| @@ -0,0 +1,107 @@
|
| +// 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/test/aura_test_base.h"
|
| +#include "ui/aura/window.h"
|
| +#include "ui/aura_shell/shell.h"
|
| +#include "ui/aura_shell/shell_window_ids.h"
|
| +#include "ui/aura_shell/test/aura_shell_test_base.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* GetDefaultContainer() {
|
| + return Shell::GetInstance()->GetContainer(
|
| + aura_shell::internal::kShellWindowId_DefaultContainer);
|
| +}
|
| +
|
| +aura::Window* GetAlwaysOnTopContainer() {
|
| + return Shell::GetInstance()->GetContainer(
|
| + aura_shell::internal::kShellWindowId_AlwaysOnTopContainer);
|
| +}
|
| +
|
| +void TestCreateWindow(views::Widget::InitParams::Type type,
|
| + bool always_on_top,
|
| + aura::Window* expected_container) {
|
| + views::Widget::InitParams widget_params(type);
|
| + widget_params.keep_on_top = always_on_top;
|
| +
|
| + views::Widget* widget = CreateTestWindow(widget_params);
|
| + widget->Show();
|
| +
|
| + EXPECT_EQ(expected_container, widget->GetNativeWindow()->parent()) <<
|
| + "TestCreateWindow: type=" << type << ", always_on_top=" << always_on_top;
|
| +
|
| + widget->Close();
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +class ShellTest : public AuraShellTestBase {
|
| + public:
|
| + ShellTest() {}
|
| + virtual ~ShellTest() {}
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(ShellTest);
|
| +};
|
| +
|
| +TEST_F(ShellTest, CreateWindow) {
|
| + // Normal window should be created in default container.
|
| + TestCreateWindow(views::Widget::InitParams::TYPE_WINDOW,
|
| + false, // always_on_top
|
| + GetDefaultContainer());
|
| + TestCreateWindow(views::Widget::InitParams::TYPE_POPUP,
|
| + false, // always_on_top
|
| + GetDefaultContainer());
|
| +
|
| + // Always-on-top window and popup are created in always-on-top container.
|
| + TestCreateWindow(views::Widget::InitParams::TYPE_WINDOW,
|
| + true, // always_on_top
|
| + GetAlwaysOnTopContainer());
|
| + TestCreateWindow(views::Widget::InitParams::TYPE_POPUP,
|
| + true, // always_on_top
|
| + GetAlwaysOnTopContainer());
|
| +}
|
| +
|
| +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(GetDefaultContainer(), widget->GetNativeWindow()->parent());
|
| +
|
| + // Flip always-on-top flag.
|
| + widget->SetAlwaysOnTop(true);
|
| + // And it should in always on top container now.
|
| + EXPECT_EQ(GetAlwaysOnTopContainer(), widget->GetNativeWindow()->parent());
|
| +
|
| + // Flip always-on-top flag.
|
| + widget->SetAlwaysOnTop(false);
|
| + // It should go back to default container.
|
| + EXPECT_EQ(GetDefaultContainer(), 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(GetDefaultContainer(), widget->GetNativeWindow()->parent());
|
| +
|
| + widget->Close();
|
| +}
|
| +
|
| +} // namespace test
|
| +} // namespace aura_shell
|
|
|