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 "chrome/app/chrome_command_ids.h" | 5 #include "chrome/app/chrome_command_ids.h" |
6 #include "chrome/browser/bookmarks/bookmark_model.h" | 6 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 7 #include "chrome/browser/ui/browser_command_controller.h" |
7 #include "chrome/browser/ui/browser_commands.h" | 8 #include "chrome/browser/ui/browser_commands.h" |
8 #include "chrome/browser/ui/browser_list.h" | 9 #include "chrome/browser/ui/browser_list.h" |
9 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
10 #include "chrome/test/base/browser_with_test_window_test.h" | 11 #include "chrome/test/base/browser_with_test_window_test.h" |
11 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
12 #include "content/public/browser/navigation_controller.h" | 13 #include "content/public/browser/navigation_controller.h" |
13 #include "content/public/browser/navigation_entry.h" | 14 #include "content/public/browser/navigation_entry.h" |
14 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
15 #include "content/public/test/test_browser_thread.h" | 16 #include "content/public/test/test_browser_thread.h" |
16 | 17 |
(...skipping 13 matching lines...) Expand all Loading... |
30 GURL about_blank(chrome::kAboutBlankURL); | 31 GURL about_blank(chrome::kAboutBlankURL); |
31 | 32 |
32 // Create three tabs. | 33 // Create three tabs. |
33 AddTab(browser(), about_blank); | 34 AddTab(browser(), about_blank); |
34 AddTab(browser(), about_blank); | 35 AddTab(browser(), about_blank); |
35 AddTab(browser(), about_blank); | 36 AddTab(browser(), about_blank); |
36 | 37 |
37 // Select the second tab. | 38 // Select the second tab. |
38 browser()->ActivateTabAt(1, false); | 39 browser()->ActivateTabAt(1, false); |
39 | 40 |
| 41 CommandUpdater* updater = browser()->command_controller()->command_updater(); |
| 42 |
40 // Navigate to the first tab using an accelerator. | 43 // Navigate to the first tab using an accelerator. |
41 browser()->ExecuteCommand(IDC_SELECT_TAB_0); | 44 updater->ExecuteCommand(IDC_SELECT_TAB_0); |
42 ASSERT_EQ(0, browser()->active_index()); | 45 ASSERT_EQ(0, browser()->active_index()); |
43 | 46 |
44 // Navigate to the second tab using the next accelerators. | 47 // Navigate to the second tab using the next accelerators. |
45 browser()->ExecuteCommand(IDC_SELECT_NEXT_TAB); | 48 updater->ExecuteCommand(IDC_SELECT_NEXT_TAB); |
46 ASSERT_EQ(1, browser()->active_index()); | 49 ASSERT_EQ(1, browser()->active_index()); |
47 | 50 |
48 // Navigate back to the first tab using the previous accelerators. | 51 // Navigate back to the first tab using the previous accelerators. |
49 browser()->ExecuteCommand(IDC_SELECT_PREVIOUS_TAB); | 52 updater->ExecuteCommand(IDC_SELECT_PREVIOUS_TAB); |
50 ASSERT_EQ(0, browser()->active_index()); | 53 ASSERT_EQ(0, browser()->active_index()); |
51 | 54 |
52 // Navigate to the last tab using the select last accelerator. | 55 // Navigate to the last tab using the select last accelerator. |
53 browser()->ExecuteCommand(IDC_SELECT_LAST_TAB); | 56 updater->ExecuteCommand(IDC_SELECT_LAST_TAB); |
54 ASSERT_EQ(2, browser()->active_index()); | 57 ASSERT_EQ(2, browser()->active_index()); |
55 } | 58 } |
56 | 59 |
57 // Tests IDC_DUPLICATE_TAB. | 60 // Tests IDC_DUPLICATE_TAB. |
58 TEST_F(BrowserCommandsTest, DuplicateTab) { | 61 TEST_F(BrowserCommandsTest, DuplicateTab) { |
59 GURL url1("http://foo/1"); | 62 GURL url1("http://foo/1"); |
60 GURL url2("http://foo/2"); | 63 GURL url2("http://foo/2"); |
61 GURL url3("http://foo/3"); | 64 GURL url3("http://foo/3"); |
62 | 65 |
63 // Navigate to the three urls, then go back. | 66 // Navigate to the three urls, then go back. |
64 AddTab(browser(), url1); | 67 AddTab(browser(), url1); |
65 NavigateAndCommitActiveTab(url2); | 68 NavigateAndCommitActiveTab(url2); |
66 NavigateAndCommitActiveTab(url3); | 69 NavigateAndCommitActiveTab(url3); |
67 | 70 |
68 size_t initial_window_count = BrowserList::size(); | 71 size_t initial_window_count = BrowserList::size(); |
69 | 72 |
70 // Duplicate the tab. | 73 // Duplicate the tab. |
71 browser()->ExecuteCommand(IDC_DUPLICATE_TAB); | 74 chrome::ExecuteCommand(browser(), IDC_DUPLICATE_TAB); |
72 | 75 |
73 // The duplicated tab should not end up in a new window. | 76 // The duplicated tab should not end up in a new window. |
74 size_t window_count = BrowserList::size(); | 77 size_t window_count = BrowserList::size(); |
75 ASSERT_EQ(initial_window_count, window_count); | 78 ASSERT_EQ(initial_window_count, window_count); |
76 | 79 |
77 // And we should have a newly duplicated tab. | 80 // And we should have a newly duplicated tab. |
78 ASSERT_EQ(2, browser()->tab_count()); | 81 ASSERT_EQ(2, browser()->tab_count()); |
79 | 82 |
80 // Verify the stack of urls. | 83 // Verify the stack of urls. |
81 content::NavigationController& controller = | 84 content::NavigationController& controller = |
82 browser()->GetWebContentsAt(1)->GetController(); | 85 browser()->GetWebContentsAt(1)->GetController(); |
83 ASSERT_EQ(3, controller.GetEntryCount()); | 86 ASSERT_EQ(3, controller.GetEntryCount()); |
84 ASSERT_EQ(2, controller.GetCurrentEntryIndex()); | 87 ASSERT_EQ(2, controller.GetCurrentEntryIndex()); |
85 ASSERT_TRUE(url1 == controller.GetEntryAtIndex(0)->GetURL()); | 88 ASSERT_TRUE(url1 == controller.GetEntryAtIndex(0)->GetURL()); |
86 ASSERT_TRUE(url2 == controller.GetEntryAtIndex(1)->GetURL()); | 89 ASSERT_TRUE(url2 == controller.GetEntryAtIndex(1)->GetURL()); |
87 ASSERT_TRUE(url3 == controller.GetEntryAtIndex(2)->GetURL()); | 90 ASSERT_TRUE(url3 == controller.GetEntryAtIndex(2)->GetURL()); |
88 } | 91 } |
89 | 92 |
90 TEST_F(BrowserCommandsTest, BookmarkCurrentPage) { | 93 TEST_F(BrowserCommandsTest, BookmarkCurrentPage) { |
91 // We use profile() here, since it's a TestingProfile. | 94 // We use profile() here, since it's a TestingProfile. |
92 profile()->CreateBookmarkModel(true); | 95 profile()->CreateBookmarkModel(true); |
93 profile()->BlockUntilBookmarkModelLoaded(); | 96 profile()->BlockUntilBookmarkModelLoaded(); |
94 | 97 |
95 // Navigate to a url. | 98 // Navigate to a url. |
96 GURL url1("http://foo/1"); | 99 GURL url1("http://foo/1"); |
97 AddTab(browser(), url1); | 100 AddTab(browser(), url1); |
98 browser()->OpenURL(OpenURLParams( | 101 browser()->OpenURL(OpenURLParams( |
99 url1, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); | 102 url1, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); |
100 | 103 |
101 // TODO(beng): remove this once we can use TabContentses directly in testing | 104 chrome::BookmarkCurrentPage(browser()); |
102 // instead of the TestTabContents which causes this command not to | |
103 // be enabled when the tab is added (and selected). | |
104 browser()->command_updater()->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, true); | |
105 | |
106 // Star it. | |
107 browser()->ExecuteCommand(IDC_BOOKMARK_PAGE); | |
108 | 105 |
109 // It should now be bookmarked in the bookmark model. | 106 // It should now be bookmarked in the bookmark model. |
110 EXPECT_EQ(profile(), browser()->profile()); | 107 EXPECT_EQ(profile(), browser()->profile()); |
111 EXPECT_TRUE(browser()->profile()->GetBookmarkModel()->IsBookmarked(url1)); | 108 EXPECT_TRUE(browser()->profile()->GetBookmarkModel()->IsBookmarked(url1)); |
112 } | 109 } |
113 | 110 |
114 // Tests back/forward in new tab (Control + Back/Forward button in the UI). | 111 // Tests back/forward in new tab (Control + Back/Forward button in the UI). |
115 TEST_F(BrowserCommandsTest, BackForwardInNewTab) { | 112 TEST_F(BrowserCommandsTest, BackForwardInNewTab) { |
116 GURL url1("http://foo/1"); | 113 GURL url1("http://foo/1"); |
117 GURL url2("http://foo/2"); | 114 GURL url2("http://foo/2"); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 ASSERT_EQ(url1, browser()->GetActiveWebContents()->GetURL()); | 167 ASSERT_EQ(url1, browser()->GetActiveWebContents()->GetURL()); |
171 | 168 |
172 // Same thing again for forward. | 169 // Same thing again for forward. |
173 // TODO(brettw) bug 11055: see the comment above about why we need this. | 170 // TODO(brettw) bug 11055: see the comment above about why we need this. |
174 CommitPendingLoad(&browser()->GetActiveWebContents()->GetController()); | 171 CommitPendingLoad(&browser()->GetActiveWebContents()->GetController()); |
175 chrome::GoForward(browser(), NEW_FOREGROUND_TAB); | 172 chrome::GoForward(browser(), NEW_FOREGROUND_TAB); |
176 ASSERT_EQ(4, browser()->active_index()); | 173 ASSERT_EQ(4, browser()->active_index()); |
177 ASSERT_EQ(url2, browser()->GetActiveWebContents()->GetURL()); | 174 ASSERT_EQ(url2, browser()->GetActiveWebContents()->GetURL()); |
178 } | 175 } |
179 | 176 |
OLD | NEW |