| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 Profile* profile = browser->profile(); | 120 Profile* profile = browser->profile(); |
| 121 | 121 |
| 122 // Close the browser. | 122 // Close the browser. |
| 123 g_browser_process->AddRefModule(); | 123 g_browser_process->AddRefModule(); |
| 124 CloseBrowserSynchronously(browser); | 124 CloseBrowserSynchronously(browser); |
| 125 | 125 |
| 126 // Create a new window, which should trigger session restore. | 126 // Create a new window, which should trigger session restore. |
| 127 ui_test_utils::BrowserAddedObserver window_observer; | 127 ui_test_utils::BrowserAddedObserver window_observer; |
| 128 SessionRestoreTestHelper restore_observer; | 128 SessionRestoreTestHelper restore_observer; |
| 129 if (url.is_empty()) { | 129 if (url.is_empty()) { |
| 130 chrome::NewEmptyWindow(profile, chrome::HOST_DESKTOP_TYPE_NATIVE); | 130 chrome::NewEmptyWindow(profile, ui::HOST_DESKTOP_TYPE_NATIVE); |
| 131 } else { | 131 } else { |
| 132 chrome::NavigateParams params(profile, | 132 chrome::NavigateParams params(profile, |
| 133 url, | 133 url, |
| 134 ui::PAGE_TRANSITION_LINK); | 134 ui::PAGE_TRANSITION_LINK); |
| 135 chrome::Navigate(¶ms); | 135 chrome::Navigate(¶ms); |
| 136 } | 136 } |
| 137 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); | 137 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); |
| 138 // Stop loading anything more if we are running out of space. | 138 // Stop loading anything more if we are running out of space. |
| 139 if (!no_memory_pressure) { | 139 if (!no_memory_pressure) { |
| 140 base::MemoryPressureListener::NotifyMemoryPressure( | 140 base::MemoryPressureListener::NotifyMemoryPressure( |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 content::NotificationService::AllSources()); | 501 content::NotificationService::AllSources()); |
| 502 chrome::AddSelectedTabWithURL(browser(), url3, | 502 chrome::AddSelectedTabWithURL(browser(), url3, |
| 503 ui::PAGE_TRANSITION_LINK); | 503 ui::PAGE_TRANSITION_LINK); |
| 504 observer.Wait(); | 504 observer.Wait(); |
| 505 } | 505 } |
| 506 | 506 |
| 507 TabRestoreService* service = | 507 TabRestoreService* service = |
| 508 TabRestoreServiceFactory::GetForProfile(browser()->profile()); | 508 TabRestoreServiceFactory::GetForProfile(browser()->profile()); |
| 509 service->ClearEntries(); | 509 service->ClearEntries(); |
| 510 | 510 |
| 511 chrome::HostDesktopType host_desktop_type = browser()->host_desktop_type(); | 511 ui::HostDesktopType host_desktop_type = browser()->host_desktop_type(); |
| 512 | 512 |
| 513 browser()->window()->Close(); | 513 browser()->window()->Close(); |
| 514 | 514 |
| 515 // Expect a window with three tabs. | 515 // Expect a window with three tabs. |
| 516 ASSERT_EQ(1U, service->entries().size()); | 516 ASSERT_EQ(1U, service->entries().size()); |
| 517 ASSERT_EQ(TabRestoreService::WINDOW, service->entries().front()->type); | 517 ASSERT_EQ(TabRestoreService::WINDOW, service->entries().front()->type); |
| 518 const TabRestoreService::Window* window = | 518 const TabRestoreService::Window* window = |
| 519 static_cast<TabRestoreService::Window*>(service->entries().front()); | 519 static_cast<TabRestoreService::Window*>(service->entries().front()); |
| 520 EXPECT_EQ(3U, window->tabs.size()); | 520 EXPECT_EQ(3U, window->tabs.size()); |
| 521 | 521 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 base::FilePath(FILE_PATH_LITERAL("title1.html")))); | 565 base::FilePath(FILE_PATH_LITERAL("title1.html")))); |
| 566 | 566 |
| 567 // Add a single tab. | 567 // Add a single tab. |
| 568 ui_test_utils::NavigateToURL(browser(), url); | 568 ui_test_utils::NavigateToURL(browser(), url); |
| 569 | 569 |
| 570 TabRestoreService* service = | 570 TabRestoreService* service = |
| 571 TabRestoreServiceFactory::GetForProfile(browser()->profile()); | 571 TabRestoreServiceFactory::GetForProfile(browser()->profile()); |
| 572 service->ClearEntries(); | 572 service->ClearEntries(); |
| 573 EXPECT_EQ(0U, service->entries().size()); | 573 EXPECT_EQ(0U, service->entries().size()); |
| 574 | 574 |
| 575 chrome::HostDesktopType host_desktop_type = browser()->host_desktop_type(); | 575 ui::HostDesktopType host_desktop_type = browser()->host_desktop_type(); |
| 576 | 576 |
| 577 // Close the window. | 577 // Close the window. |
| 578 browser()->window()->Close(); | 578 browser()->window()->Close(); |
| 579 | 579 |
| 580 // Expect the window to be converted to a tab by the TRS. | 580 // Expect the window to be converted to a tab by the TRS. |
| 581 EXPECT_EQ(1U, service->entries().size()); | 581 EXPECT_EQ(1U, service->entries().size()); |
| 582 ASSERT_EQ(TabRestoreService::TAB, service->entries().front()->type); | 582 ASSERT_EQ(TabRestoreService::TAB, service->entries().front()->type); |
| 583 const TabRestoreService::Tab* tab = | 583 const TabRestoreService::Tab* tab = |
| 584 static_cast<TabRestoreService::Tab*>(service->entries().front()); | 584 static_cast<TabRestoreService::Tab*>(service->entries().front()); |
| 585 | 585 |
| (...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1443 browser()->tab_strip_model()->ActivateTabAt(i, true); | 1443 browser()->tab_strip_model()->ActivateTabAt(i, true); |
| 1444 | 1444 |
| 1445 // Close the browser. | 1445 // Close the browser. |
| 1446 g_browser_process->AddRefModule(); | 1446 g_browser_process->AddRefModule(); |
| 1447 CloseBrowserSynchronously(browser()); | 1447 CloseBrowserSynchronously(browser()); |
| 1448 | 1448 |
| 1449 StartObserving(kExpectedNumTabs); | 1449 StartObserving(kExpectedNumTabs); |
| 1450 | 1450 |
| 1451 // Create a new window, which should trigger session restore. | 1451 // Create a new window, which should trigger session restore. |
| 1452 ui_test_utils::BrowserAddedObserver window_observer; | 1452 ui_test_utils::BrowserAddedObserver window_observer; |
| 1453 chrome::NewEmptyWindow(profile, chrome::HOST_DESKTOP_TYPE_NATIVE); | 1453 chrome::NewEmptyWindow(profile, ui::HOST_DESKTOP_TYPE_NATIVE); |
| 1454 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); | 1454 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); |
| 1455 ASSERT_TRUE(new_browser != NULL); | 1455 ASSERT_TRUE(new_browser != NULL); |
| 1456 WaitForAllTabsToStartLoading(); | 1456 WaitForAllTabsToStartLoading(); |
| 1457 g_browser_process->ReleaseModule(); | 1457 g_browser_process->ReleaseModule(); |
| 1458 | 1458 |
| 1459 ASSERT_EQ(static_cast<size_t>(kExpectedNumTabs), web_contents().size()); | 1459 ASSERT_EQ(static_cast<size_t>(kExpectedNumTabs), web_contents().size()); |
| 1460 // Test that we have observed the tabs being loaded in the inverse order of | 1460 // Test that we have observed the tabs being loaded in the inverse order of |
| 1461 // their activation (MRU). Also validate that their last active time is in the | 1461 // their activation (MRU). Also validate that their last active time is in the |
| 1462 // correct order. | 1462 // correct order. |
| 1463 for (size_t i = 0; i < web_contents().size(); i++) { | 1463 for (size_t i = 0; i < web_contents().size(); i++) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1481 // Close the browser that gets opened automatically so we can track the order | 1481 // Close the browser that gets opened automatically so we can track the order |
| 1482 // of loading of the tabs. | 1482 // of loading of the tabs. |
| 1483 g_browser_process->AddRefModule(); | 1483 g_browser_process->AddRefModule(); |
| 1484 CloseBrowserSynchronously(browser()); | 1484 CloseBrowserSynchronously(browser()); |
| 1485 // We have an extra tab that is added when the test starts, which gets ignored | 1485 // We have an extra tab that is added when the test starts, which gets ignored |
| 1486 // later when we test for proper order. | 1486 // later when we test for proper order. |
| 1487 StartObserving(kExpectedNumTabs + 1); | 1487 StartObserving(kExpectedNumTabs + 1); |
| 1488 | 1488 |
| 1489 // Create a new window, which should trigger session restore. | 1489 // Create a new window, which should trigger session restore. |
| 1490 ui_test_utils::BrowserAddedObserver window_observer; | 1490 ui_test_utils::BrowserAddedObserver window_observer; |
| 1491 chrome::NewEmptyWindow(profile, chrome::HOST_DESKTOP_TYPE_NATIVE); | 1491 chrome::NewEmptyWindow(profile, ui::HOST_DESKTOP_TYPE_NATIVE); |
| 1492 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); | 1492 Browser* new_browser = window_observer.WaitForSingleNewBrowser(); |
| 1493 ASSERT_TRUE(new_browser != NULL); | 1493 ASSERT_TRUE(new_browser != NULL); |
| 1494 WaitForAllTabsToStartLoading(); | 1494 WaitForAllTabsToStartLoading(); |
| 1495 g_browser_process->ReleaseModule(); | 1495 g_browser_process->ReleaseModule(); |
| 1496 | 1496 |
| 1497 ASSERT_EQ(static_cast<size_t>(kExpectedNumTabs + 1), web_contents().size()); | 1497 ASSERT_EQ(static_cast<size_t>(kExpectedNumTabs + 1), web_contents().size()); |
| 1498 | 1498 |
| 1499 // Test that we have observed the tabs being loaded in the inverse order of | 1499 // Test that we have observed the tabs being loaded in the inverse order of |
| 1500 // their activation (MRU). Also validate that their last active time is in the | 1500 // their activation (MRU). Also validate that their last active time is in the |
| 1501 // correct order. | 1501 // correct order. |
| 1502 // | 1502 // |
| 1503 // Note that we ignore the first tab as it's an empty one that is added | 1503 // Note that we ignore the first tab as it's an empty one that is added |
| 1504 // automatically at the start of the test. | 1504 // automatically at the start of the test. |
| 1505 for (size_t i = 1; i < web_contents().size(); i++) { | 1505 for (size_t i = 1; i < web_contents().size(); i++) { |
| 1506 GURL expected_url = GURL(kUrls[activation_order[kExpectedNumTabs - i]]); | 1506 GURL expected_url = GURL(kUrls[activation_order[kExpectedNumTabs - i]]); |
| 1507 ASSERT_EQ(expected_url, web_contents()[i]->GetLastCommittedURL()); | 1507 ASSERT_EQ(expected_url, web_contents()[i]->GetLastCommittedURL()); |
| 1508 if (i > 0) { | 1508 if (i > 0) { |
| 1509 ASSERT_GT(web_contents()[i - 1]->GetLastActiveTime(), | 1509 ASSERT_GT(web_contents()[i - 1]->GetLastActiveTime(), |
| 1510 web_contents()[i]->GetLastActiveTime()); | 1510 web_contents()[i]->GetLastActiveTime()); |
| 1511 } | 1511 } |
| 1512 } | 1512 } |
| 1513 } | 1513 } |
| OLD | NEW |