| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h" | 5 #import "chrome/browser/ui/cocoa/location_bar/zoom_decoration.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/command_line.h" |
| 8 #include "base/macros.h" | 9 #include "base/macros.h" |
| 9 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/ui/browser_window.h" | 12 #include "chrome/browser/ui/browser_window.h" |
| 12 #import "chrome/browser/ui/cocoa/browser/zoom_bubble_controller.h" | 13 #import "chrome/browser/ui/cocoa/browser/zoom_bubble_controller.h" |
| 13 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 14 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 14 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 15 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 15 #include "chrome/browser/ui/cocoa/test/run_loop_testing.h" | 16 #include "chrome/browser/ui/cocoa/test/run_loop_testing.h" |
| 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 17 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
| 18 #include "components/toolbar/test_toolbar_model.h" | 19 #include "components/toolbar/test_toolbar_model.h" |
| 19 #include "components/zoom/page_zoom.h" | 20 #include "components/zoom/page_zoom.h" |
| 20 #include "components/zoom/zoom_controller.h" | 21 #include "components/zoom/zoom_controller.h" |
| 21 #include "content/public/browser/host_zoom_map.h" | 22 #include "content/public/browser/host_zoom_map.h" |
| 22 #include "content/public/test/test_utils.h" | 23 #include "content/public/test/test_utils.h" |
| 24 #include "ui/base/ui_base_switches.h" |
| 23 | 25 |
| 24 class ZoomDecorationTest : public InProcessBrowserTest { | 26 class ZoomDecorationTest : public InProcessBrowserTest, |
| 27 public ::testing::WithParamInterface<bool> { |
| 25 protected: | 28 protected: |
| 26 ZoomDecorationTest() | 29 ZoomDecorationTest() |
| 27 : InProcessBrowserTest(), | 30 : InProcessBrowserTest(), |
| 28 should_quit_on_zoom_(false) { | 31 should_quit_on_zoom_(false) { |
| 29 } | 32 } |
| 30 | 33 |
| 34 // testing::Test: |
| 35 void SetUp() override { |
| 36 // TODO(crbug.com/630357): Remove parameterized testing for this class when |
| 37 // secondary-ui-md is enabled by default on all platforms. |
| 38 if (GetParam()) { |
| 39 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 40 switches::kExtendMdToSecondaryUi); |
| 41 } |
| 42 InProcessBrowserTest::SetUp(); |
| 43 } |
| 44 |
| 31 void SetUpOnMainThread() override { | 45 void SetUpOnMainThread() override { |
| 32 zoom_subscription_ = content::HostZoomMap::GetDefaultForBrowserContext( | 46 zoom_subscription_ = content::HostZoomMap::GetDefaultForBrowserContext( |
| 33 browser()->profile())->AddZoomLevelChangedCallback( | 47 browser()->profile())->AddZoomLevelChangedCallback( |
| 34 base::Bind(&ZoomDecorationTest::OnZoomChanged, | 48 base::Bind(&ZoomDecorationTest::OnZoomChanged, |
| 35 base::Unretained(this))); | 49 base::Unretained(this))); |
| 36 } | 50 } |
| 37 | 51 |
| 38 void TearDownOnMainThread() override { zoom_subscription_.reset(); } | 52 void TearDownOnMainThread() override { zoom_subscription_.reset(); } |
| 39 | 53 |
| 40 LocationBarViewMac* GetLocationBar() const { | 54 LocationBarViewMac* GetLocationBar() const { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 } | 87 } |
| 74 } | 88 } |
| 75 | 89 |
| 76 private: | 90 private: |
| 77 bool should_quit_on_zoom_; | 91 bool should_quit_on_zoom_; |
| 78 std::unique_ptr<content::HostZoomMap::Subscription> zoom_subscription_; | 92 std::unique_ptr<content::HostZoomMap::Subscription> zoom_subscription_; |
| 79 | 93 |
| 80 DISALLOW_COPY_AND_ASSIGN(ZoomDecorationTest); | 94 DISALLOW_COPY_AND_ASSIGN(ZoomDecorationTest); |
| 81 }; | 95 }; |
| 82 | 96 |
| 83 IN_PROC_BROWSER_TEST_F(ZoomDecorationTest, BubbleAtDefaultZoom) { | 97 IN_PROC_BROWSER_TEST_P(ZoomDecorationTest, BubbleAtDefaultZoom) { |
| 84 ZoomDecoration* zoom_decoration = GetZoomDecoration(); | 98 ZoomDecoration* zoom_decoration = GetZoomDecoration(); |
| 85 | 99 |
| 86 // TODO(wjmaclean): This shouldn't be necessary, but at present this test | 100 // TODO(wjmaclean): This shouldn't be necessary, but at present this test |
| 87 // assumes the various Zoom() calls do not invoke a notification | 101 // assumes the various Zoom() calls do not invoke a notification |
| 88 // bubble, which prior to https://codereview.chromium.org/940673002/ | 102 // bubble, which prior to https://codereview.chromium.org/940673002/ |
| 89 // was accomplished by not showing the bubble for inactive windows. | 103 // was accomplished by not showing the bubble for inactive windows. |
| 90 // Since we now need to be able to show the zoom bubble as a notification | 104 // Since we now need to be able to show the zoom bubble as a notification |
| 91 // on non-active pages, this test should be revised to account for | 105 // on non-active pages, this test should be revised to account for |
| 92 // these notifications. | 106 // these notifications. |
| 93 zoom::ZoomController::FromWebContents(GetLocationBar()->GetWebContents()) | 107 zoom::ZoomController::FromWebContents(GetLocationBar()->GetWebContents()) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 106 zoom_decoration->ShowBubble(false); | 120 zoom_decoration->ShowBubble(false); |
| 107 Zoom(content::PAGE_ZOOM_RESET); | 121 Zoom(content::PAGE_ZOOM_RESET); |
| 108 EXPECT_FALSE(zoom_decoration->IsVisible()); | 122 EXPECT_FALSE(zoom_decoration->IsVisible()); |
| 109 | 123 |
| 110 // Hide bubble and verify the decoration is hidden. | 124 // Hide bubble and verify the decoration is hidden. |
| 111 zoom_decoration->CloseBubble(); | 125 zoom_decoration->CloseBubble(); |
| 112 EXPECT_FALSE(zoom_decoration->IsVisible()); | 126 EXPECT_FALSE(zoom_decoration->IsVisible()); |
| 113 } | 127 } |
| 114 | 128 |
| 115 // Regression test for https://crbug.com/462482. | 129 // Regression test for https://crbug.com/462482. |
| 116 IN_PROC_BROWSER_TEST_F(ZoomDecorationTest, IconRemainsVisibleAfterBubble) { | 130 IN_PROC_BROWSER_TEST_P(ZoomDecorationTest, IconRemainsVisibleAfterBubble) { |
| 117 ZoomDecoration* zoom_decoration = GetZoomDecoration(); | 131 ZoomDecoration* zoom_decoration = GetZoomDecoration(); |
| 118 | 132 |
| 119 // See comment in BubbleAtDefaultZoom regarding this next line. | 133 // See comment in BubbleAtDefaultZoom regarding this next line. |
| 120 zoom::ZoomController::FromWebContents(GetLocationBar()->GetWebContents()) | 134 zoom::ZoomController::FromWebContents(GetLocationBar()->GetWebContents()) |
| 121 ->SetShowsNotificationBubble(false); | 135 ->SetShowsNotificationBubble(false); |
| 122 | 136 |
| 123 // Zoom in to turn on decoration icon. | 137 // Zoom in to turn on decoration icon. |
| 124 EXPECT_FALSE(zoom_decoration->IsVisible()); | 138 EXPECT_FALSE(zoom_decoration->IsVisible()); |
| 125 Zoom(content::PAGE_ZOOM_IN); | 139 Zoom(content::PAGE_ZOOM_IN); |
| 126 EXPECT_TRUE(zoom_decoration->IsVisible()); | 140 EXPECT_TRUE(zoom_decoration->IsVisible()); |
| 127 | 141 |
| 128 // Show zoom bubble, verify decoration icon remains visible. | 142 // Show zoom bubble, verify decoration icon remains visible. |
| 129 zoom_decoration->ShowBubble(/* auto_close = */false); | 143 zoom_decoration->ShowBubble(/* auto_close = */false); |
| 130 EXPECT_TRUE(zoom_decoration->IsVisible()); | 144 EXPECT_TRUE(zoom_decoration->IsVisible()); |
| 131 | 145 |
| 132 // Close bubble and verify the decoration is still visible. | 146 // Close bubble and verify the decoration is still visible. |
| 133 zoom_decoration->CloseBubble(); | 147 zoom_decoration->CloseBubble(); |
| 134 EXPECT_TRUE(zoom_decoration->IsVisible()); | 148 EXPECT_TRUE(zoom_decoration->IsVisible()); |
| 135 | 149 |
| 136 // Verify the decoration does go away when we expect it to. | 150 // Verify the decoration does go away when we expect it to. |
| 137 Zoom(content::PAGE_ZOOM_RESET); | 151 Zoom(content::PAGE_ZOOM_RESET); |
| 138 EXPECT_FALSE(zoom_decoration->IsVisible()); | 152 EXPECT_FALSE(zoom_decoration->IsVisible()); |
| 139 } | 153 } |
| 140 | 154 |
| 141 IN_PROC_BROWSER_TEST_F(ZoomDecorationTest, HideOnInputProgress) { | 155 IN_PROC_BROWSER_TEST_P(ZoomDecorationTest, HideOnInputProgress) { |
| 142 ZoomDecoration* zoom_decoration = GetZoomDecoration(); | 156 ZoomDecoration* zoom_decoration = GetZoomDecoration(); |
| 143 | 157 |
| 144 // Zoom in and reset. | 158 // Zoom in and reset. |
| 145 Zoom(content::PAGE_ZOOM_IN); | 159 Zoom(content::PAGE_ZOOM_IN); |
| 146 EXPECT_TRUE(zoom_decoration->IsVisible()); | 160 EXPECT_TRUE(zoom_decoration->IsVisible()); |
| 147 | 161 |
| 148 std::unique_ptr<ToolbarModel> toolbar_model(new TestToolbarModel); | 162 std::unique_ptr<ToolbarModel> toolbar_model(new TestToolbarModel); |
| 149 toolbar_model->set_input_in_progress(true); | 163 toolbar_model->set_input_in_progress(true); |
| 150 browser()->swap_toolbar_models(&toolbar_model); | 164 browser()->swap_toolbar_models(&toolbar_model); |
| 151 GetLocationBar()->ZoomChangedForActiveTab(false); | 165 GetLocationBar()->ZoomChangedForActiveTab(false); |
| 152 EXPECT_FALSE(zoom_decoration->IsVisible()); | 166 EXPECT_FALSE(zoom_decoration->IsVisible()); |
| 153 } | 167 } |
| 154 | 168 |
| 155 IN_PROC_BROWSER_TEST_F(ZoomDecorationTest, CloseBrowserWithOpenBubble) { | 169 IN_PROC_BROWSER_TEST_P(ZoomDecorationTest, CloseBrowserWithOpenBubble) { |
| 156 chrome::SetZoomBubbleAutoCloseDelayForTesting(0); | 170 chrome::SetZoomBubbleAutoCloseDelayForTesting(0); |
| 157 | 171 |
| 158 // Create a new browser so that it can be closed properly. | 172 // Create a new browser so that it can be closed properly. |
| 159 Browser* browser2 = CreateBrowser(browser()->profile()); | 173 Browser* browser2 = CreateBrowser(browser()->profile()); |
| 160 ZoomDecoration* zoom_decoration = GetZoomDecorationForBrowser(browser2); | 174 ZoomDecoration* zoom_decoration = GetZoomDecorationForBrowser(browser2); |
| 161 zoom_decoration->ShowBubble(true); | 175 zoom_decoration->ShowBubble(true); |
| 162 | 176 |
| 163 // Test shouldn't crash. | 177 // Test shouldn't crash. |
| 164 browser2->window()->Close(); | 178 browser2->window()->Close(); |
| 165 content::RunAllPendingInMessageLoop(); | 179 content::RunAllPendingInMessageLoop(); |
| 166 } | 180 } |
| 181 |
| 182 // Prefix for test instantiations intentionally left blank since the test |
| 183 // fixture class has a single parameterization. |
| 184 INSTANTIATE_TEST_CASE_P(, ZoomDecorationTest, testing::Bool()); |
| OLD | NEW |