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