| 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 <algorithm> | |
| 8 #include <set> | 7 #include <set> |
| 9 #include <vector> | 8 #include <vector> |
| 10 | 9 |
| 11 #include "base/base_switches.h" | 10 #include "base/base_switches.h" |
| 12 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 13 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 14 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 15 #include "base/macros.h" | 14 #include "base/macros.h" |
| 16 #include "base/memory/memory_pressure_listener.h" | 15 #include "base/memory/memory_pressure_listener.h" |
| 17 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 contents->GetController().LoadIfNecessary(); | 204 contents->GetController().LoadIfNecessary(); |
| 206 content::WaitForLoadStop(contents); | 205 content::WaitForLoadStop(contents); |
| 207 } | 206 } |
| 208 } | 207 } |
| 209 | 208 |
| 210 GURL url1_; | 209 GURL url1_; |
| 211 GURL url2_; | 210 GURL url2_; |
| 212 GURL url3_; | 211 GURL url3_; |
| 213 | 212 |
| 214 const BrowserList* active_browser_list_; | 213 const BrowserList* active_browser_list_; |
| 215 | |
| 216 private: | |
| 217 DISALLOW_COPY_AND_ASSIGN(SessionRestoreTest); | |
| 218 }; | 214 }; |
| 219 | 215 |
| 220 // Activates the smart restore behaviour and tracks the loading of tabs. | 216 // Activates the smart restore behaviour and tracks the loading of tabs. |
| 221 class SmartSessionRestoreTest : public SessionRestoreTest, | 217 class SmartSessionRestoreTest : public SessionRestoreTest, |
| 222 public content::NotificationObserver { | 218 public content::NotificationObserver { |
| 223 public: | 219 public: |
| 224 SmartSessionRestoreTest() {} | 220 SmartSessionRestoreTest() {} |
| 225 void StartObserving(size_t num_tabs) { | 221 void StartObserving(size_t num_tabs) { |
| 226 // Start by clearing everything so it can be reused in the same test. | 222 // Start by clearing everything so it can be reused in the same test. |
| 227 web_contents_.clear(); | 223 web_contents_.clear(); |
| (...skipping 1391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1619 // automatically at the start of the test. | 1615 // automatically at the start of the test. |
| 1620 for (size_t i = 1; i < web_contents().size(); i++) { | 1616 for (size_t i = 1; i < web_contents().size(); i++) { |
| 1621 GURL expected_url = GURL(kUrls[activation_order[kExpectedNumTabs - i]]); | 1617 GURL expected_url = GURL(kUrls[activation_order[kExpectedNumTabs - i]]); |
| 1622 ASSERT_EQ(expected_url, web_contents()[i]->GetLastCommittedURL()); | 1618 ASSERT_EQ(expected_url, web_contents()[i]->GetLastCommittedURL()); |
| 1623 if (i > 0) { | 1619 if (i > 0) { |
| 1624 ASSERT_GT(web_contents()[i - 1]->GetLastActiveTime(), | 1620 ASSERT_GT(web_contents()[i - 1]->GetLastActiveTime(), |
| 1625 web_contents()[i]->GetLastActiveTime()); | 1621 web_contents()[i]->GetLastActiveTime()); |
| 1626 } | 1622 } |
| 1627 } | 1623 } |
| 1628 } | 1624 } |
| 1629 | |
| 1630 namespace { | |
| 1631 | |
| 1632 const char kStartupURL[] = "http://example.com/"; | |
| 1633 const char kSessionURL[] = "http://localhost/"; | |
| 1634 | |
| 1635 } // namespace | |
| 1636 | |
| 1637 class SessionRestoreWithStartupURLTest : public SessionRestoreTest { | |
| 1638 public: | |
| 1639 SessionRestoreWithStartupURLTest() {} | |
| 1640 | |
| 1641 protected: | |
| 1642 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 1643 // Add startup URL to command line, but only in main test body in order | |
| 1644 // to prevent that URL from beng opened twice. | |
| 1645 if (!base::StartsWith( | |
| 1646 testing::UnitTest::GetInstance()->current_test_info()->name(), | |
| 1647 "PRE_", base::CompareCase::SENSITIVE)) { | |
| 1648 command_line->AppendArg(kStartupURL); | |
| 1649 } | |
| 1650 SessionRestoreTest::SetUpCommandLine(command_line); | |
| 1651 } | |
| 1652 | |
| 1653 private: | |
| 1654 DISALLOW_COPY_AND_ASSIGN(SessionRestoreWithStartupURLTest); | |
| 1655 }; | |
| 1656 | |
| 1657 IN_PROC_BROWSER_TEST_F(SessionRestoreWithStartupURLTest, | |
| 1658 PRE_StartupURLsWithSessionRestore) { | |
| 1659 // Prepare a session to restore in main test body. | |
| 1660 ui_test_utils::NavigateToURL(browser(), GURL(kSessionURL)); | |
| 1661 } | |
| 1662 | |
| 1663 IN_PROC_BROWSER_TEST_F(SessionRestoreWithStartupURLTest, | |
| 1664 StartupURLsWithSessionRestore) { | |
| 1665 // Check that browser is started with restored session and | |
| 1666 // tab with startup URL next to it. | |
| 1667 TabStripModel* tab_strip = browser()->tab_strip_model(); | |
| 1668 ASSERT_EQ(2, tab_strip->count()); | |
| 1669 EXPECT_EQ(kSessionURL, | |
| 1670 tab_strip->GetWebContentsAt(0)->GetURL().possibly_invalid_spec()); | |
| 1671 EXPECT_EQ(kStartupURL, | |
| 1672 tab_strip->GetWebContentsAt(1)->GetURL().possibly_invalid_spec()); | |
| 1673 } | |
| OLD | NEW |