OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // For now, immersive fullscreen is Chrome OS only. | |
6 #if defined(OS_CHROMEOS) | |
7 | |
5 #include "chrome/browser/ui/views/frame/immersive_mode_controller_ash.h" | 8 #include "chrome/browser/ui/views/frame/immersive_mode_controller_ash.h" |
6 | 9 |
10 #include "ash/ash_switches.h" | |
7 #include "ash/root_window_controller.h" | 11 #include "ash/root_window_controller.h" |
8 #include "ash/shelf/shelf_layout_manager.h" | 12 #include "ash/shelf/shelf_layout_manager.h" |
9 #include "ash/shelf/shelf_types.h" | 13 #include "ash/shelf/shelf_types.h" |
10 #include "ash/shell.h" | 14 #include "ash/shell.h" |
11 #include "ash/test/ash_test_base.h" | 15 #include "ash/test/ash_test_base.h" |
16 #include "base/command_line.h" | |
12 #include "chrome/app/chrome_command_ids.h" | 17 #include "chrome/app/chrome_command_ids.h" |
13 #include "chrome/browser/ui/browser_commands.h" | 18 #include "chrome/browser/ui/browser_commands.h" |
14 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" | 19 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
15 #include "chrome/browser/ui/fullscreen/fullscreen_controller_test.h" | 20 #include "chrome/browser/ui/fullscreen/fullscreen_controller_test.h" |
16 #include "chrome/browser/ui/views/frame/browser_view.h" | 21 #include "chrome/browser/ui/views/frame/browser_view.h" |
17 #include "chrome/browser/ui/views/frame/test_with_browser_view.h" | 22 #include "chrome/browser/ui/views/frame/test_with_browser_view.h" |
18 #include "chrome/browser/ui/views/frame/top_container_view.h" | 23 #include "chrome/browser/ui/views/frame/top_container_view.h" |
19 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 24 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
20 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 25 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
21 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
22 #include "ui/views/controls/webview/webview.h" | 27 #include "ui/views/controls/webview/webview.h" |
23 | 28 |
24 // For now, immersive fullscreen is Chrome OS only. | 29 namespace { |
25 #if defined(OS_CHROMEOS) | 30 |
31 // Returns the bounds of |view| in widget coordinates. | |
32 gfx::Rect GetBoundsInWidget(views::View* view) { | |
33 return view->ConvertRectToWidget(view->GetLocalBounds()); | |
34 } | |
35 | |
36 } // namespace | |
26 | 37 |
27 class ImmersiveModeControllerAshTest : public TestWithBrowserView { | 38 class ImmersiveModeControllerAshTest : public TestWithBrowserView { |
28 public: | 39 public: |
29 ImmersiveModeControllerAshTest() {} | 40 ImmersiveModeControllerAshTest() {} |
30 virtual ~ImmersiveModeControllerAshTest() {} | 41 virtual ~ImmersiveModeControllerAshTest() {} |
31 | 42 |
32 // TestWithBrowserView override: | 43 // TestWithBrowserView override: |
33 virtual void SetUp() OVERRIDE { | 44 virtual void SetUp() OVERRIDE { |
34 TestWithBrowserView::SetUp(); | 45 TestWithBrowserView::SetUp(); |
35 | 46 |
36 browser()->window()->Show(); | 47 browser()->window()->Show(); |
37 | 48 |
38 controller_ = browser_view()->immersive_mode_controller(); | 49 controller_ = browser_view()->immersive_mode_controller(); |
39 controller_->SetupForTest(); | 50 controller_->SetupForTest(); |
40 } | 51 } |
41 | 52 |
42 // Returns the bounds of |view| in widget coordinates. | |
43 gfx::Rect GetBoundsInWidget(views::View* view) { | |
44 return view->ConvertRectToWidget(view->GetLocalBounds()); | |
45 } | |
46 | |
47 // Toggle the browser's fullscreen state. | 53 // Toggle the browser's fullscreen state. |
48 void ToggleFullscreen() { | 54 void ToggleFullscreen() { |
49 // NOTIFICATION_FULLSCREEN_CHANGED is sent asynchronously. The notification | 55 // NOTIFICATION_FULLSCREEN_CHANGED is sent asynchronously. The notification |
50 // is used to trigger changes in whether the shelf is auto hidden and | 56 // is used to trigger changes in whether the shelf is auto hidden and |
51 // whether a "light bar" version of the tab strip is used when the | 57 // whether a "light bar" version of the tab strip is used when the |
52 // top-of-window views are hidden. | 58 // top-of-window views are hidden. |
53 scoped_ptr<FullscreenNotificationObserver> waiter( | 59 scoped_ptr<FullscreenNotificationObserver> waiter( |
54 new FullscreenNotificationObserver()); | 60 new FullscreenNotificationObserver()); |
55 chrome::ToggleFullscreenMode(browser()); | 61 chrome::ToggleFullscreenMode(browser()); |
56 waiter->Wait(); | 62 waiter->Wait(); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
244 // 3) Test that exiting tab fullscreen and immersive fullscreen | 250 // 3) Test that exiting tab fullscreen and immersive fullscreen |
245 // simultaneously correctly updates the shelf visibility and whether the tab | 251 // simultaneously correctly updates the shelf visibility and whether the tab |
246 // indicators should be hidden. | 252 // indicators should be hidden. |
247 SetTabFullscreen(true); | 253 SetTabFullscreen(true); |
248 ToggleFullscreen(); | 254 ToggleFullscreen(); |
249 ASSERT_FALSE(controller()->IsEnabled()); | 255 ASSERT_FALSE(controller()->IsEnabled()); |
250 EXPECT_EQ(ash::SHELF_VISIBLE, shelf->visibility_state()); | 256 EXPECT_EQ(ash::SHELF_VISIBLE, shelf->visibility_state()); |
251 EXPECT_TRUE(controller()->ShouldHideTabIndicators()); | 257 EXPECT_TRUE(controller()->ShouldHideTabIndicators()); |
252 } | 258 } |
253 | 259 |
260 class ImmersiveModeControllerAshTestHostedApp : public TestWithBrowserView { | |
261 public: | |
262 ImmersiveModeControllerAshTestHostedApp() {} | |
263 virtual ~ImmersiveModeControllerAshTestHostedApp() {} | |
264 | |
265 // TestWithBrowserView override: | |
266 virtual void SetUp() OVERRIDE { | |
267 CommandLine::ForCurrentProcess()->AppendSwitch( | |
268 ash::switches::kAshEnableImmersiveFullscreenForAllWindows); | |
269 | |
270 TestWithBrowserView::SetUp(); | |
271 browser()->window()->Show(); | |
272 controller_ = browser_view()->immersive_mode_controller(); | |
273 controller_->SetupForTest(); | |
274 } | |
275 | |
276 // BrowserWithTestWindowTest override: | |
277 virtual void PopulateBrowserCreateParams( | |
278 Browser::CreateParams* params) OVERRIDE { | |
279 params->type = Browser::TYPE_POPUP; | |
280 params->app_name = "Test"; | |
281 } | |
282 | |
283 ImmersiveModeController* controller() { return controller_; } | |
284 | |
285 private: | |
286 // Not owned. | |
287 ImmersiveModeController* controller_; | |
288 | |
289 DISALLOW_COPY_AND_ASSIGN(ImmersiveModeControllerAshTestHostedApp); | |
290 }; | |
291 | |
292 // Test the layout and visibility of the TopContainerView and web contents when | |
293 // a hosted app is put into immersive fullscreen. | |
294 TEST_F(ImmersiveModeControllerAshTestHostedApp, Layout) { | |
295 AddTab(browser(), GURL("about:blank")); | |
James Cook
2013/11/25 19:09:20
You might want to comment here about how it's stil
| |
296 | |
297 TabStrip* tabstrip = browser_view()->tabstrip(); | |
298 ToolbarView* toolbar = browser_view()->toolbar(); | |
299 views::WebView* contents_web_view = | |
300 browser_view()->GetContentsWebViewForTest(); | |
301 views::View* top_container = browser_view()->top_container(); | |
302 | |
303 // Immersive fullscreen starts out disabled. | |
304 ASSERT_FALSE(browser_view()->GetWidget()->IsFullscreen()); | |
305 ASSERT_FALSE(controller()->IsEnabled()); | |
306 | |
307 // The tabstrip and toolbar are not visible for hosted apps. | |
308 EXPECT_FALSE(tabstrip->visible()); | |
309 EXPECT_FALSE(toolbar->visible()); | |
310 | |
311 // The window header should be above the web contents. | |
312 int header_height = GetBoundsInWidget(contents_web_view).y(); | |
313 | |
314 chrome::ToggleFullscreenMode(browser()); | |
315 EXPECT_TRUE(browser_view()->GetWidget()->IsFullscreen()); | |
316 EXPECT_TRUE(controller()->IsEnabled()); | |
317 EXPECT_FALSE(controller()->IsRevealed()); | |
318 | |
319 // Entering immersive fullscreen should make the web contents flush with the | |
320 // top of the widget. | |
321 EXPECT_FALSE(tabstrip->visible()); | |
322 EXPECT_FALSE(toolbar->visible()); | |
323 EXPECT_TRUE(top_container->GetVisibleBounds().IsEmpty()); | |
324 EXPECT_EQ(0, GetBoundsInWidget(contents_web_view).y()); | |
325 | |
326 // Reveal the window header. | |
327 scoped_ptr<ImmersiveRevealedLock> revealed_lock( | |
328 controller()->GetRevealedLock( | |
329 ImmersiveModeControllerAsh::ANIMATE_REVEAL_NO)); | |
330 | |
331 // The tabstrip and toolbar should still be hidden and the web contents should | |
332 // still be flush with the top of the screen. | |
333 EXPECT_FALSE(tabstrip->visible()); | |
334 EXPECT_FALSE(toolbar->visible()); | |
335 EXPECT_EQ(0, GetBoundsInWidget(contents_web_view).y()); | |
336 | |
337 // During an immersive reveal, the window header should be painted to the | |
338 // TopContainerView. The TopContainerView should be flush with the top of the | |
339 // widget and have |header_height|. | |
340 gfx::Rect top_container_bounds_in_widget(GetBoundsInWidget(top_container)); | |
341 EXPECT_EQ(0, top_container_bounds_in_widget.y()); | |
342 EXPECT_EQ(header_height, top_container_bounds_in_widget.height()); | |
343 | |
344 // Exit immersive fullscreen. The web contents should be back below the window | |
345 // header. | |
346 chrome::ToggleFullscreenMode(browser()); | |
347 EXPECT_FALSE(browser_view()->GetWidget()->IsFullscreen()); | |
348 EXPECT_FALSE(controller()->IsEnabled()); | |
349 EXPECT_FALSE(tabstrip->visible()); | |
350 EXPECT_FALSE(toolbar->visible()); | |
351 EXPECT_EQ(header_height, GetBoundsInWidget(contents_web_view).y()); | |
352 } | |
353 | |
254 #endif // defined(OS_CHROMEOS) | 354 #endif // defined(OS_CHROMEOS) |
OLD | NEW |