OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/memory/memory_pressure_listener.h" | 9 #include "base/memory/memory_pressure_listener.h" |
10 #include "base/process/launch.h" | 10 #include "base/process/launch.h" |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 } | 498 } |
499 { | 499 { |
500 content::WindowedNotificationObserver observer( | 500 content::WindowedNotificationObserver observer( |
501 content::NOTIFICATION_LOAD_STOP, | 501 content::NOTIFICATION_LOAD_STOP, |
502 content::NotificationService::AllSources()); | 502 content::NotificationService::AllSources()); |
503 chrome::AddSelectedTabWithURL(browser(), url3, | 503 chrome::AddSelectedTabWithURL(browser(), url3, |
504 ui::PAGE_TRANSITION_LINK); | 504 ui::PAGE_TRANSITION_LINK); |
505 observer.Wait(); | 505 observer.Wait(); |
506 } | 506 } |
507 | 507 |
508 TabRestoreService* service = | 508 sessions::TabRestoreService* service = |
509 TabRestoreServiceFactory::GetForProfile(browser()->profile()); | 509 TabRestoreServiceFactory::GetForProfile(browser()->profile()); |
510 service->ClearEntries(); | 510 service->ClearEntries(); |
511 | 511 |
512 chrome::HostDesktopType host_desktop_type = browser()->host_desktop_type(); | 512 chrome::HostDesktopType host_desktop_type = browser()->host_desktop_type(); |
513 | 513 |
514 browser()->window()->Close(); | 514 browser()->window()->Close(); |
515 | 515 |
516 // Expect a window with three tabs. | 516 // Expect a window with three tabs. |
517 ASSERT_EQ(1U, service->entries().size()); | 517 ASSERT_EQ(1U, service->entries().size()); |
518 ASSERT_EQ(TabRestoreService::WINDOW, service->entries().front()->type); | 518 ASSERT_EQ(sessions::TabRestoreService::WINDOW, |
519 const TabRestoreService::Window* window = | 519 service->entries().front()->type); |
520 static_cast<TabRestoreService::Window*>(service->entries().front()); | 520 const sessions::TabRestoreService::Window* window = |
| 521 static_cast<sessions::TabRestoreService::Window*>( |
| 522 service->entries().front()); |
521 EXPECT_EQ(3U, window->tabs.size()); | 523 EXPECT_EQ(3U, window->tabs.size()); |
522 | 524 |
523 // Find the SessionID for entry2. Since the session service was destroyed, | 525 // Find the SessionID for entry2. Since the session service was destroyed, |
524 // there is no guarantee that the SessionID for the tab has remained the same. | 526 // there is no guarantee that the SessionID for the tab has remained the same. |
525 base::Time timestamp; | 527 base::Time timestamp; |
526 int http_status_code = 0; | 528 int http_status_code = 0; |
527 for (std::vector<TabRestoreService::Tab>::const_iterator it = | 529 for (std::vector<sessions::TabRestoreService::Tab>::const_iterator it = |
528 window->tabs.begin(); it != window->tabs.end(); ++it) { | 530 window->tabs.begin(); |
529 const TabRestoreService::Tab& tab = *it; | 531 it != window->tabs.end(); ++it) { |
| 532 const sessions::TabRestoreService::Tab& tab = *it; |
530 // If this tab held url2, then restore this single tab. | 533 // If this tab held url2, then restore this single tab. |
531 if (tab.navigations[0].virtual_url() == url2) { | 534 if (tab.navigations[0].virtual_url() == url2) { |
532 timestamp = tab.navigations[0].timestamp(); | 535 timestamp = tab.navigations[0].timestamp(); |
533 http_status_code = tab.navigations[0].http_status_code(); | 536 http_status_code = tab.navigations[0].http_status_code(); |
534 std::vector<sessions::LiveTab*> content = | 537 std::vector<sessions::LiveTab*> content = |
535 service->RestoreEntryById(NULL, tab.id, host_desktop_type, UNKNOWN); | 538 service->RestoreEntryById(NULL, tab.id, host_desktop_type, UNKNOWN); |
536 ASSERT_EQ(1U, content.size()); | 539 ASSERT_EQ(1U, content.size()); |
537 ASSERT_TRUE(content[0]); | 540 ASSERT_TRUE(content[0]); |
538 EXPECT_EQ(url2, static_cast<sessions::ContentLiveTab*>(content[0]) | 541 EXPECT_EQ(url2, static_cast<sessions::ContentLiveTab*>(content[0]) |
539 ->web_contents() | 542 ->web_contents() |
540 ->GetURL()); | 543 ->GetURL()); |
541 break; | 544 break; |
542 } | 545 } |
543 } | 546 } |
544 EXPECT_FALSE(timestamp.is_null()); | 547 EXPECT_FALSE(timestamp.is_null()); |
545 EXPECT_EQ(200, http_status_code); | 548 EXPECT_EQ(200, http_status_code); |
546 | 549 |
547 // Make sure that the restored tab is removed from the service. | 550 // Make sure that the restored tab is removed from the service. |
548 ASSERT_EQ(1U, service->entries().size()); | 551 ASSERT_EQ(1U, service->entries().size()); |
549 ASSERT_EQ(TabRestoreService::WINDOW, service->entries().front()->type); | 552 ASSERT_EQ(sessions::TabRestoreService::WINDOW, |
550 window = static_cast<TabRestoreService::Window*>(service->entries().front()); | 553 service->entries().front()->type); |
| 554 window = static_cast<sessions::TabRestoreService::Window*>( |
| 555 service->entries().front()); |
551 EXPECT_EQ(2U, window->tabs.size()); | 556 EXPECT_EQ(2U, window->tabs.size()); |
552 | 557 |
553 // Make sure that the restored tab was restored with the correct | 558 // Make sure that the restored tab was restored with the correct |
554 // timestamp and status code. | 559 // timestamp and status code. |
555 const content::WebContents* contents = | 560 const content::WebContents* contents = |
556 browser()->tab_strip_model()->GetActiveWebContents(); | 561 browser()->tab_strip_model()->GetActiveWebContents(); |
557 ASSERT_TRUE(contents); | 562 ASSERT_TRUE(contents); |
558 const content::NavigationEntry* entry = | 563 const content::NavigationEntry* entry = |
559 contents->GetController().GetActiveEntry(); | 564 contents->GetController().GetActiveEntry(); |
560 ASSERT_TRUE(entry); | 565 ASSERT_TRUE(entry); |
561 EXPECT_EQ(timestamp, entry->GetTimestamp()); | 566 EXPECT_EQ(timestamp, entry->GetTimestamp()); |
562 EXPECT_EQ(http_status_code, entry->GetHttpStatusCode()); | 567 EXPECT_EQ(http_status_code, entry->GetHttpStatusCode()); |
563 } | 568 } |
564 | 569 |
565 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, WindowWithOneTab) { | 570 IN_PROC_BROWSER_TEST_F(SessionRestoreTest, WindowWithOneTab) { |
566 GURL url(ui_test_utils::GetTestUrl( | 571 GURL url(ui_test_utils::GetTestUrl( |
567 base::FilePath(base::FilePath::kCurrentDirectory), | 572 base::FilePath(base::FilePath::kCurrentDirectory), |
568 base::FilePath(FILE_PATH_LITERAL("title1.html")))); | 573 base::FilePath(FILE_PATH_LITERAL("title1.html")))); |
569 | 574 |
570 // Add a single tab. | 575 // Add a single tab. |
571 ui_test_utils::NavigateToURL(browser(), url); | 576 ui_test_utils::NavigateToURL(browser(), url); |
572 | 577 |
573 TabRestoreService* service = | 578 sessions::TabRestoreService* service = |
574 TabRestoreServiceFactory::GetForProfile(browser()->profile()); | 579 TabRestoreServiceFactory::GetForProfile(browser()->profile()); |
575 service->ClearEntries(); | 580 service->ClearEntries(); |
576 EXPECT_EQ(0U, service->entries().size()); | 581 EXPECT_EQ(0U, service->entries().size()); |
577 | 582 |
578 chrome::HostDesktopType host_desktop_type = browser()->host_desktop_type(); | 583 chrome::HostDesktopType host_desktop_type = browser()->host_desktop_type(); |
579 | 584 |
580 // Close the window. | 585 // Close the window. |
581 browser()->window()->Close(); | 586 browser()->window()->Close(); |
582 | 587 |
583 // Expect the window to be converted to a tab by the TRS. | 588 // Expect the window to be converted to a tab by the TRS. |
584 EXPECT_EQ(1U, service->entries().size()); | 589 EXPECT_EQ(1U, service->entries().size()); |
585 ASSERT_EQ(TabRestoreService::TAB, service->entries().front()->type); | 590 ASSERT_EQ(sessions::TabRestoreService::TAB, service->entries().front()->type); |
586 const TabRestoreService::Tab* tab = | 591 const sessions::TabRestoreService::Tab* tab = |
587 static_cast<TabRestoreService::Tab*>(service->entries().front()); | 592 static_cast<sessions::TabRestoreService::Tab*>( |
| 593 service->entries().front()); |
588 | 594 |
589 // Restore the tab. | 595 // Restore the tab. |
590 std::vector<sessions::LiveTab*> content = | 596 std::vector<sessions::LiveTab*> content = |
591 service->RestoreEntryById(NULL, tab->id, host_desktop_type, UNKNOWN); | 597 service->RestoreEntryById(NULL, tab->id, host_desktop_type, UNKNOWN); |
592 ASSERT_EQ(1U, content.size()); | 598 ASSERT_EQ(1U, content.size()); |
593 ASSERT_TRUE(content[0]); | 599 ASSERT_TRUE(content[0]); |
594 EXPECT_EQ(url, static_cast<sessions::ContentLiveTab*>(content[0]) | 600 EXPECT_EQ(url, static_cast<sessions::ContentLiveTab*>(content[0]) |
595 ->web_contents() | 601 ->web_contents() |
596 ->GetURL()); | 602 ->GetURL()); |
597 | 603 |
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1509 // automatically at the start of the test. | 1515 // automatically at the start of the test. |
1510 for (size_t i = 1; i < web_contents().size(); i++) { | 1516 for (size_t i = 1; i < web_contents().size(); i++) { |
1511 GURL expected_url = GURL(kUrls[activation_order[kExpectedNumTabs - i]]); | 1517 GURL expected_url = GURL(kUrls[activation_order[kExpectedNumTabs - i]]); |
1512 ASSERT_EQ(expected_url, web_contents()[i]->GetLastCommittedURL()); | 1518 ASSERT_EQ(expected_url, web_contents()[i]->GetLastCommittedURL()); |
1513 if (i > 0) { | 1519 if (i > 0) { |
1514 ASSERT_GT(web_contents()[i - 1]->GetLastActiveTime(), | 1520 ASSERT_GT(web_contents()[i - 1]->GetLastActiveTime(), |
1515 web_contents()[i]->GetLastActiveTime()); | 1521 web_contents()[i]->GetLastActiveTime()); |
1516 } | 1522 } |
1517 } | 1523 } |
1518 } | 1524 } |
OLD | NEW |