blob: b87eb89558bbb87e4dd45fb7663dbb992480eeeb [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
[email protected]1a3aba82010-11-08 23:52:545#include "chrome/app/chrome_command_ids.h"
[email protected]fa50dea02012-08-01 23:20:376#include "chrome/browser/bookmarks/bookmark_model_factory.h"
[email protected]5d98294912012-06-27 22:57:407#include "chrome/browser/ui/browser_command_controller.h"
[email protected]a37d4b02012-06-25 21:56:108#include "chrome/browser/ui/browser_commands.h"
[email protected]0665ebe2013-02-13 09:53:199#include "chrome/browser/ui/browser_finder.h"
[email protected]57892182012-12-03 19:15:3910#include "chrome/browser/ui/tabs/tab_strip_model.h"
a.sarkar.arundaadc712015-02-26 05:39:0811#include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
[email protected]9423d9412009-04-14 22:13:5512#include "chrome/common/url_constants.h"
[email protected]a4ff9eae2011-08-01 19:58:1613#include "chrome/test/base/browser_with_test_window_test.h"
14#include "chrome/test/base/testing_profile.h"
[email protected]a90c8ca2014-05-20 17:16:0415#include "components/bookmarks/browser/bookmark_model.h"
16#include "components/bookmarks/test/bookmark_test_helpers.h"
wjmaclean91ddc472015-01-15 19:58:2717#include "components/ui/zoom/page_zoom.h"
wjmaclean7f63c6b2014-12-09 14:59:5518#include "components/ui/zoom/zoom_controller.h"
[email protected]cdcb1dee2012-01-04 00:46:2019#include "content/public/browser/navigation_controller.h"
[email protected]022af742011-12-28 18:37:2520#include "content/public/browser/navigation_entry.h"
[email protected]6acde6352012-01-04 16:52:2021#include "content/public/browser/web_contents.h"
a.sarkar.arundaadc712015-02-26 05:39:0822#include "testing/gtest/include/gtest/gtest.h"
[email protected]be3877f2009-01-14 15:51:1023
24typedef BrowserWithTestWindowTest BrowserCommandsTest;
25
tfarinaa0ec34e2015-01-12 18:46:4826using bookmarks::BookmarkModel;
[email protected]e5d549d2011-12-28 01:29:2027using content::OpenURLParams;
28using content::Referrer;
[email protected]6acde6352012-01-04 16:52:2029using content::WebContents;
wjmaclean7f63c6b2014-12-09 14:59:5530using ui_zoom::ZoomController;
[email protected]e5d549d2011-12-28 01:29:2031
[email protected]be3877f2009-01-14 15:51:1032// Tests IDC_SELECT_TAB_0, IDC_SELECT_NEXT_TAB, IDC_SELECT_PREVIOUS_TAB and
33// IDC_SELECT_LAST_TAB.
[email protected]6df642082009-08-13 22:31:3734TEST_F(BrowserCommandsTest, TabNavigationAccelerators) {
[email protected]8e09c7af2014-06-10 11:46:1735 GURL about_blank(url::kAboutBlankURL);
[email protected]9423d9412009-04-14 22:13:5536
[email protected]be3877f2009-01-14 15:51:1037 // Create three tabs.
[email protected]9423d9412009-04-14 22:13:5538 AddTab(browser(), about_blank);
39 AddTab(browser(), about_blank);
40 AddTab(browser(), about_blank);
[email protected]be3877f2009-01-14 15:51:1041
42 // Select the second tab.
[email protected]57892182012-12-03 19:15:3943 browser()->tab_strip_model()->ActivateTabAt(1, false);
[email protected]be3877f2009-01-14 15:51:1044
[email protected]5d98294912012-06-27 22:57:4045 CommandUpdater* updater = browser()->command_controller()->command_updater();
46
[email protected]be3877f2009-01-14 15:51:1047 // Navigate to the first tab using an accelerator.
[email protected]5d98294912012-06-27 22:57:4048 updater->ExecuteCommand(IDC_SELECT_TAB_0);
[email protected]57892182012-12-03 19:15:3949 ASSERT_EQ(0, browser()->tab_strip_model()->active_index());
[email protected]be3877f2009-01-14 15:51:1050
51 // Navigate to the second tab using the next accelerators.
[email protected]5d98294912012-06-27 22:57:4052 updater->ExecuteCommand(IDC_SELECT_NEXT_TAB);
[email protected]57892182012-12-03 19:15:3953 ASSERT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]be3877f2009-01-14 15:51:1054
55 // Navigate back to the first tab using the previous accelerators.
[email protected]5d98294912012-06-27 22:57:4056 updater->ExecuteCommand(IDC_SELECT_PREVIOUS_TAB);
[email protected]57892182012-12-03 19:15:3957 ASSERT_EQ(0, browser()->tab_strip_model()->active_index());
[email protected]be3877f2009-01-14 15:51:1058
59 // Navigate to the last tab using the select last accelerator.
[email protected]5d98294912012-06-27 22:57:4060 updater->ExecuteCommand(IDC_SELECT_LAST_TAB);
[email protected]57892182012-12-03 19:15:3961 ASSERT_EQ(2, browser()->tab_strip_model()->active_index());
[email protected]be3877f2009-01-14 15:51:1062}
63
64// Tests IDC_DUPLICATE_TAB.
65TEST_F(BrowserCommandsTest, DuplicateTab) {
[email protected]9423d9412009-04-14 22:13:5566 GURL url1("http://foo/1");
67 GURL url2("http://foo/2");
68 GURL url3("http://foo/3");
[email protected]8fcc7bf2012-08-14 18:14:5069 GURL url4("http://foo/4");
[email protected]be3877f2009-01-14 15:51:1070
[email protected]8fcc7bf2012-08-14 18:14:5071 // Navigate to three urls, plus a pending URL that hasn't committed.
[email protected]9423d9412009-04-14 22:13:5572 AddTab(browser(), url1);
[email protected]0683cf62009-04-10 19:31:4073 NavigateAndCommitActiveTab(url2);
74 NavigateAndCommitActiveTab(url3);
[email protected]8fcc7bf2012-08-14 18:14:5075 content::NavigationController& orig_controller =
[email protected]57892182012-12-03 19:15:3976 browser()->tab_strip_model()->GetWebContentsAt(0)->GetController();
[email protected]8fcc7bf2012-08-14 18:14:5077 orig_controller.LoadURL(
Sylvain Defresnec6ccc77d2014-09-19 10:19:3578 url4, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
[email protected]8fcc7bf2012-08-14 18:14:5079 EXPECT_EQ(3, orig_controller.GetEntryCount());
80 EXPECT_TRUE(orig_controller.GetPendingEntry());
[email protected]be3877f2009-01-14 15:51:1081
[email protected]0665ebe2013-02-13 09:53:1982 size_t initial_window_count = chrome::GetTotalBrowserCount();
[email protected]be3877f2009-01-14 15:51:1083
84 // Duplicate the tab.
[email protected]5d98294912012-06-27 22:57:4085 chrome::ExecuteCommand(browser(), IDC_DUPLICATE_TAB);
[email protected]be3877f2009-01-14 15:51:1086
87 // The duplicated tab should not end up in a new window.
[email protected]0665ebe2013-02-13 09:53:1988 size_t window_count = chrome::GetTotalBrowserCount();
[email protected]be3877f2009-01-14 15:51:1089 ASSERT_EQ(initial_window_count, window_count);
90
91 // And we should have a newly duplicated tab.
[email protected]57892182012-12-03 19:15:3992 ASSERT_EQ(2, browser()->tab_strip_model()->count());
[email protected]be3877f2009-01-14 15:51:1093
94 // Verify the stack of urls.
[email protected]cdcb1dee2012-01-04 00:46:2095 content::NavigationController& controller =
[email protected]57892182012-12-03 19:15:3996 browser()->tab_strip_model()->GetWebContentsAt(1)->GetController();
[email protected]8fcc7bf2012-08-14 18:14:5097 EXPECT_EQ(3, controller.GetEntryCount());
98 EXPECT_EQ(2, controller.GetCurrentEntryIndex());
99 EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL());
100 EXPECT_EQ(url2, controller.GetEntryAtIndex(1)->GetURL());
101 EXPECT_EQ(url3, controller.GetEntryAtIndex(2)->GetURL());
102 EXPECT_FALSE(controller.GetPendingEntry());
103}
104
105// Tests IDC_VIEW_SOURCE (See http://crbug.com/138140).
106TEST_F(BrowserCommandsTest, ViewSource) {
107 GURL url1("http://foo/1");
108 GURL url2("http://foo/2");
109
110 // Navigate to a URL, plus a pending URL that hasn't committed.
111 AddTab(browser(), url1);
112 content::NavigationController& orig_controller =
[email protected]57892182012-12-03 19:15:39113 browser()->tab_strip_model()->GetWebContentsAt(0)->GetController();
[email protected]8fcc7bf2012-08-14 18:14:50114 orig_controller.LoadURL(
Sylvain Defresnec6ccc77d2014-09-19 10:19:35115 url2, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string());
[email protected]8fcc7bf2012-08-14 18:14:50116 EXPECT_EQ(1, orig_controller.GetEntryCount());
117 EXPECT_TRUE(orig_controller.GetPendingEntry());
118
[email protected]0665ebe2013-02-13 09:53:19119 size_t initial_window_count = chrome::GetTotalBrowserCount();
[email protected]8fcc7bf2012-08-14 18:14:50120
121 // View Source.
122 chrome::ExecuteCommand(browser(), IDC_VIEW_SOURCE);
123
124 // The view source tab should not end up in a new window.
[email protected]0665ebe2013-02-13 09:53:19125 size_t window_count = chrome::GetTotalBrowserCount();
[email protected]8fcc7bf2012-08-14 18:14:50126 ASSERT_EQ(initial_window_count, window_count);
127
128 // And we should have a newly duplicated tab.
[email protected]57892182012-12-03 19:15:39129 ASSERT_EQ(2, browser()->tab_strip_model()->count());
[email protected]8fcc7bf2012-08-14 18:14:50130
131 // Verify we are viewing the source of the last committed entry.
132 GURL view_source_url("view-source:http://foo/1");
133 content::NavigationController& controller =
[email protected]57892182012-12-03 19:15:39134 browser()->tab_strip_model()->GetWebContentsAt(1)->GetController();
[email protected]8fcc7bf2012-08-14 18:14:50135 EXPECT_EQ(1, controller.GetEntryCount());
136 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
137 EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL());
138 EXPECT_EQ(view_source_url, controller.GetEntryAtIndex(0)->GetVirtualURL());
139 EXPECT_FALSE(controller.GetPendingEntry());
[email protected]be3877f2009-01-14 15:51:10140}
[email protected]b7ca4e62009-01-23 20:37:29141
142TEST_F(BrowserCommandsTest, BookmarkCurrentPage) {
143 // We use profile() here, since it's a TestingProfile.
144 profile()->CreateBookmarkModel(true);
[email protected]1f9c74192013-03-25 23:04:35145
146 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile());
tfarina8f4aae22014-10-23 17:46:11147 bookmarks::test::WaitForBookmarkModelToLoad(model);
[email protected]b7ca4e62009-01-23 20:37:29148
149 // Navigate to a url.
[email protected]9423d9412009-04-14 22:13:55150 GURL url1("http://foo/1");
151 AddTab(browser(), url1);
[email protected]e5d549d2011-12-28 01:29:20152 browser()->OpenURL(OpenURLParams(
Sylvain Defresnec6ccc77d2014-09-19 10:19:35153 url1, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false));
[email protected]b7ca4e62009-01-23 20:37:29154
deepak.m154a7f392014-12-15 04:41:43155 chrome::BookmarkCurrentPageAllowingExtensionOverrides(browser());
[email protected]b7ca4e62009-01-23 20:37:29156
157 // It should now be bookmarked in the bookmark model.
158 EXPECT_EQ(profile(), browser()->profile());
[email protected]1f9c74192013-03-25 23:04:35159 EXPECT_TRUE(model->IsBookmarked(url1));
[email protected]b7ca4e62009-01-23 20:37:29160}
[email protected]e21e8c92009-04-29 02:42:09161
162// Tests back/forward in new tab (Control + Back/Forward button in the UI).
163TEST_F(BrowserCommandsTest, BackForwardInNewTab) {
164 GURL url1("http://foo/1");
165 GURL url2("http://foo/2");
166
167 // Make a tab with the two pages navigated in it.
168 AddTab(browser(), url1);
169 NavigateAndCommitActiveTab(url2);
170
171 // Go back in a new background tab.
[email protected]a37d4b02012-06-25 21:56:10172 chrome::GoBack(browser(), NEW_BACKGROUND_TAB);
[email protected]57892182012-12-03 19:15:39173 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
174 ASSERT_EQ(2, browser()->tab_strip_model()->count());
[email protected]e21e8c92009-04-29 02:42:09175
[email protected]57892182012-12-03 19:15:39176 WebContents* zeroth = browser()->tab_strip_model()->GetWebContentsAt(0);
[email protected]e022aca2013-07-18 19:10:18177 WebContents* first = browser()->tab_strip_model()->GetWebContentsAt(1);
178
179 // The original tab should be unchanged.
180 EXPECT_EQ(url2, zeroth->GetLastCommittedURL());
[email protected]f5fa20e2011-12-21 22:35:56181 EXPECT_TRUE(zeroth->GetController().CanGoBack());
182 EXPECT_FALSE(zeroth->GetController().CanGoForward());
[email protected]e21e8c92009-04-29 02:42:09183
[email protected]e022aca2013-07-18 19:10:18184 // The new tab should be like the first one but navigated back. Since we
185 // didn't wait for the load to complete, we can't use GetLastCommittedURL.
[email protected]a093ce02013-07-22 20:53:14186 EXPECT_EQ(url1, first->GetVisibleURL());
[email protected]f5fa20e2011-12-21 22:35:56187 EXPECT_FALSE(first->GetController().CanGoBack());
188 EXPECT_TRUE(first->GetController().CanGoForward());
[email protected]e21e8c92009-04-29 02:42:09189
190 // Select the second tab and make it go forward in a new background tab.
[email protected]57892182012-12-03 19:15:39191 browser()->tab_strip_model()->ActivateTabAt(1, true);
[email protected]e21e8c92009-04-29 02:42:09192 // TODO(brettw) bug 11055: It should not be necessary to commit the load here,
193 // but because of this bug, it will assert later if we don't. When the bug is
194 // fixed, one of the three commits here related to this bug should be removed
195 // (to test both codepaths).
[email protected]f5fa20e2011-12-21 22:35:56196 CommitPendingLoad(&first->GetController());
[email protected]57892182012-12-03 19:15:39197 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]a37d4b02012-06-25 21:56:10198 chrome::GoForward(browser(), NEW_BACKGROUND_TAB);
[email protected]e21e8c92009-04-29 02:42:09199
200 // The previous tab should be unchanged and still in the foreground.
[email protected]e022aca2013-07-18 19:10:18201 EXPECT_EQ(url1, first->GetLastCommittedURL());
[email protected]f5fa20e2011-12-21 22:35:56202 EXPECT_FALSE(first->GetController().CanGoBack());
203 EXPECT_TRUE(first->GetController().CanGoForward());
[email protected]57892182012-12-03 19:15:39204 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
[email protected]e21e8c92009-04-29 02:42:09205
206 // There should be a new tab navigated forward.
[email protected]57892182012-12-03 19:15:39207 ASSERT_EQ(3, browser()->tab_strip_model()->count());
208 WebContents* second = browser()->tab_strip_model()->GetWebContentsAt(2);
[email protected]e022aca2013-07-18 19:10:18209 // Since we didn't wait for load to complete, we can't use
210 // GetLastCommittedURL.
[email protected]a093ce02013-07-22 20:53:14211 EXPECT_EQ(url2, second->GetVisibleURL());
[email protected]f5fa20e2011-12-21 22:35:56212 EXPECT_TRUE(second->GetController().CanGoBack());
213 EXPECT_FALSE(second->GetController().CanGoForward());
[email protected]e21e8c92009-04-29 02:42:09214
215 // Now do back in a new foreground tab. Don't bother re-checking every sngle
216 // thing above, just validate that it's opening properly.
[email protected]57892182012-12-03 19:15:39217 browser()->tab_strip_model()->ActivateTabAt(2, true);
[email protected]e21e8c92009-04-29 02:42:09218 // TODO(brettw) bug 11055: see the comment above about why we need this.
[email protected]f5fa20e2011-12-21 22:35:56219 CommitPendingLoad(&second->GetController());
[email protected]a37d4b02012-06-25 21:56:10220 chrome::GoBack(browser(), NEW_FOREGROUND_TAB);
[email protected]57892182012-12-03 19:15:39221 ASSERT_EQ(3, browser()->tab_strip_model()->active_index());
222 ASSERT_EQ(url1,
[email protected]e022aca2013-07-18 19:10:18223 browser()->tab_strip_model()->GetActiveWebContents()->
[email protected]a093ce02013-07-22 20:53:14224 GetVisibleURL());
[email protected]e21e8c92009-04-29 02:42:09225
226 // Same thing again for forward.
227 // TODO(brettw) bug 11055: see the comment above about why we need this.
[email protected]57892182012-12-03 19:15:39228 CommitPendingLoad(&
229 browser()->tab_strip_model()->GetActiveWebContents()->GetController());
[email protected]a37d4b02012-06-25 21:56:10230 chrome::GoForward(browser(), NEW_FOREGROUND_TAB);
[email protected]57892182012-12-03 19:15:39231 ASSERT_EQ(4, browser()->tab_strip_model()->active_index());
232 ASSERT_EQ(url2,
[email protected]e022aca2013-07-18 19:10:18233 browser()->tab_strip_model()->GetActiveWebContents()->
[email protected]a093ce02013-07-22 20:53:14234 GetVisibleURL());
[email protected]e21e8c92009-04-29 02:42:09235}
[email protected]d93dbd12014-08-04 23:42:53236
237TEST_F(BrowserCommandsTest, OnMaxZoomIn) {
238 TabStripModel* tab_strip_model = browser()->tab_strip_model();
239
240 GURL url("http://www.google.com");
241 AddTab(browser(), url);
a.sarkar.arun93c53be2015-02-27 17:10:10242 WebContents* first_tab = tab_strip_model->GetWebContentsAt(0);
[email protected]d93dbd12014-08-04 23:42:53243
244 // Continue to zoom in until zoom percent reaches 500.
245 for (int i = 0; i < 9; ++i) {
a.sarkar.arun93c53be2015-02-27 17:10:10246 ui_zoom::PageZoom::Zoom(first_tab, content::PAGE_ZOOM_IN);
[email protected]d93dbd12014-08-04 23:42:53247 }
248
249 // TODO([email protected]): Figure out why Zoom-In menu item is not
250 // disabled after Max-zoom is reached. Force disable Zoom-In menu item
251 // from the context menu since it breaks try jobs on bots.
252 if (chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS))
253 chrome::UpdateCommandEnabled(browser(), IDC_ZOOM_PLUS, false);
254
a.sarkar.arun93c53be2015-02-27 17:10:10255 ZoomController* zoom_controller = ZoomController::FromWebContents(first_tab);
a.sarkar.arundaadc712015-02-26 05:39:08256 EXPECT_FLOAT_EQ(500.0f, zoom_controller->GetZoomPercent());
[email protected]d93dbd12014-08-04 23:42:53257 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
258 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
259 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
260}
261
262TEST_F(BrowserCommandsTest, OnMaxZoomOut) {
263 TabStripModel* tab_strip_model = browser()->tab_strip_model();
264
265 GURL url("http://www.google.com");
266 AddTab(browser(), url);
a.sarkar.arun93c53be2015-02-27 17:10:10267 WebContents* first_tab = tab_strip_model->GetWebContentsAt(0);
[email protected]d93dbd12014-08-04 23:42:53268
269 // Continue to zoom out until zoom percent reaches 25.
270 for (int i = 0; i < 7; ++i) {
a.sarkar.arun93c53be2015-02-27 17:10:10271 ui_zoom::PageZoom::Zoom(first_tab, content::PAGE_ZOOM_OUT);
[email protected]d93dbd12014-08-04 23:42:53272 }
273
a.sarkar.arun93c53be2015-02-27 17:10:10274 ZoomController* zoom_controller = ZoomController::FromWebContents(first_tab);
a.sarkar.arundaadc712015-02-26 05:39:08275 EXPECT_FLOAT_EQ(25.0f, zoom_controller->GetZoomPercent());
[email protected]d93dbd12014-08-04 23:42:53276 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
277 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
278 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
279}
280
281TEST_F(BrowserCommandsTest, OnZoomReset) {
282 TabStripModel* tab_strip_model = browser()->tab_strip_model();
283
284 GURL url("http://www.google.com");
285 AddTab(browser(), url);
a.sarkar.arun93c53be2015-02-27 17:10:10286 WebContents* first_tab = tab_strip_model->GetWebContentsAt(0);
[email protected]d93dbd12014-08-04 23:42:53287
288 // Change the zoom percentage to 100.
a.sarkar.arun93c53be2015-02-27 17:10:10289 ui_zoom::PageZoom::Zoom(first_tab, content::PAGE_ZOOM_RESET);
[email protected]d93dbd12014-08-04 23:42:53290
a.sarkar.arun93c53be2015-02-27 17:10:10291 ZoomController* zoom_controller = ZoomController::FromWebContents(first_tab);
a.sarkar.arundaadc712015-02-26 05:39:08292 EXPECT_FLOAT_EQ(100.0f, zoom_controller->GetZoomPercent());
[email protected]d93dbd12014-08-04 23:42:53293 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
294 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
295 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
ccameronb7c1d6c2015-03-09 17:08:24296
297 // Changing the page scale factor will re-enable IDC_ZOOM_NORMAL
298 zoom_controller->SetPageScaleFactorIsOneForTesting(false);
299 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
[email protected]d93dbd12014-08-04 23:42:53300}
301
302TEST_F(BrowserCommandsTest, OnZoomLevelChanged) {
303 TabStripModel* tab_strip_model = browser()->tab_strip_model();
304
305 GURL url("http://www.google.com");
306 AddTab(browser(), url);
a.sarkar.arun93c53be2015-02-27 17:10:10307 WebContents* first_tab = tab_strip_model->GetWebContentsAt(0);
[email protected]d93dbd12014-08-04 23:42:53308
309 // Changing zoom percentage from default should enable all the zoom
310 // NSMenuItems.
a.sarkar.arun93c53be2015-02-27 17:10:10311 ui_zoom::PageZoom::Zoom(first_tab, content::PAGE_ZOOM_IN);
[email protected]d93dbd12014-08-04 23:42:53312
a.sarkar.arun93c53be2015-02-27 17:10:10313 ZoomController* zoom_controller = ZoomController::FromWebContents(first_tab);
a.sarkar.arundaadc712015-02-26 05:39:08314 EXPECT_FLOAT_EQ(110.0f, zoom_controller->GetZoomPercent());
[email protected]d93dbd12014-08-04 23:42:53315 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
316 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
317 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
318}
319
320TEST_F(BrowserCommandsTest, OnZoomChangedForActiveTab) {
321 TabStripModel* tab_strip_model = browser()->tab_strip_model();
322
323 GURL url("http://www.google.com");
324 GURL url1("http://code.google.com");
325
326 // Add First tab.
327 AddTab(browser(), url);
328 AddTab(browser(), url1);
a.sarkar.arun93c53be2015-02-27 17:10:10329 WebContents* first_tab = tab_strip_model->GetWebContentsAt(0);
[email protected]d93dbd12014-08-04 23:42:53330
a.sarkar.arun93c53be2015-02-27 17:10:10331 ZoomController* zoom_controller = ZoomController::FromWebContents(first_tab);
a.sarkar.arundaadc712015-02-26 05:39:08332 EXPECT_FLOAT_EQ(100.0f, zoom_controller->GetZoomPercent());
[email protected]d93dbd12014-08-04 23:42:53333 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
334 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
335 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
336
337 // Add Second tab.
a.sarkar.arun93c53be2015-02-27 17:10:10338 WebContents* second_tab = tab_strip_model->GetWebContentsAt(1);
[email protected]d93dbd12014-08-04 23:42:53339
340 tab_strip_model->ActivateTabAt(1, true);
341 EXPECT_TRUE(tab_strip_model->IsTabSelected(1));
a.sarkar.arun93c53be2015-02-27 17:10:10342 ui_zoom::PageZoom::Zoom(second_tab, content::PAGE_ZOOM_OUT);
[email protected]d93dbd12014-08-04 23:42:53343
a.sarkar.arun93c53be2015-02-27 17:10:10344 zoom_controller = ZoomController::FromWebContents(second_tab);
a.sarkar.arundaadc712015-02-26 05:39:08345 EXPECT_FLOAT_EQ(90.0f, zoom_controller->GetZoomPercent());
346 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
347 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
348 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
349}
350
351TEST_F(BrowserCommandsTest, OnDefaultZoomLevelChanged) {
352 TabStripModel* tab_strip_model = browser()->tab_strip_model();
353 GURL url("http://code.google.com");
354 AddTab(browser(), url);
a.sarkar.arun93c53be2015-02-27 17:10:10355 WebContents* tab = tab_strip_model->GetWebContentsAt(0);
356 ZoomController* zoom_controller = ZoomController::FromWebContents(tab);
a.sarkar.arundaadc712015-02-26 05:39:08357
358 // Set the default zoom level to 125.
359 profile()->GetZoomLevelPrefs()->SetDefaultZoomLevelPref(
360 content::ZoomFactorToZoomLevel(1.25));
361 EXPECT_FLOAT_EQ(125.0f, zoom_controller->GetZoomPercent());
362
363 // Actual Size from context menu should be disabled now.
364 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
365 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
366 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
367
368 // Change the zoom level.
a.sarkar.arun93c53be2015-02-27 17:10:10369 ui_zoom::PageZoom::Zoom(tab, content::PAGE_ZOOM_IN);
a.sarkar.arundaadc712015-02-26 05:39:08370
371 EXPECT_FLOAT_EQ(150.0f, zoom_controller->GetZoomPercent());
372
373 // Tab no longer at default zoom hence actual size should be enabled.
[email protected]d93dbd12014-08-04 23:42:53374 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS));
375 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL));
376 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS));
377}