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

Side by Side Diff: chrome/browser/browser_commands_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: Fixed Nit 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 | « AUTHORS ('k') | chrome/browser/ui/browser.cc » ('j') | 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 #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
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
233 TEST_F(BrowserCommandsTest, OnMaxZoomIn) {
234 TabStripModel* tab_strip_model = browser()->tab_strip_model();
235
236 GURL url("http://www.google.com");
237 AddTab(browser(), url);
238 content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0);
239
240 // Continue to zoom in until zoom percent reaches 500.
241 for (int i = 0; i < 9; ++i) {
242 chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_IN);
243 }
244
245 // TODO(a.sarkar.arun@gmail.com): Figure out why Zoom-In menu item is not
246 // disabled after Max-zoom is reached. Force disable Zoom-In menu item
247 // from the context menu since it breaks try jobs on bots.
248 if (chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS))
249 chrome::UpdateCommandEnabled(browser(), IDC_ZOOM_PLUS, false);
250
251 ZoomController* zoom_controller = ZoomController::FromWebContents(contents1);
252 EXPECT_EQ(zoom_controller->GetZoomPercent(), 500.0f);
253 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
254 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
255 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
256 }
257
258 TEST_F(BrowserCommandsTest, OnMaxZoomOut) {
259 TabStripModel* tab_strip_model = browser()->tab_strip_model();
260
261 GURL url("http://www.google.com");
262 AddTab(browser(), url);
263 content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0);
264
265 // Continue to zoom out until zoom percent reaches 25.
266 for (int i = 0; i < 7; ++i) {
267 chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_OUT);
268 }
269
270 ZoomController* zoom_controller = ZoomController::FromWebContents(contents1);
271 EXPECT_EQ(zoom_controller->GetZoomPercent(), 25.0f);
272 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
273 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
274 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
275 }
276
277 TEST_F(BrowserCommandsTest, OnZoomReset) {
278 TabStripModel* tab_strip_model = browser()->tab_strip_model();
279
280 GURL url("http://www.google.com");
281 AddTab(browser(), url);
282 content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0);
283
284 // Change the zoom percentage to 100.
285 chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_RESET);
286
287 ZoomController* zoom_controller = ZoomController::FromWebContents(contents1);
288 EXPECT_EQ(zoom_controller->GetZoomPercent(), 100.0f);
289 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
290 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
291 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
292 }
293
294 TEST_F(BrowserCommandsTest, OnZoomLevelChanged) {
295 TabStripModel* tab_strip_model = browser()->tab_strip_model();
296
297 GURL url("http://www.google.com");
298 AddTab(browser(), url);
299 content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0);
300
301 // Changing zoom percentage from default should enable all the zoom
302 // NSMenuItems.
303 chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_IN);
304
305 ZoomController* zoom_controller = ZoomController::FromWebContents(contents1);
306 EXPECT_EQ(zoom_controller->GetZoomPercent(), 110.0f);
307 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
308 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
309 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
310 }
311
312 TEST_F(BrowserCommandsTest, OnZoomChangedForActiveTab) {
313 TabStripModel* tab_strip_model = browser()->tab_strip_model();
314
315 GURL url("http://www.google.com");
316 GURL url1("http://code.google.com");
317
318 // Add First tab.
319 AddTab(browser(), url);
320 AddTab(browser(), url1);
321 content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0);
322
323 ZoomController* zoom_controller = ZoomController::FromWebContents(contents1);
324 EXPECT_EQ(zoom_controller->GetZoomPercent(), 100.0f);
325 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
326 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
327 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
328
329 // Add Second tab.
330 content::WebContents* contents2 = tab_strip_model->GetWebContentsAt(1);
331
332 tab_strip_model->ActivateTabAt(1, true);
333 EXPECT_TRUE(tab_strip_model->IsTabSelected(1));
334 chrome_page_zoom::Zoom(contents2, content::PAGE_ZOOM_OUT);
335
336 zoom_controller = ZoomController::FromWebContents(contents2);
337 EXPECT_EQ(zoom_controller->GetZoomPercent(), 90.0f);
338 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
339 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
340 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
341 }
OLDNEW
« no previous file with comments | « AUTHORS ('k') | chrome/browser/ui/browser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698