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

Side by Side Diff: chrome/browser/ui/views/frame/app_browser_frame_view_ash_browsertest.cc

Issue 25536010: Make packaged apps use AppNonClientFrameViewAsh when maximized (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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
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/wm/caption_buttons/hideable_caption_button_container.h"
5 #include "chrome/browser/chrome_notification_types.h" 6 #include "chrome/browser/chrome_notification_types.h"
6 #include "chrome/browser/ui/browser.h" 7 #include "chrome/browser/ui/browser.h"
7 #include "chrome/browser/ui/browser_finder.h" 8 #include "chrome/browser/ui/browser_finder.h"
8 #include "chrome/browser/ui/browser_list.h" 9 #include "chrome/browser/ui/browser_list.h"
9 #include "chrome/browser/ui/browser_tabstrip.h" 10 #include "chrome/browser/ui/browser_tabstrip.h"
10 #include "chrome/browser/ui/browser_window.h" 11 #include "chrome/browser/ui/browser_window.h"
11 #include "chrome/browser/ui/views/frame/app_non_client_frame_view_ash.h" 12 #include "chrome/browser/ui/views/frame/app_browser_frame_view_ash.h"
12 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.h" 13 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.h"
13 #include "chrome/browser/ui/views/frame/browser_view.h" 14 #include "chrome/browser/ui/views/frame/browser_view.h"
14 #include "chrome/test/base/in_process_browser_test.h" 15 #include "chrome/test/base/in_process_browser_test.h"
15 #include "content/public/test/test_utils.h" 16 #include "content/public/test/test_utils.h"
16 #include "ui/aura/client/aura_constants.h" 17 #include "ui/aura/client/aura_constants.h"
17 #include "ui/aura/root_window.h" 18 #include "ui/aura/root_window.h"
18 #include "ui/aura/test/event_generator.h" 19 #include "ui/aura/test/event_generator.h"
19 #include "ui/aura/window.h" 20 #include "ui/aura/window.h"
20 #include "ui/gfx/screen.h" 21 #include "ui/gfx/screen.h"
21 22
(...skipping 21 matching lines...) Expand all
43 void MinimizeWindow(aura::Window* window) { 44 void MinimizeWindow(aura::Window* window) {
44 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); 45 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
45 } 46 }
46 47
47 void RestoreWindow(Window* window) { 48 void RestoreWindow(Window* window) {
48 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 49 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
49 } 50 }
50 51
51 } // namespace 52 } // namespace
52 53
53 class AppNonClientFrameViewAshTest : public InProcessBrowserTest { 54 class AppBrowserFrameViewAshTest : public InProcessBrowserTest {
54 public: 55 public:
55 AppNonClientFrameViewAshTest() : InProcessBrowserTest(), app_browser_(NULL) { 56 AppBrowserFrameViewAshTest() : InProcessBrowserTest(), app_browser_(NULL) {
56 } 57 }
57 virtual ~AppNonClientFrameViewAshTest() {} 58 virtual ~AppBrowserFrameViewAshTest() {}
58 59
59 virtual void SetUpOnMainThread() OVERRIDE { 60 virtual void SetUpOnMainThread() OVERRIDE {
60 Browser::CreateParams params = Browser::CreateParams::CreateForApp( 61 Browser::CreateParams params = Browser::CreateParams::CreateForApp(
61 Browser::TYPE_POPUP, 62 Browser::TYPE_POPUP,
62 std::string("Test"), 63 std::string("Test"),
63 gfx::Rect(), 64 gfx::Rect(),
64 browser()->profile(), 65 browser()->profile(),
65 browser()->host_desktop_type()); 66 browser()->host_desktop_type());
66 params.initial_show_state = ui::SHOW_STATE_MAXIMIZED; 67 params.initial_show_state = ui::SHOW_STATE_MAXIMIZED;
67 params.app_type = Browser::APP_TYPE_HOST; 68 params.app_type = Browser::APP_TYPE_HOST;
(...skipping 22 matching lines...) Expand all
90 Browser* app_browser() const { return app_browser_; } 91 Browser* app_browser() const { return app_browser_; }
91 92
92 private: 93 private:
93 Browser *app_browser_; 94 Browser *app_browser_;
94 }; 95 };
95 96
96 #if defined(USE_ASH) 97 #if defined(USE_ASH)
97 // Ensure that restoring the app window replaces the frame with a normal one, 98 // Ensure that restoring the app window replaces the frame with a normal one,
98 // and maximizing again brings back the app frame. This has been the source of 99 // and maximizing again brings back the app frame. This has been the source of
99 // some crash bugs like crbug.com/155634 100 // some crash bugs like crbug.com/155634
100 IN_PROC_BROWSER_TEST_F(AppNonClientFrameViewAshTest, SwitchFrames) { 101 IN_PROC_BROWSER_TEST_F(AppBrowserFrameViewAshTest, SwitchFrames) {
101 // Convert to std::string so Windows can match EXPECT_EQ. 102 // Convert to std::string so Windows can match EXPECT_EQ.
102 const std::string kAppFrameClassName = 103 const std::string kAppFrameClassName =
103 AppNonClientFrameViewAsh::kViewClassName; 104 AppBrowserFrameViewAsh::kViewClassName;
104 const std::string kNormalFrameClassName = 105 const std::string kNormalFrameClassName =
105 BrowserNonClientFrameViewAsh::kViewClassName; 106 BrowserNonClientFrameViewAsh::kViewClassName;
106 107
107 // We start with the app frame. 108 // We start with the app frame.
108 EXPECT_EQ(kAppFrameClassName, GetFrameClassName()); 109 EXPECT_EQ(kAppFrameClassName, GetFrameClassName());
109 110
110 // Restoring the window gives us the normal frame. 111 // Restoring the window gives us the normal frame.
111 Window* native_window = app_browser()->window()->GetNativeWindow(); 112 Window* native_window = app_browser()->window()->GetNativeWindow();
112 RestoreWindow(native_window); 113 RestoreWindow(native_window);
113 EXPECT_EQ(kNormalFrameClassName, GetFrameClassName()); 114 EXPECT_EQ(kNormalFrameClassName, GetFrameClassName());
(...skipping 15 matching lines...) Expand all
129 // One more restore/maximize cycle for good measure. 130 // One more restore/maximize cycle for good measure.
130 RestoreWindow(native_window); 131 RestoreWindow(native_window);
131 EXPECT_EQ(kNormalFrameClassName, GetFrameClassName()); 132 EXPECT_EQ(kNormalFrameClassName, GetFrameClassName());
132 MaximizeWindow(native_window); 133 MaximizeWindow(native_window);
133 EXPECT_EQ(kAppFrameClassName, GetFrameClassName()); 134 EXPECT_EQ(kAppFrameClassName, GetFrameClassName());
134 } 135 }
135 #endif // USE_ASH 136 #endif // USE_ASH
136 137
137 // Ensure that we can click the close button when the controls are shown. 138 // Ensure that we can click the close button when the controls are shown.
138 // In particular make sure that we can click it on the top pixel of the button. 139 // In particular make sure that we can click it on the top pixel of the button.
139 IN_PROC_BROWSER_TEST_F(AppNonClientFrameViewAshTest, ClickClose) { 140 IN_PROC_BROWSER_TEST_F(AppBrowserFrameViewAshTest, ClickClose) {
140 aura::RootWindow* root_window = GetRootWindow(); 141 aura::RootWindow* root_window = GetRootWindow();
141 aura::test::EventGenerator eg(root_window, gfx::Point(0, 1)); 142 aura::test::EventGenerator eg(root_window, gfx::Point(0, 1));
142 143
143 // Click close button. 144 // Click close button.
144 eg.MoveMouseTo(root_window->bounds().width() - 1, 0); 145 eg.MoveMouseTo(root_window->bounds().width() - 1, 0);
145 content::WindowedNotificationObserver signal( 146 content::WindowedNotificationObserver signal(
146 chrome::NOTIFICATION_BROWSER_CLOSED, 147 chrome::NOTIFICATION_BROWSER_CLOSED,
147 content::Source<Browser>(app_browser())); 148 content::Source<Browser>(app_browser()));
148 eg.ClickLeftButton(); 149 eg.ClickLeftButton();
149 signal.Wait(); 150 signal.Wait();
150 EXPECT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), 151 EXPECT_EQ(1u, chrome::GetBrowserCount(browser()->profile(),
151 browser()->host_desktop_type())); 152 browser()->host_desktop_type()));
152 } 153 }
153 154
154 // Ensure that closing a maximized app with Ctrl-W does not crash the 155 // Ensure that closing a maximized app with Ctrl-W does not crash the
155 // application. crbug.com/147635 156 // application. crbug.com/147635
156 IN_PROC_BROWSER_TEST_F(AppNonClientFrameViewAshTest, KeyboardClose) { 157 IN_PROC_BROWSER_TEST_F(AppBrowserFrameViewAshTest, KeyboardClose) {
157 aura::RootWindow* root_window = GetRootWindow(); 158 aura::RootWindow* root_window = GetRootWindow();
158 aura::test::EventGenerator eg(root_window); 159 aura::test::EventGenerator eg(root_window);
159 160
160 // Base browser and app browser. 161 // Base browser and app browser.
161 EXPECT_EQ(2u, chrome::GetBrowserCount(browser()->profile(), 162 EXPECT_EQ(2u, chrome::GetBrowserCount(browser()->profile(),
162 browser()->host_desktop_type())); 163 browser()->host_desktop_type()));
163 164
164 // Send Control-W. 165 // Send Control-W.
165 content::WindowedNotificationObserver signal( 166 content::WindowedNotificationObserver signal(
166 chrome::NOTIFICATION_BROWSER_CLOSED, 167 chrome::NOTIFICATION_BROWSER_CLOSED,
167 content::Source<Browser>(app_browser())); 168 content::Source<Browser>(app_browser()));
168 eg.PressKey(ui::VKEY_W, ui::EF_CONTROL_DOWN); 169 eg.PressKey(ui::VKEY_W, ui::EF_CONTROL_DOWN);
169 eg.ReleaseKey(ui::VKEY_W, ui::EF_CONTROL_DOWN); 170 eg.ReleaseKey(ui::VKEY_W, ui::EF_CONTROL_DOWN);
170 signal.Wait(); 171 signal.Wait();
171 172
172 // App browser is closed. 173 // App browser is closed.
173 EXPECT_EQ(1u, chrome::GetBrowserCount(browser()->profile(), 174 EXPECT_EQ(1u, chrome::GetBrowserCount(browser()->profile(),
174 browser()->host_desktop_type())); 175 browser()->host_desktop_type()));
175 } 176 }
176 177
177 // Ensure that snapping left with Alt-[ closes the control window. 178 // Ensure that snapping left with Alt-[ closes the control window.
178 IN_PROC_BROWSER_TEST_F(AppNonClientFrameViewAshTest, SnapLeftClosesControls) { 179 IN_PROC_BROWSER_TEST_F(AppBrowserFrameViewAshTest, SnapLeftClosesControls) {
180 const char* kControlWindowName =
181 ash::HideableCaptionButtonContainer::kButtonWindowName;
182
179 aura::RootWindow* root_window = GetRootWindow(); 183 aura::RootWindow* root_window = GetRootWindow();
180 aura::test::EventGenerator eg(root_window); 184 aura::test::EventGenerator eg(root_window);
181 aura::Window* native_window = app_browser()->window()->GetNativeWindow(); 185 aura::Window* native_window = app_browser()->window()->GetNativeWindow();
182 186
183 // Control window exists. 187 // Control window exists.
184 EXPECT_TRUE(HasChildWindowNamed( 188 EXPECT_TRUE(HasChildWindowNamed(native_window, kControlWindowName));
185 native_window, AppNonClientFrameViewAsh::kControlWindowName));
186 189
187 // Send Alt-[ 190 // Send Alt-[
188 eg.PressKey(ui::VKEY_OEM_4, ui::EF_ALT_DOWN); 191 eg.PressKey(ui::VKEY_OEM_4, ui::EF_ALT_DOWN);
189 eg.ReleaseKey(ui::VKEY_OEM_4, ui::EF_ALT_DOWN); 192 eg.ReleaseKey(ui::VKEY_OEM_4, ui::EF_ALT_DOWN);
190 content::RunAllPendingInMessageLoop(); 193 content::RunAllPendingInMessageLoop();
191 194
192 // Control window is gone. 195 // Control window is gone.
193 EXPECT_FALSE(HasChildWindowNamed( 196 EXPECT_FALSE(HasChildWindowNamed(native_window, kControlWindowName));
194 native_window, AppNonClientFrameViewAsh::kControlWindowName));
195 } 197 }
196 198
197 // Ensure that the controls are at the proper locations. 199 // Ensure that the controls are at the proper locations.
198 IN_PROC_BROWSER_TEST_F(AppNonClientFrameViewAshTest, ControlsAtRightSide) { 200 IN_PROC_BROWSER_TEST_F(AppBrowserFrameViewAshTest, ControlsAtRightSide) {
201 const char* kControlWindowName =
202 ash::HideableCaptionButtonContainer::kButtonWindowName;
203
199 aura::RootWindow* root_window = GetRootWindow(); 204 aura::RootWindow* root_window = GetRootWindow();
200 aura::test::EventGenerator eg(root_window); 205 aura::test::EventGenerator eg(root_window);
201 aura::Window* native_window = app_browser()->window()->GetNativeWindow(); 206 aura::Window* native_window = app_browser()->window()->GetNativeWindow();
202 const gfx::Rect work_area = 207 const gfx::Rect work_area =
203 gfx::Screen::GetScreenFor(native_window)->GetPrimaryDisplay().work_area(); 208 gfx::Screen::GetScreenFor(native_window)->GetPrimaryDisplay().work_area();
204 209
205 // Control window exists. 210 // Control window exists.
206 aura::Window* window = GetChildWindowNamed( 211 aura::Window* window = GetChildWindowNamed(native_window, kControlWindowName);
207 native_window, AppNonClientFrameViewAsh::kControlWindowName);
208 212
209 ASSERT_TRUE(window); 213 ASSERT_TRUE(window);
210 gfx::Rect rect = window->bounds(); 214 gfx::Rect rect = window->bounds();
211 EXPECT_EQ(work_area.right(), rect.right()); 215 EXPECT_EQ(work_area.right(), rect.right());
212 EXPECT_EQ(work_area.y(), rect.y()); 216 EXPECT_EQ(work_area.y(), rect.y());
213 217
214 MinimizeWindow(native_window); 218 MinimizeWindow(native_window);
215 content::RunAllPendingInMessageLoop(); 219 content::RunAllPendingInMessageLoop();
216 window = GetChildWindowNamed( 220 window = GetChildWindowNamed(native_window, kControlWindowName);
217 native_window, AppNonClientFrameViewAsh::kControlWindowName);
218 EXPECT_FALSE(window); 221 EXPECT_FALSE(window);
219 MaximizeWindow(native_window); 222 MaximizeWindow(native_window);
220 content::RunAllPendingInMessageLoop(); 223 content::RunAllPendingInMessageLoop();
221 224
222 // Control window exists. 225 // Control window exists.
223 aura::Window* window_after = GetChildWindowNamed( 226 aura::Window* window_after = GetChildWindowNamed(
224 native_window, AppNonClientFrameViewAsh::kControlWindowName); 227 native_window, kControlWindowName);
225 ASSERT_TRUE(window_after); 228 ASSERT_TRUE(window_after);
226 gfx::Rect rect_after = window_after->bounds(); 229 gfx::Rect rect_after = window_after->bounds();
227 EXPECT_EQ(work_area.right(), rect_after.right()); 230 EXPECT_EQ(work_area.right(), rect_after.right());
228 EXPECT_EQ(work_area.y(), rect_after.y()); 231 EXPECT_EQ(work_area.y(), rect_after.y());
229 } 232 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698