1 // Copyright 2012 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.
5 #include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
7 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/ui/browser_commands.h"
9 #include "chrome/browser/ui/views/frame/browser_view.h"
10 #include "chrome/test/base/in_process_browser_test.h"
11 #include "content/public/browser/web_contents.h"
12 #include "content/public/browser/web_contents_view.h"
13 #include "ui/aura/window.h"
17 // Returns the bounds of |view| in widget coordinates.
18 gfx::Rect GetRectInWidget(views::View* view) {
19 return view->ConvertRectToWidget(view->GetLocalBounds());
24 // TODO(jamescook): If immersive mode becomes popular on CrOS, consider porting
25 // it to other Aura platforms (win_aura, linux_aura). http://crbug.com/163931
26 #if defined(OS_CHROMEOS)
28 class ImmersiveModeControllerAshTest : public InProcessBrowserTest {
30 ImmersiveModeControllerAshTest() : browser_view_(NULL), controller_(NULL) {}
31 virtual ~ImmersiveModeControllerAshTest() {}
33 BrowserView* browser_view() { return browser_view_; }
34 ImmersiveModeController* controller() { return controller_; }
36 // content::BrowserTestBase overrides:
37 virtual void SetUpOnMainThread() OVERRIDE {
38 browser_view_ = static_cast<BrowserView*>(browser()->window());
39 controller_ = browser_view_->immersive_mode_controller();
40 controller_->SetupForTest();
44 BrowserView* browser_view_;
45 ImmersiveModeController* controller_;
47 DISALLOW_COPY_AND_ASSIGN(ImmersiveModeControllerAshTest);
50 // Validate top container touch insets are being updated at the correct time in
52 IN_PROC_BROWSER_TEST_F(ImmersiveModeControllerAshTest,
53 ImmersiveTopContainerInsets) {
54 content::WebContents* contents = browser_view()->GetActiveWebContents();
55 aura::Window* window = contents->GetView()->GetContentNativeView();
57 // Turning immersive mode on sets positive top touch insets on the render view
59 chrome::ToggleFullscreenMode(browser());
60 ASSERT_TRUE(browser_view()->IsFullscreen());
61 ASSERT_TRUE(controller()->IsEnabled());
62 ASSERT_FALSE(controller()->IsRevealed());
63 EXPECT_TRUE(window->hit_test_bounds_override_outer_touch().top() > 0);
65 // Trigger a reveal resets insets as now the touch target for the top
66 // container is large enough.
67 scoped_ptr<ImmersiveRevealedLock> lock(controller()->GetRevealedLock(
68 ImmersiveModeController::ANIMATE_REVEAL_NO));
69 EXPECT_TRUE(controller()->IsRevealed());
70 EXPECT_TRUE(window->hit_test_bounds_override_outer_touch().top() == 0);
72 // End reveal by moving the mouse off the top-of-window views. We
73 // should see the top insets being positive again to allow a bigger touch
76 EXPECT_FALSE(controller()->IsRevealed());
77 EXPECT_TRUE(window->hit_test_bounds_override_outer_touch().top() > 0);
79 // Disabling immersive mode resets the top touch insets to 0.
80 chrome::ToggleFullscreenMode(browser());
81 ASSERT_FALSE(browser_view()->IsFullscreen());
82 ASSERT_FALSE(controller()->IsEnabled());
83 EXPECT_TRUE(window->hit_test_bounds_override_outer_touch().top() == 0);
86 #endif // defined(OS_CHROMEOS)