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

Side by Side Diff: ash/shell_unittest.cc

Issue 11795004: Continue threading context through unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 months 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
« no previous file with comments | « ash/shell/window_type_launcher.cc ('k') | ash/test/ash_test_base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/shell.h" 5 #include "ash/shell.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/ash_switches.h" 10 #include "ash/ash_switches.h"
(...skipping 13 matching lines...) Expand all
24 #include "ui/gfx/size.h" 24 #include "ui/gfx/size.h"
25 #include "ui/views/widget/widget.h" 25 #include "ui/views/widget/widget.h"
26 #include "ui/views/widget/widget_delegate.h" 26 #include "ui/views/widget/widget_delegate.h"
27 27
28 using aura::RootWindow; 28 using aura::RootWindow;
29 29
30 namespace ash { 30 namespace ash {
31 31
32 namespace { 32 namespace {
33 33
34 views::Widget* CreateTestWindow(const views::Widget::InitParams& params) {
35 views::Widget* widget = new views::Widget;
36 widget->Init(params);
37 return widget;
38 }
39
40 aura::Window* GetDefaultContainer() { 34 aura::Window* GetDefaultContainer() {
41 return Shell::GetContainer( 35 return Shell::GetContainer(
42 Shell::GetPrimaryRootWindow(), 36 Shell::GetPrimaryRootWindow(),
43 internal::kShellWindowId_DefaultContainer); 37 internal::kShellWindowId_DefaultContainer);
44 } 38 }
45 39
46 aura::Window* GetAlwaysOnTopContainer() { 40 aura::Window* GetAlwaysOnTopContainer() {
47 return Shell::GetContainer( 41 return Shell::GetContainer(
48 Shell::GetPrimaryRootWindow(), 42 Shell::GetPrimaryRootWindow(),
49 internal::kShellWindowId_AlwaysOnTopContainer); 43 internal::kShellWindowId_AlwaysOnTopContainer);
(...skipping 25 matching lines...) Expand all
75 EXPECT_TRUE(Shell::GetContainer( 69 EXPECT_TRUE(Shell::GetContainer(
76 root_window, internal::kShellWindowId_MenuContainer)); 70 root_window, internal::kShellWindowId_MenuContainer));
77 EXPECT_TRUE(Shell::GetContainer( 71 EXPECT_TRUE(Shell::GetContainer(
78 root_window, internal::kShellWindowId_DragImageAndTooltipContainer)); 72 root_window, internal::kShellWindowId_DragImageAndTooltipContainer));
79 EXPECT_TRUE(Shell::GetContainer( 73 EXPECT_TRUE(Shell::GetContainer(
80 root_window, internal::kShellWindowId_SettingBubbleContainer)); 74 root_window, internal::kShellWindowId_SettingBubbleContainer));
81 EXPECT_TRUE(Shell::GetContainer( 75 EXPECT_TRUE(Shell::GetContainer(
82 root_window, internal::kShellWindowId_OverlayContainer)); 76 root_window, internal::kShellWindowId_OverlayContainer));
83 } 77 }
84 78
85 void TestCreateWindow(views::Widget::InitParams::Type type,
86 bool always_on_top,
87 aura::Window* expected_container) {
88 views::Widget::InitParams widget_params(type);
89 widget_params.keep_on_top = always_on_top;
90
91 views::Widget* widget = CreateTestWindow(widget_params);
92 widget->Show();
93
94 EXPECT_TRUE(expected_container->Contains(
95 widget->GetNativeWindow()->parent())) <<
96 "TestCreateWindow: type=" << type << ", always_on_top=" << always_on_top;
97
98 widget->Close();
99 }
100
101 class ModalWindow : public views::WidgetDelegateView { 79 class ModalWindow : public views::WidgetDelegateView {
102 public: 80 public:
103 ModalWindow() {} 81 ModalWindow() {}
104 virtual ~ModalWindow() {} 82 virtual ~ModalWindow() {}
105 83
106 // Overridden from views::WidgetDelegate: 84 // Overridden from views::WidgetDelegate:
107 virtual views::View* GetContentsView() OVERRIDE { 85 virtual views::View* GetContentsView() OVERRIDE {
108 return this; 86 return this;
109 } 87 }
110 virtual bool CanResize() const OVERRIDE { 88 virtual bool CanResize() const OVERRIDE {
111 return true; 89 return true;
112 } 90 }
113 virtual string16 GetWindowTitle() const OVERRIDE { 91 virtual string16 GetWindowTitle() const OVERRIDE {
114 return ASCIIToUTF16("Modal Window"); 92 return ASCIIToUTF16("Modal Window");
115 } 93 }
116 virtual ui::ModalType GetModalType() const OVERRIDE { 94 virtual ui::ModalType GetModalType() const OVERRIDE {
117 return ui::MODAL_TYPE_SYSTEM; 95 return ui::MODAL_TYPE_SYSTEM;
118 } 96 }
119 97
120 private: 98 private:
121 DISALLOW_COPY_AND_ASSIGN(ModalWindow); 99 DISALLOW_COPY_AND_ASSIGN(ModalWindow);
122 }; 100 };
123 101
124 } // namespace 102 } // namespace
125 103
126 typedef test::AshTestBase ShellTest; 104 class ShellTest : public test::AshTestBase {
105 public:
106 views::Widget* CreateTestWindow(views::Widget::InitParams params) {
107 views::Widget* widget = new views::Widget;
108 params.context = CurrentContext();
109 widget->Init(params);
110 return widget;
111 }
112
113 void TestCreateWindow(views::Widget::InitParams::Type type,
114 bool always_on_top,
115 aura::Window* expected_container) {
116 views::Widget::InitParams widget_params(type);
117 widget_params.keep_on_top = always_on_top;
118
119 views::Widget* widget = CreateTestWindow(widget_params);
120 widget->Show();
121
122 EXPECT_TRUE(
123 expected_container->Contains(widget->GetNativeWindow()->parent())) <<
124 "TestCreateWindow: type=" << type << ", always_on_top=" <<
125 always_on_top;
126
127 widget->Close();
128 }
129
130 };
127 131
128 TEST_F(ShellTest, CreateWindow) { 132 TEST_F(ShellTest, CreateWindow) {
129 // Normal window should be created in default container. 133 // Normal window should be created in default container.
130 TestCreateWindow(views::Widget::InitParams::TYPE_WINDOW, 134 TestCreateWindow(views::Widget::InitParams::TYPE_WINDOW,
131 false, // always_on_top 135 false, // always_on_top
132 GetDefaultContainer()); 136 GetDefaultContainer());
133 TestCreateWindow(views::Widget::InitParams::TYPE_POPUP, 137 TestCreateWindow(views::Widget::InitParams::TYPE_POPUP,
134 false, // always_on_top 138 false, // always_on_top
135 GetDefaultContainer()); 139 GetDefaultContainer());
136 140
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 private: 408 private:
405 DISALLOW_COPY_AND_ASSIGN(ShellTest2); 409 DISALLOW_COPY_AND_ASSIGN(ShellTest2);
406 }; 410 };
407 411
408 TEST_F(ShellTest2, DontCrashWhenWindowDeleted) { 412 TEST_F(ShellTest2, DontCrashWhenWindowDeleted) {
409 window_.reset(new aura::Window(NULL)); 413 window_.reset(new aura::Window(NULL));
410 window_->Init(ui::LAYER_NOT_DRAWN); 414 window_->Init(ui::LAYER_NOT_DRAWN);
411 } 415 }
412 416
413 } // namespace ash 417 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shell/window_type_launcher.cc ('k') | ash/test/ash_test_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698