| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 sessions::TabRestoreService* service = | 536 sessions::TabRestoreService* service = |
| 537 TabRestoreServiceFactory::GetForProfile(browser()->profile()); | 537 TabRestoreServiceFactory::GetForProfile(browser()->profile()); |
| 538 service->ClearEntries(); | 538 service->ClearEntries(); |
| 539 | 539 |
| 540 browser()->window()->Close(); | 540 browser()->window()->Close(); |
| 541 | 541 |
| 542 // Expect a window with three tabs. | 542 // Expect a window with three tabs. |
| 543 ASSERT_EQ(1U, service->entries().size()); | 543 ASSERT_EQ(1U, service->entries().size()); |
| 544 ASSERT_EQ(sessions::TabRestoreService::WINDOW, | 544 ASSERT_EQ(sessions::TabRestoreService::WINDOW, |
| 545 service->entries().front()->type); | 545 service->entries().front()->type); |
| 546 const sessions::TabRestoreService::Window* window = | 546 auto* window = static_cast<sessions::TabRestoreService::Window*>( |
| 547 static_cast<sessions::TabRestoreService::Window*>( | 547 service->entries().front().get()); |
| 548 service->entries().front()); | |
| 549 EXPECT_EQ(3U, window->tabs.size()); | 548 EXPECT_EQ(3U, window->tabs.size()); |
| 550 | 549 |
| 551 // Find the SessionID for entry2. Since the session service was destroyed, | 550 // Find the SessionID for entry2. Since the session service was destroyed, |
| 552 // there is no guarantee that the SessionID for the tab has remained the same. | 551 // there is no guarantee that the SessionID for the tab has remained the same. |
| 553 base::Time timestamp; | 552 base::Time timestamp; |
| 554 int http_status_code = 0; | 553 int http_status_code = 0; |
| 555 for (const sessions::TabRestoreService::Tab& tab : window->tabs) { | 554 for (const auto& tab_ptr : window->tabs) { |
| 555 const sessions::TabRestoreService::Tab& tab = *tab_ptr; |
| 556 // If this tab held url2, then restore this single tab. | 556 // If this tab held url2, then restore this single tab. |
| 557 if (tab.navigations[0].virtual_url() == url2) { | 557 if (tab.navigations[0].virtual_url() == url2) { |
| 558 timestamp = tab.navigations[0].timestamp(); | 558 timestamp = tab.navigations[0].timestamp(); |
| 559 http_status_code = tab.navigations[0].http_status_code(); | 559 http_status_code = tab.navigations[0].http_status_code(); |
| 560 std::vector<sessions::LiveTab*> content = | 560 std::vector<sessions::LiveTab*> content = |
| 561 service->RestoreEntryById(NULL, tab.id, UNKNOWN); | 561 service->RestoreEntryById(NULL, tab.id, UNKNOWN); |
| 562 ASSERT_EQ(1U, content.size()); | 562 ASSERT_EQ(1U, content.size()); |
| 563 sessions::ContentLiveTab* live_tab = | 563 sessions::ContentLiveTab* live_tab = |
| 564 static_cast<sessions::ContentLiveTab*>(content[0]); | 564 static_cast<sessions::ContentLiveTab*>(content[0]); |
| 565 ASSERT_TRUE(live_tab); | 565 ASSERT_TRUE(live_tab); |
| 566 EXPECT_EQ(url2, live_tab->web_contents()->GetURL()); | 566 EXPECT_EQ(url2, live_tab->web_contents()->GetURL()); |
| 567 break; | 567 break; |
| 568 } | 568 } |
| 569 } | 569 } |
| 570 EXPECT_FALSE(timestamp.is_null()); | 570 EXPECT_FALSE(timestamp.is_null()); |
| 571 EXPECT_EQ(200, http_status_code); | 571 EXPECT_EQ(200, http_status_code); |
| 572 | 572 |
| 573 // Make sure that the restored tab is removed from the service. | 573 // Make sure that the restored tab is removed from the service. |
| 574 ASSERT_EQ(1U, service->entries().size()); | 574 ASSERT_EQ(1U, service->entries().size()); |
| 575 ASSERT_EQ(sessions::TabRestoreService::WINDOW, | 575 ASSERT_EQ(sessions::TabRestoreService::WINDOW, |
| 576 service->entries().front()->type); | 576 service->entries().front()->type); |
| 577 window = static_cast<sessions::TabRestoreService::Window*>( | 577 window = static_cast<sessions::TabRestoreService::Window*>( |
| 578 service->entries().front()); | 578 service->entries().front().get()); |
| 579 EXPECT_EQ(2U, window->tabs.size()); | 579 EXPECT_EQ(2U, window->tabs.size()); |
| 580 | 580 |
| 581 // Make sure that the restored tab was restored with the correct | 581 // Make sure that the restored tab was restored with the correct |
| 582 // timestamp and status code. | 582 // timestamp and status code. |
| 583 const content::WebContents* contents = | 583 const content::WebContents* contents = |
| 584 browser()->tab_strip_model()->GetActiveWebContents(); | 584 browser()->tab_strip_model()->GetActiveWebContents(); |
| 585 ASSERT_TRUE(contents); | 585 ASSERT_TRUE(contents); |
| 586 const content::NavigationEntry* entry = | 586 const content::NavigationEntry* entry = |
| 587 contents->GetController().GetActiveEntry(); | 587 contents->GetController().GetActiveEntry(); |
| 588 ASSERT_TRUE(entry); | 588 ASSERT_TRUE(entry); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 608 TabRestoreServiceFactory::GetForProfile(browser()->profile()); | 608 TabRestoreServiceFactory::GetForProfile(browser()->profile()); |
| 609 service->ClearEntries(); | 609 service->ClearEntries(); |
| 610 EXPECT_EQ(0U, service->entries().size()); | 610 EXPECT_EQ(0U, service->entries().size()); |
| 611 | 611 |
| 612 // Close the window. | 612 // Close the window. |
| 613 browser()->window()->Close(); | 613 browser()->window()->Close(); |
| 614 | 614 |
| 615 // Expect the window to be converted to a tab by the TRS. | 615 // Expect the window to be converted to a tab by the TRS. |
| 616 EXPECT_EQ(1U, service->entries().size()); | 616 EXPECT_EQ(1U, service->entries().size()); |
| 617 ASSERT_EQ(sessions::TabRestoreService::TAB, service->entries().front()->type); | 617 ASSERT_EQ(sessions::TabRestoreService::TAB, service->entries().front()->type); |
| 618 const sessions::TabRestoreService::Tab* tab = | 618 auto* tab = static_cast<const sessions::TabRestoreService::Tab*>( |
| 619 static_cast<sessions::TabRestoreService::Tab*>( | 619 service->entries().front().get()); |
| 620 service->entries().front()); | |
| 621 | 620 |
| 622 // Restore the tab. | 621 // Restore the tab. |
| 623 std::vector<sessions::LiveTab*> content = | 622 std::vector<sessions::LiveTab*> content = |
| 624 service->RestoreEntryById(NULL, tab->id, UNKNOWN); | 623 service->RestoreEntryById(NULL, tab->id, UNKNOWN); |
| 625 ASSERT_EQ(1U, content.size()); | 624 ASSERT_EQ(1U, content.size()); |
| 626 ASSERT_TRUE(content[0]); | 625 ASSERT_TRUE(content[0]); |
| 627 EXPECT_EQ(url, static_cast<sessions::ContentLiveTab*>(content[0]) | 626 EXPECT_EQ(url, static_cast<sessions::ContentLiveTab*>(content[0]) |
| 628 ->web_contents() | 627 ->web_contents() |
| 629 ->GetURL()); | 628 ->GetURL()); |
| 630 | 629 |
| (...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1469 // automatically at the start of the test. | 1468 // automatically at the start of the test. |
| 1470 for (size_t i = 1; i < web_contents().size(); i++) { | 1469 for (size_t i = 1; i < web_contents().size(); i++) { |
| 1471 GURL expected_url = GURL(kUrls[activation_order[kExpectedNumTabs - i]]); | 1470 GURL expected_url = GURL(kUrls[activation_order[kExpectedNumTabs - i]]); |
| 1472 ASSERT_EQ(expected_url, web_contents()[i]->GetLastCommittedURL()); | 1471 ASSERT_EQ(expected_url, web_contents()[i]->GetLastCommittedURL()); |
| 1473 if (i > 0) { | 1472 if (i > 0) { |
| 1474 ASSERT_GT(web_contents()[i - 1]->GetLastActiveTime(), | 1473 ASSERT_GT(web_contents()[i - 1]->GetLastActiveTime(), |
| 1475 web_contents()[i]->GetLastActiveTime()); | 1474 web_contents()[i]->GetLastActiveTime()); |
| 1476 } | 1475 } |
| 1477 } | 1476 } |
| 1478 } | 1477 } |
| OLD | NEW |