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

Side by Side Diff: chrome/browser/browser_commands_unittest.cc

Issue 847703003: Refactor to move chrome_page_zoom functions to components/ui/zoom. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Mac compile. Created 5 years, 11 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 | « no previous file | chrome/browser/chrome_page_zoom.h » ('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"
8 #include "chrome/browser/ui/browser_command_controller.h" 7 #include "chrome/browser/ui/browser_command_controller.h"
9 #include "chrome/browser/ui/browser_commands.h" 8 #include "chrome/browser/ui/browser_commands.h"
10 #include "chrome/browser/ui/browser_finder.h" 9 #include "chrome/browser/ui/browser_finder.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" 10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/common/url_constants.h" 11 #include "chrome/common/url_constants.h"
13 #include "chrome/test/base/browser_with_test_window_test.h" 12 #include "chrome/test/base/browser_with_test_window_test.h"
14 #include "chrome/test/base/testing_profile.h" 13 #include "chrome/test/base/testing_profile.h"
15 #include "components/bookmarks/browser/bookmark_model.h" 14 #include "components/bookmarks/browser/bookmark_model.h"
16 #include "components/bookmarks/test/bookmark_test_helpers.h" 15 #include "components/bookmarks/test/bookmark_test_helpers.h"
16 #include "components/ui/zoom/page_zoom.h"
17 #include "components/ui/zoom/zoom_controller.h" 17 #include "components/ui/zoom/zoom_controller.h"
18 #include "content/public/browser/navigation_controller.h" 18 #include "content/public/browser/navigation_controller.h"
19 #include "content/public/browser/navigation_entry.h" 19 #include "content/public/browser/navigation_entry.h"
20 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
21 21
22 typedef BrowserWithTestWindowTest BrowserCommandsTest; 22 typedef BrowserWithTestWindowTest BrowserCommandsTest;
23 23
24 using bookmarks::BookmarkModel; 24 using bookmarks::BookmarkModel;
25 using content::OpenURLParams; 25 using content::OpenURLParams;
26 using content::Referrer; 26 using content::Referrer;
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 234
235 TEST_F(BrowserCommandsTest, OnMaxZoomIn) { 235 TEST_F(BrowserCommandsTest, OnMaxZoomIn) {
236 TabStripModel* tab_strip_model = browser()->tab_strip_model(); 236 TabStripModel* tab_strip_model = browser()->tab_strip_model();
237 237
238 GURL url("http://www.google.com"); 238 GURL url("http://www.google.com");
239 AddTab(browser(), url); 239 AddTab(browser(), url);
240 content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0); 240 content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0);
241 241
242 // Continue to zoom in until zoom percent reaches 500. 242 // Continue to zoom in until zoom percent reaches 500.
243 for (int i = 0; i < 9; ++i) { 243 for (int i = 0; i < 9; ++i) {
244 chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_IN); 244 ui_zoom::PageZoom::Zoom(contents1, content::PAGE_ZOOM_IN);
245 } 245 }
246 246
247 // TODO(a.sarkar.arun@gmail.com): Figure out why Zoom-In menu item is not 247 // TODO(a.sarkar.arun@gmail.com): Figure out why Zoom-In menu item is not
248 // disabled after Max-zoom is reached. Force disable Zoom-In menu item 248 // disabled after Max-zoom is reached. Force disable Zoom-In menu item
249 // from the context menu since it breaks try jobs on bots. 249 // from the context menu since it breaks try jobs on bots.
250 if (chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)) 250 if (chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS))
251 chrome::UpdateCommandEnabled(browser(), IDC_ZOOM_PLUS, false); 251 chrome::UpdateCommandEnabled(browser(), IDC_ZOOM_PLUS, false);
252 252
253 ZoomController* zoom_controller = ZoomController::FromWebContents(contents1); 253 ZoomController* zoom_controller = ZoomController::FromWebContents(contents1);
254 EXPECT_EQ(zoom_controller->GetZoomPercent(), 500.0f); 254 EXPECT_EQ(zoom_controller->GetZoomPercent(), 500.0f);
255 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); 255 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
256 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); 256 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
257 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); 257 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
258 } 258 }
259 259
260 TEST_F(BrowserCommandsTest, OnMaxZoomOut) { 260 TEST_F(BrowserCommandsTest, OnMaxZoomOut) {
261 TabStripModel* tab_strip_model = browser()->tab_strip_model(); 261 TabStripModel* tab_strip_model = browser()->tab_strip_model();
262 262
263 GURL url("http://www.google.com"); 263 GURL url("http://www.google.com");
264 AddTab(browser(), url); 264 AddTab(browser(), url);
265 content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0); 265 content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0);
266 266
267 // Continue to zoom out until zoom percent reaches 25. 267 // Continue to zoom out until zoom percent reaches 25.
268 for (int i = 0; i < 7; ++i) { 268 for (int i = 0; i < 7; ++i) {
269 chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_OUT); 269 ui_zoom::PageZoom::Zoom(contents1, content::PAGE_ZOOM_OUT);
270 } 270 }
271 271
272 ZoomController* zoom_controller = ZoomController::FromWebContents(contents1); 272 ZoomController* zoom_controller = ZoomController::FromWebContents(contents1);
273 EXPECT_EQ(zoom_controller->GetZoomPercent(), 25.0f); 273 EXPECT_EQ(zoom_controller->GetZoomPercent(), 25.0f);
274 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); 274 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
275 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); 275 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
276 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); 276 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
277 } 277 }
278 278
279 TEST_F(BrowserCommandsTest, OnZoomReset) { 279 TEST_F(BrowserCommandsTest, OnZoomReset) {
280 TabStripModel* tab_strip_model = browser()->tab_strip_model(); 280 TabStripModel* tab_strip_model = browser()->tab_strip_model();
281 281
282 GURL url("http://www.google.com"); 282 GURL url("http://www.google.com");
283 AddTab(browser(), url); 283 AddTab(browser(), url);
284 content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0); 284 content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0);
285 285
286 // Change the zoom percentage to 100. 286 // Change the zoom percentage to 100.
287 chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_RESET); 287 ui_zoom::PageZoom::Zoom(contents1, content::PAGE_ZOOM_RESET);
288 288
289 ZoomController* zoom_controller = ZoomController::FromWebContents(contents1); 289 ZoomController* zoom_controller = ZoomController::FromWebContents(contents1);
290 EXPECT_EQ(zoom_controller->GetZoomPercent(), 100.0f); 290 EXPECT_EQ(zoom_controller->GetZoomPercent(), 100.0f);
291 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); 291 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
292 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); 292 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
293 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); 293 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
294 } 294 }
295 295
296 TEST_F(BrowserCommandsTest, OnZoomLevelChanged) { 296 TEST_F(BrowserCommandsTest, OnZoomLevelChanged) {
297 TabStripModel* tab_strip_model = browser()->tab_strip_model(); 297 TabStripModel* tab_strip_model = browser()->tab_strip_model();
298 298
299 GURL url("http://www.google.com"); 299 GURL url("http://www.google.com");
300 AddTab(browser(), url); 300 AddTab(browser(), url);
301 content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0); 301 content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0);
302 302
303 // Changing zoom percentage from default should enable all the zoom 303 // Changing zoom percentage from default should enable all the zoom
304 // NSMenuItems. 304 // NSMenuItems.
305 chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_IN); 305 ui_zoom::PageZoom::Zoom(contents1, content::PAGE_ZOOM_IN);
306 306
307 ZoomController* zoom_controller = ZoomController::FromWebContents(contents1); 307 ZoomController* zoom_controller = ZoomController::FromWebContents(contents1);
308 EXPECT_EQ(zoom_controller->GetZoomPercent(), 110.0f); 308 EXPECT_EQ(zoom_controller->GetZoomPercent(), 110.0f);
309 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); 309 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
310 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); 310 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
311 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); 311 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
312 } 312 }
313 313
314 TEST_F(BrowserCommandsTest, OnZoomChangedForActiveTab) { 314 TEST_F(BrowserCommandsTest, OnZoomChangedForActiveTab) {
315 TabStripModel* tab_strip_model = browser()->tab_strip_model(); 315 TabStripModel* tab_strip_model = browser()->tab_strip_model();
(...skipping 10 matching lines...) Expand all
326 EXPECT_EQ(zoom_controller->GetZoomPercent(), 100.0f); 326 EXPECT_EQ(zoom_controller->GetZoomPercent(), 100.0f);
327 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); 327 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
328 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); 328 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
329 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); 329 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
330 330
331 // Add Second tab. 331 // Add Second tab.
332 content::WebContents* contents2 = tab_strip_model->GetWebContentsAt(1); 332 content::WebContents* contents2 = tab_strip_model->GetWebContentsAt(1);
333 333
334 tab_strip_model->ActivateTabAt(1, true); 334 tab_strip_model->ActivateTabAt(1, true);
335 EXPECT_TRUE(tab_strip_model->IsTabSelected(1)); 335 EXPECT_TRUE(tab_strip_model->IsTabSelected(1));
336 chrome_page_zoom::Zoom(contents2, content::PAGE_ZOOM_OUT); 336 ui_zoom::PageZoom::Zoom(contents2, content::PAGE_ZOOM_OUT);
337 337
338 zoom_controller = ZoomController::FromWebContents(contents2); 338 zoom_controller = ZoomController::FromWebContents(contents2);
339 EXPECT_EQ(zoom_controller->GetZoomPercent(), 90.0f); 339 EXPECT_EQ(zoom_controller->GetZoomPercent(), 90.0f);
340 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); 340 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
341 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); 341 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
342 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); 342 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
343 } 343 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chrome_page_zoom.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698