Chromium Code Reviews| 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/chrome_notification_types.h" | |
| 9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_commands.h" | |
| 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 12 #include "chrome/browser/ui/webui/signin/login_ui_test_utils.h" | 14 #include "chrome/browser/ui/webui/signin/login_ui_test_utils.h" |
| 13 #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" | 15 #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" |
| 14 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 15 #include "chrome/test/base/in_process_browser_test.h" | 17 #include "chrome/test/base/in_process_browser_test.h" |
| 16 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
| 17 #include "components/signin/core/common/profile_management_switches.h" | 19 #include "components/signin/core/common/profile_management_switches.h" |
| 18 #include "content/public/browser/host_zoom_map.h" | 20 #include "content/public/browser/host_zoom_map.h" |
| 19 #include "content/public/browser/navigation_entry.h" | 21 #include "content/public/browser/navigation_entry.h" |
| 22 #include "content/public/browser/notification_service.h" | |
| 23 #include "content/public/browser/notification_types.h" | |
| 20 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
| 21 #include "content/public/browser/render_view_host.h" | 25 #include "content/public/browser/render_view_host.h" |
| 22 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 23 #include "content/public/common/page_type.h" | 27 #include "content/public/common/page_type.h" |
| 24 #include "content/public/test/browser_test_utils.h" | 28 #include "content/public/test/browser_test_utils.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
| 26 | 30 |
| 27 using ui_zoom::ZoomController; | 31 using ui_zoom::ZoomController; |
| 28 using ui_zoom::ZoomObserver; | 32 using ui_zoom::ZoomObserver; |
| 29 | 33 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 | 165 |
| 162 double old_zoom_level = zoom_controller->GetZoomLevel(); | 166 double old_zoom_level = zoom_controller->GetZoomLevel(); |
| 163 double new_zoom_level = old_zoom_level + 0.5; | 167 double new_zoom_level = old_zoom_level + 0.5; |
| 164 | 168 |
| 165 // The following attempt to change the zoom level for an error page should | 169 // The following attempt to change the zoom level for an error page should |
| 166 // fail. | 170 // fail. |
| 167 zoom_controller->SetZoomLevel(new_zoom_level); | 171 zoom_controller->SetZoomLevel(new_zoom_level); |
| 168 EXPECT_FLOAT_EQ(new_zoom_level, zoom_controller->GetZoomLevel()); | 172 EXPECT_FLOAT_EQ(new_zoom_level, zoom_controller->GetZoomLevel()); |
| 169 } | 173 } |
| 170 | 174 |
| 175 IN_PROC_BROWSER_TEST_F(ZoomControllerBrowserTest, | |
| 176 ErrorPagesCanZoomAfterTabRestore) { | |
| 177 GURL url("http://kjfhkjsdf.com"); | |
|
Charlie Reis
2015/02/13 21:38:37
Let's add a comment saying this is meant to cause
wjmaclean
2015/02/17 20:39:14
Done.
| |
| 178 | |
| 179 TabStripModel* tab_strip = browser()->tab_strip_model(); | |
| 180 ASSERT_TRUE(tab_strip); | |
| 181 | |
| 182 ui_test_utils::NavigateToURLWithDisposition( | |
| 183 browser(), url, NEW_FOREGROUND_TAB, | |
| 184 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
| 185 { | |
| 186 content::WebContents* web_contents = tab_strip->GetActiveWebContents(); | |
| 187 | |
| 188 EXPECT_EQ( | |
| 189 content::PAGE_TYPE_ERROR, | |
| 190 web_contents->GetController().GetLastCommittedEntry()->GetPageType()); | |
| 191 | |
| 192 content::WebContentsDestroyedWatcher destroyed_watcher(web_contents); | |
| 193 tab_strip->CloseWebContentsAt(tab_strip->active_index(), | |
| 194 TabStripModel::CLOSE_CREATE_HISTORICAL_TAB); | |
| 195 destroyed_watcher.Wait(); | |
| 196 } | |
| 197 EXPECT_EQ(1, tab_strip->count()); | |
| 198 | |
| 199 content::WindowedNotificationObserver tab_added_observer( | |
|
Charlie Reis
2015/02/13 21:38:36
Can we use content::WebContentsAddedObserver plus
wjmaclean
2015/02/17 20:39:14
Done.
| |
| 200 chrome::NOTIFICATION_TAB_PARENTED, | |
| 201 content::NotificationService::AllSources()); | |
| 202 content::WindowedNotificationObserver tab_loaded_observer( | |
| 203 content::NOTIFICATION_LOAD_STOP, | |
| 204 content::NotificationService::AllSources()); | |
| 205 | |
| 206 chrome::RestoreTab(browser()); | |
| 207 | |
| 208 tab_added_observer.Wait(); | |
| 209 tab_loaded_observer.Wait(); | |
| 210 EXPECT_EQ(2, tab_strip->count()); | |
| 211 | |
| 212 content::WebContents* web_contents = tab_strip->GetActiveWebContents(); | |
| 213 | |
| 214 EXPECT_EQ( | |
| 215 content::PAGE_TYPE_ERROR, | |
| 216 web_contents->GetController().GetLastCommittedEntry()->GetPageType()); | |
| 217 | |
| 218 ZoomController* zoom_controller = | |
| 219 ZoomController::FromWebContents(web_contents); | |
| 220 | |
| 221 double old_zoom_level = zoom_controller->GetZoomLevel(); | |
| 222 double new_zoom_level = old_zoom_level + 0.5; | |
| 223 | |
| 224 // The following attempt to change the zoom level for an error page should | |
| 225 // fail. | |
| 226 zoom_controller->SetZoomLevel(new_zoom_level); | |
| 227 EXPECT_FLOAT_EQ(new_zoom_level, zoom_controller->GetZoomLevel()); | |
| 228 } | |
| 229 | |
| 171 IN_PROC_BROWSER_TEST_F(ZoomControllerBrowserTest, Observe) { | 230 IN_PROC_BROWSER_TEST_F(ZoomControllerBrowserTest, Observe) { |
| 172 content::WebContents* web_contents = | 231 content::WebContents* web_contents = |
| 173 browser()->tab_strip_model()->GetActiveWebContents(); | 232 browser()->tab_strip_model()->GetActiveWebContents(); |
| 174 | 233 |
| 175 double new_zoom_level = 1.0; | 234 double new_zoom_level = 1.0; |
| 176 // When the event is initiated from HostZoomMap, the old zoom level is not | 235 // When the event is initiated from HostZoomMap, the old zoom level is not |
| 177 // available. | 236 // available. |
| 178 ZoomController::ZoomChangedEventData zoom_change_data( | 237 ZoomController::ZoomChangedEventData zoom_change_data( |
| 179 web_contents, | 238 web_contents, |
| 180 new_zoom_level, | 239 new_zoom_level, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 web_contents, | 321 web_contents, |
| 263 old_zoom_level, | 322 old_zoom_level, |
| 264 new_zoom_level, | 323 new_zoom_level, |
| 265 ZoomController::ZOOM_MODE_DEFAULT, | 324 ZoomController::ZOOM_MODE_DEFAULT, |
| 266 true); // We have a non-empty host, so this will be 'true'. | 325 true); // We have a non-empty host, so this will be 'true'. |
| 267 ZoomChangedWatcher zoom_change_watcher(web_contents, zoom_change_data); | 326 ZoomChangedWatcher zoom_change_watcher(web_contents, zoom_change_data); |
| 268 zoom_controller->SetZoomLevel(new_zoom_level); | 327 zoom_controller->SetZoomLevel(new_zoom_level); |
| 269 zoom_change_watcher.Wait(); | 328 zoom_change_watcher.Wait(); |
| 270 } | 329 } |
| 271 #endif // !defined(OS_CHROMEOS) | 330 #endif // !defined(OS_CHROMEOS) |
| OLD | NEW |