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