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 namespace { |
27 | |
28 // An enum to parameterize the tests so that the tests can be run with and | |
msw
2017/04/24 18:53:38
nit: simplify this to a bool param or extract the
varkha
2017/04/26 04:52:59
Done. Not sure about refactoring this, this is use
| |
29 // without the secondary-ui-md flag. | |
30 enum class SecondaryUiMd { | |
31 ENABLED, | |
32 DISABLED, | |
33 }; | |
34 | |
35 // Generates the test name suffix depending on the value of the SecondaryUiMd | |
36 // param. | |
37 std::string SecondaryUiMdStatusToString( | |
38 const ::testing::TestParamInfo<SecondaryUiMd>& info) { | |
39 switch (info.param) { | |
40 case SecondaryUiMd::ENABLED: | |
41 return "SecondaryUiMdEnabled"; | |
42 case SecondaryUiMd::DISABLED: | |
43 return "SecondaryUiMdDisabled"; | |
44 } | |
45 NOTREACHED(); | |
46 return std::string(); | |
47 } | |
48 | |
49 } // namespace | |
50 | |
51 class ZoomDecorationTest : public InProcessBrowserTest, | |
52 public ::testing::WithParamInterface<SecondaryUiMd> { | |
25 protected: | 53 protected: |
26 ZoomDecorationTest() | 54 ZoomDecorationTest() |
27 : InProcessBrowserTest(), | 55 : InProcessBrowserTest(), |
28 should_quit_on_zoom_(false) { | 56 should_quit_on_zoom_(false) { |
29 } | 57 } |
30 | 58 |
59 void SetUp() override { | |
60 // TODO(crbug.com/630357): Remove parameterized testing for this class when | |
61 // secondary-ui-md is enabled by default on all platforms. | |
62 if (GetParam() == SecondaryUiMd::ENABLED) { | |
63 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
64 switches::kExtendMdToSecondaryUi); | |
65 } | |
66 InProcessBrowserTest::SetUp(); | |
67 } | |
68 | |
31 void SetUpOnMainThread() override { | 69 void SetUpOnMainThread() override { |
32 zoom_subscription_ = content::HostZoomMap::GetDefaultForBrowserContext( | 70 zoom_subscription_ = content::HostZoomMap::GetDefaultForBrowserContext( |
33 browser()->profile())->AddZoomLevelChangedCallback( | 71 browser()->profile())->AddZoomLevelChangedCallback( |
34 base::Bind(&ZoomDecorationTest::OnZoomChanged, | 72 base::Bind(&ZoomDecorationTest::OnZoomChanged, |
35 base::Unretained(this))); | 73 base::Unretained(this))); |
36 } | 74 } |
37 | 75 |
38 void TearDownOnMainThread() override { zoom_subscription_.reset(); } | 76 void TearDownOnMainThread() override { zoom_subscription_.reset(); } |
39 | 77 |
40 LocationBarViewMac* GetLocationBar() const { | 78 LocationBarViewMac* GetLocationBar() const { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 } | 111 } |
74 } | 112 } |
75 | 113 |
76 private: | 114 private: |
77 bool should_quit_on_zoom_; | 115 bool should_quit_on_zoom_; |
78 std::unique_ptr<content::HostZoomMap::Subscription> zoom_subscription_; | 116 std::unique_ptr<content::HostZoomMap::Subscription> zoom_subscription_; |
79 | 117 |
80 DISALLOW_COPY_AND_ASSIGN(ZoomDecorationTest); | 118 DISALLOW_COPY_AND_ASSIGN(ZoomDecorationTest); |
81 }; | 119 }; |
82 | 120 |
83 IN_PROC_BROWSER_TEST_F(ZoomDecorationTest, BubbleAtDefaultZoom) { | 121 IN_PROC_BROWSER_TEST_P(ZoomDecorationTest, BubbleAtDefaultZoom) { |
84 ZoomDecoration* zoom_decoration = GetZoomDecoration(); | 122 ZoomDecoration* zoom_decoration = GetZoomDecoration(); |
85 | 123 |
86 // TODO(wjmaclean): This shouldn't be necessary, but at present this test | 124 // TODO(wjmaclean): This shouldn't be necessary, but at present this test |
87 // assumes the various Zoom() calls do not invoke a notification | 125 // assumes the various Zoom() calls do not invoke a notification |
88 // bubble, which prior to https://codereview.chromium.org/940673002/ | 126 // bubble, which prior to https://codereview.chromium.org/940673002/ |
89 // was accomplished by not showing the bubble for inactive windows. | 127 // 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 | 128 // 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 | 129 // on non-active pages, this test should be revised to account for |
92 // these notifications. | 130 // these notifications. |
93 zoom::ZoomController::FromWebContents(GetLocationBar()->GetWebContents()) | 131 zoom::ZoomController::FromWebContents(GetLocationBar()->GetWebContents()) |
(...skipping 12 matching lines...) Expand all Loading... | |
106 zoom_decoration->ShowBubble(false); | 144 zoom_decoration->ShowBubble(false); |
107 Zoom(content::PAGE_ZOOM_RESET); | 145 Zoom(content::PAGE_ZOOM_RESET); |
108 EXPECT_FALSE(zoom_decoration->IsVisible()); | 146 EXPECT_FALSE(zoom_decoration->IsVisible()); |
109 | 147 |
110 // Hide bubble and verify the decoration is hidden. | 148 // Hide bubble and verify the decoration is hidden. |
111 zoom_decoration->CloseBubble(); | 149 zoom_decoration->CloseBubble(); |
112 EXPECT_FALSE(zoom_decoration->IsVisible()); | 150 EXPECT_FALSE(zoom_decoration->IsVisible()); |
113 } | 151 } |
114 | 152 |
115 // Regression test for https://crbug.com/462482. | 153 // Regression test for https://crbug.com/462482. |
116 IN_PROC_BROWSER_TEST_F(ZoomDecorationTest, IconRemainsVisibleAfterBubble) { | 154 IN_PROC_BROWSER_TEST_P(ZoomDecorationTest, IconRemainsVisibleAfterBubble) { |
117 ZoomDecoration* zoom_decoration = GetZoomDecoration(); | 155 ZoomDecoration* zoom_decoration = GetZoomDecoration(); |
118 | 156 |
119 // See comment in BubbleAtDefaultZoom regarding this next line. | 157 // See comment in BubbleAtDefaultZoom regarding this next line. |
120 zoom::ZoomController::FromWebContents(GetLocationBar()->GetWebContents()) | 158 zoom::ZoomController::FromWebContents(GetLocationBar()->GetWebContents()) |
121 ->SetShowsNotificationBubble(false); | 159 ->SetShowsNotificationBubble(false); |
122 | 160 |
123 // Zoom in to turn on decoration icon. | 161 // Zoom in to turn on decoration icon. |
124 EXPECT_FALSE(zoom_decoration->IsVisible()); | 162 EXPECT_FALSE(zoom_decoration->IsVisible()); |
125 Zoom(content::PAGE_ZOOM_IN); | 163 Zoom(content::PAGE_ZOOM_IN); |
126 EXPECT_TRUE(zoom_decoration->IsVisible()); | 164 EXPECT_TRUE(zoom_decoration->IsVisible()); |
127 | 165 |
128 // Show zoom bubble, verify decoration icon remains visible. | 166 // Show zoom bubble, verify decoration icon remains visible. |
129 zoom_decoration->ShowBubble(/* auto_close = */false); | 167 zoom_decoration->ShowBubble(/* auto_close = */false); |
130 EXPECT_TRUE(zoom_decoration->IsVisible()); | 168 EXPECT_TRUE(zoom_decoration->IsVisible()); |
131 | 169 |
132 // Close bubble and verify the decoration is still visible. | 170 // Close bubble and verify the decoration is still visible. |
133 zoom_decoration->CloseBubble(); | 171 zoom_decoration->CloseBubble(); |
134 EXPECT_TRUE(zoom_decoration->IsVisible()); | 172 EXPECT_TRUE(zoom_decoration->IsVisible()); |
135 | 173 |
136 // Verify the decoration does go away when we expect it to. | 174 // Verify the decoration does go away when we expect it to. |
137 Zoom(content::PAGE_ZOOM_RESET); | 175 Zoom(content::PAGE_ZOOM_RESET); |
138 EXPECT_FALSE(zoom_decoration->IsVisible()); | 176 EXPECT_FALSE(zoom_decoration->IsVisible()); |
139 } | 177 } |
140 | 178 |
141 IN_PROC_BROWSER_TEST_F(ZoomDecorationTest, HideOnInputProgress) { | 179 IN_PROC_BROWSER_TEST_P(ZoomDecorationTest, HideOnInputProgress) { |
142 ZoomDecoration* zoom_decoration = GetZoomDecoration(); | 180 ZoomDecoration* zoom_decoration = GetZoomDecoration(); |
143 | 181 |
144 // Zoom in and reset. | 182 // Zoom in and reset. |
145 Zoom(content::PAGE_ZOOM_IN); | 183 Zoom(content::PAGE_ZOOM_IN); |
146 EXPECT_TRUE(zoom_decoration->IsVisible()); | 184 EXPECT_TRUE(zoom_decoration->IsVisible()); |
147 | 185 |
148 std::unique_ptr<ToolbarModel> toolbar_model(new TestToolbarModel); | 186 std::unique_ptr<ToolbarModel> toolbar_model(new TestToolbarModel); |
149 toolbar_model->set_input_in_progress(true); | 187 toolbar_model->set_input_in_progress(true); |
150 browser()->swap_toolbar_models(&toolbar_model); | 188 browser()->swap_toolbar_models(&toolbar_model); |
151 GetLocationBar()->ZoomChangedForActiveTab(false); | 189 GetLocationBar()->ZoomChangedForActiveTab(false); |
152 EXPECT_FALSE(zoom_decoration->IsVisible()); | 190 EXPECT_FALSE(zoom_decoration->IsVisible()); |
153 } | 191 } |
154 | 192 |
155 IN_PROC_BROWSER_TEST_F(ZoomDecorationTest, CloseBrowserWithOpenBubble) { | 193 IN_PROC_BROWSER_TEST_P(ZoomDecorationTest, CloseBrowserWithOpenBubble) { |
156 chrome::SetZoomBubbleAutoCloseDelayForTesting(0); | 194 chrome::SetZoomBubbleAutoCloseDelayForTesting(0); |
157 | 195 |
158 // Create a new browser so that it can be closed properly. | 196 // Create a new browser so that it can be closed properly. |
159 Browser* browser2 = CreateBrowser(browser()->profile()); | 197 Browser* browser2 = CreateBrowser(browser()->profile()); |
160 ZoomDecoration* zoom_decoration = GetZoomDecorationForBrowser(browser2); | 198 ZoomDecoration* zoom_decoration = GetZoomDecorationForBrowser(browser2); |
161 zoom_decoration->ShowBubble(true); | 199 zoom_decoration->ShowBubble(true); |
162 | 200 |
163 // Test shouldn't crash. | 201 // Test shouldn't crash. |
164 browser2->window()->Close(); | 202 browser2->window()->Close(); |
165 content::RunAllPendingInMessageLoop(); | 203 content::RunAllPendingInMessageLoop(); |
166 } | 204 } |
205 | |
206 // Prefix for test instantiations intentionally left blank since the test | |
207 // fixture class has a single parameterization. | |
208 INSTANTIATE_TEST_CASE_P(, | |
209 ZoomDecorationTest, | |
210 ::testing::Values(SecondaryUiMd::ENABLED, | |
211 SecondaryUiMd::DISABLED), | |
212 &SecondaryUiMdStatusToString); | |
OLD | NEW |