[email protected] | 93cc27b | 2012-03-21 12:44:32 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame^] | 5 | #include <stddef.h> |
| 6 | |
[email protected] | 1a3aba8 | 2010-11-08 23:52:54 | [diff] [blame] | 7 | #include "chrome/app/chrome_command_ids.h" |
[email protected] | fa50dea0 | 2012-08-01 23:20:37 | [diff] [blame] | 8 | #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 9 | #include "chrome/browser/ui/browser_command_controller.h" |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 10 | #include "chrome/browser/ui/browser_commands.h" |
[email protected] | 0665ebe | 2013-02-13 09:53:19 | [diff] [blame] | 11 | #include "chrome/browser/ui/browser_finder.h" |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 12 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
a.sarkar.arun | daadc71 | 2015-02-26 05:39:08 | [diff] [blame] | 13 | #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" |
[email protected] | 9423d941 | 2009-04-14 22:13:55 | [diff] [blame] | 14 | #include "chrome/common/url_constants.h" |
[email protected] | a4ff9eae | 2011-08-01 19:58:16 | [diff] [blame] | 15 | #include "chrome/test/base/browser_with_test_window_test.h" |
| 16 | #include "chrome/test/base/testing_profile.h" |
[email protected] | a90c8ca | 2014-05-20 17:16:04 | [diff] [blame] | 17 | #include "components/bookmarks/browser/bookmark_model.h" |
| 18 | #include "components/bookmarks/test/bookmark_test_helpers.h" |
wjmaclean | 91ddc47 | 2015-01-15 19:58:27 | [diff] [blame] | 19 | #include "components/ui/zoom/page_zoom.h" |
wjmaclean | 7f63c6b | 2014-12-09 14:59:55 | [diff] [blame] | 20 | #include "components/ui/zoom/zoom_controller.h" |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 21 | #include "content/public/browser/navigation_controller.h" |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 22 | #include "content/public/browser/navigation_entry.h" |
[email protected] | 6acde635 | 2012-01-04 16:52:20 | [diff] [blame] | 23 | #include "content/public/browser/web_contents.h" |
a.sarkar.arun | daadc71 | 2015-02-26 05:39:08 | [diff] [blame] | 24 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 25 | |
| 26 | typedef BrowserWithTestWindowTest BrowserCommandsTest; |
| 27 | |
tfarina | a0ec34e | 2015-01-12 18:46:48 | [diff] [blame] | 28 | using bookmarks::BookmarkModel; |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 29 | using content::OpenURLParams; |
| 30 | using content::Referrer; |
[email protected] | 6acde635 | 2012-01-04 16:52:20 | [diff] [blame] | 31 | using content::WebContents; |
wjmaclean | 7f63c6b | 2014-12-09 14:59:55 | [diff] [blame] | 32 | using ui_zoom::ZoomController; |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 33 | |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 34 | // Tests IDC_SELECT_TAB_0, IDC_SELECT_NEXT_TAB, IDC_SELECT_PREVIOUS_TAB and |
| 35 | // IDC_SELECT_LAST_TAB. |
[email protected] | 6df64208 | 2009-08-13 22:31:37 | [diff] [blame] | 36 | TEST_F(BrowserCommandsTest, TabNavigationAccelerators) { |
[email protected] | 8e09c7af | 2014-06-10 11:46:17 | [diff] [blame] | 37 | GURL about_blank(url::kAboutBlankURL); |
[email protected] | 9423d941 | 2009-04-14 22:13:55 | [diff] [blame] | 38 | |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 39 | // Create three tabs. |
[email protected] | 9423d941 | 2009-04-14 22:13:55 | [diff] [blame] | 40 | AddTab(browser(), about_blank); |
| 41 | AddTab(browser(), about_blank); |
| 42 | AddTab(browser(), about_blank); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 43 | |
| 44 | // Select the second tab. |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 45 | browser()->tab_strip_model()->ActivateTabAt(1, false); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 46 | |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 47 | CommandUpdater* updater = browser()->command_controller()->command_updater(); |
| 48 | |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 49 | // Navigate to the first tab using an accelerator. |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 50 | updater->ExecuteCommand(IDC_SELECT_TAB_0); |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 51 | ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 52 | |
| 53 | // Navigate to the second tab using the next accelerators. |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 54 | updater->ExecuteCommand(IDC_SELECT_NEXT_TAB); |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 55 | ASSERT_EQ(1, browser()->tab_strip_model()->active_index()); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 56 | |
| 57 | // Navigate back to the first tab using the previous accelerators. |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 58 | updater->ExecuteCommand(IDC_SELECT_PREVIOUS_TAB); |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 59 | ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 60 | |
| 61 | // Navigate to the last tab using the select last accelerator. |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 62 | updater->ExecuteCommand(IDC_SELECT_LAST_TAB); |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 63 | ASSERT_EQ(2, browser()->tab_strip_model()->active_index()); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | // Tests IDC_DUPLICATE_TAB. |
| 67 | TEST_F(BrowserCommandsTest, DuplicateTab) { |
[email protected] | 9423d941 | 2009-04-14 22:13:55 | [diff] [blame] | 68 | GURL url1("http://foo/1"); |
| 69 | GURL url2("http://foo/2"); |
| 70 | GURL url3("http://foo/3"); |
[email protected] | 8fcc7bf | 2012-08-14 18:14:50 | [diff] [blame] | 71 | GURL url4("http://foo/4"); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 72 | |
[email protected] | 8fcc7bf | 2012-08-14 18:14:50 | [diff] [blame] | 73 | // Navigate to three urls, plus a pending URL that hasn't committed. |
[email protected] | 9423d941 | 2009-04-14 22:13:55 | [diff] [blame] | 74 | AddTab(browser(), url1); |
[email protected] | 0683cf6 | 2009-04-10 19:31:40 | [diff] [blame] | 75 | NavigateAndCommitActiveTab(url2); |
| 76 | NavigateAndCommitActiveTab(url3); |
[email protected] | 8fcc7bf | 2012-08-14 18:14:50 | [diff] [blame] | 77 | content::NavigationController& orig_controller = |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 78 | browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); |
[email protected] | 8fcc7bf | 2012-08-14 18:14:50 | [diff] [blame] | 79 | orig_controller.LoadURL( |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 80 | url4, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
[email protected] | 8fcc7bf | 2012-08-14 18:14:50 | [diff] [blame] | 81 | EXPECT_EQ(3, orig_controller.GetEntryCount()); |
| 82 | EXPECT_TRUE(orig_controller.GetPendingEntry()); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 83 | |
[email protected] | 0665ebe | 2013-02-13 09:53:19 | [diff] [blame] | 84 | size_t initial_window_count = chrome::GetTotalBrowserCount(); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 85 | |
| 86 | // Duplicate the tab. |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 87 | chrome::ExecuteCommand(browser(), IDC_DUPLICATE_TAB); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 88 | |
| 89 | // The duplicated tab should not end up in a new window. |
[email protected] | 0665ebe | 2013-02-13 09:53:19 | [diff] [blame] | 90 | size_t window_count = chrome::GetTotalBrowserCount(); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 91 | ASSERT_EQ(initial_window_count, window_count); |
| 92 | |
| 93 | // And we should have a newly duplicated tab. |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 94 | ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 95 | |
| 96 | // Verify the stack of urls. |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 97 | content::NavigationController& controller = |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 98 | browser()->tab_strip_model()->GetWebContentsAt(1)->GetController(); |
[email protected] | 8fcc7bf | 2012-08-14 18:14:50 | [diff] [blame] | 99 | 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). |
| 108 | TEST_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] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 115 | browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); |
[email protected] | 8fcc7bf | 2012-08-14 18:14:50 | [diff] [blame] | 116 | orig_controller.LoadURL( |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 117 | url2, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
[email protected] | 8fcc7bf | 2012-08-14 18:14:50 | [diff] [blame] | 118 | EXPECT_EQ(1, orig_controller.GetEntryCount()); |
| 119 | EXPECT_TRUE(orig_controller.GetPendingEntry()); |
| 120 | |
[email protected] | 0665ebe | 2013-02-13 09:53:19 | [diff] [blame] | 121 | size_t initial_window_count = chrome::GetTotalBrowserCount(); |
[email protected] | 8fcc7bf | 2012-08-14 18:14:50 | [diff] [blame] | 122 | |
| 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] | 0665ebe | 2013-02-13 09:53:19 | [diff] [blame] | 127 | size_t window_count = chrome::GetTotalBrowserCount(); |
[email protected] | 8fcc7bf | 2012-08-14 18:14:50 | [diff] [blame] | 128 | ASSERT_EQ(initial_window_count, window_count); |
| 129 | |
| 130 | // And we should have a newly duplicated tab. |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 131 | ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
[email protected] | 8fcc7bf | 2012-08-14 18:14:50 | [diff] [blame] | 132 | |
| 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] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 136 | browser()->tab_strip_model()->GetWebContentsAt(1)->GetController(); |
[email protected] | 8fcc7bf | 2012-08-14 18:14:50 | [diff] [blame] | 137 | 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] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 142 | } |
[email protected] | b7ca4e6 | 2009-01-23 20:37:29 | [diff] [blame] | 143 | |
| 144 | TEST_F(BrowserCommandsTest, BookmarkCurrentPage) { |
| 145 | // We use profile() here, since it's a TestingProfile. |
| 146 | profile()->CreateBookmarkModel(true); |
[email protected] | 1f9c7419 | 2013-03-25 23:04:35 | [diff] [blame] | 147 | |
| 148 | BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
tfarina | 8f4aae2 | 2014-10-23 17:46:11 | [diff] [blame] | 149 | bookmarks::test::WaitForBookmarkModelToLoad(model); |
[email protected] | b7ca4e6 | 2009-01-23 20:37:29 | [diff] [blame] | 150 | |
| 151 | // Navigate to a url. |
[email protected] | 9423d941 | 2009-04-14 22:13:55 | [diff] [blame] | 152 | GURL url1("http://foo/1"); |
| 153 | AddTab(browser(), url1); |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 154 | browser()->OpenURL(OpenURLParams( |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 155 | url1, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); |
[email protected] | b7ca4e6 | 2009-01-23 20:37:29 | [diff] [blame] | 156 | |
deepak.m1 | 54a7f39 | 2014-12-15 04:41:43 | [diff] [blame] | 157 | chrome::BookmarkCurrentPageAllowingExtensionOverrides(browser()); |
[email protected] | b7ca4e6 | 2009-01-23 20:37:29 | [diff] [blame] | 158 | |
| 159 | // It should now be bookmarked in the bookmark model. |
| 160 | EXPECT_EQ(profile(), browser()->profile()); |
[email protected] | 1f9c7419 | 2013-03-25 23:04:35 | [diff] [blame] | 161 | EXPECT_TRUE(model->IsBookmarked(url1)); |
[email protected] | b7ca4e6 | 2009-01-23 20:37:29 | [diff] [blame] | 162 | } |
[email protected] | e21e8c9 | 2009-04-29 02:42:09 | [diff] [blame] | 163 | |
| 164 | // Tests back/forward in new tab (Control + Back/Forward button in the UI). |
| 165 | TEST_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] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 174 | chrome::GoBack(browser(), NEW_BACKGROUND_TAB); |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 175 | EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); |
| 176 | ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
[email protected] | e21e8c9 | 2009-04-29 02:42:09 | [diff] [blame] | 177 | |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 178 | WebContents* zeroth = browser()->tab_strip_model()->GetWebContentsAt(0); |
[email protected] | e022aca | 2013-07-18 19:10:18 | [diff] [blame] | 179 | WebContents* first = browser()->tab_strip_model()->GetWebContentsAt(1); |
| 180 | |
| 181 | // The original tab should be unchanged. |
| 182 | EXPECT_EQ(url2, zeroth->GetLastCommittedURL()); |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 183 | EXPECT_TRUE(zeroth->GetController().CanGoBack()); |
| 184 | EXPECT_FALSE(zeroth->GetController().CanGoForward()); |
[email protected] | e21e8c9 | 2009-04-29 02:42:09 | [diff] [blame] | 185 | |
[email protected] | e022aca | 2013-07-18 19:10:18 | [diff] [blame] | 186 | // 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] | a093ce0 | 2013-07-22 20:53:14 | [diff] [blame] | 188 | EXPECT_EQ(url1, first->GetVisibleURL()); |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 189 | EXPECT_FALSE(first->GetController().CanGoBack()); |
| 190 | EXPECT_TRUE(first->GetController().CanGoForward()); |
[email protected] | e21e8c9 | 2009-04-29 02:42:09 | [diff] [blame] | 191 | |
| 192 | // Select the second tab and make it go forward in a new background tab. |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 193 | browser()->tab_strip_model()->ActivateTabAt(1, true); |
[email protected] | e21e8c9 | 2009-04-29 02:42:09 | [diff] [blame] | 194 | // 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] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 198 | CommitPendingLoad(&first->GetController()); |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 199 | EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 200 | chrome::GoForward(browser(), NEW_BACKGROUND_TAB); |
[email protected] | e21e8c9 | 2009-04-29 02:42:09 | [diff] [blame] | 201 | |
| 202 | // The previous tab should be unchanged and still in the foreground. |
[email protected] | e022aca | 2013-07-18 19:10:18 | [diff] [blame] | 203 | EXPECT_EQ(url1, first->GetLastCommittedURL()); |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 204 | EXPECT_FALSE(first->GetController().CanGoBack()); |
| 205 | EXPECT_TRUE(first->GetController().CanGoForward()); |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 206 | EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); |
[email protected] | e21e8c9 | 2009-04-29 02:42:09 | [diff] [blame] | 207 | |
| 208 | // There should be a new tab navigated forward. |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 209 | ASSERT_EQ(3, browser()->tab_strip_model()->count()); |
| 210 | WebContents* second = browser()->tab_strip_model()->GetWebContentsAt(2); |
[email protected] | e022aca | 2013-07-18 19:10:18 | [diff] [blame] | 211 | // Since we didn't wait for load to complete, we can't use |
| 212 | // GetLastCommittedURL. |
[email protected] | a093ce0 | 2013-07-22 20:53:14 | [diff] [blame] | 213 | EXPECT_EQ(url2, second->GetVisibleURL()); |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 214 | EXPECT_TRUE(second->GetController().CanGoBack()); |
| 215 | EXPECT_FALSE(second->GetController().CanGoForward()); |
[email protected] | e21e8c9 | 2009-04-29 02:42:09 | [diff] [blame] | 216 | |
| 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] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 219 | browser()->tab_strip_model()->ActivateTabAt(2, true); |
[email protected] | e21e8c9 | 2009-04-29 02:42:09 | [diff] [blame] | 220 | // TODO(brettw) bug 11055: see the comment above about why we need this. |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 221 | CommitPendingLoad(&second->GetController()); |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 222 | chrome::GoBack(browser(), NEW_FOREGROUND_TAB); |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 223 | ASSERT_EQ(3, browser()->tab_strip_model()->active_index()); |
| 224 | ASSERT_EQ(url1, |
[email protected] | e022aca | 2013-07-18 19:10:18 | [diff] [blame] | 225 | browser()->tab_strip_model()->GetActiveWebContents()-> |
[email protected] | a093ce0 | 2013-07-22 20:53:14 | [diff] [blame] | 226 | GetVisibleURL()); |
[email protected] | e21e8c9 | 2009-04-29 02:42:09 | [diff] [blame] | 227 | |
| 228 | // Same thing again for forward. |
| 229 | // TODO(brettw) bug 11055: see the comment above about why we need this. |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 230 | CommitPendingLoad(& |
| 231 | browser()->tab_strip_model()->GetActiveWebContents()->GetController()); |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 232 | chrome::GoForward(browser(), NEW_FOREGROUND_TAB); |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 233 | ASSERT_EQ(4, browser()->tab_strip_model()->active_index()); |
| 234 | ASSERT_EQ(url2, |
[email protected] | e022aca | 2013-07-18 19:10:18 | [diff] [blame] | 235 | browser()->tab_strip_model()->GetActiveWebContents()-> |
[email protected] | a093ce0 | 2013-07-22 20:53:14 | [diff] [blame] | 236 | GetVisibleURL()); |
[email protected] | e21e8c9 | 2009-04-29 02:42:09 | [diff] [blame] | 237 | } |
[email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 238 | |
| 239 | TEST_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.arun | 93c53be | 2015-02-27 17:10:10 | [diff] [blame] | 244 | WebContents* first_tab = tab_strip_model->GetWebContentsAt(0); |
[email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 245 | |
| 246 | // Continue to zoom in until zoom percent reaches 500. |
| 247 | for (int i = 0; i < 9; ++i) { |
a.sarkar.arun | 93c53be | 2015-02-27 17:10:10 | [diff] [blame] | 248 | ui_zoom::PageZoom::Zoom(first_tab, content::PAGE_ZOOM_IN); |
[email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 249 | } |
| 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.arun | 93c53be | 2015-02-27 17:10:10 | [diff] [blame] | 257 | ZoomController* zoom_controller = ZoomController::FromWebContents(first_tab); |
a.sarkar.arun | daadc71 | 2015-02-26 05:39:08 | [diff] [blame] | 258 | EXPECT_FLOAT_EQ(500.0f, zoom_controller->GetZoomPercent()); |
[email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 259 | 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 | |
| 264 | TEST_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.arun | 93c53be | 2015-02-27 17:10:10 | [diff] [blame] | 269 | WebContents* first_tab = tab_strip_model->GetWebContentsAt(0); |
[email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 270 | |
| 271 | // Continue to zoom out until zoom percent reaches 25. |
| 272 | for (int i = 0; i < 7; ++i) { |
a.sarkar.arun | 93c53be | 2015-02-27 17:10:10 | [diff] [blame] | 273 | ui_zoom::PageZoom::Zoom(first_tab, content::PAGE_ZOOM_OUT); |
[email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 274 | } |
| 275 | |
a.sarkar.arun | 93c53be | 2015-02-27 17:10:10 | [diff] [blame] | 276 | ZoomController* zoom_controller = ZoomController::FromWebContents(first_tab); |
a.sarkar.arun | daadc71 | 2015-02-26 05:39:08 | [diff] [blame] | 277 | EXPECT_FLOAT_EQ(25.0f, zoom_controller->GetZoomPercent()); |
[email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 278 | 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 | |
| 283 | TEST_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.arun | 93c53be | 2015-02-27 17:10:10 | [diff] [blame] | 288 | WebContents* first_tab = tab_strip_model->GetWebContentsAt(0); |
[email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 289 | |
| 290 | // Change the zoom percentage to 100. |
a.sarkar.arun | 93c53be | 2015-02-27 17:10:10 | [diff] [blame] | 291 | ui_zoom::PageZoom::Zoom(first_tab, content::PAGE_ZOOM_RESET); |
[email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 292 | |
a.sarkar.arun | 93c53be | 2015-02-27 17:10:10 | [diff] [blame] | 293 | ZoomController* zoom_controller = ZoomController::FromWebContents(first_tab); |
a.sarkar.arun | daadc71 | 2015-02-26 05:39:08 | [diff] [blame] | 294 | EXPECT_FLOAT_EQ(100.0f, zoom_controller->GetZoomPercent()); |
[email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 295 | 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)); |
ccameron | b7c1d6c | 2015-03-09 17:08:24 | [diff] [blame] | 298 | |
| 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] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | TEST_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.arun | 93c53be | 2015-02-27 17:10:10 | [diff] [blame] | 309 | WebContents* first_tab = tab_strip_model->GetWebContentsAt(0); |
[email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 310 | |
| 311 | // Changing zoom percentage from default should enable all the zoom |
| 312 | // NSMenuItems. |
a.sarkar.arun | 93c53be | 2015-02-27 17:10:10 | [diff] [blame] | 313 | ui_zoom::PageZoom::Zoom(first_tab, content::PAGE_ZOOM_IN); |
[email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 314 | |
a.sarkar.arun | 93c53be | 2015-02-27 17:10:10 | [diff] [blame] | 315 | ZoomController* zoom_controller = ZoomController::FromWebContents(first_tab); |
a.sarkar.arun | daadc71 | 2015-02-26 05:39:08 | [diff] [blame] | 316 | EXPECT_FLOAT_EQ(110.0f, zoom_controller->GetZoomPercent()); |
[email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 317 | 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 | |
| 322 | TEST_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.arun | 93c53be | 2015-02-27 17:10:10 | [diff] [blame] | 331 | WebContents* first_tab = tab_strip_model->GetWebContentsAt(0); |
[email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 332 | |
a.sarkar.arun | 93c53be | 2015-02-27 17:10:10 | [diff] [blame] | 333 | ZoomController* zoom_controller = ZoomController::FromWebContents(first_tab); |
a.sarkar.arun | daadc71 | 2015-02-26 05:39:08 | [diff] [blame] | 334 | EXPECT_FLOAT_EQ(100.0f, zoom_controller->GetZoomPercent()); |
[email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 335 | 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.arun | 93c53be | 2015-02-27 17:10:10 | [diff] [blame] | 340 | WebContents* second_tab = tab_strip_model->GetWebContentsAt(1); |
[email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 341 | |
| 342 | tab_strip_model->ActivateTabAt(1, true); |
| 343 | EXPECT_TRUE(tab_strip_model->IsTabSelected(1)); |
a.sarkar.arun | 93c53be | 2015-02-27 17:10:10 | [diff] [blame] | 344 | ui_zoom::PageZoom::Zoom(second_tab, content::PAGE_ZOOM_OUT); |
[email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 345 | |
a.sarkar.arun | 93c53be | 2015-02-27 17:10:10 | [diff] [blame] | 346 | zoom_controller = ZoomController::FromWebContents(second_tab); |
a.sarkar.arun | daadc71 | 2015-02-26 05:39:08 | [diff] [blame] | 347 | 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 | |
| 353 | TEST_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.arun | 93c53be | 2015-02-27 17:10:10 | [diff] [blame] | 357 | WebContents* tab = tab_strip_model->GetWebContentsAt(0); |
| 358 | ZoomController* zoom_controller = ZoomController::FromWebContents(tab); |
a.sarkar.arun | daadc71 | 2015-02-26 05:39:08 | [diff] [blame] | 359 | |
| 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.arun | 93c53be | 2015-02-27 17:10:10 | [diff] [blame] | 371 | ui_zoom::PageZoom::Zoom(tab, content::PAGE_ZOOM_IN); |
a.sarkar.arun | daadc71 | 2015-02-26 05:39:08 | [diff] [blame] | 372 | |
| 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] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 376 | 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 | } |