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