OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/ui/zoom/zoom_controller.h" | 5 #include "components/ui/zoom/zoom_controller.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/process/kill.h" | 8 #include "base/process/kill.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 12 #include "chrome/browser/ui/webui/signin/login_ui_test_utils.h" |
12 #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" | 13 #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" |
13 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
14 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
15 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
| 17 #include "components/signin/core/common/profile_management_switches.h" |
16 #include "content/public/browser/host_zoom_map.h" | 18 #include "content/public/browser/host_zoom_map.h" |
17 #include "content/public/browser/navigation_entry.h" | 19 #include "content/public/browser/navigation_entry.h" |
18 #include "content/public/browser/render_process_host.h" | 20 #include "content/public/browser/render_process_host.h" |
19 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
20 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
21 #include "content/public/common/page_type.h" | 23 #include "content/public/common/page_type.h" |
22 #include "content/public/test/browser_test_utils.h" | 24 #include "content/public/test/browser_test_utils.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
24 | 26 |
25 using ui_zoom::ZoomController; | 27 using ui_zoom::ZoomController; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 ZoomChangedWatcher zoom_change_watcher(web_contents, zoom_change_data); | 156 ZoomChangedWatcher zoom_change_watcher(web_contents, zoom_change_data); |
155 | 157 |
156 content::HostZoomMap* host_zoom_map = | 158 content::HostZoomMap* host_zoom_map = |
157 content::HostZoomMap::GetDefaultForBrowserContext( | 159 content::HostZoomMap::GetDefaultForBrowserContext( |
158 web_contents->GetBrowserContext()); | 160 web_contents->GetBrowserContext()); |
159 | 161 |
160 host_zoom_map->SetZoomLevelForHost("about:blank", new_zoom_level); | 162 host_zoom_map->SetZoomLevelForHost("about:blank", new_zoom_level); |
161 zoom_change_watcher.Wait(); | 163 zoom_change_watcher.Wait(); |
162 } | 164 } |
163 | 165 |
| 166 #if !defined(OS_CHROMEOS) |
164 // Regression test: crbug.com/438979. | 167 // Regression test: crbug.com/438979. |
165 IN_PROC_BROWSER_TEST_F(ZoomControllerBrowserTest, | 168 IN_PROC_BROWSER_TEST_F(ZoomControllerBrowserTest, |
166 SettingsZoomAfterSigninWorks) { | 169 SettingsZoomAfterSigninWorks) { |
167 GURL signin_url( | 170 GURL signin_url( |
168 std::string(chrome::kChromeUIChromeSigninURL).append("?source=0")); | 171 std::string(chrome::kChromeUIChromeSigninURL).append("?source=0")); |
169 // We open the signin page in a new tab so that the ZoomController is | 172 // We open the signin page in a new tab so that the ZoomController is |
170 // created against the HostZoomMap of the special StoragePartition that | 173 // created against the HostZoomMap of the special StoragePartition that |
171 // backs the signin page. When we subsequently navigate away from the | 174 // backs the signin page. When we subsequently navigate away from the |
172 // signin page, the HostZoomMap changes, and we need to test that the | 175 // signin page, the HostZoomMap changes, and we need to test that the |
173 // ZoomController correctly detects this. | 176 // ZoomController correctly detects this. |
174 // TODO(wjmaclean): It would be nice if detecting when the signin page is | 177 ui_test_utils::NavigateToURLWithDisposition( |
175 // fully loaded without needing a hard-coded value. | 178 browser(), signin_url, NEW_FOREGROUND_TAB, |
176 const int kLoadStopsBeforeSigninPageIsFullyLoaded = 3; | 179 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
177 ui_test_utils::NavigateToURLWithDispositionBlockUntilNavigationsComplete( | 180 login_ui_test_utils::WaitUntilUIReady(browser()); |
178 browser(), signin_url, kLoadStopsBeforeSigninPageIsFullyLoaded, | |
179 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
180 content::WebContents* web_contents = | 181 content::WebContents* web_contents = |
181 browser()->tab_strip_model()->GetActiveWebContents(); | 182 browser()->tab_strip_model()->GetActiveWebContents(); |
182 EXPECT_NE( | 183 EXPECT_NE( |
183 content::PAGE_TYPE_ERROR, | 184 content::PAGE_TYPE_ERROR, |
184 web_contents->GetController().GetLastCommittedEntry()->GetPageType()); | 185 web_contents->GetController().GetLastCommittedEntry()->GetPageType()); |
185 | 186 |
186 EXPECT_EQ(signin_url, web_contents->GetLastCommittedURL()); | 187 EXPECT_EQ(signin_url, web_contents->GetLastCommittedURL()); |
187 ZoomController* zoom_controller = | 188 ZoomController* zoom_controller = |
188 ZoomController::FromWebContents(web_contents); | 189 ZoomController::FromWebContents(web_contents); |
189 | 190 |
190 content::HostZoomMap* host_zoom_map_signin = | 191 content::HostZoomMap* host_zoom_map_signin = |
191 content::HostZoomMap::GetForWebContents(web_contents); | 192 content::HostZoomMap::GetForWebContents(web_contents); |
192 | 193 |
193 GURL settings_url(chrome::kChromeUISettingsURL); | 194 GURL settings_url(chrome::kChromeUISettingsURL); |
194 ui_test_utils::NavigateToURL(browser(), settings_url); | 195 ui_test_utils::NavigateToURL(browser(), settings_url); |
195 EXPECT_NE( | 196 EXPECT_NE( |
196 content::PAGE_TYPE_ERROR, | 197 content::PAGE_TYPE_ERROR, |
197 web_contents->GetController().GetLastCommittedEntry()->GetPageType()); | 198 web_contents->GetController().GetLastCommittedEntry()->GetPageType()); |
198 | 199 |
199 // Verify new tab was created. | 200 // Verify new tab was created. |
200 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 201 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
201 // Verify that the settings page is using the same WebContents. | 202 // Verify that the settings page is using the same WebContents. |
202 EXPECT_EQ(web_contents, browser()->tab_strip_model()->GetActiveWebContents()); | 203 EXPECT_EQ(web_contents, browser()->tab_strip_model()->GetActiveWebContents()); |
203 // TODO(wjmaclean): figure out why this next line fails, i.e. why does this | 204 // TODO(wjmaclean): figure out why this next line fails, i.e. why does this |
204 // test not properly trigger a navigation to the settings page. | 205 // test not properly trigger a navigation to the settings page. |
205 EXPECT_EQ(settings_url, web_contents->GetLastCommittedURL()); | 206 EXPECT_EQ(settings_url, web_contents->GetLastCommittedURL()); |
206 EXPECT_EQ(zoom_controller, ZoomController::FromWebContents(web_contents)); | 207 EXPECT_EQ(zoom_controller, ZoomController::FromWebContents(web_contents)); |
207 | 208 |
208 // We expect the navigation from the chrome sign in page to the settings | 209 // For the webview based sign-in code, the sign in page uses the default host |
209 // page to invoke a storage partition switch, and thus a different HostZoomMap | 210 // zoom map. |
210 // for the web_contents. | 211 if (!switches::IsEnableWebviewBasedSignin()) { |
211 content::HostZoomMap* host_zoom_map_settings = | 212 // We expect the navigation from the chrome sign in page to the settings |
212 content::HostZoomMap::GetForWebContents(web_contents); | 213 // page to invoke a storage partition switch, and thus a different |
213 EXPECT_NE(host_zoom_map_signin, host_zoom_map_settings); | 214 // HostZoomMap for the web_contents. |
| 215 content::HostZoomMap* host_zoom_map_settings = |
| 216 content::HostZoomMap::GetForWebContents(web_contents); |
| 217 EXPECT_NE(host_zoom_map_signin, host_zoom_map_settings); |
| 218 } |
214 | 219 |
215 // If we zoom the new page, it should still generate a ZoomController event. | 220 // If we zoom the new page, it should still generate a ZoomController event. |
216 double old_zoom_level = zoom_controller->GetZoomLevel(); | 221 double old_zoom_level = zoom_controller->GetZoomLevel(); |
217 double new_zoom_level = old_zoom_level + 0.5; | 222 double new_zoom_level = old_zoom_level + 0.5; |
218 | 223 |
219 ZoomController::ZoomChangedEventData zoom_change_data( | 224 ZoomController::ZoomChangedEventData zoom_change_data( |
220 web_contents, | 225 web_contents, |
221 old_zoom_level, | 226 old_zoom_level, |
222 new_zoom_level, | 227 new_zoom_level, |
223 ZoomController::ZOOM_MODE_DEFAULT, | 228 ZoomController::ZOOM_MODE_DEFAULT, |
224 true); // We have a non-empty host, so this will be 'true'. | 229 true); // We have a non-empty host, so this will be 'true'. |
225 ZoomChangedWatcher zoom_change_watcher(web_contents, zoom_change_data); | 230 ZoomChangedWatcher zoom_change_watcher(web_contents, zoom_change_data); |
226 zoom_controller->SetZoomLevel(new_zoom_level); | 231 zoom_controller->SetZoomLevel(new_zoom_level); |
227 zoom_change_watcher.Wait(); | 232 zoom_change_watcher.Wait(); |
228 } | 233 } |
| 234 #endif // !defined(OS_CHROMEOS) |
OLD | NEW |