Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: chrome/browser/sessions/session_restore_browsertest.cc

Issue 2798143004: Fix for URL opening code (Closed)
Patch Set: Added test, fixed opening URL case when browser is already started. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1598 matching lines...) Expand 10 before | Expand all | Expand 10 after
1615 // automatically at the start of the test. 1616 // automatically at the start of the test.
1616 for (size_t i = 1; i < web_contents().size(); i++) { 1617 for (size_t i = 1; i < web_contents().size(); i++) {
1617 GURL expected_url = GURL(kUrls[activation_order[kExpectedNumTabs - i]]); 1618 GURL expected_url = GURL(kUrls[activation_order[kExpectedNumTabs - i]]);
1618 ASSERT_EQ(expected_url, web_contents()[i]->GetLastCommittedURL()); 1619 ASSERT_EQ(expected_url, web_contents()[i]->GetLastCommittedURL());
1619 if (i > 0) { 1620 if (i > 0) {
1620 ASSERT_GT(web_contents()[i - 1]->GetLastActiveTime(), 1621 ASSERT_GT(web_contents()[i - 1]->GetLastActiveTime(),
1621 web_contents()[i]->GetLastActiveTime()); 1622 web_contents()[i]->GetLastActiveTime());
1622 } 1623 }
1623 } 1624 }
1624 } 1625 }
1626
1627 namespace {
1628
1629 const char kStartupURL[] = "http://example.com/";
1630 const char kSessionURL[] = "http://localhost/";
1631
1632 template <class Container>
1633 bool BeginsWith(const Container& container, const Container& prefix) {
sky 2017/05/04 23:40:46 Why are you using a template here? Can't you use s
eugenebng 2017/05/15 06:17:09 Done.
1634 return container.size() >= prefix.size() &&
1635 equal(prefix.begin(), prefix.end(), container.begin());
1636 }
1637
1638 } // namespace
1639
1640 class SessionRestoreWithStartupURLTest : public SessionRestoreTest {
1641 protected:
1642 void SetUpCommandLine(base::CommandLine* command_line) override {
1643 // Add startup URL to command line
1644 const testing::TestInfo* const test_info =
1645 testing::UnitTest::GetInstance()->current_test_info();
1646 std::string test_name = test_info->name();
1647 // Do not add startup URL in PRE_ test to prevent it from opening twice
1648 // in main test body.
1649 if (!BeginsWith(test_name, std::string("PRE_"))) {
1650 command_line->AppendArg(kStartupURL);
1651 }
1652 SessionRestoreTest::SetUpCommandLine(command_line);
1653 }
1654 };
sky 2017/05/04 23:40:46 private: DISALLOW...
eugenebng 2017/05/15 06:17:08 Done.
1655
1656 IN_PROC_BROWSER_TEST_F(SessionRestoreWithStartupURLTest,
1657 PRE_StartupURLsWithSessionRestore) {
1658 // Prepare a session to restore in main test body.
1659 ui_test_utils::NavigateToURL(browser(), GURL(kSessionURL));
1660 }
1661
1662 IN_PROC_BROWSER_TEST_F(SessionRestoreWithStartupURLTest,
1663 StartupURLsWithSessionRestore) {
1664 // Check that browser is started with restored session and
1665 // tab with startup URL next to it.
1666 // ui_test_utils::NavigateToURL(browser(),GURL(kSessionURL));
sky 2017/05/04 23:40:46 Why is this commented out?
eugenebng 2017/05/15 06:17:08 Done.
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());
eugenebng 2017/05/03 16:05:30 Added test.
1673 }
OLDNEW
« chrome/browser/sessions/session_restore.h ('K') | « chrome/browser/sessions/session_restore.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698