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

Side by Side Diff: chrome/browser/sessions/session_restore_browsertest.cc

Issue 22837005: Add HTTP status code to navigation data structures (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix bug Created 7 years, 3 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
OLDNEW
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 <vector> 5 #include <vector>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/process/launch.h" 9 #include "base/process/launch.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 301
302 // And the first url should be url. 302 // And the first url should be url.
303 EXPECT_EQ(url, new_browser->tab_strip_model()->GetWebContentsAt(0)->GetURL()); 303 EXPECT_EQ(url, new_browser->tab_strip_model()->GetWebContentsAt(0)->GetURL());
304 } 304 }
305 #endif // !OS_CHROMEOS 305 #endif // !OS_CHROMEOS
306 306
307 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreIndividualTabFromWindow) { 307 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, RestoreIndividualTabFromWindow) {
308 GURL url1(ui_test_utils::GetTestUrl( 308 GURL url1(ui_test_utils::GetTestUrl(
309 base::FilePath(base::FilePath::kCurrentDirectory), 309 base::FilePath(base::FilePath::kCurrentDirectory),
310 base::FilePath(FILE_PATH_LITERAL("title1.html")))); 310 base::FilePath(FILE_PATH_LITERAL("title1.html"))));
311 GURL url2(ui_test_utils::GetTestUrl( 311 // Any page that will yield a 200 status code will work here.
312 base::FilePath(base::FilePath::kCurrentDirectory), 312 GURL url2("about:version");
313 base::FilePath(FILE_PATH_LITERAL("title2.html"))));
314 GURL url3(ui_test_utils::GetTestUrl( 313 GURL url3(ui_test_utils::GetTestUrl(
315 base::FilePath(base::FilePath::kCurrentDirectory), 314 base::FilePath(base::FilePath::kCurrentDirectory),
316 base::FilePath(FILE_PATH_LITERAL("title3.html")))); 315 base::FilePath(FILE_PATH_LITERAL("title3.html"))));
317 316
318 // Add and navigate three tabs. 317 // Add and navigate three tabs.
319 ui_test_utils::NavigateToURL(browser(), url1); 318 ui_test_utils::NavigateToURL(browser(), url1);
320 { 319 {
321 content::WindowedNotificationObserver observer( 320 content::WindowedNotificationObserver observer(
322 content::NOTIFICATION_LOAD_STOP, 321 content::NOTIFICATION_LOAD_STOP,
323 content::NotificationService::AllSources()); 322 content::NotificationService::AllSources());
(...skipping 21 matching lines...) Expand all
345 // Expect a window with three tabs. 344 // Expect a window with three tabs.
346 ASSERT_EQ(1U, service->entries().size()); 345 ASSERT_EQ(1U, service->entries().size());
347 ASSERT_EQ(TabRestoreService::WINDOW, service->entries().front()->type); 346 ASSERT_EQ(TabRestoreService::WINDOW, service->entries().front()->type);
348 const TabRestoreService::Window* window = 347 const TabRestoreService::Window* window =
349 static_cast<TabRestoreService::Window*>(service->entries().front()); 348 static_cast<TabRestoreService::Window*>(service->entries().front());
350 EXPECT_EQ(3U, window->tabs.size()); 349 EXPECT_EQ(3U, window->tabs.size());
351 350
352 // Find the SessionID for entry2. Since the session service was destroyed, 351 // Find the SessionID for entry2. Since the session service was destroyed,
353 // there is no guarantee that the SessionID for the tab has remained the same. 352 // there is no guarantee that the SessionID for the tab has remained the same.
354 base::Time timestamp; 353 base::Time timestamp;
354 int http_status_code = 0;
355 for (std::vector<TabRestoreService::Tab>::const_iterator it = 355 for (std::vector<TabRestoreService::Tab>::const_iterator it =
356 window->tabs.begin(); it != window->tabs.end(); ++it) { 356 window->tabs.begin(); it != window->tabs.end(); ++it) {
357 const TabRestoreService::Tab& tab = *it; 357 const TabRestoreService::Tab& tab = *it;
358 // If this tab held url2, then restore this single tab. 358 // If this tab held url2, then restore this single tab.
359 if (tab.navigations[0].virtual_url() == url2) { 359 if (tab.navigations[0].virtual_url() == url2) {
360 timestamp = tab.navigations[0].timestamp(); 360 timestamp = tab.navigations[0].timestamp();
361 http_status_code = tab.navigations[0].http_status_code();
361 std::vector<content::WebContents*> content = 362 std::vector<content::WebContents*> content =
362 service->RestoreEntryById(NULL, tab.id, host_desktop_type, UNKNOWN); 363 service->RestoreEntryById(NULL, tab.id, host_desktop_type, UNKNOWN);
363 ASSERT_EQ(1U, content.size()); 364 ASSERT_EQ(1U, content.size());
364 ASSERT_TRUE(content[0]); 365 ASSERT_TRUE(content[0]);
365 EXPECT_EQ(url2, content[0]->GetURL()); 366 EXPECT_EQ(url2, content[0]->GetURL());
366 break; 367 break;
367 } 368 }
368 } 369 }
369 EXPECT_FALSE(timestamp.is_null()); 370 EXPECT_FALSE(timestamp.is_null());
371 EXPECT_EQ(200, http_status_code);
370 372
371 // Make sure that the restored tab is removed from the service. 373 // Make sure that the restored tab is removed from the service.
372 ASSERT_EQ(1U, service->entries().size()); 374 ASSERT_EQ(1U, service->entries().size());
373 ASSERT_EQ(TabRestoreService::WINDOW, service->entries().front()->type); 375 ASSERT_EQ(TabRestoreService::WINDOW, service->entries().front()->type);
374 window = static_cast<TabRestoreService::Window*>(service->entries().front()); 376 window = static_cast<TabRestoreService::Window*>(service->entries().front());
375 EXPECT_EQ(2U, window->tabs.size()); 377 EXPECT_EQ(2U, window->tabs.size());
376 378
377 // Make sure that the restored tab was restored with the correct 379 // Make sure that the restored tab was restored with the correct
378 // timestamp. 380 // timestamp and status code.
379 const content::WebContents* contents = 381 const content::WebContents* contents =
380 browser()->tab_strip_model()->GetActiveWebContents(); 382 browser()->tab_strip_model()->GetActiveWebContents();
381 ASSERT_TRUE(contents); 383 ASSERT_TRUE(contents);
382 const content::NavigationEntry* entry = 384 const content::NavigationEntry* entry =
383 contents->GetController().GetActiveEntry(); 385 contents->GetController().GetActiveEntry();
384 ASSERT_TRUE(entry); 386 ASSERT_TRUE(entry);
385 EXPECT_EQ(timestamp, entry->GetTimestamp()); 387 EXPECT_EQ(timestamp, entry->GetTimestamp());
388 EXPECT_EQ(http_status_code, entry->GetHttpStatusCode());
386 } 389 }
387 390
388 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, WindowWithOneTab) { 391 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, WindowWithOneTab) {
389 GURL url(ui_test_utils::GetTestUrl( 392 GURL url(ui_test_utils::GetTestUrl(
390 base::FilePath(base::FilePath::kCurrentDirectory), 393 base::FilePath(base::FilePath::kCurrentDirectory),
391 base::FilePath(FILE_PATH_LITERAL("title1.html")))); 394 base::FilePath(FILE_PATH_LITERAL("title1.html"))));
392 395
393 // Add a single tab. 396 // Add a single tab.
394 ui_test_utils::NavigateToURL(browser(), url); 397 ui_test_utils::NavigateToURL(browser(), url);
395 398
(...skipping 749 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 content::NavigationController* controller = 1148 content::NavigationController* controller =
1146 &browser()->tab_strip_model()->GetActiveWebContents()->GetController(); 1149 &browser()->tab_strip_model()->GetActiveWebContents()->GetController();
1147 EXPECT_TRUE( 1150 EXPECT_TRUE(
1148 controller->GetDefaultSessionStorageNamespace()->should_persist()); 1151 controller->GetDefaultSessionStorageNamespace()->should_persist());
1149 1152
1150 // Quit and restore. Check that no extra tabs were created. 1153 // Quit and restore. Check that no extra tabs were created.
1151 Browser* new_browser = QuitBrowserAndRestore(browser(), 1); 1154 Browser* new_browser = QuitBrowserAndRestore(browser(), 1);
1152 ASSERT_EQ(1u, active_browser_list_->size()); 1155 ASSERT_EQ(1u, active_browser_list_->size());
1153 EXPECT_EQ(1, new_browser->tab_strip_model()->count()); 1156 EXPECT_EQ(1, new_browser->tab_strip_model()->count());
1154 } 1157 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698