blob: 2c39bbbf8b7f08ec52cb76ed1de931f920f6c6dd [file] [log] [blame]
[email protected]93cc27b2012-03-21 12:44:321// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]be3877f2009-01-14 15:51:102// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
avie4d7b6f2015-12-26 00:59:185#include <stddef.h>
6
[email protected]1a3aba82010-11-08 23:52:547#include "chrome/app/chrome_command_ids.h"
[email protected]fa50dea02012-08-01 23:20:378#include "chrome/browser/bookmarks/bookmark_model_factory.h"
[email protected]5d98294912012-06-27 22:57:409#include "chrome/browser/ui/browser_command_controller.h"
[email protected]a37d4b02012-06-25 21:56:1010#include "chrome/browser/ui/browser_commands.h"
[email protected]0665ebe2013-02-13 09:53:1911#include "chrome/browser/ui/browser_finder.h"
[email protected]57892182012-12-03 19:15:3912#include "chrome/browser/ui/tabs/tab_strip_model.h"
a.sarkar.arundaadc712015-02-26 05:39:0813#include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
[email protected]9423d9412009-04-14 22:13:5514#include "chrome/common/url_constants.h"
[email protected]a4ff9eae2011-08-01 19:58:1615#include "chrome/test/base/browser_with_test_window_test.h"
16#include "chrome/test/base/testing_profile.h"
[email protected]a90c8ca2014-05-20 17:16:0417#include "components/bookmarks/browser/bookmark_model.h"
18#include "components/bookmarks/test/bookmark_test_helpers.h"
wjmaclean91ddc472015-01-15 19:58:2719#include "components/ui/zoom/page_zoom.h"
wjmaclean7f63c6b2014-12-09 14:59:5520#include "components/ui/zoom/zoom_controller.h"
[email protected]cdcb1dee2012-01-04 00:46:2021#include "content/public/browser/navigation_controller.h"
[email protected]022af742011-12-28 18:37:2522#include "content/public/browser/navigation_entry.h"
[email protected]6acde6352012-01-04 16:52:2023#include "content/public/browser/web_contents.h"
a.sarkar.arundaadc712015-02-26 05:39:0824#include "testing/gtest/include/gtest/gtest.h"
[email protected]be3877f2009-01-14 15:51:1025
26typedef BrowserWithTestWindowTest BrowserCommandsTest;
27
tfarinaa0ec34e2015-01-12 18:46:4828using bookmarks::BookmarkModel;
[email protected]e5d549d2011-12-28 01:29:2029using content::OpenURLParams;
30using content::Referrer;
[email protected]6acde6352012-01-04 16:52:2031using content::WebContents;
wjmaclean7f63c6b2014-12-09 14:59:5532using ui_zoom::ZoomController;
[email protected]e5d549d2011-12-28 01:29:2033
[email protected]be3877f2009-01-14 15:51:1034// Tests IDC_SELECT_TAB_0, IDC_SELECT_NEXT_TAB, IDC_SELECT_PREVIOUS_TAB and
35// IDC_SELECT_LAST_TAB.
[email protected]6df642082009-08-13 22:31:3736TEST_F(BrowserCommandsTest, TabNavigationAccelerators) {
[email protected]8e09c7af2014-06-10 11:46:1737 GURL about_blank(url::kAboutBlankURL);
[email protected]9423d9412009-04-14 22:13:5538
[email protected]be3877f2009-01-14 15:51:1039 // Create three tabs.
[email protected]9423d9412009-04-14 22:13:5540 AddTab(browser(), about_blank);
41 AddTab(browser(), about_blank);
42 AddTab(browser(), about_blank);
[email protected]be3877f2009-01-14 15:51:1043
44 // Select the second tab.
[email protected]57892182012-12-03 19:15:3945 browser()->tab_strip_model()->ActivateTabAt(1, false);
[email protected]be3877f2009-01-14 15:51:1046
[email protected]5d98294912012-06-27 22:57:4047 CommandUpdater* updater = browser()->command_controller()->command_updater();
48
[email protected]be3877f2009-01-14 15:51:1049 // Navigate to the first tab using an accelerator.
[email protected]5d98294912012-06-27 22:57:4050 updater->ExecuteCommand(IDC_SELECT_TAB_0);
[email protected]57892182012-12-03 19:15:3951 ASSERT_EQ(0, browser()->tab_strip_model()->active_index());
[email protected]be3877f2009-01-14 15:51:1052
53 // Navigate to the second tab using the next accelerators.
[email protected]5d98294912012-06-27 22:57:4054 updater->ExecuteCommand(IDC_SELECT_NEXT_TAB);
[email protected]57892182012-12-03 19:15:3955 ASSERT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]be3877f2009-01-14 15:51:1056
57 // Navigate back to the first tab using the previous accelerators.
[email protected]5d98294912012-06-27 22:57:4058 updater->ExecuteCommand(IDC_SELECT_PREVIOUS_TAB);
[email protected]57892182012-12-03 19:15:3959 ASSERT_EQ(0, browser()->tab_strip_model()->active_index());
[email protected]be3877f2009-01-14 15:51:1060
61 // Navigate to the last tab using the select last accelerator.
[email protected]5d98294912012-06-27 22:57:4062 updater->ExecuteCommand(IDC_SELECT_LAST_TAB);
[email protected]57892182012-12-03 19:15:3963 ASSERT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]be3877f2009-01-14 15:51:1064}
65
66// Tests IDC_DUPLICATE_TAB.
67TEST_F(BrowserCommandsTest, DuplicateTab) {
[email protected]9423d9412009-04-14 22:13:5568 GURL url1("http://foo/1");
69 GURL url2("http://foo/2");
70 GURL url3("http://foo/3");
[email protected]8fcc7bf2012-08-14 18:14:5071 GURL url4("http://foo/4");
[email protected]be3877f2009-01-14 15:51:1072
[email protected]8fcc7bf2012-08-14 18:14:5073 // Navigate to three urls, plus a pending URL that hasn't committed.
[email protected]9423d9412009-04-14 22:13:5574 AddTab(browser(), url1);
[email protected]0683cf62009-04-10 19:31:4075 NavigateAndCommitActiveTab(url2);
76 NavigateAndCommitActiveTab(url3);
[email protected]8fcc7bf2012-08-14 18:14:5077 content::NavigationController& orig_controller =
[email protected]57892182012-12-03 19:15:3978 browser()->tab_strip_model()->GetWebContentsAt(0)->GetController();
[email protected]8fcc7bf2012-08-14 18:14:5079 orig_controller.LoadURL(
Sylvain Defresnec6ccc77d2014-09-19 10:19:3580 url4, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
[email protected]8fcc7bf2012-08-14 18:14:5081 EXPECT_EQ(3, orig_controller.GetEntryCount());
82 EXPECT_TRUE(orig_controller.GetPendingEntry());
[email protected]be3877f2009-01-14 15:51:1083
[email protected]0665ebe2013-02-13 09:53:1984 size_t initial_window_count = chrome::GetTotalBrowserCount();
[email protected]be3877f2009-01-14 15:51:1085
86 // Duplicate the tab.
[email protected]5d98294912012-06-27 22:57:4087 chrome::ExecuteCommand(browser(), IDC_DUPLICATE_TAB);
[email protected]be3877f2009-01-14 15:51:1088
89 // The duplicated tab should not end up in a new window.
[email protected]0665ebe2013-02-13 09:53:1990 size_t window_count = chrome::GetTotalBrowserCount();
[email protected]be3877f2009-01-14 15:51:1091 ASSERT_EQ(initial_window_count, window_count);
92
93 // And we should have a newly duplicated tab.
[email protected]57892182012-12-03 19:15:3994 ASSERT_EQ(2, browser()->tab_strip_model()->count());
[email protected]be3877f2009-01-14 15:51:1095
96 // Verify the stack of urls.
[email protected]cdcb1dee2012-01-04 00:46:2097 content::NavigationController& controller =
[email protected]57892182012-12-03 19:15:3998 browser()->tab_strip_model()->GetWebContentsAt(1)->GetController();
[email protected]8fcc7bf2012-08-14 18:14:5099 EXPECT_EQ(3, controller.GetEntryCount());
100 EXPECT_EQ(2, controller.GetCurrentEntryIndex());
101 EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL());
102 EXPECT_EQ(url2, controller.GetEntryAtIndex(1)->GetURL());
103 EXPECT_EQ(url3, controller.GetEntryAtIndex(2)->GetURL());
104 EXPECT_FALSE(controller.GetPendingEntry());
105}
106
107// Tests IDC_VIEW_SOURCE (See http://crbug.com/138140).
108TEST_F(BrowserCommandsTest, ViewSource) {
109 GURL url1("http://foo/1");
110 GURL url2("http://foo/2");
111
112 // Navigate to a URL, plus a pending URL that hasn't committed.
113 AddTab(browser(), url1);
114 content::NavigationController& orig_controller =
[email protected]57892182012-12-03 19:15:39115 browser()->tab_strip_model()->GetWebContentsAt(0)->GetController();
[email protected]8fcc7bf2012-08-14 18:14:50116 orig_controller.LoadURL(
Sylvain Defresnec6ccc77d2014-09-19 10:19:35117 url2, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
[email protected]8fcc7bf2012-08-14 18:14:50118 EXPECT_EQ(1, orig_controller.GetEntryCount());
119 EXPECT_TRUE(orig_controller.GetPendingEntry());
120
[email protected]0665ebe2013-02-13 09:53:19121 size_t initial_window_count = chrome::GetTotalBrowserCount();
[email protected]8fcc7bf2012-08-14 18:14:50122
123 // View Source.
124 chrome::ExecuteCommand(browser(), IDC_VIEW_SOURCE);
125
126 // The view source tab should not end up in a new window.
[email protected]0665ebe2013-02-13 09:53:19127 size_t window_count = chrome::GetTotalBrowserCount();
[email protected]8fcc7bf2012-08-14 18:14:50128 ASSERT_EQ(initial_window_count, window_count);
129
130 // And we should have a newly duplicated tab.
[email protected]57892182012-12-03 19:15:39131 ASSERT_EQ(2, browser()->tab_strip_model()->count());
[email protected]8fcc7bf2012-08-14 18:14:50132
133 // Verify we are viewing the source of the last committed entry.
134 GURL view_source_url("view-source:http://foo/1");
135 content::NavigationController& controller =
[email protected]57892182012-12-03 19:15:39136 browser()->tab_strip_model()->GetWebContentsAt(1)->GetController();
[email protected]8fcc7bf2012-08-14 18:14:50137 EXPECT_EQ(1, controller.GetEntryCount());
138 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
139 EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL());
140 EXPECT_EQ(view_source_url, controller.GetEntryAtIndex(0)->GetVirtualURL());
141 EXPECT_FALSE(controller.GetPendingEntry());
[email protected]be3877f2009-01-14 15:51:10142}
[email protected]b7ca4e62009-01-23 20:37:29143
144TEST_F(BrowserCommandsTest, BookmarkCurrentPage) {
145 // We use profile() here, since it's a TestingProfile.
146 profile()->CreateBookmarkModel(true);
[email protected]1f9c74192013-03-25 23:04:35147
148 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile());
tfarina8f4aae22014-10-23 17:46:11149 bookmarks::test::WaitForBookmarkModelToLoad(model);
[email protected]b7ca4e62009-01-23 20:37:29150
151 // Navigate to a url.
[email protected]9423d9412009-04-14 22:13:55152 GURL url1("http://foo/1");
153 AddTab(browser(), url1);
[email protected]e5d549d2011-12-28 01:29:20154 browser()->OpenURL(OpenURLParams(
Sylvain Defresnec6ccc77d2014-09-19 10:19:35155 url1, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false));
[email protected]b7ca4e62009-01-23 20:37:29156
deepak.m154a7f392014-12-15 04:41:43157 chrome::BookmarkCurrentPageAllowingExtensionOverrides(browser());
[email protected]b7ca4e62009-01-23 20:37:29158
159 // It should now be bookmarked in the bookmark model.
160 EXPECT_EQ(profile(), browser()->profile());
[email protected]1f9c74192013-03-25 23:04:35161 EXPECT_TRUE(model->IsBookmarked(url1));
[email protected]b7ca4e62009-01-23 20:37:29162}
[email protected]e21e8c92009-04-29 02:42:09163
164// Tests back/forward in new tab (Control + Back/Forward button in the UI).
165TEST_F(BrowserCommandsTest, BackForwardInNewTab) {
166 GURL url1("http://foo/1");
167 GURL url2("http://foo/2");
168
169 // Make a tab with the two pages navigated in it.
170 AddTab(browser(), url1);
171 NavigateAndCommitActiveTab(url2);
172
173 // Go back in a new background tab.
[email protected]a37d4b02012-06-25 21:56:10174 chrome::GoBack(browser(), NEW_BACKGROUND_TAB);
[email protected]57892182012-12-03 19:15:39175 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
176 ASSERT_EQ(2, browser()->tab_strip_model()->count());
[email protected]e21e8c92009-04-29 02:42:09177
[email protected]57892182012-12-03 19:15:39178 WebContents* zeroth = browser()->tab_strip_model()->GetWebContentsAt(0);
[email protected]e022aca2013-07-18 19:10:18179 WebContents* first = browser()->tab_strip_model()->GetWebContentsAt(1);
180
181 // The original tab should be unchanged.
182 EXPECT_EQ(url2, zeroth->GetLastCommittedURL());
[email protected]f5fa20e2011-12-21 22:35:56183 EXPECT_TRUE(zeroth->GetController().CanGoBack());
184 EXPECT_FALSE(zeroth->GetController().CanGoForward());
[email protected]e21e8c92009-04-29 02:42:09185
[email protected]e022aca2013-07-18 19:10:18186 // The new tab should be like the first one but navigated back. Since we
187 // didn't wait for the load to complete, we can't use GetLastCommittedURL.
[email protected]a093ce02013-07-22 20:53:14188 EXPECT_EQ(url1, first->GetVisibleURL());
[email protected]f5fa20e2011-12-21 22:35:56189 EXPECT_FALSE(first->GetController().CanGoBack());
190 EXPECT_TRUE(first->GetController().CanGoForward());
[email protected]e21e8c92009-04-29 02:42:09191
192 // Select the second tab and make it go forward in a new background tab.
[email protected]57892182012-12-03 19:15:39193 browser()->tab_strip_model()->ActivateTabAt(1, true);
[email protected]e21e8c92009-04-29 02:42:09194 // TODO(brettw) bug 11055: It should not be necessary to commit the load here,
195 // but because of this bug, it will assert later if we don't. When the bug is
196 // fixed, one of the three commits here related to this bug should be removed
197 // (to test both codepaths).
[email protected]f5fa20e2011-12-21 22:35:56198 CommitPendingLoad(&first->GetController());
[email protected]57892182012-12-03 19:15:39199 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a37d4b02012-06-25 21:56:10200 chrome::GoForward(browser(), NEW_BACKGROUND_TAB);
[email protected]e21e8c92009-04-29 02:42:09201
202 // The previous tab should be unchanged and still in the foreground.
[email protected]e022aca2013-07-18 19:10:18203 EXPECT_EQ(url1, first->GetLastCommittedURL());
[email protected]f5fa20e2011-12-21 22:35:56204 EXPECT_FALSE(first->GetController().CanGoBack());
205 EXPECT_TRUE(first->GetController().CanGoForward());
[email protected]57892182012-12-03 19:15:39206 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]e21e8c92009-04-29 02:42:09207
208 // There should be a new tab navigated forward.
[email protected]57892182012-12-03 19:15:39209 ASSERT_EQ(3, browser()->tab_strip_model()->count());
210 WebContents* second = browser()->tab_strip_model()->GetWebContentsAt(2);
[email protected]e022aca2013-07-18 19:10:18211 // Since we didn't wait for load to complete, we can't use
212 // GetLastCommittedURL.
[email protected]a093ce02013-07-22 20:53:14213 EXPECT_EQ(url2, second->GetVisibleURL());
[email protected]f5fa20e2011-12-21 22:35:56214 EXPECT_TRUE(second->GetController().CanGoBack());
215 EXPECT_FALSE(second->GetController().CanGoForward());
[email protected]e21e8c92009-04-29 02:42:09216
217 // Now do back in a new foreground tab. Don't bother re-checking every sngle
218 // thing above, just validate that it's opening properly.
[email protected]57892182012-12-03 19:15:39219 browser()->tab_strip_model()->ActivateTabAt(2, true);
[email protected]e21e8c92009-04-29 02:42:09220 // TODO(brettw) bug 11055: see the comment above about why we need this.
[email protected]f5fa20e2011-12-21 22:35:56221 CommitPendingLoad(&second->GetController());
[email protected]a37d4b02012-06-25 21:56:10222 chrome::GoBack(browser(), NEW_FOREGROUND_TAB);
[email protected]57892182012-12-03 19:15:39223 ASSERT_EQ(3, browser()->tab_strip_model()->active_index());
224 ASSERT_EQ(url1,
[email protected]e022aca2013-07-18 19:10:18225 browser()->tab_strip_model()->GetActiveWebContents()->
[email protected]a093ce02013-07-22 20:53:14226 GetVisibleURL());
[email protected]e21e8c92009-04-29 02:42:09227
228 // Same thing again for forward.
229 // TODO(brettw) bug 11055: see the comment above about why we need this.
[email protected]57892182012-12-03 19:15:39230 CommitPendingLoad(&
231 browser()->tab_strip_model()->GetActiveWebContents()->GetController());
[email protected]a37d4b02012-06-25 21:56:10232 chrome::GoForward(browser(), NEW_FOREGROUND_TAB);
[email protected]57892182012-12-03 19:15:39233 ASSERT_EQ(4, browser()->tab_strip_model()->active_index());
234 ASSERT_EQ(url2,
[email protected]e022aca2013-07-18 19:10:18235 browser()->tab_strip_model()->GetActiveWebContents()->
[email protected]a093ce02013-07-22 20:53:14236 GetVisibleURL());
[email protected]e21e8c92009-04-29 02:42:09237}
[email protected]d93dbd12014-08-04 23:42:53238
239TEST_F(BrowserCommandsTest, OnMaxZoomIn) {
240 TabStripModel* tab_strip_model = browser()->tab_strip_model();
241
242 GURL url("http://www.google.com");
243 AddTab(browser(), url);
a.sarkar.arun93c53be2015-02-27 17:10:10244 WebContents* first_tab = tab_strip_model->GetWebContentsAt(0);
[email protected]d93dbd12014-08-04 23:42:53245
246 // Continue to zoom in until zoom percent reaches 500.
247 for (int i = 0; i < 9; ++i) {
a.sarkar.arun93c53be2015-02-27 17:10:10248 ui_zoom::PageZoom::Zoom(first_tab, content::PAGE_ZOOM_IN);
[email protected]d93dbd12014-08-04 23:42:53249 }
250
251 // TODO([email protected]): Figure out why Zoom-In menu item is not
252 // disabled after Max-zoom is reached. Force disable Zoom-In menu item
253 // from the context menu since it breaks try jobs on bots.
254 if (chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS))
255 chrome::UpdateCommandEnabled(browser(), IDC_ZOOM_PLUS, false);
256
a.sarkar.arun93c53be2015-02-27 17:10:10257 ZoomController* zoom_controller = ZoomController::FromWebContents(first_tab);
a.sarkar.arundaadc712015-02-26 05:39:08258 EXPECT_FLOAT_EQ(500.0f, zoom_controller->GetZoomPercent());
[email protected]d93dbd12014-08-04 23:42:53259 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
260 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
261 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
262}
263
264TEST_F(BrowserCommandsTest, OnMaxZoomOut) {
265 TabStripModel* tab_strip_model = browser()->tab_strip_model();
266
267 GURL url("http://www.google.com");
268 AddTab(browser(), url);
a.sarkar.arun93c53be2015-02-27 17:10:10269 WebContents* first_tab = tab_strip_model->GetWebContentsAt(0);
[email protected]d93dbd12014-08-04 23:42:53270
271 // Continue to zoom out until zoom percent reaches 25.
272 for (int i = 0; i < 7; ++i) {
a.sarkar.arun93c53be2015-02-27 17:10:10273 ui_zoom::PageZoom::Zoom(first_tab, content::PAGE_ZOOM_OUT);
[email protected]d93dbd12014-08-04 23:42:53274 }
275
a.sarkar.arun93c53be2015-02-27 17:10:10276 ZoomController* zoom_controller = ZoomController::FromWebContents(first_tab);
a.sarkar.arundaadc712015-02-26 05:39:08277 EXPECT_FLOAT_EQ(25.0f, zoom_controller->GetZoomPercent());
[email protected]d93dbd12014-08-04 23:42:53278 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
279 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
280 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
281}
282
283TEST_F(BrowserCommandsTest, OnZoomReset) {
284 TabStripModel* tab_strip_model = browser()->tab_strip_model();
285
286 GURL url("http://www.google.com");
287 AddTab(browser(), url);
a.sarkar.arun93c53be2015-02-27 17:10:10288 WebContents* first_tab = tab_strip_model->GetWebContentsAt(0);
[email protected]d93dbd12014-08-04 23:42:53289
290 // Change the zoom percentage to 100.
a.sarkar.arun93c53be2015-02-27 17:10:10291 ui_zoom::PageZoom::Zoom(first_tab, content::PAGE_ZOOM_RESET);
[email protected]d93dbd12014-08-04 23:42:53292
a.sarkar.arun93c53be2015-02-27 17:10:10293 ZoomController* zoom_controller = ZoomController::FromWebContents(first_tab);
a.sarkar.arundaadc712015-02-26 05:39:08294 EXPECT_FLOAT_EQ(100.0f, zoom_controller->GetZoomPercent());
[email protected]d93dbd12014-08-04 23:42:53295 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
296 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
297 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
ccameronb7c1d6c2015-03-09 17:08:24298
299 // Changing the page scale factor will re-enable IDC_ZOOM_NORMAL
300 zoom_controller->SetPageScaleFactorIsOneForTesting(false);
301 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
[email protected]d93dbd12014-08-04 23:42:53302}
303
304TEST_F(BrowserCommandsTest, OnZoomLevelChanged) {
305 TabStripModel* tab_strip_model = browser()->tab_strip_model();
306
307 GURL url("http://www.google.com");
308 AddTab(browser(), url);
a.sarkar.arun93c53be2015-02-27 17:10:10309 WebContents* first_tab = tab_strip_model->GetWebContentsAt(0);
[email protected]d93dbd12014-08-04 23:42:53310
311 // Changing zoom percentage from default should enable all the zoom
312 // NSMenuItems.
a.sarkar.arun93c53be2015-02-27 17:10:10313 ui_zoom::PageZoom::Zoom(first_tab, content::PAGE_ZOOM_IN);
[email protected]d93dbd12014-08-04 23:42:53314
a.sarkar.arun93c53be2015-02-27 17:10:10315 ZoomController* zoom_controller = ZoomController::FromWebContents(first_tab);
a.sarkar.arundaadc712015-02-26 05:39:08316 EXPECT_FLOAT_EQ(110.0f, zoom_controller->GetZoomPercent());
[email protected]d93dbd12014-08-04 23:42:53317 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
318 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
319 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
320}
321
322TEST_F(BrowserCommandsTest, OnZoomChangedForActiveTab) {
323 TabStripModel* tab_strip_model = browser()->tab_strip_model();
324
325 GURL url("http://www.google.com");
326 GURL url1("http://code.google.com");
327
328 // Add First tab.
329 AddTab(browser(), url);
330 AddTab(browser(), url1);
a.sarkar.arun93c53be2015-02-27 17:10:10331 WebContents* first_tab = tab_strip_model->GetWebContentsAt(0);
[email protected]d93dbd12014-08-04 23:42:53332
a.sarkar.arun93c53be2015-02-27 17:10:10333 ZoomController* zoom_controller = ZoomController::FromWebContents(first_tab);
a.sarkar.arundaadc712015-02-26 05:39:08334 EXPECT_FLOAT_EQ(100.0f, zoom_controller->GetZoomPercent());
[email protected]d93dbd12014-08-04 23:42:53335 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
336 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
337 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
338
339 // Add Second tab.
a.sarkar.arun93c53be2015-02-27 17:10:10340 WebContents* second_tab = tab_strip_model->GetWebContentsAt(1);
[email protected]d93dbd12014-08-04 23:42:53341
342 tab_strip_model->ActivateTabAt(1, true);
343 EXPECT_TRUE(tab_strip_model->IsTabSelected(1));
a.sarkar.arun93c53be2015-02-27 17:10:10344 ui_zoom::PageZoom::Zoom(second_tab, content::PAGE_ZOOM_OUT);
[email protected]d93dbd12014-08-04 23:42:53345
a.sarkar.arun93c53be2015-02-27 17:10:10346 zoom_controller = ZoomController::FromWebContents(second_tab);
a.sarkar.arundaadc712015-02-26 05:39:08347 EXPECT_FLOAT_EQ(90.0f, zoom_controller->GetZoomPercent());
348 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
349 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
350 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
351}
352
353TEST_F(BrowserCommandsTest, OnDefaultZoomLevelChanged) {
354 TabStripModel* tab_strip_model = browser()->tab_strip_model();
355 GURL url("http://code.google.com");
356 AddTab(browser(), url);
a.sarkar.arun93c53be2015-02-27 17:10:10357 WebContents* tab = tab_strip_model->GetWebContentsAt(0);
358 ZoomController* zoom_controller = ZoomController::FromWebContents(tab);
a.sarkar.arundaadc712015-02-26 05:39:08359
360 // Set the default zoom level to 125.
361 profile()->GetZoomLevelPrefs()->SetDefaultZoomLevelPref(
362 content::ZoomFactorToZoomLevel(1.25));
363 EXPECT_FLOAT_EQ(125.0f, zoom_controller->GetZoomPercent());
364
365 // Actual Size from context menu should be disabled now.
366 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
367 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
368 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
369
370 // Change the zoom level.
a.sarkar.arun93c53be2015-02-27 17:10:10371 ui_zoom::PageZoom::Zoom(tab, content::PAGE_ZOOM_IN);
a.sarkar.arundaadc712015-02-26 05:39:08372
373 EXPECT_FLOAT_EQ(150.0f, zoom_controller->GetZoomPercent());
374
375 // Tab no longer at default zoom hence actual size should be enabled.
[email protected]d93dbd12014-08-04 23:42:53376 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
377 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
378 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
379}