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 82e3372d503fd183d707d06370c74951a15b49b3..8cd14ce96ad700a8cea0bf54a876d45308abc01e 100644 |
| --- a/chrome/browser/ui/zoom/zoom_controller_unittest.cc |
| +++ b/chrome/browser/ui/zoom/zoom_controller_unittest.cc |
| @@ -2,22 +2,36 @@ |
| // 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" |
| +using content::SiteInstance; |
| +using content::WebContents; |
| +using content::WebContentsTester; |
|
Alexei Svitkine (slow)
2014/07/31 15:43:33
Do you need these using decls - I thought you remo
sarka
2014/07/31 16:05:57
My bad. Removing this patch.
Thanks
|
| + |
| bool operator==(const ZoomController::ZoomChangedEventData& lhs, |
| const ZoomController::ZoomChangedEventData& rhs) { |
| return lhs.web_contents == rhs.web_contents && |
| @@ -125,3 +139,136 @@ TEST_F(ZoomControllerTest, Observe_ZoomController) { |
| zoom_controller_->SetZoomLevel(new_zoom_level); |
| } |
| + |
| +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); |
| +}; |
| + |
| +TEST_F(ZoomCommandsUnitTest, OnMaxZoomIn) { |
| + |
|
Alexei Svitkine (slow)
2014/07/31 15:43:33
Nit: Remove empty line.
sarka
2014/07/31 16:02:03
Done.
|
| + 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(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); |
| + |
| + 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); |
| + |
| + for (int i = 0; i < 7; ++i) { |
|
Alexei Svitkine (slow)
2014/07/31 15:41:56
Please add a comment explaining the purpose of thi
sarka
2014/07/31 16:02:03
Done.
|
| + chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_OUT); |
| + } |
| + |
| + 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)); |
| +} |
| + |