Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/app/chrome_command_ids.h" | 5 #include "chrome/app/chrome_command_ids.h" |
| 6 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 6 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 7 #include "chrome/browser/ui/browser_command_controller.h" | 7 #include "chrome/browser/ui/browser_command_controller.h" |
| 8 #include "chrome/browser/ui/browser_commands.h" | 8 #include "chrome/browser/ui/browser_commands.h" |
| 9 #include "chrome/browser/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 11 #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" | |
| 11 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
| 12 #include "chrome/test/base/browser_with_test_window_test.h" | 13 #include "chrome/test/base/browser_with_test_window_test.h" |
| 13 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
| 14 #include "components/bookmarks/browser/bookmark_model.h" | 15 #include "components/bookmarks/browser/bookmark_model.h" |
| 15 #include "components/bookmarks/test/bookmark_test_helpers.h" | 16 #include "components/bookmarks/test/bookmark_test_helpers.h" |
| 16 #include "components/ui/zoom/page_zoom.h" | 17 #include "components/ui/zoom/page_zoom.h" |
| 17 #include "components/ui/zoom/zoom_controller.h" | 18 #include "components/ui/zoom/zoom_controller.h" |
| 18 #include "content/public/browser/navigation_controller.h" | 19 #include "content/public/browser/navigation_controller.h" |
| 19 #include "content/public/browser/navigation_entry.h" | 20 #include "content/public/browser/navigation_entry.h" |
| 20 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | |
| 21 | 23 |
| 22 typedef BrowserWithTestWindowTest BrowserCommandsTest; | 24 typedef BrowserWithTestWindowTest BrowserCommandsTest; |
| 23 | 25 |
| 24 using bookmarks::BookmarkModel; | 26 using bookmarks::BookmarkModel; |
| 25 using content::OpenURLParams; | 27 using content::OpenURLParams; |
| 26 using content::Referrer; | 28 using content::Referrer; |
| 27 using content::WebContents; | 29 using content::WebContents; |
| 28 using ui_zoom::ZoomController; | 30 using ui_zoom::ZoomController; |
| 29 | 31 |
| 30 // Tests IDC_SELECT_TAB_0, IDC_SELECT_NEXT_TAB, IDC_SELECT_PREVIOUS_TAB and | 32 // Tests IDC_SELECT_TAB_0, IDC_SELECT_NEXT_TAB, IDC_SELECT_PREVIOUS_TAB and |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 ASSERT_EQ(url2, | 232 ASSERT_EQ(url2, |
| 231 browser()->tab_strip_model()->GetActiveWebContents()-> | 233 browser()->tab_strip_model()->GetActiveWebContents()-> |
| 232 GetVisibleURL()); | 234 GetVisibleURL()); |
| 233 } | 235 } |
| 234 | 236 |
| 235 TEST_F(BrowserCommandsTest, OnMaxZoomIn) { | 237 TEST_F(BrowserCommandsTest, OnMaxZoomIn) { |
| 236 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 238 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| 237 | 239 |
| 238 GURL url("http://www.google.com"); | 240 GURL url("http://www.google.com"); |
| 239 AddTab(browser(), url); | 241 AddTab(browser(), url); |
| 240 content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0); | 242 WebContents* firstTab = tab_strip_model->GetWebContentsAt(0); |
|
Alexei Svitkine (slow)
2015/02/26 14:26:35
Hmm, not sure at which point this slipped through
sarka
2015/02/26 15:37:22
My bad, I updated the names in the last CL. The na
| |
| 241 | 243 |
| 242 // Continue to zoom in until zoom percent reaches 500. | 244 // Continue to zoom in until zoom percent reaches 500. |
| 243 for (int i = 0; i < 9; ++i) { | 245 for (int i = 0; i < 9; ++i) { |
| 244 ui_zoom::PageZoom::Zoom(contents1, content::PAGE_ZOOM_IN); | 246 ui_zoom::PageZoom::Zoom(firstTab, content::PAGE_ZOOM_IN); |
| 245 } | 247 } |
| 246 | 248 |
| 247 // TODO(a.sarkar.arun@gmail.com): Figure out why Zoom-In menu item is not | 249 // TODO(a.sarkar.arun@gmail.com): Figure out why Zoom-In menu item is not |
| 248 // disabled after Max-zoom is reached. Force disable Zoom-In menu item | 250 // disabled after Max-zoom is reached. Force disable Zoom-In menu item |
| 249 // from the context menu since it breaks try jobs on bots. | 251 // from the context menu since it breaks try jobs on bots. |
| 250 if (chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)) | 252 if (chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)) |
| 251 chrome::UpdateCommandEnabled(browser(), IDC_ZOOM_PLUS, false); | 253 chrome::UpdateCommandEnabled(browser(), IDC_ZOOM_PLUS, false); |
| 252 | 254 |
| 253 ZoomController* zoom_controller = ZoomController::FromWebContents(contents1); | 255 ZoomController* zoom_controller = ZoomController::FromWebContents(firstTab); |
| 254 EXPECT_EQ(zoom_controller->GetZoomPercent(), 500.0f); | 256 EXPECT_FLOAT_EQ(500.0f, zoom_controller->GetZoomPercent()); |
| 255 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | 257 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); |
| 256 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | 258 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); |
| 257 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | 259 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); |
| 258 } | 260 } |
| 259 | 261 |
| 260 TEST_F(BrowserCommandsTest, OnMaxZoomOut) { | 262 TEST_F(BrowserCommandsTest, OnMaxZoomOut) { |
| 261 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 263 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| 262 | 264 |
| 263 GURL url("http://www.google.com"); | 265 GURL url("http://www.google.com"); |
| 264 AddTab(browser(), url); | 266 AddTab(browser(), url); |
| 265 content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0); | 267 WebContents* firstTab = tab_strip_model->GetWebContentsAt(0); |
| 266 | 268 |
| 267 // Continue to zoom out until zoom percent reaches 25. | 269 // Continue to zoom out until zoom percent reaches 25. |
| 268 for (int i = 0; i < 7; ++i) { | 270 for (int i = 0; i < 7; ++i) { |
| 269 ui_zoom::PageZoom::Zoom(contents1, content::PAGE_ZOOM_OUT); | 271 ui_zoom::PageZoom::Zoom(firstTab, content::PAGE_ZOOM_OUT); |
| 270 } | 272 } |
| 271 | 273 |
| 272 ZoomController* zoom_controller = ZoomController::FromWebContents(contents1); | 274 ZoomController* zoom_controller = ZoomController::FromWebContents(firstTab); |
| 273 EXPECT_EQ(zoom_controller->GetZoomPercent(), 25.0f); | 275 EXPECT_FLOAT_EQ(25.0f, zoom_controller->GetZoomPercent()); |
| 274 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | 276 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); |
| 275 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | 277 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); |
| 276 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | 278 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); |
| 277 } | 279 } |
| 278 | 280 |
| 279 TEST_F(BrowserCommandsTest, OnZoomReset) { | 281 TEST_F(BrowserCommandsTest, OnZoomReset) { |
| 280 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 282 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| 281 | 283 |
| 282 GURL url("http://www.google.com"); | 284 GURL url("http://www.google.com"); |
| 283 AddTab(browser(), url); | 285 AddTab(browser(), url); |
| 284 content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0); | 286 WebContents* firstTab = tab_strip_model->GetWebContentsAt(0); |
| 285 | 287 |
| 286 // Change the zoom percentage to 100. | 288 // Change the zoom percentage to 100. |
| 287 ui_zoom::PageZoom::Zoom(contents1, content::PAGE_ZOOM_RESET); | 289 ui_zoom::PageZoom::Zoom(firstTab, content::PAGE_ZOOM_RESET); |
| 288 | 290 |
| 289 ZoomController* zoom_controller = ZoomController::FromWebContents(contents1); | 291 ZoomController* zoom_controller = ZoomController::FromWebContents(firstTab); |
| 290 EXPECT_EQ(zoom_controller->GetZoomPercent(), 100.0f); | 292 EXPECT_FLOAT_EQ(100.0f, zoom_controller->GetZoomPercent()); |
| 291 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | 293 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); |
| 292 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | 294 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); |
| 293 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | 295 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); |
| 294 } | 296 } |
| 295 | 297 |
| 296 TEST_F(BrowserCommandsTest, OnZoomLevelChanged) { | 298 TEST_F(BrowserCommandsTest, OnZoomLevelChanged) { |
| 297 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 299 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| 298 | 300 |
| 299 GURL url("http://www.google.com"); | 301 GURL url("http://www.google.com"); |
| 300 AddTab(browser(), url); | 302 AddTab(browser(), url); |
| 301 content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0); | 303 WebContents* firstTab = tab_strip_model->GetWebContentsAt(0); |
| 302 | 304 |
| 303 // Changing zoom percentage from default should enable all the zoom | 305 // Changing zoom percentage from default should enable all the zoom |
| 304 // NSMenuItems. | 306 // NSMenuItems. |
| 305 ui_zoom::PageZoom::Zoom(contents1, content::PAGE_ZOOM_IN); | 307 ui_zoom::PageZoom::Zoom(firstTab, content::PAGE_ZOOM_IN); |
| 306 | 308 |
| 307 ZoomController* zoom_controller = ZoomController::FromWebContents(contents1); | 309 ZoomController* zoom_controller = ZoomController::FromWebContents(firstTab); |
| 308 EXPECT_EQ(zoom_controller->GetZoomPercent(), 110.0f); | 310 EXPECT_FLOAT_EQ(110.0f, zoom_controller->GetZoomPercent()); |
| 309 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | 311 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); |
| 310 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | 312 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); |
| 311 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | 313 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); |
| 312 } | 314 } |
| 313 | 315 |
| 314 TEST_F(BrowserCommandsTest, OnZoomChangedForActiveTab) { | 316 TEST_F(BrowserCommandsTest, OnZoomChangedForActiveTab) { |
| 315 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 317 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| 316 | 318 |
| 317 GURL url("http://www.google.com"); | 319 GURL url("http://www.google.com"); |
| 318 GURL url1("http://code.google.com"); | 320 GURL url1("http://code.google.com"); |
| 319 | 321 |
| 320 // Add First tab. | 322 // Add First tab. |
| 321 AddTab(browser(), url); | 323 AddTab(browser(), url); |
| 322 AddTab(browser(), url1); | 324 AddTab(browser(), url1); |
| 323 content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0); | 325 WebContents* firstTab = tab_strip_model->GetWebContentsAt(0); |
| 324 | 326 |
| 325 ZoomController* zoom_controller = ZoomController::FromWebContents(contents1); | 327 ZoomController* zoom_controller = ZoomController::FromWebContents(firstTab); |
| 326 EXPECT_EQ(zoom_controller->GetZoomPercent(), 100.0f); | 328 EXPECT_FLOAT_EQ(100.0f, zoom_controller->GetZoomPercent()); |
| 327 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | 329 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); |
| 328 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | 330 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); |
| 329 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | 331 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); |
| 330 | 332 |
| 331 // Add Second tab. | 333 // Add Second tab. |
| 332 content::WebContents* contents2 = tab_strip_model->GetWebContentsAt(1); | 334 WebContents* secondTab = tab_strip_model->GetWebContentsAt(1); |
| 333 | 335 |
| 334 tab_strip_model->ActivateTabAt(1, true); | 336 tab_strip_model->ActivateTabAt(1, true); |
| 335 EXPECT_TRUE(tab_strip_model->IsTabSelected(1)); | 337 EXPECT_TRUE(tab_strip_model->IsTabSelected(1)); |
| 336 ui_zoom::PageZoom::Zoom(contents2, content::PAGE_ZOOM_OUT); | 338 ui_zoom::PageZoom::Zoom(secondTab, content::PAGE_ZOOM_OUT); |
| 337 | 339 |
| 338 zoom_controller = ZoomController::FromWebContents(contents2); | 340 zoom_controller = ZoomController::FromWebContents(secondTab); |
| 339 EXPECT_EQ(zoom_controller->GetZoomPercent(), 90.0f); | 341 EXPECT_FLOAT_EQ(90.0f, zoom_controller->GetZoomPercent()); |
| 340 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | 342 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); |
| 341 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | 343 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); |
| 342 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | 344 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); |
| 345 } | |
| 346 | |
| 347 TEST_F(BrowserCommandsTest, OnDefaultZoomLevelChanged) { | |
| 348 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
| 349 GURL url("http://code.google.com"); | |
| 350 AddTab(browser(), url); | |
| 351 WebContents* currentTab = tab_strip_model->GetWebContentsAt(0); | |
| 352 ZoomController* zoom_controller = ZoomController::FromWebContents(currentTab); | |
| 353 | |
| 354 // Set the default zoom level to 125. | |
| 355 profile()->GetZoomLevelPrefs()->SetDefaultZoomLevelPref( | |
| 356 content::ZoomFactorToZoomLevel(1.25)); | |
| 357 EXPECT_FLOAT_EQ(125.0f, zoom_controller->GetZoomPercent()); | |
| 358 | |
| 359 // Actual Size from context menu should be disabled now. | |
| 360 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | |
| 361 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | |
| 362 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | |
| 363 | |
| 364 // Change the zoom level. | |
| 365 ui_zoom::PageZoom::Zoom(currentTab, content::PAGE_ZOOM_IN); | |
| 366 | |
| 367 EXPECT_FLOAT_EQ(150.0f, zoom_controller->GetZoomPercent()); | |
| 368 | |
| 369 // Tab no longer at default zoom hence actual size should be enabled. | |
| 370 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | |
| 371 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | |
| 372 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | |
| 343 } | 373 } |
| OLD | NEW |