[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 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] | b782578e | 2009-02-27 23:52:34 | [diff] [blame] | 5 | #include "chrome/app/chrome_dll_resource.h" |
[email protected] | b7ca4e6 | 2009-01-23 20:37:29 | [diff] [blame] | 6 | #include "chrome/browser/bookmarks/bookmark_model.h" |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 7 | #include "chrome/browser/browser.h" |
| 8 | #include "chrome/browser/browser_list.h" |
[email protected] | f3ec774 | 2009-01-15 00:59:16 | [diff] [blame] | 9 | #include "chrome/browser/tab_contents/navigation_controller.h" |
| 10 | #include "chrome/browser/tab_contents/navigation_entry.h" |
[email protected] | 9423d941 | 2009-04-14 22:13:55 | [diff] [blame^] | 11 | #include "chrome/common/url_constants.h" |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 12 | #include "chrome/test/browser_with_test_window_test.h" |
[email protected] | b7ca4e6 | 2009-01-23 20:37:29 | [diff] [blame] | 13 | #include "chrome/test/testing_profile.h" |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 14 | |
| 15 | typedef BrowserWithTestWindowTest BrowserCommandsTest; |
| 16 | |
| 17 | // Tests IDC_SELECT_TAB_0, IDC_SELECT_NEXT_TAB, IDC_SELECT_PREVIOUS_TAB and |
| 18 | // IDC_SELECT_LAST_TAB. |
| 19 | TEST_F(BrowserCommandsTest, TabNavigationAccelerators) { |
[email protected] | 9423d941 | 2009-04-14 22:13:55 | [diff] [blame^] | 20 | GURL about_blank(chrome::kAboutBlankURL); |
| 21 | |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 22 | // Create three tabs. |
[email protected] | 9423d941 | 2009-04-14 22:13:55 | [diff] [blame^] | 23 | AddTab(browser(), about_blank); |
| 24 | AddTab(browser(), about_blank); |
| 25 | AddTab(browser(), about_blank); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 26 | |
| 27 | // Select the second tab. |
| 28 | browser()->SelectTabContentsAt(1, false); |
| 29 | |
| 30 | // Navigate to the first tab using an accelerator. |
| 31 | browser()->ExecuteCommand(IDC_SELECT_TAB_0); |
| 32 | ASSERT_EQ(0, browser()->selected_index()); |
| 33 | |
| 34 | // Navigate to the second tab using the next accelerators. |
| 35 | browser()->ExecuteCommand(IDC_SELECT_NEXT_TAB); |
| 36 | ASSERT_EQ(1, browser()->selected_index()); |
| 37 | |
| 38 | // Navigate back to the first tab using the previous accelerators. |
| 39 | browser()->ExecuteCommand(IDC_SELECT_PREVIOUS_TAB); |
| 40 | ASSERT_EQ(0, browser()->selected_index()); |
| 41 | |
| 42 | // Navigate to the last tab using the select last accelerator. |
| 43 | browser()->ExecuteCommand(IDC_SELECT_LAST_TAB); |
| 44 | ASSERT_EQ(2, browser()->selected_index()); |
| 45 | } |
| 46 | |
| 47 | // Tests IDC_DUPLICATE_TAB. |
| 48 | TEST_F(BrowserCommandsTest, DuplicateTab) { |
[email protected] | 9423d941 | 2009-04-14 22:13:55 | [diff] [blame^] | 49 | GURL url1("http://foo/1"); |
| 50 | GURL url2("http://foo/2"); |
| 51 | GURL url3("http://foo/3"); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 52 | |
| 53 | // Navigate to the three urls, then go back. |
[email protected] | 9423d941 | 2009-04-14 22:13:55 | [diff] [blame^] | 54 | AddTab(browser(), url1); |
[email protected] | 0683cf6 | 2009-04-10 19:31:40 | [diff] [blame] | 55 | NavigateAndCommitActiveTab(url2); |
| 56 | NavigateAndCommitActiveTab(url3); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 57 | |
| 58 | size_t initial_window_count = BrowserList::size(); |
| 59 | |
| 60 | // Duplicate the tab. |
| 61 | browser()->ExecuteCommand(IDC_DUPLICATE_TAB); |
| 62 | |
| 63 | // The duplicated tab should not end up in a new window. |
[email protected] | a0a8b1d | 2009-03-11 14:57:22 | [diff] [blame] | 64 | size_t window_count = BrowserList::size(); |
[email protected] | be3877f | 2009-01-14 15:51:10 | [diff] [blame] | 65 | ASSERT_EQ(initial_window_count, window_count); |
| 66 | |
| 67 | // And we should have a newly duplicated tab. |
| 68 | ASSERT_EQ(2, browser()->tab_count()); |
| 69 | |
| 70 | // Verify the stack of urls. |
| 71 | NavigationController* controller = |
| 72 | browser()->GetTabContentsAt(1)->controller(); |
| 73 | ASSERT_EQ(3, controller->GetEntryCount()); |
| 74 | ASSERT_EQ(2, controller->GetCurrentEntryIndex()); |
| 75 | ASSERT_TRUE(url1 == controller->GetEntryAtIndex(0)->url()); |
| 76 | ASSERT_TRUE(url2 == controller->GetEntryAtIndex(1)->url()); |
| 77 | ASSERT_TRUE(url3 == controller->GetEntryAtIndex(2)->url()); |
| 78 | } |
[email protected] | b7ca4e6 | 2009-01-23 20:37:29 | [diff] [blame] | 79 | |
| 80 | TEST_F(BrowserCommandsTest, BookmarkCurrentPage) { |
| 81 | // We use profile() here, since it's a TestingProfile. |
| 82 | profile()->CreateBookmarkModel(true); |
| 83 | profile()->BlockUntilBookmarkModelLoaded(); |
| 84 | |
| 85 | // Navigate to a url. |
[email protected] | 9423d941 | 2009-04-14 22:13:55 | [diff] [blame^] | 86 | GURL url1("http://foo/1"); |
| 87 | AddTab(browser(), url1); |
[email protected] | b7ca4e6 | 2009-01-23 20:37:29 | [diff] [blame] | 88 | browser()->OpenURL(url1, GURL(), CURRENT_TAB, PageTransition::TYPED); |
| 89 | |
| 90 | // TODO(beng): remove this once we can use WebContentses directly in testing |
| 91 | // instead of the TestTabContents which causes this command not to |
| 92 | // be enabled when the tab is added (and selected). |
| 93 | browser()->command_updater()->UpdateCommandEnabled(IDC_STAR, true); |
| 94 | |
| 95 | // Star it. |
| 96 | browser()->ExecuteCommand(IDC_STAR); |
| 97 | |
| 98 | // It should now be bookmarked in the bookmark model. |
| 99 | EXPECT_EQ(profile(), browser()->profile()); |
| 100 | EXPECT_TRUE(browser()->profile()->GetBookmarkModel()->IsBookmarked(url1)); |
| 101 | } |