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/chrome_page_zoom.h" | |
| 7 #include "chrome/browser/ui/browser_command_controller.h" | 8 #include "chrome/browser/ui/browser_command_controller.h" |
| 8 #include "chrome/browser/ui/browser_commands.h" | 9 #include "chrome/browser/ui/browser_commands.h" |
| 9 #include "chrome/browser/ui/browser_finder.h" | 10 #include "chrome/browser/ui/browser_finder.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 12 #include "chrome/browser/ui/zoom/zoom_controller.h" | |
| 11 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
| 12 #include "chrome/test/base/browser_with_test_window_test.h" | 14 #include "chrome/test/base/browser_with_test_window_test.h" |
| 13 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
| 14 #include "components/bookmarks/browser/bookmark_model.h" | 16 #include "components/bookmarks/browser/bookmark_model.h" |
| 15 #include "components/bookmarks/test/bookmark_test_helpers.h" | 17 #include "components/bookmarks/test/bookmark_test_helpers.h" |
| 16 #include "content/public/browser/navigation_controller.h" | 18 #include "content/public/browser/navigation_controller.h" |
| 17 #include "content/public/browser/navigation_entry.h" | 19 #include "content/public/browser/navigation_entry.h" |
| 18 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 19 | 21 |
| 20 typedef BrowserWithTestWindowTest BrowserCommandsTest; | 22 typedef BrowserWithTestWindowTest BrowserCommandsTest; |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 // Same thing again for forward. | 222 // Same thing again for forward. |
| 221 // TODO(brettw) bug 11055: see the comment above about why we need this. | 223 // TODO(brettw) bug 11055: see the comment above about why we need this. |
| 222 CommitPendingLoad(& | 224 CommitPendingLoad(& |
| 223 browser()->tab_strip_model()->GetActiveWebContents()->GetController()); | 225 browser()->tab_strip_model()->GetActiveWebContents()->GetController()); |
| 224 chrome::GoForward(browser(), NEW_FOREGROUND_TAB); | 226 chrome::GoForward(browser(), NEW_FOREGROUND_TAB); |
| 225 ASSERT_EQ(4, browser()->tab_strip_model()->active_index()); | 227 ASSERT_EQ(4, browser()->tab_strip_model()->active_index()); |
| 226 ASSERT_EQ(url2, | 228 ASSERT_EQ(url2, |
| 227 browser()->tab_strip_model()->GetActiveWebContents()-> | 229 browser()->tab_strip_model()->GetActiveWebContents()-> |
| 228 GetVisibleURL()); | 230 GetVisibleURL()); |
| 229 } | 231 } |
| 232 // Note: Run these tests for non-android platform only. Since TabStripModel | |
| 233 // doesn't exist for Android. | |
| 234 #if !defined(OS_ANDROID) | |
|
Alexei Svitkine (slow)
2014/08/04 15:49:15
I don't think this ifdef is needed - the test righ
| |
| 235 TEST_F(BrowserCommandsTest, OnMaxZoomIn) { | |
| 236 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
| 237 | |
| 238 GURL url("http://www.google.com"); | |
| 239 AddTab(browser(), url); | |
| 240 content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0); | |
| 241 | |
| 242 // Continue to zoom in until zoom percent reaches 500. | |
| 243 for (int i = 0; i < 9; ++i) { | |
| 244 chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_IN); | |
| 245 } | |
| 246 | |
| 247 // 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 | |
| 249 // from the context menu since it breaks try jobs on bots. | |
| 250 if (chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)) | |
| 251 chrome::UpdateCommandEnabled(browser(), IDC_ZOOM_PLUS, false); | |
| 252 | |
| 253 ZoomController* zoom_controller = ZoomController::FromWebContents(contents1); | |
| 254 EXPECT_EQ(zoom_controller->GetZoomPercent(), 500.0f); | |
| 255 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | |
| 256 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | |
| 257 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | |
| 258 } | |
| 259 | |
| 260 TEST_F(BrowserCommandsTest, OnMaxZoomOut) { | |
| 261 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
| 262 | |
| 263 GURL url("http://www.google.com"); | |
| 264 AddTab(browser(), url); | |
| 265 content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0); | |
| 266 | |
| 267 // Continue to zoom out until zoom percent reaches 25. | |
| 268 for (int i = 0; i < 7; ++i) { | |
| 269 chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_OUT); | |
| 270 } | |
| 271 | |
| 272 ZoomController* zoom_controller = ZoomController::FromWebContents(contents1); | |
| 273 EXPECT_EQ(zoom_controller->GetZoomPercent(), 25.0f); | |
| 274 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | |
| 275 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | |
| 276 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | |
| 277 } | |
| 278 | |
| 279 TEST_F(BrowserCommandsTest, OnZoomReset) { | |
| 280 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
| 281 | |
| 282 GURL url("http://www.google.com"); | |
| 283 AddTab(browser(), url); | |
| 284 content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0); | |
| 285 | |
| 286 // Change the zoom percentage to 100. | |
| 287 chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_RESET); | |
| 288 | |
| 289 ZoomController* zoom_controller = ZoomController::FromWebContents(contents1); | |
| 290 EXPECT_EQ(zoom_controller->GetZoomPercent(), 100.0f); | |
| 291 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | |
| 292 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | |
| 293 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | |
| 294 } | |
| 295 | |
| 296 TEST_F(BrowserCommandsTest, OnZoomLevelChanged) { | |
| 297 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
| 298 | |
| 299 GURL url("http://www.google.com"); | |
| 300 AddTab(browser(), url); | |
| 301 content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0); | |
| 302 | |
| 303 // Changing zoom percentage from default should enable all the zoom | |
| 304 // NSMenuItems. | |
| 305 chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_IN); | |
| 306 | |
| 307 ZoomController* zoom_controller = ZoomController::FromWebContents(contents1); | |
| 308 EXPECT_EQ(zoom_controller->GetZoomPercent(), 110.0f); | |
| 309 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | |
| 310 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | |
| 311 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | |
| 312 } | |
| 313 | |
| 314 TEST_F(BrowserCommandsTest, OnZoomChangedForActiveTab) { | |
| 315 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | |
| 316 | |
| 317 GURL url("http://www.google.com"); | |
| 318 GURL url1("http://code.google.com"); | |
| 319 | |
| 320 // Add First tab. | |
| 321 AddTab(browser(), url); | |
| 322 AddTab(browser(), url1); | |
| 323 content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0); | |
| 324 | |
| 325 ZoomController* zoom_controller = ZoomController::FromWebContents(contents1); | |
| 326 EXPECT_EQ(zoom_controller->GetZoomPercent(), 100.0f); | |
| 327 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | |
| 328 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | |
| 329 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | |
| 330 | |
| 331 // Add Second tab. | |
| 332 content::WebContents* contents2 = tab_strip_model->GetWebContentsAt(1); | |
| 333 | |
| 334 tab_strip_model->ActivateTabAt(1, true); | |
| 335 EXPECT_TRUE(tab_strip_model->IsTabSelected(1)); | |
| 336 chrome_page_zoom::Zoom(contents2, content::PAGE_ZOOM_OUT); | |
| 337 | |
| 338 zoom_controller = ZoomController::FromWebContents(contents2); | |
| 339 EXPECT_EQ(zoom_controller->GetZoomPercent(), 90.0f); | |
| 340 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | |
| 341 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | |
| 342 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | |
| 343 } | |
| 344 #endif | |
| OLD | NEW |