Chromium Code Reviews| Index: chrome/browser/browser_commands_unittest.cc |
| diff --git a/chrome/browser/browser_commands_unittest.cc b/chrome/browser/browser_commands_unittest.cc |
| index 45497e60bb048b3259fa286ca416c5d6a3d9124d..dac47af8d8fdd35b0514816522e4994b6c5176e1 100644 |
| --- a/chrome/browser/browser_commands_unittest.cc |
| +++ b/chrome/browser/browser_commands_unittest.cc |
| @@ -4,10 +4,12 @@ |
| #include "chrome/app/chrome_command_ids.h" |
| #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| +#include "chrome/browser/chrome_page_zoom.h" |
| #include "chrome/browser/ui/browser_command_controller.h" |
| #include "chrome/browser/ui/browser_commands.h" |
| #include "chrome/browser/ui/browser_finder.h" |
| #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| +#include "chrome/browser/ui/zoom/zoom_controller.h" |
| #include "chrome/common/url_constants.h" |
| #include "chrome/test/base/browser_with_test_window_test.h" |
| #include "chrome/test/base/testing_profile.h" |
| @@ -227,3 +229,116 @@ TEST_F(BrowserCommandsTest, BackForwardInNewTab) { |
| browser()->tab_strip_model()->GetActiveWebContents()-> |
| GetVisibleURL()); |
| } |
| +// Note: Run these tests for non-android platform only. Since TabStripModel |
| +// doesn't exist for Android. |
| +#if !defined(OS_ANDROID) |
|
Alexei Svitkine (slow)
2014/08/04 15:49:15
I don't think this ifdef is needed - the test righ
|
| +TEST_F(BrowserCommandsTest, OnMaxZoomIn) { |
| + TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| + |
| + GURL url("http://www.google.com"); |
| + AddTab(browser(), url); |
| + content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0); |
| + |
| + // Continue to zoom in until zoom percent reaches 500. |
| + for (int i = 0; i < 9; ++i) { |
| + chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_IN); |
| + } |
| + |
| + // TODO(a.sarkar.arun@gmail.com): Figure out why Zoom-In menu item is not |
| + // disabled after Max-zoom is reached. Force disable Zoom-In menu item |
| + // from the context menu since it breaks try jobs on bots. |
| + if (chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)) |
| + chrome::UpdateCommandEnabled(browser(), IDC_ZOOM_PLUS, false); |
| + |
| + ZoomController* zoom_controller = ZoomController::FromWebContents(contents1); |
| + EXPECT_EQ(zoom_controller->GetZoomPercent(), 500.0f); |
| + EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); |
| + EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); |
| + EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); |
| +} |
| + |
| +TEST_F(BrowserCommandsTest, OnMaxZoomOut) { |
| + TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| + |
| + GURL url("http://www.google.com"); |
| + AddTab(browser(), url); |
| + content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0); |
| + |
| + // Continue to zoom out until zoom percent reaches 25. |
| + for (int i = 0; i < 7; ++i) { |
| + chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_OUT); |
| + } |
| + |
| + ZoomController* zoom_controller = ZoomController::FromWebContents(contents1); |
| + EXPECT_EQ(zoom_controller->GetZoomPercent(), 25.0f); |
| + EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); |
| + EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); |
| + EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); |
| +} |
| + |
| +TEST_F(BrowserCommandsTest, OnZoomReset) { |
| + TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| + |
| + GURL url("http://www.google.com"); |
| + AddTab(browser(), url); |
| + content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0); |
| + |
| + // Change the zoom percentage to 100. |
| + chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_RESET); |
| + |
| + ZoomController* zoom_controller = ZoomController::FromWebContents(contents1); |
| + EXPECT_EQ(zoom_controller->GetZoomPercent(), 100.0f); |
| + EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); |
| + EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); |
| + EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); |
| +} |
| + |
| +TEST_F(BrowserCommandsTest, OnZoomLevelChanged) { |
| + TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| + |
| + GURL url("http://www.google.com"); |
| + AddTab(browser(), url); |
| + content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0); |
| + |
| + // Changing zoom percentage from default should enable all the zoom |
| + // NSMenuItems. |
| + chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_IN); |
| + |
| + ZoomController* zoom_controller = ZoomController::FromWebContents(contents1); |
| + EXPECT_EQ(zoom_controller->GetZoomPercent(), 110.0f); |
| + EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); |
| + EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); |
| + EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); |
| +} |
| + |
| +TEST_F(BrowserCommandsTest, OnZoomChangedForActiveTab) { |
| + TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| + |
| + GURL url("http://www.google.com"); |
| + GURL url1("http://code.google.com"); |
| + |
| + // Add First tab. |
| + AddTab(browser(), url); |
| + AddTab(browser(), url1); |
| + content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0); |
| + |
| + ZoomController* zoom_controller = ZoomController::FromWebContents(contents1); |
| + EXPECT_EQ(zoom_controller->GetZoomPercent(), 100.0f); |
| + EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); |
| + EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); |
| + EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); |
| + |
| + // Add Second tab. |
| + content::WebContents* contents2 = tab_strip_model->GetWebContentsAt(1); |
| + |
| + tab_strip_model->ActivateTabAt(1, true); |
| + EXPECT_TRUE(tab_strip_model->IsTabSelected(1)); |
| + chrome_page_zoom::Zoom(contents2, content::PAGE_ZOOM_OUT); |
| + |
| + zoom_controller = ZoomController::FromWebContents(contents2); |
| + EXPECT_EQ(zoom_controller->GetZoomPercent(), 90.0f); |
| + EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); |
| + EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); |
| + EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); |
| +} |
| +#endif |