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

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

Issue 113722: Make automation proxy objects to ref_counted. That allows to process async no... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 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 | « chrome/browser/tab_contents/view_source_uitest.cc ('k') | chrome/browser/unload_uitest.cc » ('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-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #if defined(OS_WIN) 8 #if defined(OS_WIN)
9 #include "base/win_util.h" 9 #include "base/win_util.h"
10 #endif 10 #endif
(...skipping 27 matching lines...) Expand all
38 // window (since the index is 0-based). 38 // window (since the index is 0-based).
39 void RestoreTab(int expected_window_index, 39 void RestoreTab(int expected_window_index,
40 int expected_tabstrip_index) { 40 int expected_tabstrip_index) {
41 int tab_count = 0; 41 int tab_count = 0;
42 int window_count = 0; 42 int window_count = 0;
43 43
44 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); 44 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count));
45 ASSERT_GT(window_count, 0); 45 ASSERT_GT(window_count, 0);
46 46
47 bool expect_new_window = (expected_window_index == window_count); 47 bool expect_new_window = (expected_window_index == window_count);
48 scoped_ptr<BrowserProxy> browser_proxy; 48 scoped_refptr<BrowserProxy> browser_proxy;
49 if (expect_new_window) { 49 if (expect_new_window) {
50 browser_proxy.reset(automation()->GetBrowserWindow(0)); 50 browser_proxy = automation()->GetBrowserWindow(0);
51 } else { 51 } else {
52 ASSERT_GT(window_count, expected_window_index); 52 ASSERT_GT(window_count, expected_window_index);
53 browser_proxy.reset( 53 browser_proxy = automation()->GetBrowserWindow(expected_window_index);
54 automation()->GetBrowserWindow(expected_window_index));
55 } 54 }
56 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); 55 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
57 ASSERT_GT(tab_count, 0); 56 ASSERT_GT(tab_count, 0);
58 57
59 // Restore the tab. 58 // Restore the tab.
60 ASSERT_TRUE(browser_proxy->RunCommand(IDC_RESTORE_TAB)); 59 ASSERT_TRUE(browser_proxy->RunCommand(IDC_RESTORE_TAB));
61 60
62 if (expect_new_window) { 61 if (expect_new_window) {
63 int new_window_count = 0; 62 int new_window_count = 0;
64 ASSERT_TRUE(automation()->GetBrowserWindowCount(&new_window_count)); 63 ASSERT_TRUE(automation()->GetBrowserWindowCount(&new_window_count));
65 EXPECT_EQ(++window_count, new_window_count); 64 EXPECT_EQ(++window_count, new_window_count);
66 browser_proxy.reset(automation()-> 65 browser_proxy = automation()->GetBrowserWindow(expected_window_index);
67 GetBrowserWindow(expected_window_index));
68 } else { 66 } else {
69 int new_tab_count = 0; 67 int new_tab_count = 0;
70 ASSERT_TRUE(browser_proxy->GetTabCount(&new_tab_count)); 68 ASSERT_TRUE(browser_proxy->GetTabCount(&new_tab_count));
71 EXPECT_EQ(++tab_count, new_tab_count); 69 EXPECT_EQ(++tab_count, new_tab_count);
72 } 70 }
73 71
74 // Get a handle to the restored tab. 72 // Get a handle to the restored tab.
75 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); 73 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
76 ASSERT_GT(tab_count, expected_tabstrip_index); 74 ASSERT_GT(tab_count, expected_tabstrip_index);
77 scoped_ptr<TabProxy> restored_tab_proxy( 75 scoped_refptr<TabProxy> restored_tab_proxy(
78 browser_proxy->GetTab(expected_tabstrip_index)); 76 browser_proxy->GetTab(expected_tabstrip_index));
79 // Wait for the restored tab to finish loading. 77 // Wait for the restored tab to finish loading.
80 ASSERT_TRUE(restored_tab_proxy->WaitForTabToBeRestored( 78 ASSERT_TRUE(restored_tab_proxy->WaitForTabToBeRestored(
81 action_max_timeout_ms())); 79 action_max_timeout_ms()));
82 80
83 // Ensure that the tab and window are active. 81 // Ensure that the tab and window are active.
84 CheckActiveWindow(browser_proxy.get()); 82 CheckActiveWindow(browser_proxy.get());
85 EXPECT_EQ(expected_tabstrip_index, 83 EXPECT_EQ(expected_tabstrip_index,
86 GetActiveTabIndex(expected_window_index)); 84 GetActiveTabIndex(expected_window_index));
87 } 85 }
(...skipping 20 matching lines...) Expand all
108 // Ensure that the given browser occupies the currently active window. 106 // Ensure that the given browser occupies the currently active window.
109 void CheckActiveWindow(const BrowserProxy* browser) { 107 void CheckActiveWindow(const BrowserProxy* browser) {
110 // This entire check is disabled because even the IsActive() call 108 // This entire check is disabled because even the IsActive() call
111 // sporadically fails to complete successfully. See http://crbug.com/10916. 109 // sporadically fails to complete successfully. See http://crbug.com/10916.
112 // TODO(pamg): Investigate and re-enable. Also find a way to have the 110 // TODO(pamg): Investigate and re-enable. Also find a way to have the
113 // calling location reported in the gtest error, by inlining this again if 111 // calling location reported in the gtest error, by inlining this again if
114 // nothing else. 112 // nothing else.
115 return; 113 return;
116 114
117 bool is_active = false; 115 bool is_active = false;
118 scoped_ptr<WindowProxy> window_proxy(browser->GetWindow()); 116 scoped_refptr<WindowProxy> window_proxy(browser->GetWindow());
119 ASSERT_TRUE(window_proxy->IsActive(&is_active)); 117 ASSERT_TRUE(window_proxy->IsActive(&is_active));
120 // The check for is_active may fail if other apps are active while running 118 // The check for is_active may fail if other apps are active while running
121 // the tests, because Chromium won't be the foremost application at all. 119 // the tests, because Chromium won't be the foremost application at all.
122 // So we'll have it log an error, but not report one through gtest, to 120 // So we'll have it log an error, but not report one through gtest, to
123 // keep the test result deterministic and the buildbots happy. 121 // keep the test result deterministic and the buildbots happy.
124 if (!is_active) 122 if (!is_active)
125 LOG(ERROR) << "WARNING: is_active was false, expected true. (This may " 123 LOG(ERROR) << "WARNING: is_active was false, expected true. (This may "
126 "be simply because Chromium isn't the front application.)"; 124 "be simply because Chromium isn't the front application.)";
127 } 125 }
128 126
129 GURL url1_; 127 GURL url1_;
130 GURL url2_; 128 GURL url2_;
131 129
132 private: 130 private:
133 DISALLOW_COPY_AND_ASSIGN(TabRestoreUITest); 131 DISALLOW_COPY_AND_ASSIGN(TabRestoreUITest);
134 }; 132 };
135 133
136 // Close the end tab in the current window, then restore it. The tab should be 134 // Close the end tab in the current window, then restore it. The tab should be
137 // in its original position, and active. 135 // in its original position, and active.
138 TEST_F(TabRestoreUITest, Basic) { 136 TEST_F(TabRestoreUITest, Basic) {
139 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); 137 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0));
140 138
141 int starting_tab_count; 139 int starting_tab_count;
142 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count)); 140 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count));
143 int tab_count = AddSomeTabs(browser_proxy.get(), 1); 141 int tab_count = AddSomeTabs(browser_proxy.get(), 1);
144 142
145 int closed_tab_index = tab_count - 1; 143 int closed_tab_index = tab_count - 1;
146 scoped_ptr<TabProxy> new_tab(browser_proxy->GetTab(closed_tab_index)); 144 scoped_refptr<TabProxy> new_tab(browser_proxy->GetTab(closed_tab_index));
147 // Make sure we're at url. 145 // Make sure we're at url.
148 new_tab->NavigateToURL(url1_); 146 new_tab->NavigateToURL(url1_);
149 // Close the tab. 147 // Close the tab.
150 new_tab->Close(true); 148 new_tab->Close(true);
151 new_tab.reset(); 149 new_tab = NULL;
152 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); 150 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
153 EXPECT_EQ(starting_tab_count, tab_count); 151 EXPECT_EQ(starting_tab_count, tab_count);
154 152
155 RestoreTab(0, closed_tab_index); 153 RestoreTab(0, closed_tab_index);
156 154
157 // And make sure everything looks right. 155 // And make sure everything looks right.
158 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); 156 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
159 EXPECT_EQ(starting_tab_count + 1, tab_count); 157 EXPECT_EQ(starting_tab_count + 1, tab_count);
160 EXPECT_EQ(closed_tab_index, GetActiveTabIndex()); 158 EXPECT_EQ(closed_tab_index, GetActiveTabIndex());
161 EXPECT_EQ(url1_, GetActiveTabURL()); 159 EXPECT_EQ(url1_, GetActiveTabURL());
162 } 160 }
163 161
164 // Close a tab not at the end of the current window, then restore it. The tab 162 // Close a tab not at the end of the current window, then restore it. The tab
165 // should be in its original position, and active. 163 // should be in its original position, and active.
166 TEST_F(TabRestoreUITest, MiddleTab) { 164 TEST_F(TabRestoreUITest, MiddleTab) {
167 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); 165 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0));
168 166
169 int starting_tab_count; 167 int starting_tab_count;
170 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count)); 168 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count));
171 int tab_count = AddSomeTabs(browser_proxy.get(), 3); 169 int tab_count = AddSomeTabs(browser_proxy.get(), 3);
172 170
173 // Close one in the middle 171 // Close one in the middle
174 int closed_tab_index = starting_tab_count + 1; 172 int closed_tab_index = starting_tab_count + 1;
175 scoped_ptr<TabProxy> new_tab(browser_proxy->GetTab(closed_tab_index)); 173 scoped_refptr<TabProxy> new_tab(browser_proxy->GetTab(closed_tab_index));
176 // Make sure we're at url. 174 // Make sure we're at url.
177 new_tab->NavigateToURL(url1_); 175 new_tab->NavigateToURL(url1_);
178 // Close the tab. 176 // Close the tab.
179 new_tab->Close(true); 177 new_tab->Close(true);
180 new_tab.reset(); 178 new_tab = NULL;
181 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); 179 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
182 EXPECT_EQ(starting_tab_count + 2, tab_count); 180 EXPECT_EQ(starting_tab_count + 2, tab_count);
183 181
184 RestoreTab(0, closed_tab_index); 182 RestoreTab(0, closed_tab_index);
185 183
186 // And make sure everything looks right. 184 // And make sure everything looks right.
187 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); 185 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
188 EXPECT_EQ(starting_tab_count + 3, tab_count); 186 EXPECT_EQ(starting_tab_count + 3, tab_count);
189 EXPECT_EQ(closed_tab_index, GetActiveTabIndex()); 187 EXPECT_EQ(closed_tab_index, GetActiveTabIndex());
190 EXPECT_EQ(url1_, GetActiveTabURL()); 188 EXPECT_EQ(url1_, GetActiveTabURL());
191 } 189 }
192 190
193 // Close a tab, switch windows, then restore the tab. The tab should be in its 191 // Close a tab, switch windows, then restore the tab. The tab should be in its
194 // original window and position, and active. 192 // original window and position, and active.
195 TEST_F(TabRestoreUITest, RestoreToDifferentWindow) { 193 TEST_F(TabRestoreUITest, RestoreToDifferentWindow) {
196 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); 194 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0));
197 195
198 // This call is virtually guaranteed to pass, assuming that Chromium is the 196 // This call is virtually guaranteed to pass, assuming that Chromium is the
199 // active application, which will establish a baseline for later calls to 197 // active application, which will establish a baseline for later calls to
200 // CheckActiveWindow(). See comments in that function. 198 // CheckActiveWindow(). See comments in that function.
201 CheckActiveWindow(browser_proxy.get()); 199 CheckActiveWindow(browser_proxy.get());
202 200
203 int starting_tab_count; 201 int starting_tab_count;
204 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count)); 202 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count));
205 int tab_count = AddSomeTabs(browser_proxy.get(), 3); 203 int tab_count = AddSomeTabs(browser_proxy.get(), 3);
206 204
207 // Close one in the middle 205 // Close one in the middle
208 int closed_tab_index = starting_tab_count + 1; 206 int closed_tab_index = starting_tab_count + 1;
209 scoped_ptr<TabProxy> new_tab(browser_proxy->GetTab(closed_tab_index)); 207 scoped_refptr<TabProxy> new_tab(browser_proxy->GetTab(closed_tab_index));
210 // Make sure we're at url. 208 // Make sure we're at url.
211 new_tab->NavigateToURL(url1_); 209 new_tab->NavigateToURL(url1_);
212 // Close the tab. 210 // Close the tab.
213 new_tab->Close(true); 211 new_tab->Close(true);
214 new_tab.reset(); 212 new_tab = NULL;
215 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); 213 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
216 EXPECT_EQ(starting_tab_count + 2, tab_count); 214 EXPECT_EQ(starting_tab_count + 2, tab_count);
217 215
218 // Create a new browser. 216 // Create a new browser.
219 ASSERT_TRUE(automation()->OpenNewBrowserWindow(false)); 217 ASSERT_TRUE(automation()->OpenNewBrowserWindow(false));
220 int window_count; 218 int window_count;
221 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); 219 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count));
222 EXPECT_EQ(2, window_count); 220 EXPECT_EQ(2, window_count);
223 221
224 CheckActiveWindow(automation()->GetBrowserWindow(1)); 222 CheckActiveWindow(automation()->GetBrowserWindow(1));
225 223
226 // Restore tab into original browser. 224 // Restore tab into original browser.
227 RestoreTab(0, closed_tab_index); 225 RestoreTab(0, closed_tab_index);
228 226
229 // And make sure everything looks right. 227 // And make sure everything looks right.
230 CheckActiveWindow(browser_proxy.get()); 228 CheckActiveWindow(browser_proxy.get());
231 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); 229 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
232 EXPECT_EQ(starting_tab_count + 3, tab_count); 230 EXPECT_EQ(starting_tab_count + 3, tab_count);
233 EXPECT_EQ(closed_tab_index, GetActiveTabIndex(0)); 231 EXPECT_EQ(closed_tab_index, GetActiveTabIndex(0));
234 EXPECT_EQ(url1_, GetActiveTabURL(0)); 232 EXPECT_EQ(url1_, GetActiveTabURL(0));
235 } 233 }
236 234
237 // Close a tab, open a new window, close the first window, then restore the 235 // Close a tab, open a new window, close the first window, then restore the
238 // tab. It should be in a new window. 236 // tab. It should be in a new window.
239 TEST_F(TabRestoreUITest, BasicRestoreFromClosedWindow) { 237 TEST_F(TabRestoreUITest, BasicRestoreFromClosedWindow) {
240 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); 238 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0));
241 CheckActiveWindow(browser_proxy.get()); 239 CheckActiveWindow(browser_proxy.get());
242 240
243 int tab_count; 241 int tab_count;
244 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); 242 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
245 243
246 // Close tabs until we only have one open. 244 // Close tabs until we only have one open.
247 while (tab_count > 1) { 245 while (tab_count > 1) {
248 scoped_ptr<TabProxy> tab_to_close(browser_proxy->GetTab(0)); 246 scoped_refptr<TabProxy> tab_to_close(browser_proxy->GetTab(0));
249 tab_to_close->Close(true); 247 tab_to_close->Close(true);
250 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); 248 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
251 } 249 }
252 250
253 // Navigate to url1 then url2. 251 // Navigate to url1 then url2.
254 scoped_ptr<TabProxy> tab_proxy(browser_proxy->GetTab(0)); 252 scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetTab(0));
255 tab_proxy->NavigateToURL(url1_); 253 tab_proxy->NavigateToURL(url1_);
256 tab_proxy->NavigateToURL(url2_); 254 tab_proxy->NavigateToURL(url2_);
257 255
258 // Create a new browser. 256 // Create a new browser.
259 ASSERT_TRUE(automation()->OpenNewBrowserWindow(false)); 257 ASSERT_TRUE(automation()->OpenNewBrowserWindow(false));
260 int window_count; 258 int window_count;
261 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); 259 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count));
262 EXPECT_EQ(2, window_count); 260 EXPECT_EQ(2, window_count);
263 CheckActiveWindow(automation()->GetBrowserWindow(1)); 261 CheckActiveWindow(automation()->GetBrowserWindow(1));
264 262
265 // Close the final tab in the first browser. 263 // Close the final tab in the first browser.
266 EXPECT_TRUE(tab_proxy->Close(true)); 264 EXPECT_TRUE(tab_proxy->Close(true));
267 ASSERT_TRUE(automation()->WaitForWindowCountToBecome( 265 ASSERT_TRUE(automation()->WaitForWindowCountToBecome(
268 1, action_max_timeout_ms())); 266 1, action_max_timeout_ms()));
269 267
270 // Tab and browser are no longer valid. 268 // Tab and browser are no longer valid.
271 tab_proxy.reset(); 269 tab_proxy = NULL;
272 browser_proxy.reset(); 270 browser_proxy = NULL;
273 271
274 RestoreTab(1, 0); 272 RestoreTab(1, 0);
275 273
276 // Tab should be in a new window. 274 // Tab should be in a new window.
277 browser_proxy.reset(automation()->GetBrowserWindow(1)); 275 browser_proxy = automation()->GetBrowserWindow(1);
278 CheckActiveWindow(browser_proxy.get()); 276 CheckActiveWindow(browser_proxy.get());
279 tab_proxy.reset(browser_proxy->GetActiveTab()); 277 tab_proxy = browser_proxy->GetActiveTab();
280 // And make sure the URLs matches. 278 // And make sure the URLs matches.
281 EXPECT_EQ(url2_, GetActiveTabURL(1)); 279 EXPECT_EQ(url2_, GetActiveTabURL(1));
282 EXPECT_TRUE(tab_proxy->GoBack()); 280 EXPECT_TRUE(tab_proxy->GoBack());
283 EXPECT_EQ(url1_, GetActiveTabURL(1)); 281 EXPECT_EQ(url1_, GetActiveTabURL(1));
284 } 282 }
285 283
286 // Open a window with multiple tabs, close a tab, then close the window. 284 // Open a window with multiple tabs, close a tab, then close the window.
287 // Restore both and make sure the tab goes back into the window. 285 // Restore both and make sure the tab goes back into the window.
288 TEST_F(TabRestoreUITest, RestoreWindowAndTab) { 286 TEST_F(TabRestoreUITest, RestoreWindowAndTab) {
289 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); 287 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0));
290 CheckActiveWindow(browser_proxy.get()); 288 CheckActiveWindow(browser_proxy.get());
291 289
292 int starting_tab_count; 290 int starting_tab_count;
293 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count)); 291 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count));
294 int tab_count = AddSomeTabs(browser_proxy.get(), 3); 292 int tab_count = AddSomeTabs(browser_proxy.get(), 3);
295 293
296 // Close one in the middle 294 // Close one in the middle
297 int closed_tab_index = starting_tab_count + 1; 295 int closed_tab_index = starting_tab_count + 1;
298 scoped_ptr<TabProxy> new_tab(browser_proxy->GetTab(closed_tab_index)); 296 scoped_refptr<TabProxy> new_tab(browser_proxy->GetTab(closed_tab_index));
299 // Make sure we're at url. 297 // Make sure we're at url.
300 new_tab->NavigateToURL(url1_); 298 new_tab->NavigateToURL(url1_);
301 // Close the tab. 299 // Close the tab.
302 new_tab->Close(true); 300 new_tab->Close(true);
303 new_tab.reset(); 301 new_tab = NULL;
304 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); 302 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
305 EXPECT_EQ(starting_tab_count + 2, tab_count); 303 EXPECT_EQ(starting_tab_count + 2, tab_count);
306 304
307 // Create a new browser. 305 // Create a new browser.
308 ASSERT_TRUE(automation()->OpenNewBrowserWindow(false)); 306 ASSERT_TRUE(automation()->OpenNewBrowserWindow(false));
309 int window_count; 307 int window_count;
310 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); 308 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count));
311 EXPECT_EQ(2, window_count); 309 EXPECT_EQ(2, window_count);
312 CheckActiveWindow(automation()->GetBrowserWindow(1)); 310 CheckActiveWindow(automation()->GetBrowserWindow(1));
313 311
314 // Close the first browser. 312 // Close the first browser.
315 bool application_closing; 313 bool application_closing;
316 EXPECT_TRUE(CloseBrowser(browser_proxy.get(), &application_closing)); 314 EXPECT_TRUE(CloseBrowser(browser_proxy.get(), &application_closing));
317 EXPECT_FALSE(application_closing); 315 EXPECT_FALSE(application_closing);
318 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); 316 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count));
319 EXPECT_EQ(1, window_count); 317 EXPECT_EQ(1, window_count);
320 318
321 // Browser is no longer valid. 319 // Browser is no longer valid.
322 browser_proxy.reset(); 320 browser_proxy = NULL;
323 321
324 // Restore the first window. The expected_tabstrip_index (second argument) 322 // Restore the first window. The expected_tabstrip_index (second argument)
325 // indicates the expected active tab. 323 // indicates the expected active tab.
326 RestoreTab(1, starting_tab_count + 1); 324 RestoreTab(1, starting_tab_count + 1);
327 browser_proxy.reset(automation()->GetBrowserWindow(1)); 325 browser_proxy = automation()->GetBrowserWindow(1);
328 CheckActiveWindow(browser_proxy.get()); 326 CheckActiveWindow(browser_proxy.get());
329 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); 327 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
330 EXPECT_EQ(starting_tab_count + 2, tab_count); 328 EXPECT_EQ(starting_tab_count + 2, tab_count);
331 329
332 // Restore the closed tab. 330 // Restore the closed tab.
333 RestoreTab(1, closed_tab_index); 331 RestoreTab(1, closed_tab_index);
334 CheckActiveWindow(browser_proxy.get()); 332 CheckActiveWindow(browser_proxy.get());
335 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); 333 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
336 EXPECT_EQ(starting_tab_count + 3, tab_count); 334 EXPECT_EQ(starting_tab_count + 3, tab_count);
337 EXPECT_EQ(url1_, GetActiveTabURL(1)); 335 EXPECT_EQ(url1_, GetActiveTabURL(1));
338 } 336 }
339 337
340 // Open a window with two tabs, close both (closing the window), then restore 338 // Open a window with two tabs, close both (closing the window), then restore
341 // both. Make sure both restored tabs are in the same window. 339 // both. Make sure both restored tabs are in the same window.
342 TEST_F(TabRestoreUITest, RestoreIntoSameWindow) { 340 TEST_F(TabRestoreUITest, RestoreIntoSameWindow) {
343 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); 341 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0));
344 CheckActiveWindow(browser_proxy.get()); 342 CheckActiveWindow(browser_proxy.get());
345 343
346 int starting_tab_count; 344 int starting_tab_count;
347 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count)); 345 ASSERT_TRUE(browser_proxy->GetTabCount(&starting_tab_count));
348 int tab_count = AddSomeTabs(browser_proxy.get(), 2); 346 int tab_count = AddSomeTabs(browser_proxy.get(), 2);
349 347
350 // Navigate the rightmost one to url2_ for easier identification. 348 // Navigate the rightmost one to url2_ for easier identification.
351 scoped_ptr<TabProxy> tab_proxy(browser_proxy->GetTab(tab_count - 1)); 349 scoped_refptr<TabProxy> tab_proxy(browser_proxy->GetTab(tab_count - 1));
352 tab_proxy->NavigateToURL(url2_); 350 tab_proxy->NavigateToURL(url2_);
353 351
354 // Create a new browser. 352 // Create a new browser.
355 ASSERT_TRUE(automation()->OpenNewBrowserWindow(false)); 353 ASSERT_TRUE(automation()->OpenNewBrowserWindow(false));
356 int window_count; 354 int window_count;
357 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); 355 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count));
358 EXPECT_EQ(2, window_count); 356 EXPECT_EQ(2, window_count);
359 CheckActiveWindow(automation()->GetBrowserWindow(1)); 357 CheckActiveWindow(automation()->GetBrowserWindow(1));
360 358
361 // Close all but one tab in the first browser, left to right. 359 // Close all but one tab in the first browser, left to right.
362 while (tab_count > 1) { 360 while (tab_count > 1) {
363 scoped_ptr<TabProxy> tab_to_close(browser_proxy->GetTab(0)); 361 scoped_refptr<TabProxy> tab_to_close(browser_proxy->GetTab(0));
364 tab_to_close->Close(true); 362 tab_to_close->Close(true);
365 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); 363 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
366 } 364 }
367 365
368 // Close the last tab, closing the browser. 366 // Close the last tab, closing the browser.
369 tab_proxy.reset(browser_proxy->GetTab(0)); 367 tab_proxy = browser_proxy->GetTab(0);
370 EXPECT_TRUE(tab_proxy->Close(true)); 368 EXPECT_TRUE(tab_proxy->Close(true));
371 ASSERT_TRUE(automation()->WaitForWindowCountToBecome( 369 ASSERT_TRUE(automation()->WaitForWindowCountToBecome(
372 1, action_max_timeout_ms())); 370 1, action_max_timeout_ms()));
373 browser_proxy.reset(); 371 browser_proxy = NULL;
374 tab_proxy.reset(); 372 tab_proxy = NULL;
375 373
376 // Restore the last-closed tab into a new window. 374 // Restore the last-closed tab into a new window.
377 RestoreTab(1, 0); 375 RestoreTab(1, 0);
378 browser_proxy.reset(automation()->GetBrowserWindow(1)); 376 browser_proxy = automation()->GetBrowserWindow(1);
379 CheckActiveWindow(browser_proxy.get()); 377 CheckActiveWindow(browser_proxy.get());
380 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); 378 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
381 EXPECT_EQ(1, tab_count); 379 EXPECT_EQ(1, tab_count);
382 EXPECT_EQ(url2_, GetActiveTabURL(1)); 380 EXPECT_EQ(url2_, GetActiveTabURL(1));
383 381
384 // Restore the next-to-last-closed tab into the same window. 382 // Restore the next-to-last-closed tab into the same window.
385 RestoreTab(1, 0); 383 RestoreTab(1, 0);
386 CheckActiveWindow(browser_proxy.get()); 384 CheckActiveWindow(browser_proxy.get());
387 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); 385 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
388 EXPECT_EQ(2, tab_count); 386 EXPECT_EQ(2, tab_count);
389 EXPECT_EQ(url1_, GetActiveTabURL(1)); 387 EXPECT_EQ(url1_, GetActiveTabURL(1));
390 } 388 }
391 389
392 // Tests that a duplicate history entry is not created when we restore a page 390 // Tests that a duplicate history entry is not created when we restore a page
393 // to an existing SiteInstance. (Bug 1230446) 391 // to an existing SiteInstance. (Bug 1230446)
394 TEST_F(TabRestoreUITest, RestoreWithExistingSiteInstance) { 392 TEST_F(TabRestoreUITest, RestoreWithExistingSiteInstance) {
395 const wchar_t kDocRoot[] = L"chrome/test/data"; 393 const wchar_t kDocRoot[] = L"chrome/test/data";
396 scoped_refptr<HTTPTestServer> server = 394 scoped_refptr<HTTPTestServer> server =
397 HTTPTestServer::CreateServer(kDocRoot, NULL); 395 HTTPTestServer::CreateServer(kDocRoot, NULL);
398 ASSERT_TRUE(NULL != server.get()); 396 ASSERT_TRUE(NULL != server.get());
399 GURL http_url1(server->TestServerPageW(L"files/title1.html")); 397 GURL http_url1(server->TestServerPageW(L"files/title1.html"));
400 GURL http_url2(server->TestServerPageW(L"files/title2.html")); 398 GURL http_url2(server->TestServerPageW(L"files/title2.html"));
401 399
402 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); 400 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0));
403 int tab_count; 401 int tab_count;
404 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); 402 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
405 403
406 // Add a tab 404 // Add a tab
407 browser_proxy->AppendTab(http_url1); 405 browser_proxy->AppendTab(http_url1);
408 int new_tab_count; 406 int new_tab_count;
409 ASSERT_TRUE(browser_proxy->GetTabCount(&new_tab_count)); 407 ASSERT_TRUE(browser_proxy->GetTabCount(&new_tab_count));
410 EXPECT_EQ(++tab_count, new_tab_count); 408 EXPECT_EQ(++tab_count, new_tab_count);
411 scoped_ptr<TabProxy> tab(browser_proxy->GetTab(tab_count - 1)); 409 scoped_refptr<TabProxy> tab(browser_proxy->GetTab(tab_count - 1));
412 410
413 // Navigate to another same-site URL. 411 // Navigate to another same-site URL.
414 tab->NavigateToURL(http_url2); 412 tab->NavigateToURL(http_url2);
415 413
416 // Close the tab. 414 // Close the tab.
417 tab->Close(true); 415 tab->Close(true);
418 tab.reset(); 416 tab = NULL;
419 417
420 // Create a new tab to the original site. Assuming process-per-site is 418 // Create a new tab to the original site. Assuming process-per-site is
421 // enabled, this will ensure that the SiteInstance used by the restored tab 419 // enabled, this will ensure that the SiteInstance used by the restored tab
422 // will already exist when the restore happens. 420 // will already exist when the restore happens.
423 browser_proxy->AppendTab(http_url2); 421 browser_proxy->AppendTab(http_url2);
424 422
425 // Restore the closed tab. 423 // Restore the closed tab.
426 RestoreTab(0, tab_count - 1); 424 RestoreTab(0, tab_count - 1);
427 tab.reset(browser_proxy->GetActiveTab()); 425 tab = browser_proxy->GetActiveTab();
428 426
429 // And make sure the URLs match. 427 // And make sure the URLs match.
430 EXPECT_EQ(http_url2, GetActiveTabURL()); 428 EXPECT_EQ(http_url2, GetActiveTabURL());
431 EXPECT_TRUE(tab->GoBack()); 429 EXPECT_TRUE(tab->GoBack());
432 EXPECT_EQ(http_url1, GetActiveTabURL()); 430 EXPECT_EQ(http_url1, GetActiveTabURL());
433 } 431 }
434 432
435 // Tests that the SiteInstances used for entries in a restored tab's history 433 // Tests that the SiteInstances used for entries in a restored tab's history
436 // are given appropriate max page IDs, even if the renderer for the entry 434 // are given appropriate max page IDs, even if the renderer for the entry
437 // already exists. (Bug 1204135) 435 // already exists. (Bug 1204135)
438 TEST_F(TabRestoreUITest, RestoreCrossSiteWithExistingSiteInstance) { 436 TEST_F(TabRestoreUITest, RestoreCrossSiteWithExistingSiteInstance) {
439 const wchar_t kDocRoot[] = L"chrome/test/data"; 437 const wchar_t kDocRoot[] = L"chrome/test/data";
440 scoped_refptr<HTTPTestServer> server = 438 scoped_refptr<HTTPTestServer> server =
441 HTTPTestServer::CreateServer(kDocRoot, NULL); 439 HTTPTestServer::CreateServer(kDocRoot, NULL);
442 ASSERT_TRUE(NULL != server.get()); 440 ASSERT_TRUE(NULL != server.get());
443 GURL http_url1(server->TestServerPageW(L"files/title1.html")); 441 GURL http_url1(server->TestServerPageW(L"files/title1.html"));
444 GURL http_url2(server->TestServerPageW(L"files/title2.html")); 442 GURL http_url2(server->TestServerPageW(L"files/title2.html"));
445 443
446 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); 444 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0));
447 int tab_count; 445 int tab_count;
448 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count)); 446 ASSERT_TRUE(browser_proxy->GetTabCount(&tab_count));
449 447
450 // Add a tab 448 // Add a tab
451 browser_proxy->AppendTab(http_url1); 449 browser_proxy->AppendTab(http_url1);
452 int new_tab_count; 450 int new_tab_count;
453 ASSERT_TRUE(browser_proxy->GetTabCount(&new_tab_count)); 451 ASSERT_TRUE(browser_proxy->GetTabCount(&new_tab_count));
454 EXPECT_EQ(++tab_count, new_tab_count); 452 EXPECT_EQ(++tab_count, new_tab_count);
455 scoped_ptr<TabProxy> tab(browser_proxy->GetTab(tab_count - 1)); 453 scoped_refptr<TabProxy> tab(browser_proxy->GetTab(tab_count - 1));
456 454
457 // Navigate to more URLs, then a cross-site URL. 455 // Navigate to more URLs, then a cross-site URL.
458 tab->NavigateToURL(http_url2); 456 tab->NavigateToURL(http_url2);
459 tab->NavigateToURL(http_url1); 457 tab->NavigateToURL(http_url1);
460 tab->NavigateToURL(url1_); 458 tab->NavigateToURL(url1_);
461 459
462 // Close the tab. 460 // Close the tab.
463 tab->Close(true); 461 tab->Close(true);
464 tab.reset(); 462 tab = NULL;
465 463
466 // Create a new tab to the original site. Assuming process-per-site is 464 // Create a new tab to the original site. Assuming process-per-site is
467 // enabled, this will ensure that the SiteInstance will already exist when 465 // enabled, this will ensure that the SiteInstance will already exist when
468 // the user clicks Back in the restored tab. 466 // the user clicks Back in the restored tab.
469 browser_proxy->AppendTab(http_url2); 467 browser_proxy->AppendTab(http_url2);
470 468
471 // Restore the closed tab. 469 // Restore the closed tab.
472 RestoreTab(0, tab_count - 1); 470 RestoreTab(0, tab_count - 1);
473 tab.reset(browser_proxy->GetActiveTab()); 471 tab = browser_proxy->GetActiveTab();
474 472
475 // And make sure the URLs match. 473 // And make sure the URLs match.
476 EXPECT_EQ(url1_, GetActiveTabURL()); 474 EXPECT_EQ(url1_, GetActiveTabURL());
477 EXPECT_TRUE(tab->GoBack()); 475 EXPECT_TRUE(tab->GoBack());
478 EXPECT_EQ(http_url1, GetActiveTabURL()); 476 EXPECT_EQ(http_url1, GetActiveTabURL());
479 477
480 // Navigating to a new URL should clear the forward list, because the max 478 // Navigating to a new URL should clear the forward list, because the max
481 // page ID of the renderer should have been updated when we restored the tab. 479 // page ID of the renderer should have been updated when we restored the tab.
482 tab->NavigateToURL(http_url2); 480 tab->NavigateToURL(http_url2);
483 EXPECT_FALSE(tab->GoForward()); 481 EXPECT_FALSE(tab->GoForward());
484 EXPECT_EQ(http_url2, GetActiveTabURL()); 482 EXPECT_EQ(http_url2, GetActiveTabURL());
485 } 483 }
486 484
487 TEST_F(TabRestoreUITest, RestoreWindow) { 485 TEST_F(TabRestoreUITest, RestoreWindow) {
488 // Create a new window. 486 // Create a new window.
489 int window_count; 487 int window_count;
490 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); 488 ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count));
491 ASSERT_TRUE(automation()->OpenNewBrowserWindow(false)); 489 ASSERT_TRUE(automation()->OpenNewBrowserWindow(false));
492 int new_window_count = 0; 490 int new_window_count = 0;
493 ASSERT_TRUE(automation()->GetBrowserWindowCount(&new_window_count)); 491 ASSERT_TRUE(automation()->GetBrowserWindowCount(&new_window_count));
494 EXPECT_EQ(++window_count, new_window_count); 492 EXPECT_EQ(++window_count, new_window_count);
495 493
496 // Create two more tabs, one with url1, the other url2. 494 // Create two more tabs, one with url1, the other url2.
497 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); 495 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0));
498 int initial_tab_count; 496 int initial_tab_count;
499 ASSERT_TRUE(browser_proxy->GetTabCount(&initial_tab_count)); 497 ASSERT_TRUE(browser_proxy->GetTabCount(&initial_tab_count));
500 browser_proxy->AppendTab(url1_); 498 browser_proxy->AppendTab(url1_);
501 ASSERT_TRUE(browser_proxy->WaitForTabCountToBecome(initial_tab_count + 1, 499 ASSERT_TRUE(browser_proxy->WaitForTabCountToBecome(initial_tab_count + 1,
502 action_max_timeout_ms())); 500 action_max_timeout_ms()));
503 scoped_ptr<TabProxy> new_tab(browser_proxy->GetTab(initial_tab_count)); 501 scoped_refptr<TabProxy> new_tab(browser_proxy->GetTab(initial_tab_count));
504 new_tab->NavigateToURL(url1_); 502 new_tab->NavigateToURL(url1_);
505 browser_proxy->AppendTab(url2_); 503 browser_proxy->AppendTab(url2_);
506 ASSERT_TRUE(browser_proxy->WaitForTabCountToBecome(initial_tab_count + 2, 504 ASSERT_TRUE(browser_proxy->WaitForTabCountToBecome(initial_tab_count + 2,
507 action_max_timeout_ms())); 505 action_max_timeout_ms()));
508 new_tab.reset(browser_proxy->GetTab(initial_tab_count + 1)); 506 new_tab = browser_proxy->GetTab(initial_tab_count + 1);
509 new_tab->NavigateToURL(url2_); 507 new_tab->NavigateToURL(url2_);
510 508
511 // Close the window. 509 // Close the window.
512 ASSERT_TRUE(browser_proxy->RunCommand(IDC_CLOSE_WINDOW)); 510 ASSERT_TRUE(browser_proxy->RunCommand(IDC_CLOSE_WINDOW));
513 browser_proxy.reset(); 511 browser_proxy = NULL;
514 new_tab.reset(); 512 new_tab = NULL;
515 ASSERT_TRUE(automation()->GetBrowserWindowCount(&new_window_count)); 513 ASSERT_TRUE(automation()->GetBrowserWindowCount(&new_window_count));
516 EXPECT_EQ(window_count - 1, new_window_count); 514 EXPECT_EQ(window_count - 1, new_window_count);
517 515
518 // Restore the window. 516 // Restore the window.
519 browser_proxy.reset(automation()->GetBrowserWindow(0)); 517 browser_proxy = automation()->GetBrowserWindow(0);
520 ASSERT_TRUE(browser_proxy->RunCommand(IDC_RESTORE_TAB)); 518 ASSERT_TRUE(browser_proxy->RunCommand(IDC_RESTORE_TAB));
521 ASSERT_TRUE(automation()->GetBrowserWindowCount(&new_window_count)); 519 ASSERT_TRUE(automation()->GetBrowserWindowCount(&new_window_count));
522 EXPECT_EQ(window_count, new_window_count); 520 EXPECT_EQ(window_count, new_window_count);
523 521
524 browser_proxy.reset(automation()->GetBrowserWindow(1)); 522 browser_proxy = automation()->GetBrowserWindow(1);
525 int tab_count; 523 int tab_count;
526 EXPECT_TRUE(browser_proxy->GetTabCount(&tab_count)); 524 EXPECT_TRUE(browser_proxy->GetTabCount(&tab_count));
527 EXPECT_EQ(initial_tab_count + 2, tab_count); 525 EXPECT_EQ(initial_tab_count + 2, tab_count);
528 526
529 scoped_ptr<TabProxy> restored_tab_proxy( 527 scoped_refptr<TabProxy> restored_tab_proxy(
530 browser_proxy->GetTab(initial_tab_count)); 528 browser_proxy->GetTab(initial_tab_count));
531 ASSERT_TRUE(restored_tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); 529 ASSERT_TRUE(restored_tab_proxy->WaitForTabToBeRestored(action_timeout_ms()));
532 GURL url; 530 GURL url;
533 ASSERT_TRUE(restored_tab_proxy->GetCurrentURL(&url)); 531 ASSERT_TRUE(restored_tab_proxy->GetCurrentURL(&url));
534 EXPECT_TRUE(url == url1_); 532 EXPECT_TRUE(url == url1_);
535 533
536 restored_tab_proxy.reset( 534 restored_tab_proxy = browser_proxy->GetTab(initial_tab_count + 1);
537 browser_proxy->GetTab(initial_tab_count + 1));
538 ASSERT_TRUE(restored_tab_proxy->WaitForTabToBeRestored(action_timeout_ms())); 535 ASSERT_TRUE(restored_tab_proxy->WaitForTabToBeRestored(action_timeout_ms()));
539 ASSERT_TRUE(restored_tab_proxy->GetCurrentURL(&url)); 536 ASSERT_TRUE(restored_tab_proxy->GetCurrentURL(&url));
540 EXPECT_TRUE(url == url2_); 537 EXPECT_TRUE(url == url2_);
541 } 538 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/view_source_uitest.cc ('k') | chrome/browser/unload_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698