Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1674)

Side by Side Diff: chrome/browser/ui/zoom/zoom_controller_unittest.cc

Issue 310913002: Issue 32919: Update the Zoom NSMenuItems (Zoom-In/Zoom-out/Actual-Size) when the zoom state changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Modified zoom_controller_unittests to pass try jobs on bots. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/browser_commands.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
5 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
6 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/chrome_page_zoom.h"
7 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_command_controller.h"
12 #include "chrome/browser/ui/browser_commands.h"
8 #include "chrome/browser/ui/browser_finder.h" 13 #include "chrome/browser/ui/browser_finder.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
9 #include "chrome/browser/ui/zoom/zoom_controller.h" 15 #include "chrome/browser/ui/zoom/zoom_controller.h"
10 #include "chrome/browser/ui/zoom/zoom_observer.h" 16 #include "chrome/browser/ui/zoom/zoom_observer.h"
11 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "chrome/test/base/browser_with_test_window_test.h"
12 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 19 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
13 #include "chrome/test/base/testing_profile.h" 20 #include "chrome/test/base/testing_profile.h"
14 #include "content/public/browser/host_zoom_map.h" 21 #include "content/public/browser/host_zoom_map.h"
15 #include "content/public/browser/navigation_details.h" 22 #include "content/public/browser/navigation_details.h"
23 #include "content/public/browser/site_instance.h"
24 #include "content/public/browser/web_contents.h"
16 #include "content/public/common/frame_navigate_params.h" 25 #include "content/public/common/frame_navigate_params.h"
17 #include "content/public/test/test_utils.h" 26 #include "content/public/test/test_utils.h"
27 #include "content/public/test/web_contents_tester.h"
18 #include "testing/gmock/include/gmock/gmock.h" 28 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
20 30
21 class TestZoomObserver : public ZoomObserver { 31 class TestZoomObserver : public ZoomObserver {
22 public: 32 public:
23 MOCK_METHOD2(OnZoomChanged, void(content::WebContents*, bool)); 33 MOCK_METHOD2(OnZoomChanged, void(content::WebContents*, bool));
24 }; 34 };
25 35
26 class ZoomControllerTest : public ChromeRenderViewHostTestHarness { 36 class ZoomControllerTest : public ChromeRenderViewHostTestHarness {
27 public: 37 public:
(...skipping 26 matching lines...) Expand all
54 64
55 TEST_F(ZoomControllerTest, Observe) { 65 TEST_F(ZoomControllerTest, Observe) {
56 EXPECT_CALL(zoom_observer_, OnZoomChanged(web_contents(), false)).Times(1); 66 EXPECT_CALL(zoom_observer_, OnZoomChanged(web_contents(), false)).Times(1);
57 67
58 content::HostZoomMap* host_zoom_map = 68 content::HostZoomMap* host_zoom_map =
59 content::HostZoomMap::GetForBrowserContext( 69 content::HostZoomMap::GetForBrowserContext(
60 web_contents()->GetBrowserContext()); 70 web_contents()->GetBrowserContext());
61 71
62 host_zoom_map->SetZoomLevelForHost(std::string(), 110.0f); 72 host_zoom_map->SetZoomLevelForHost(std::string(), 110.0f);
63 } 73 }
74
75 class ZoomCommandsUnitTest : public BrowserWithTestWindowTest {
76 public:
77 ZoomCommandsUnitTest() {}
78 virtual ~ZoomCommandsUnitTest() {}
79
80 content::WebContents* CreateTestWebContents() {
81 return content::WebContentsTester::CreateTestWebContents(
82 profile(), content::SiteInstance::Create(profile()));
83 }
84
85 private:
86 DISALLOW_COPY_AND_ASSIGN(ZoomCommandsUnitTest);
87 protected:
88 TestZoomObserver zoom_observer_;
Alexei Svitkine (slow) 2014/07/30 19:08:14 Nit: Protected should be above private: Also, add
89 };
90
91 TEST_F(ZoomCommandsUnitTest, OnMaxZoomIn) {
92
93 TabStripModel* tab_strip_model = browser()->tab_strip_model();
94
95 GURL url("http://www.google.com");
96 content::WebContents* contents1 = CreateTestWebContents();
97 tab_strip_model->AppendWebContents(contents1, true);
98 content::WebContentsTester::For(contents1)->NavigateAndCommit(url);
99
100 for (int i = 0; i < 9; ++i) {
101 chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_IN);
102 }
103
104 // 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
105 // Force to disable Zoom-In from context menu since it breaks try bots.
106 if (chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS))
107 chrome::UpdateCommandEnabled(browser(), IDC_ZOOM_PLUS, false);
108
109 bool dummy = false;
110 EXPECT_EQ(contents1->GetZoomPercent(&dummy, &dummy), 500.0f);
111 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
112 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
113 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
114 }
115
116 TEST_F(ZoomCommandsUnitTest, OnMaxZoomOut) {
117 TabStripModel* tab_strip_model = browser()->tab_strip_model();
118
119 GURL url("http://www.google.com");
120 content::WebContents* contents1 = CreateTestWebContents();
121 tab_strip_model->AppendWebContents(contents1, true);
122 content::WebContentsTester::For(contents1)->NavigateAndCommit(url);
123 for (int i = 0; i < 7; ++i) {
124 chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_OUT);
125 }
126
127 bool dummy = false;
128
129 EXPECT_EQ(contents1->GetZoomPercent(&dummy, &dummy), 25.0f);
130 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
131 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
132 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
133 }
134
135 TEST_F(ZoomCommandsUnitTest, OnZoomReset) {
136 TabStripModel* tab_strip_model = browser()->tab_strip_model();
137
138 GURL url("http://www.google.com");
139 content::WebContents* contents1 = CreateTestWebContents();
140 tab_strip_model->AppendWebContents(contents1, true);
141 content::WebContentsTester::For(contents1)->NavigateAndCommit(url);
142
143 chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_RESET);
144
145 bool dummy = false;
146
147 EXPECT_EQ(contents1->GetZoomPercent(&dummy, &dummy), 100.0f);
148 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
149 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
150 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
151 }
152
153 TEST_F(ZoomCommandsUnitTest, OnZoomLevelChanged) {
154 TabStripModel* tab_strip_model = browser()->tab_strip_model();
155
156 GURL url("http://www.google.com");
157 content::WebContents* contents1 = CreateTestWebContents();
158 tab_strip_model->AppendWebContents(contents1, true);
159 content::WebContentsTester::For(contents1)->NavigateAndCommit(url);
160
161 chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_IN);
162
163 bool dummy = false;
164
165 EXPECT_EQ(contents1->GetZoomPercent(&dummy, &dummy), 110.0f);
166 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
167 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
168 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
169 }
170
171 TEST_F(ZoomCommandsUnitTest, OnZoomChangedForActiveTab) {
172 TabStripModel* tab_strip_model = browser()->tab_strip_model();
173
174 GURL url("http://www.google.com");
175 GURL url1("http://code.google.com");
176
177 // Add First tab
178 content::WebContents* contents1 = CreateTestWebContents();
179 tab_strip_model->AppendWebContents(contents1, true);
180 content::WebContentsTester::For(contents1)->NavigateAndCommit(url);
181
182 bool dummy = false;
183
184 EXPECT_EQ(contents1->GetZoomPercent(&dummy, &dummy), 100.0f);
185 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
186 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
187 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
188
189 // Add Second tab
190 content::WebContents* contents2 = CreateTestWebContents();
191 tab_strip_model->AppendWebContents(contents2, true);
192 content::WebContentsTester::For(contents2)->NavigateAndCommit(url1);
193
194 tab_strip_model->ActivateTabAt(1, true);
195 EXPECT_TRUE(tab_strip_model->IsTabSelected(1));
196 chrome_page_zoom::Zoom(contents2, content::PAGE_ZOOM_OUT);
197
198 EXPECT_EQ(contents2->GetZoomPercent(&dummy, &dummy), 90.0f);
199 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
200 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
201 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
202 }
203
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_commands.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698