| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "chrome/app/chrome_command_ids.h" | 7 #include "chrome/app/chrome_command_ids.h" |
| 8 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 8 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 9 #include "chrome/browser/ui/browser_command_controller.h" | 9 #include "chrome/browser/ui/browser_command_controller.h" |
| 10 #include "chrome/browser/ui/browser_commands.h" | 10 #include "chrome/browser/ui/browser_commands.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 TEST_F(BrowserCommandsTest, BookmarkCurrentPage) { | 157 TEST_F(BrowserCommandsTest, BookmarkCurrentPage) { |
| 158 // We use profile() here, since it's a TestingProfile. | 158 // We use profile() here, since it's a TestingProfile. |
| 159 profile()->CreateBookmarkModel(true); | 159 profile()->CreateBookmarkModel(true); |
| 160 | 160 |
| 161 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | 161 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
| 162 bookmarks::test::WaitForBookmarkModelToLoad(model); | 162 bookmarks::test::WaitForBookmarkModelToLoad(model); |
| 163 | 163 |
| 164 // Navigate to a url. | 164 // Navigate to a url. |
| 165 GURL url1("http://foo/1"); | 165 GURL url1("http://foo/1"); |
| 166 AddTab(browser(), url1); | 166 AddTab(browser(), url1); |
| 167 browser()->OpenURL(OpenURLParams( | 167 browser()->OpenURL(OpenURLParams(url1, Referrer(), |
| 168 url1, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); | 168 WindowOpenDisposition::CURRENT_TAB, |
| 169 ui::PAGE_TRANSITION_TYPED, false)); |
| 169 | 170 |
| 170 chrome::BookmarkCurrentPageAllowingExtensionOverrides(browser()); | 171 chrome::BookmarkCurrentPageAllowingExtensionOverrides(browser()); |
| 171 | 172 |
| 172 // It should now be bookmarked in the bookmark model. | 173 // It should now be bookmarked in the bookmark model. |
| 173 EXPECT_EQ(profile(), browser()->profile()); | 174 EXPECT_EQ(profile(), browser()->profile()); |
| 174 EXPECT_TRUE(model->IsBookmarked(url1)); | 175 EXPECT_TRUE(model->IsBookmarked(url1)); |
| 175 } | 176 } |
| 176 | 177 |
| 177 // Tests back/forward in new tab (Control + Back/Forward button in the UI). | 178 // Tests back/forward in new tab (Control + Back/Forward button in the UI). |
| 178 TEST_F(BrowserCommandsTest, BackForwardInNewTab) { | 179 TEST_F(BrowserCommandsTest, BackForwardInNewTab) { |
| 179 GURL url1("http://foo/1"); | 180 GURL url1("http://foo/1"); |
| 180 GURL url2("http://foo/2"); | 181 GURL url2("http://foo/2"); |
| 181 | 182 |
| 182 // Make a tab with the two pages navigated in it. | 183 // Make a tab with the two pages navigated in it. |
| 183 AddTab(browser(), url1); | 184 AddTab(browser(), url1); |
| 184 NavigateAndCommitActiveTab(url2); | 185 NavigateAndCommitActiveTab(url2); |
| 185 | 186 |
| 186 // Go back in a new background tab. | 187 // Go back in a new background tab. |
| 187 chrome::GoBack(browser(), NEW_BACKGROUND_TAB); | 188 chrome::GoBack(browser(), WindowOpenDisposition::NEW_BACKGROUND_TAB); |
| 188 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); | 189 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); |
| 189 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 190 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
| 190 | 191 |
| 191 WebContents* zeroth = browser()->tab_strip_model()->GetWebContentsAt(0); | 192 WebContents* zeroth = browser()->tab_strip_model()->GetWebContentsAt(0); |
| 192 WebContents* first = browser()->tab_strip_model()->GetWebContentsAt(1); | 193 WebContents* first = browser()->tab_strip_model()->GetWebContentsAt(1); |
| 193 | 194 |
| 194 // The original tab should be unchanged. | 195 // The original tab should be unchanged. |
| 195 EXPECT_EQ(url2, zeroth->GetLastCommittedURL()); | 196 EXPECT_EQ(url2, zeroth->GetLastCommittedURL()); |
| 196 EXPECT_TRUE(zeroth->GetController().CanGoBack()); | 197 EXPECT_TRUE(zeroth->GetController().CanGoBack()); |
| 197 EXPECT_FALSE(zeroth->GetController().CanGoForward()); | 198 EXPECT_FALSE(zeroth->GetController().CanGoForward()); |
| 198 | 199 |
| 199 // The new tab should be like the first one but navigated back. Since we | 200 // The new tab should be like the first one but navigated back. Since we |
| 200 // didn't wait for the load to complete, we can't use GetLastCommittedURL. | 201 // didn't wait for the load to complete, we can't use GetLastCommittedURL. |
| 201 EXPECT_EQ(url1, first->GetVisibleURL()); | 202 EXPECT_EQ(url1, first->GetVisibleURL()); |
| 202 EXPECT_FALSE(first->GetController().CanGoBack()); | 203 EXPECT_FALSE(first->GetController().CanGoBack()); |
| 203 EXPECT_TRUE(first->GetController().CanGoForward()); | 204 EXPECT_TRUE(first->GetController().CanGoForward()); |
| 204 | 205 |
| 205 // Select the second tab and make it go forward in a new background tab. | 206 // Select the second tab and make it go forward in a new background tab. |
| 206 browser()->tab_strip_model()->ActivateTabAt(1, true); | 207 browser()->tab_strip_model()->ActivateTabAt(1, true); |
| 207 // TODO(brettw) bug 11055: It should not be necessary to commit the load here, | 208 // TODO(brettw) bug 11055: It should not be necessary to commit the load here, |
| 208 // but because of this bug, it will assert later if we don't. When the bug is | 209 // but because of this bug, it will assert later if we don't. When the bug is |
| 209 // fixed, one of the three commits here related to this bug should be removed | 210 // fixed, one of the three commits here related to this bug should be removed |
| 210 // (to test both codepaths). | 211 // (to test both codepaths). |
| 211 CommitPendingLoad(&first->GetController()); | 212 CommitPendingLoad(&first->GetController()); |
| 212 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); | 213 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); |
| 213 chrome::GoForward(browser(), NEW_BACKGROUND_TAB); | 214 chrome::GoForward(browser(), WindowOpenDisposition::NEW_BACKGROUND_TAB); |
| 214 | 215 |
| 215 // The previous tab should be unchanged and still in the foreground. | 216 // The previous tab should be unchanged and still in the foreground. |
| 216 EXPECT_EQ(url1, first->GetLastCommittedURL()); | 217 EXPECT_EQ(url1, first->GetLastCommittedURL()); |
| 217 EXPECT_FALSE(first->GetController().CanGoBack()); | 218 EXPECT_FALSE(first->GetController().CanGoBack()); |
| 218 EXPECT_TRUE(first->GetController().CanGoForward()); | 219 EXPECT_TRUE(first->GetController().CanGoForward()); |
| 219 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); | 220 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); |
| 220 | 221 |
| 221 // There should be a new tab navigated forward. | 222 // There should be a new tab navigated forward. |
| 222 ASSERT_EQ(3, browser()->tab_strip_model()->count()); | 223 ASSERT_EQ(3, browser()->tab_strip_model()->count()); |
| 223 WebContents* second = browser()->tab_strip_model()->GetWebContentsAt(2); | 224 WebContents* second = browser()->tab_strip_model()->GetWebContentsAt(2); |
| 224 // Since we didn't wait for load to complete, we can't use | 225 // Since we didn't wait for load to complete, we can't use |
| 225 // GetLastCommittedURL. | 226 // GetLastCommittedURL. |
| 226 EXPECT_EQ(url2, second->GetVisibleURL()); | 227 EXPECT_EQ(url2, second->GetVisibleURL()); |
| 227 EXPECT_TRUE(second->GetController().CanGoBack()); | 228 EXPECT_TRUE(second->GetController().CanGoBack()); |
| 228 EXPECT_FALSE(second->GetController().CanGoForward()); | 229 EXPECT_FALSE(second->GetController().CanGoForward()); |
| 229 | 230 |
| 230 // Now do back in a new foreground tab. Don't bother re-checking every sngle | 231 // Now do back in a new foreground tab. Don't bother re-checking every sngle |
| 231 // thing above, just validate that it's opening properly. | 232 // thing above, just validate that it's opening properly. |
| 232 browser()->tab_strip_model()->ActivateTabAt(2, true); | 233 browser()->tab_strip_model()->ActivateTabAt(2, true); |
| 233 // TODO(brettw) bug 11055: see the comment above about why we need this. | 234 // TODO(brettw) bug 11055: see the comment above about why we need this. |
| 234 CommitPendingLoad(&second->GetController()); | 235 CommitPendingLoad(&second->GetController()); |
| 235 chrome::GoBack(browser(), NEW_FOREGROUND_TAB); | 236 chrome::GoBack(browser(), WindowOpenDisposition::NEW_FOREGROUND_TAB); |
| 236 ASSERT_EQ(3, browser()->tab_strip_model()->active_index()); | 237 ASSERT_EQ(3, browser()->tab_strip_model()->active_index()); |
| 237 ASSERT_EQ(url1, | 238 ASSERT_EQ(url1, |
| 238 browser()->tab_strip_model()->GetActiveWebContents()-> | 239 browser()->tab_strip_model()->GetActiveWebContents()-> |
| 239 GetVisibleURL()); | 240 GetVisibleURL()); |
| 240 | 241 |
| 241 // Same thing again for forward. | 242 // Same thing again for forward. |
| 242 // TODO(brettw) bug 11055: see the comment above about why we need this. | 243 // TODO(brettw) bug 11055: see the comment above about why we need this. |
| 243 CommitPendingLoad(& | 244 CommitPendingLoad(& |
| 244 browser()->tab_strip_model()->GetActiveWebContents()->GetController()); | 245 browser()->tab_strip_model()->GetActiveWebContents()->GetController()); |
| 245 chrome::GoForward(browser(), NEW_FOREGROUND_TAB); | 246 chrome::GoForward(browser(), WindowOpenDisposition::NEW_FOREGROUND_TAB); |
| 246 ASSERT_EQ(4, browser()->tab_strip_model()->active_index()); | 247 ASSERT_EQ(4, browser()->tab_strip_model()->active_index()); |
| 247 ASSERT_EQ(url2, | 248 ASSERT_EQ(url2, |
| 248 browser()->tab_strip_model()->GetActiveWebContents()-> | 249 browser()->tab_strip_model()->GetActiveWebContents()-> |
| 249 GetVisibleURL()); | 250 GetVisibleURL()); |
| 250 } | 251 } |
| 251 | 252 |
| 252 TEST_F(BrowserCommandsTest, OnMaxZoomIn) { | 253 TEST_F(BrowserCommandsTest, OnMaxZoomIn) { |
| 253 TabStripModel* tab_strip_model = browser()->tab_strip_model(); | 254 TabStripModel* tab_strip_model = browser()->tab_strip_model(); |
| 254 | 255 |
| 255 GURL url("http://www.google.com"); | 256 GURL url("http://www.google.com"); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 // Change the zoom level. | 384 // Change the zoom level. |
| 384 zoom::PageZoom::Zoom(tab, content::PAGE_ZOOM_IN); | 385 zoom::PageZoom::Zoom(tab, content::PAGE_ZOOM_IN); |
| 385 | 386 |
| 386 EXPECT_FLOAT_EQ(150.0f, zoom_controller->GetZoomPercent()); | 387 EXPECT_FLOAT_EQ(150.0f, zoom_controller->GetZoomPercent()); |
| 387 | 388 |
| 388 // Tab no longer at default zoom hence actual size should be enabled. | 389 // Tab no longer at default zoom hence actual size should be enabled. |
| 389 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); | 390 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_PLUS)); |
| 390 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); | 391 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_NORMAL)); |
| 391 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); | 392 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ZOOM_MINUS)); |
| 392 } | 393 } |
| OLD | NEW |