Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(595)

Side by Side Diff: chrome/browser/browser_commands_unittest.cc

Issue 100031: Write a test for my previous patch to fix a crash in back/forward navigations... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/test/browser_with_test_window_test.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 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 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_dll_resource.h" 5 #include "chrome/app/chrome_dll_resource.h"
6 #include "chrome/browser/bookmarks/bookmark_model.h" 6 #include "chrome/browser/bookmarks/bookmark_model.h"
7 #include "chrome/browser/browser.h" 7 #include "chrome/browser/browser.h"
8 #include "chrome/browser/browser_list.h" 8 #include "chrome/browser/browser_list.h"
9 #include "chrome/browser/tab_contents/navigation_controller.h" 9 #include "chrome/browser/tab_contents/navigation_controller.h"
10 #include "chrome/browser/tab_contents/navigation_entry.h" 10 #include "chrome/browser/tab_contents/navigation_entry.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 // be enabled when the tab is added (and selected). 92 // be enabled when the tab is added (and selected).
93 browser()->command_updater()->UpdateCommandEnabled(IDC_STAR, true); 93 browser()->command_updater()->UpdateCommandEnabled(IDC_STAR, true);
94 94
95 // Star it. 95 // Star it.
96 browser()->ExecuteCommand(IDC_STAR); 96 browser()->ExecuteCommand(IDC_STAR);
97 97
98 // It should now be bookmarked in the bookmark model. 98 // It should now be bookmarked in the bookmark model.
99 EXPECT_EQ(profile(), browser()->profile()); 99 EXPECT_EQ(profile(), browser()->profile());
100 EXPECT_TRUE(browser()->profile()->GetBookmarkModel()->IsBookmarked(url1)); 100 EXPECT_TRUE(browser()->profile()->GetBookmarkModel()->IsBookmarked(url1));
101 } 101 }
102
103 // Tests back/forward in new tab (Control + Back/Forward button in the UI).
104 TEST_F(BrowserCommandsTest, BackForwardInNewTab) {
105 GURL url1("http://foo/1");
106 GURL url2("http://foo/2");
107
108 // Make a tab with the two pages navigated in it.
109 AddTab(browser(), url1);
110 NavigateAndCommitActiveTab(url2);
111
112 // Go back in a new background tab.
113 browser()->GoBack(NEW_BACKGROUND_TAB);
114 EXPECT_EQ(0, browser()->selected_index());
115 ASSERT_EQ(2, browser()->tab_count());
116
117 // The original tab should be unchanged.
118 TabContents* zeroth = browser()->GetTabContentsAt(0);
119 EXPECT_EQ(url2, zeroth->GetURL());
120 EXPECT_TRUE(zeroth->controller().CanGoBack());
121 EXPECT_FALSE(zeroth->controller().CanGoForward());
122
123 // The new tab should be like the first one but navigated back.
124 TabContents* first = browser()->GetTabContentsAt(1);
125 EXPECT_EQ(url1, browser()->GetTabContentsAt(1)->GetURL());
126 EXPECT_FALSE(first->controller().CanGoBack());
127 EXPECT_TRUE(first->controller().CanGoForward());
128
129 // Select the second tab and make it go forward in a new background tab.
130 browser()->SelectTabContentsAt(1, true);
131 // TODO(brettw) bug 11055: It should not be necessary to commit the load here,
132 // but because of this bug, it will assert later if we don't. When the bug is
133 // fixed, one of the three commits here related to this bug should be removed
134 // (to test both codepaths).
135 CommitPendingLoad(&first->controller());
136 EXPECT_EQ(1, browser()->selected_index());
137 browser()->GoForward(NEW_BACKGROUND_TAB);
138
139 // The previous tab should be unchanged and still in the foreground.
140 EXPECT_EQ(url1, first->GetURL());
141 EXPECT_FALSE(first->controller().CanGoBack());
142 EXPECT_TRUE(first->controller().CanGoForward());
143 EXPECT_EQ(1, browser()->selected_index());
144
145 // There should be a new tab navigated forward.
146 ASSERT_EQ(3, browser()->tab_count());
147 TabContents* second = browser()->GetTabContentsAt(2);
148 EXPECT_EQ(url2, second->GetURL());
149 EXPECT_TRUE(second->controller().CanGoBack());
150 EXPECT_FALSE(second->controller().CanGoForward());
151
152 // Now do back in a new foreground tab. Don't bother re-checking every sngle
153 // thing above, just validate that it's opening properly.
154 browser()->SelectTabContentsAt(2, true);
155 // TODO(brettw) bug 11055: see the comment above about why we need this.
156 CommitPendingLoad(&second->controller());
157 browser()->GoBack(NEW_FOREGROUND_TAB);
158 ASSERT_EQ(3, browser()->selected_index());
159 ASSERT_EQ(url1, browser()->GetSelectedTabContents()->GetURL());
160
161 // Same thing again for forward.
162 // TODO(brettw) bug 11055: see the comment above about why we need this.
163 CommitPendingLoad(&browser()->GetSelectedTabContents()->controller());
164 browser()->GoForward(NEW_FOREGROUND_TAB);
165 ASSERT_EQ(4, browser()->selected_index());
166 ASSERT_EQ(url2, browser()->GetSelectedTabContents()->GetURL());
167 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/browser_with_test_window_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698