[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] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 7 | #include "chrome/browser/chrome_page_zoom.h" |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 8 | #include "chrome/browser/ui/browser_command_controller.h" |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 9 | #include "chrome/browser/ui/browser_commands.h" |
[email protected] | 0665ebe | 2013-02-13 09:53:19 | [diff] [blame] | 10 | #include "chrome/browser/ui/browser_finder.h" |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 11 | #include "chrome/browser/ui/tabs/tab_strip_model.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 | 7f63c6b | 2014-12-09 14:59:55 | [diff] [blame] | 17 | #include "components/ui/zoom/zoom_controller.h" |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 18 | #include "content/public/browser/navigation_controller.h" |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 19 | #include "content/public/browser/navigation_entry.h" |
[email protected] | 6acde635 | 2012-01-04 16:52:20 | [diff] [blame] | 20 | #include "content/public/browser/web_contents.h" |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 21 | |
| 22 | typedef BrowserWithTestWindowTest BrowserCommandsTest; |
| 23 | |
tfarina | a0ec34e | 2015-01-12 18:46:48 | [diff] [blame^] | 24 | using bookmarks::BookmarkModel; |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 25 | using content::OpenURLParams; |
| 26 | using content::Referrer; |
[email protected] | 6acde635 | 2012-01-04 16:52:20 | [diff] [blame] | 27 | using content::WebContents; |
wjmaclean | 7f63c6b | 2014-12-09 14:59:55 | [diff] [blame] | 28 | using ui_zoom::ZoomController; |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 29 | |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 30 | // Tests IDC_SELECT_TAB_0, IDC_SELECT_NEXT_TAB, IDC_SELECT_PREVIOUS_TAB and |
| 31 | // IDC_SELECT_LAST_TAB. |
[email protected] | 6df64208 | 2009-08-13 22:31:37 | [diff] [blame] | 32 | TEST_F(BrowserCommandsTest, TabNavigationAccelerators) { |
[email protected] | 8e09c7af | 2014-06-10 11:46:17 | [diff] [blame] | 33 | GURL about_blank(url::kAboutBlankURL); |
[email protected] | 9423d941 | 2009-04-14 22:13:55 | [diff] [blame] | 34 | |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 35 | // Create three tabs. |
[email protected] | 9423d941 | 2009-04-14 22:13:55 | [diff] [blame] | 36 | AddTab(browser(), about_blank); |
| 37 | AddTab(browser(), about_blank); |
| 38 | AddTab(browser(), about_blank); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 39 | |
| 40 | // Select the second tab. |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 41 | browser()->tab_strip_model()->ActivateTabAt(1, false); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 42 | |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 43 | CommandUpdater* updater = browser()->command_controller()->command_updater(); |
| 44 | |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 45 | // Navigate to the first tab using an accelerator. |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 46 | updater->ExecuteCommand(IDC_SELECT_TAB_0); |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 47 | ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 48 | |
| 49 | // Navigate to the second tab using the next accelerators. |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 50 | updater->ExecuteCommand(IDC_SELECT_NEXT_TAB); |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 51 | ASSERT_EQ(1, browser()->tab_strip_model()->active_index()); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 52 | |
| 53 | // Navigate back to the first tab using the previous accelerators. |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 54 | updater->ExecuteCommand(IDC_SELECT_PREVIOUS_TAB); |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 55 | ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 56 | |
| 57 | // Navigate to the last tab using the select last accelerator. |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 58 | updater->ExecuteCommand(IDC_SELECT_LAST_TAB); |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 59 | ASSERT_EQ(2, browser()->tab_strip_model()->active_index()); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | // Tests IDC_DUPLICATE_TAB. |
| 63 | TEST_F(BrowserCommandsTest, DuplicateTab) { |
[email protected] | 9423d941 | 2009-04-14 22:13:55 | [diff] [blame] | 64 | GURL url1("http://foo/1"); |
| 65 | GURL url2("http://foo/2"); |
| 66 | GURL url3("http://foo/3"); |
[email protected] | 8fcc7bf | 2012-08-14 18:14:50 | [diff] [blame] | 67 | GURL url4("http://foo/4"); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 68 | |
[email protected] | 8fcc7bf | 2012-08-14 18:14:50 | [diff] [blame] | 69 | // Navigate to three urls, plus a pending URL that hasn't committed. |
[email protected] | 9423d941 | 2009-04-14 22:13:55 | [diff] [blame] | 70 | AddTab(browser(), url1); |
[email protected] | 0683cf6 | 2009-04-10 19:31:40 | [diff] [blame] | 71 | NavigateAndCommitActiveTab(url2); |
| 72 | NavigateAndCommitActiveTab(url3); |
[email protected] | 8fcc7bf | 2012-08-14 18:14:50 | [diff] [blame] | 73 | content::NavigationController& orig_controller = |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 74 | browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); |
[email protected] | 8fcc7bf | 2012-08-14 18:14:50 | [diff] [blame] | 75 | orig_controller.LoadURL( |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 76 | url4, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
[email protected] | 8fcc7bf | 2012-08-14 18:14:50 | [diff] [blame] | 77 | EXPECT_EQ(3, orig_controller.GetEntryCount()); |
| 78 | EXPECT_TRUE(orig_controller.GetPendingEntry()); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 79 | |
[email protected] | 0665ebe | 2013-02-13 09:53:19 | [diff] [blame] | 80 | size_t initial_window_count = chrome::GetTotalBrowserCount(); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 81 | |
| 82 | // Duplicate the tab. |
[email protected] | 5d9829491 | 2012-06-27 22:57:40 | [diff] [blame] | 83 | chrome::ExecuteCommand(browser(), IDC_DUPLICATE_TAB); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 84 | |
| 85 | // The duplicated tab should not end up in a new window. |
[email protected] | 0665ebe | 2013-02-13 09:53:19 | [diff] [blame] | 86 | size_t window_count = chrome::GetTotalBrowserCount(); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 87 | ASSERT_EQ(initial_window_count, window_count); |
| 88 | |
| 89 | // And we should have a newly duplicated tab. |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 90 | ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 91 | |
| 92 | // Verify the stack of urls. |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 93 | content::NavigationController& controller = |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 94 | browser()->tab_strip_model()->GetWebContentsAt(1)->GetController(); |
[email protected] | 8fcc7bf | 2012-08-14 18:14:50 | [diff] [blame] | 95 | EXPECT_EQ(3, controller.GetEntryCount()); |
| 96 | EXPECT_EQ(2, controller.GetCurrentEntryIndex()); |
| 97 | EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL()); |
| 98 | EXPECT_EQ(url2, controller.GetEntryAtIndex(1)->GetURL()); |
| 99 | EXPECT_EQ(url3, controller.GetEntryAtIndex(2)->GetURL()); |
| 100 | EXPECT_FALSE(controller.GetPendingEntry()); |
| 101 | } |
| 102 | |
| 103 | // Tests IDC_VIEW_SOURCE (See http://crbug.com/138140). |
| 104 | TEST_F(BrowserCommandsTest, ViewSource) { |
| 105 | GURL url1("http://foo/1"); |
| 106 | GURL url2("http://foo/2"); |
| 107 | |
| 108 | // Navigate to a URL, plus a pending URL that hasn't committed. |
| 109 | AddTab(browser(), url1); |
| 110 | content::NavigationController& orig_controller = |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 111 | browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); |
[email protected] | 8fcc7bf | 2012-08-14 18:14:50 | [diff] [blame] | 112 | orig_controller.LoadURL( |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 113 | url2, content::Referrer(), ui::PAGE_TRANSITION_LINK, std::string()); |
[email protected] | 8fcc7bf | 2012-08-14 18:14:50 | [diff] [blame] | 114 | EXPECT_EQ(1, orig_controller.GetEntryCount()); |
| 115 | EXPECT_TRUE(orig_controller.GetPendingEntry()); |
| 116 | |
[email protected] | 0665ebe | 2013-02-13 09:53:19 | [diff] [blame] | 117 | size_t initial_window_count = chrome::GetTotalBrowserCount(); |
[email protected] | 8fcc7bf | 2012-08-14 18:14:50 | [diff] [blame] | 118 | |
| 119 | // View Source. |
| 120 | chrome::ExecuteCommand(browser(), IDC_VIEW_SOURCE); |
| 121 | |
| 122 | // The view source tab should not end up in a new window. |
[email protected] | 0665ebe | 2013-02-13 09:53:19 | [diff] [blame] | 123 | size_t window_count = chrome::GetTotalBrowserCount(); |
[email protected] | 8fcc7bf | 2012-08-14 18:14:50 | [diff] [blame] | 124 | ASSERT_EQ(initial_window_count, window_count); |
| 125 | |
| 126 | // And we should have a newly duplicated tab. |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 127 | ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
[email protected] | 8fcc7bf | 2012-08-14 18:14:50 | [diff] [blame] | 128 | |
| 129 | // Verify we are viewing the source of the last committed entry. |
| 130 | GURL view_source_url("view-source:http://foo/1"); |
| 131 | content::NavigationController& controller = |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 132 | browser()->tab_strip_model()->GetWebContentsAt(1)->GetController(); |
[email protected] | 8fcc7bf | 2012-08-14 18:14:50 | [diff] [blame] | 133 | EXPECT_EQ(1, controller.GetEntryCount()); |
| 134 | EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
| 135 | EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL()); |
| 136 | EXPECT_EQ(view_source_url, controller.GetEntryAtIndex(0)->GetVirtualURL()); |
| 137 | EXPECT_FALSE(controller.GetPendingEntry()); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 138 | } |
[email protected] | b7ca4e6 | 2009-01-23 20:37:29 | [diff] [blame] | 139 | |
| 140 | TEST_F(BrowserCommandsTest, BookmarkCurrentPage) { |
| 141 | // We use profile() here, since it's a TestingProfile. |
| 142 | profile()->CreateBookmarkModel(true); |
[email protected] | 1f9c7419 | 2013-03-25 23:04:35 | [diff] [blame] | 143 | |
| 144 | BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); |
tfarina | 8f4aae2 | 2014-10-23 17:46:11 | [diff] [blame] | 145 | bookmarks::test::WaitForBookmarkModelToLoad(model); |
[email protected] | b7ca4e6 | 2009-01-23 20:37:29 | [diff] [blame] | 146 | |
| 147 | // Navigate to a url. |
[email protected] | 9423d941 | 2009-04-14 22:13:55 | [diff] [blame] | 148 | GURL url1("http://foo/1"); |
| 149 | AddTab(browser(), url1); |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 150 | browser()->OpenURL(OpenURLParams( |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 151 | url1, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); |
[email protected] | b7ca4e6 | 2009-01-23 20:37:29 | [diff] [blame] | 152 | |
deepak.m1 | 54a7f39 | 2014-12-15 04:41:43 | [diff] [blame] | 153 | chrome::BookmarkCurrentPageAllowingExtensionOverrides(browser()); |
[email protected] | b7ca4e6 | 2009-01-23 20:37:29 | [diff] [blame] | 154 | |
| 155 | // It should now be bookmarked in the bookmark model. |
| 156 | EXPECT_EQ(profile(), browser()->profile()); |
[email protected] | 1f9c7419 | 2013-03-25 23:04:35 | [diff] [blame] | 157 | EXPECT_TRUE(model->IsBookmarked(url1)); |
[email protected] | b7ca4e6 | 2009-01-23 20:37:29 | [diff] [blame] | 158 | } |
[email protected] | e21e8c9 | 2009-04-29 02:42:09 | [diff] [blame] | 159 | |
| 160 | // Tests back/forward in new tab (Control + Back/Forward button in the UI). |
| 161 | TEST_F(BrowserCommandsTest, BackForwardInNewTab) { |
| 162 | GURL url1("http://foo/1"); |
| 163 | GURL url2("http://foo/2"); |
| 164 | |
| 165 | // Make a tab with the two pages navigated in it. |
| 166 | AddTab(browser(), url1); |
| 167 | NavigateAndCommitActiveTab(url2); |
| 168 | |
| 169 | // Go back in a new background tab. |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 170 | chrome::GoBack(browser(), NEW_BACKGROUND_TAB); |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 171 | EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); |
| 172 | ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
[email protected] | e21e8c9 | 2009-04-29 02:42:09 | [diff] [blame] | 173 | |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 174 | WebContents* zeroth = browser()->tab_strip_model()->GetWebContentsAt(0); |
[email protected] | e022aca | 2013-07-18 19:10:18 | [diff] [blame] | 175 | WebContents* first = browser()->tab_strip_model()->GetWebContentsAt(1); |
| 176 | |
| 177 | // The original tab should be unchanged. |
| 178 | EXPECT_EQ(url2, zeroth->GetLastCommittedURL()); |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 179 | EXPECT_TRUE(zeroth->GetController().CanGoBack()); |
| 180 | EXPECT_FALSE(zeroth->GetController().CanGoForward()); |
[email protected] | e21e8c9 | 2009-04-29 02:42:09 | [diff] [blame] | 181 | |
[email protected] | e022aca | 2013-07-18 19:10:18 | [diff] [blame] | 182 | // The new tab should be like the first one but navigated back. Since we |
| 183 | // didn't wait for the load to complete, we can't use GetLastCommittedURL. |
[email protected] | a093ce0 | 2013-07-22 20:53:14 | [diff] [blame] | 184 | EXPECT_EQ(url1, first->GetVisibleURL()); |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 185 | EXPECT_FALSE(first->GetController().CanGoBack()); |
| 186 | EXPECT_TRUE(first->GetController().CanGoForward()); |
[email protected] | e21e8c9 | 2009-04-29 02:42:09 | [diff] [blame] | 187 | |
| 188 | // 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] | 189 | browser()->tab_strip_model()->ActivateTabAt(1, true); |
[email protected] | e21e8c9 | 2009-04-29 02:42:09 | [diff] [blame] | 190 | // TODO(brettw) bug 11055: It should not be necessary to commit the load here, |
| 191 | // but because of this bug, it will assert later if we don't. When the bug is |
| 192 | // fixed, one of the three commits here related to this bug should be removed |
| 193 | // (to test both codepaths). |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 194 | CommitPendingLoad(&first->GetController()); |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 195 | EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 196 | chrome::GoForward(browser(), NEW_BACKGROUND_TAB); |
[email protected] | e21e8c9 | 2009-04-29 02:42:09 | [diff] [blame] | 197 | |
| 198 | // The previous tab should be unchanged and still in the foreground. |
[email protected] | e022aca | 2013-07-18 19:10:18 | [diff] [blame] | 199 | EXPECT_EQ(url1, first->GetLastCommittedURL()); |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 200 | EXPECT_FALSE(first->GetController().CanGoBack()); |
| 201 | EXPECT_TRUE(first->GetController().CanGoForward()); |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 202 | EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); |
[email protected] | e21e8c9 | 2009-04-29 02:42:09 | [diff] [blame] | 203 | |
| 204 | // There should be a new tab navigated forward. |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 205 | ASSERT_EQ(3, browser()->tab_strip_model()->count()); |
| 206 | WebContents* second = browser()->tab_strip_model()->GetWebContentsAt(2); |
[email protected] | e022aca | 2013-07-18 19:10:18 | [diff] [blame] | 207 | // Since we didn't wait for load to complete, we can't use |
| 208 | // GetLastCommittedURL. |
[email protected] | a093ce0 | 2013-07-22 20:53:14 | [diff] [blame] | 209 | EXPECT_EQ(url2, second->GetVisibleURL()); |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 210 | EXPECT_TRUE(second->GetController().CanGoBack()); |
| 211 | EXPECT_FALSE(second->GetController().CanGoForward()); |
[email protected] | e21e8c9 | 2009-04-29 02:42:09 | [diff] [blame] | 212 | |
| 213 | // Now do back in a new foreground tab. Don't bother re-checking every sngle |
| 214 | // thing above, just validate that it's opening properly. |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 215 | browser()->tab_strip_model()->ActivateTabAt(2, true); |
[email protected] | e21e8c9 | 2009-04-29 02:42:09 | [diff] [blame] | 216 | // TODO(brettw) bug 11055: see the comment above about why we need this. |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 217 | CommitPendingLoad(&second->GetController()); |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 218 | chrome::GoBack(browser(), NEW_FOREGROUND_TAB); |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 219 | ASSERT_EQ(3, browser()->tab_strip_model()->active_index()); |
| 220 | ASSERT_EQ(url1, |
[email protected] | e022aca | 2013-07-18 19:10:18 | [diff] [blame] | 221 | browser()->tab_strip_model()->GetActiveWebContents()-> |
[email protected] | a093ce0 | 2013-07-22 20:53:14 | [diff] [blame] | 222 | GetVisibleURL()); |
[email protected] | e21e8c9 | 2009-04-29 02:42:09 | [diff] [blame] | 223 | |
| 224 | // Same thing again for forward. |
| 225 | // TODO(brettw) bug 11055: see the comment above about why we need this. |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 226 | CommitPendingLoad(& |
| 227 | browser()->tab_strip_model()->GetActiveWebContents()->GetController()); |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 228 | chrome::GoForward(browser(), NEW_FOREGROUND_TAB); |
[email protected] | 5789218 | 2012-12-03 19:15:39 | [diff] [blame] | 229 | ASSERT_EQ(4, browser()->tab_strip_model()->active_index()); |
| 230 | ASSERT_EQ(url2, |
[email protected] | e022aca | 2013-07-18 19:10:18 | [diff] [blame] | 231 | browser()->tab_strip_model()->GetActiveWebContents()-> |
[email protected] | a093ce0 | 2013-07-22 20:53:14 | [diff] [blame] | 232 | GetVisibleURL()); |
[email protected] | e21e8c9 | 2009-04-29 02:42:09 | [diff] [blame] | 233 | } |
[email protected] | d93dbd1 | 2014-08-04 23:42:53 | [diff] [blame] | 234 | |
| 235 | TEST_F(BrowserCommandsTest, OnMaxZoomIn) { |
| 236 | TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| 237 | |
| 238 | GURL url("http://www.google.com"); |
| 239 | AddTab(browser(), url); |
| 240 | content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0); |
| 241 | |
| 242 | // Continue to zoom in until zoom percent reaches 500. |
| 243 | for (int i = 0; i < 9; ++i) { |
| 244 | chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_IN); |
| 245 | } |
| 246 | |
| 247 | // TODO([email protected]): Figure out why Zoom-In menu item is not |
| 248 | // disabled after Max-zoom is reached. Force disable Zoom-In menu item |
| 249 | // from the context menu since it breaks try jobs on bots. |
| 250 | if (chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)) |
| 251 | chrome::UpdateCommandEnabled(browser(), IDC_ZOOM_PLUS, false); |
| 252 | |
| 253 | ZoomController* zoom_controller = ZoomController::FromWebContents(contents1); |
| 254 | EXPECT_EQ(zoom_controller->GetZoomPercent(), 500.0f); |
| 255 | EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); |
| 256 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); |
| 257 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); |
| 258 | } |
| 259 | |
| 260 | TEST_F(BrowserCommandsTest, OnMaxZoomOut) { |
| 261 | TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| 262 | |
| 263 | GURL url("http://www.google.com"); |
| 264 | AddTab(browser(), url); |
| 265 | content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0); |
| 266 | |
| 267 | // Continue to zoom out until zoom percent reaches 25. |
| 268 | for (int i = 0; i < 7; ++i) { |
| 269 | chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_OUT); |
| 270 | } |
| 271 | |
| 272 | ZoomController* zoom_controller = ZoomController::FromWebContents(contents1); |
| 273 | EXPECT_EQ(zoom_controller->GetZoomPercent(), 25.0f); |
| 274 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); |
| 275 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); |
| 276 | EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); |
| 277 | } |
| 278 | |
| 279 | TEST_F(BrowserCommandsTest, OnZoomReset) { |
| 280 | TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| 281 | |
| 282 | GURL url("http://www.google.com"); |
| 283 | AddTab(browser(), url); |
| 284 | content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0); |
| 285 | |
| 286 | // Change the zoom percentage to 100. |
| 287 | chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_RESET); |
| 288 | |
| 289 | ZoomController* zoom_controller = ZoomController::FromWebContents(contents1); |
| 290 | EXPECT_EQ(zoom_controller->GetZoomPercent(), 100.0f); |
| 291 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); |
| 292 | EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); |
| 293 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); |
| 294 | } |
| 295 | |
| 296 | TEST_F(BrowserCommandsTest, OnZoomLevelChanged) { |
| 297 | TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| 298 | |
| 299 | GURL url("http://www.google.com"); |
| 300 | AddTab(browser(), url); |
| 301 | content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0); |
| 302 | |
| 303 | // Changing zoom percentage from default should enable all the zoom |
| 304 | // NSMenuItems. |
| 305 | chrome_page_zoom::Zoom(contents1, content::PAGE_ZOOM_IN); |
| 306 | |
| 307 | ZoomController* zoom_controller = ZoomController::FromWebContents(contents1); |
| 308 | EXPECT_EQ(zoom_controller->GetZoomPercent(), 110.0f); |
| 309 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); |
| 310 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); |
| 311 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); |
| 312 | } |
| 313 | |
| 314 | TEST_F(BrowserCommandsTest, OnZoomChangedForActiveTab) { |
| 315 | TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| 316 | |
| 317 | GURL url("http://www.google.com"); |
| 318 | GURL url1("http://code.google.com"); |
| 319 | |
| 320 | // Add First tab. |
| 321 | AddTab(browser(), url); |
| 322 | AddTab(browser(), url1); |
| 323 | content::WebContents* contents1 = tab_strip_model->GetWebContentsAt(0); |
| 324 | |
| 325 | ZoomController* zoom_controller = ZoomController::FromWebContents(contents1); |
| 326 | EXPECT_EQ(zoom_controller->GetZoomPercent(), 100.0f); |
| 327 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); |
| 328 | EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); |
| 329 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); |
| 330 | |
| 331 | // Add Second tab. |
| 332 | content::WebContents* contents2 = tab_strip_model->GetWebContentsAt(1); |
| 333 | |
| 334 | tab_strip_model->ActivateTabAt(1, true); |
| 335 | EXPECT_TRUE(tab_strip_model->IsTabSelected(1)); |
| 336 | chrome_page_zoom::Zoom(contents2, content::PAGE_ZOOM_OUT); |
| 337 | |
| 338 | zoom_controller = ZoomController::FromWebContents(contents2); |
| 339 | EXPECT_EQ(zoom_controller->GetZoomPercent(), 90.0f); |
| 340 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); |
| 341 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); |
| 342 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); |
| 343 | } |