Chromium Code Reviews| Index: chrome/browser/ui/zoom/zoom_controller_unittest.cc |
| diff --git a/chrome/browser/ui/zoom/zoom_controller_unittest.cc b/chrome/browser/ui/zoom/zoom_controller_unittest.cc |
| index cba7933eef340254d99e31d9b7bc48a618e77919..16030644091ec1c13fa2807a14c4787b5cb05984 100644 |
| --- a/chrome/browser/ui/zoom/zoom_controller_unittest.cc |
| +++ b/chrome/browser/ui/zoom/zoom_controller_unittest.cc |
| @@ -2,19 +2,29 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| + |
| #include "base/message_loop/message_loop.h" |
| #include "base/prefs/pref_service.h" |
| +#include "chrome/app/chrome_command_ids.h" |
| +#include "chrome/browser/chrome_page_zoom.h" |
| #include "chrome/browser/ui/browser.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/browser/ui/zoom/zoom_observer.h" |
| #include "chrome/common/pref_names.h" |
| +#include "chrome/test/base/browser_with_test_window_test.h" |
| #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| #include "chrome/test/base/testing_profile.h" |
| #include "content/public/browser/host_zoom_map.h" |
| #include "content/public/browser/navigation_details.h" |
| +#include "content/public/browser/site_instance.h" |
| +#include "content/public/browser/web_contents.h" |
| #include "content/public/common/frame_navigate_params.h" |
| #include "content/public/test/test_utils.h" |
| +#include "content/public/test/web_contents_tester.h" |
| #include "testing/gmock/include/gmock/gmock.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -61,3 +71,133 @@ TEST_F(ZoomControllerTest, Observe) { |
| host_zoom_map->SetZoomLevelForHost(std::string(), 110.0f); |
| } |
| + |
| +class ZoomCommandsUnitTest : public BrowserWithTestWindowTest { |
| + public: |
| + ZoomCommandsUnitTest() {} |
| + virtual ~ZoomCommandsUnitTest() {} |
| + |
| + content::WebContents* CreateTestWebContents() { |
| + return content::WebContentsTester::CreateTestWebContents( |
| + profile(), content::SiteInstance::Create(profile())); |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(ZoomCommandsUnitTest); |
| + protected: |
| + TestZoomObserver zoom_observer_; |
|
Alexei Svitkine (slow)
2014/07/30 19:08:14
Nit: Protected should be above private:
Also, add
|
| +}; |
| + |
| +TEST_F(ZoomCommandsUnitTest, OnMaxZoomIn) { |
| + |
| + TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| + |
| + GURL url("http://www.google.com"); |
| + content::WebContents* contents1 = CreateTestWebContents(); |
| + tab_strip_model->AppendWebContents(contents1, true); |
| + content::WebContentsTester::For(contents1)->NavigateAndCommit(url); |
| + |
| + for (int i = 0; i < 9; ++i) { |
| + chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_IN); |
| + } |
| + |
| + // TODO: Figure out why Zoom-In is not disabled after Max-zoom is reached. |
|
Alexei Svitkine (slow)
2014/07/30 19:08:14
TODO's should have a username behind them. (e.g. T
|
| + // Force to disable Zoom-In from context menu since it breaks try bots. |
| + if (chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)) |
| + chrome::UpdateCommandEnabled(browser(), IDC_ZOOM_PLUS, false); |
| + |
| + bool dummy = false; |
| + EXPECT_EQ(contents1->GetZoomPercent(&dummy, &dummy), 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(ZoomCommandsUnitTest, OnMaxZoomOut) { |
| + TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| + |
| + GURL url("http://www.google.com"); |
| + content::WebContents* contents1 = CreateTestWebContents(); |
| + tab_strip_model->AppendWebContents(contents1, true); |
| + content::WebContentsTester::For(contents1)->NavigateAndCommit(url); |
| + for (int i = 0; i < 7; ++i) { |
| + chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_OUT); |
| + } |
| + |
| + bool dummy = false; |
| + |
| + EXPECT_EQ(contents1->GetZoomPercent(&dummy, &dummy), 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(ZoomCommandsUnitTest, OnZoomReset) { |
| + TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| + |
| + GURL url("http://www.google.com"); |
| + content::WebContents* contents1 = CreateTestWebContents(); |
| + tab_strip_model->AppendWebContents(contents1, true); |
| + content::WebContentsTester::For(contents1)->NavigateAndCommit(url); |
| + |
| + chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_RESET); |
| + |
| + bool dummy = false; |
| + |
| + EXPECT_EQ(contents1->GetZoomPercent(&dummy, &dummy), 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(ZoomCommandsUnitTest, OnZoomLevelChanged) { |
| + TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| + |
| + GURL url("http://www.google.com"); |
| + content::WebContents* contents1 = CreateTestWebContents(); |
| + tab_strip_model->AppendWebContents(contents1, true); |
| + content::WebContentsTester::For(contents1)->NavigateAndCommit(url); |
| + |
| + chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_IN); |
| + |
| + bool dummy = false; |
| + |
| + EXPECT_EQ(contents1->GetZoomPercent(&dummy, &dummy), 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(ZoomCommandsUnitTest, OnZoomChangedForActiveTab) { |
| + TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| + |
| + GURL url("http://www.google.com"); |
| + GURL url1("http://code.google.com"); |
| + |
| + // Add First tab |
| + content::WebContents* contents1 = CreateTestWebContents(); |
| + tab_strip_model->AppendWebContents(contents1, true); |
| + content::WebContentsTester::For(contents1)->NavigateAndCommit(url); |
| + |
| + bool dummy = false; |
| + |
| + EXPECT_EQ(contents1->GetZoomPercent(&dummy, &dummy), 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 = CreateTestWebContents(); |
| + tab_strip_model->AppendWebContents(contents2, true); |
| + content::WebContentsTester::For(contents2)->NavigateAndCommit(url1); |
| + |
| + tab_strip_model->ActivateTabAt(1, true); |
| + EXPECT_TRUE(tab_strip_model->IsTabSelected(1)); |
| + chrome_page_zoom::Zoom(contents2, content::PAGE_ZOOM_OUT); |
| + |
| + EXPECT_EQ(contents2->GetZoomPercent(&dummy, &dummy), 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)); |
| +} |
| + |