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

Side by Side Diff: chrome/browser/ui/startup/startup_browser_creator_browsertest.cc

Issue 1294923003: Add a triggered profile reset mechanism. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: grt nits Created 5 years, 3 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/test/histogram_tester.h" 12 #include "base/test/histogram_tester.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/extensions/extension_browsertest.h" 14 #include "chrome/browser/extensions/extension_browsertest.h"
15 #include "chrome/browser/extensions/extension_service.h" 15 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/extensions/extension_util.h" 16 #include "chrome/browser/extensions/extension_util.h"
17 #include "chrome/browser/extensions/launch_util.h" 17 #include "chrome/browser/extensions/launch_util.h"
18 #include "chrome/browser/first_run/first_run.h" 18 #include "chrome/browser/first_run/first_run.h"
19 #include "chrome/browser/infobars/infobar_service.h" 19 #include "chrome/browser/infobars/infobar_service.h"
20 #include "chrome/browser/prefs/session_startup_pref.h" 20 #include "chrome/browser/prefs/session_startup_pref.h"
21 #include "chrome/browser/profile_resetter/triggered_profile_resetter.h"
22 #include "chrome/browser/profile_resetter/triggered_profile_resetter_factory.h"
21 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/profiles/profile_impl.h" 24 #include "chrome/browser/profiles/profile_impl.h"
23 #include "chrome/browser/profiles/profile_manager.h" 25 #include "chrome/browser/profiles/profile_manager.h"
24 #include "chrome/browser/sessions/session_restore.h" 26 #include "chrome/browser/sessions/session_restore.h"
25 #include "chrome/browser/signin/signin_promo.h" 27 #include "chrome/browser/signin/signin_promo.h"
26 #include "chrome/browser/ui/browser.h" 28 #include "chrome/browser/ui/browser.h"
27 #include "chrome/browser/ui/browser_commands.h" 29 #include "chrome/browser/ui/browser_commands.h"
28 #include "chrome/browser/ui/browser_finder.h" 30 #include "chrome/browser/ui/browser_finder.h"
29 #include "chrome/browser/ui/browser_iterator.h" 31 #include "chrome/browser/ui/browser_iterator.h"
30 #include "chrome/browser/ui/browser_list.h" 32 #include "chrome/browser/ui/browser_list.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } 95 }
94 96
95 bool IsWindows10OrNewer() { 97 bool IsWindows10OrNewer() {
96 #if defined(OS_WIN) 98 #if defined(OS_WIN)
97 return base::win::GetVersion() >= base::win::VERSION_WIN10; 99 return base::win::GetVersion() >= base::win::VERSION_WIN10;
98 #else 100 #else
99 return false; 101 return false;
100 #endif 102 #endif
101 } 103 }
102 104
105 class MockTriggeredProfileResetter : public TriggeredProfileResetter {
106 public:
107 MockTriggeredProfileResetter() : TriggeredProfileResetter(nullptr) {}
108
109 void Activate() override {}
110 bool HasResetTrigger() override { return true; }
111 };
112
113 #if defined(OS_WIN)
114
115 scoped_ptr<KeyedService> BuildMockTriggeredProfileResetter(
116 content::BrowserContext* context) {
117 return make_scoped_ptr(new MockTriggeredProfileResetter);
118 }
119
120 #endif // defined(OS_WIN)
121
103 } // namespace 122 } // namespace
104 123
105 class StartupBrowserCreatorTest : public ExtensionBrowserTest { 124 class StartupBrowserCreatorTest : public ExtensionBrowserTest {
106 protected: 125 protected:
107 StartupBrowserCreatorTest() {} 126 StartupBrowserCreatorTest() {}
108 127
109 bool SetUpUserDataDirectory() override { 128 bool SetUpUserDataDirectory() override {
110 return ExtensionBrowserTest::SetUpUserDataDirectory(); 129 return ExtensionBrowserTest::SetUpUserDataDirectory();
111 } 130 }
112 131
(...skipping 1513 matching lines...) Expand 10 before | Expand all | Expand 10 after
1626 ASSERT_EQ(1, tab_strip->count()); 1645 ASSERT_EQ(1, tab_strip->count());
1627 EXPECT_EQ("title1.html", 1646 EXPECT_EQ("title1.html",
1628 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName()); 1647 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName());
1629 } 1648 }
1630 #endif // defined(ENABLE_CONFIGURATION_POLICY) 1649 #endif // defined(ENABLE_CONFIGURATION_POLICY)
1631 1650
1632 #endif // !defined(OS_LINUX) || !defined(GOOGLE_CHROME_BUILD) || 1651 #endif // !defined(OS_LINUX) || !defined(GOOGLE_CHROME_BUILD) ||
1633 // defined(ENABLE_CONFIGURATION_POLICY) 1652 // defined(ENABLE_CONFIGURATION_POLICY)
1634 1653
1635 #endif // !defined(OS_CHROMEOS) 1654 #endif // !defined(OS_CHROMEOS)
1655
1656 #if defined(OS_WIN)
1657
1658 class StartupBrowserCreatorTriggeredResetTest : public InProcessBrowserTest {
1659 protected:
1660 void SetUpCommandLine(base::CommandLine* command_line) override;
1661 void SetUpInProcessBrowserTestFixture() override;
1662 };
1663
1664 void StartupBrowserCreatorTriggeredResetTest::SetUpCommandLine(
1665 base::CommandLine* command_line) {
1666 command_line->AppendArg("http://www.chromium.org");
1667 }
1668
1669 void StartupBrowserCreatorTriggeredResetTest::
1670 SetUpInProcessBrowserTestFixture() {
1671 TriggeredProfileResetterFactory::GetInstance()->SetGlobalTestingFactory(
1672 &BuildMockTriggeredProfileResetter);
1673 }
1674
1675 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTriggeredResetTest,
1676 TestTriggeredReset) {
1677 // Use a couple same-site HTTP URLs.
1678 ASSERT_TRUE(test_server()->Start());
1679 std::vector<GURL> urls;
1680 urls.push_back(test_server()->GetURL("files/title1.html"));
1681 urls.push_back(test_server()->GetURL("files/title2.html"));
1682
1683 Profile* profile = browser()->profile();
1684 chrome::HostDesktopType host_desktop_type = browser()->host_desktop_type();
1685
1686 // Set the startup preference to open these URLs.
1687 SessionStartupPref pref(SessionStartupPref::URLS);
1688 pref.urls = urls;
1689 SessionStartupPref::SetStartupPref(profile, pref);
1690
1691 // Keep the browser process running while browsers are closed.
1692 g_browser_process->AddRefModule();
1693
1694 // Close the browser.
1695 CloseBrowserAsynchronously(browser());
1696
1697 // Do a simple non-process-startup browser launch.
1698 base::CommandLine dummy(base::CommandLine::NO_PROGRAM);
1699 chrome::startup::IsFirstRun first_run =
1700 first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN
1701 : chrome::startup::IS_NOT_FIRST_RUN;
1702 {
1703 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run);
1704 ASSERT_TRUE(
1705 launch.Launch(profile, std::vector<GURL>(), false, host_desktop_type));
1706 }
1707
1708 // This should have created a new browser window. |browser()| is still
1709 // around at this point, even though we've closed its window.
1710 Browser* new_browser = FindOneOtherBrowser(browser());
1711 ASSERT_TRUE(new_browser);
1712
1713 std::vector<GURL> expected_urls(urls);
1714 if (IsWindows10OrNewer())
1715 expected_urls.insert(expected_urls.begin(), internals::GetWelcomePageURL());
1716 expected_urls.insert(expected_urls.begin(), internals::GetResetSettingsURL());
1717
1718 TabStripModel* tab_strip = new_browser->tab_strip_model();
1719 ASSERT_EQ(static_cast<int>(expected_urls.size()), tab_strip->count());
1720 for (size_t i = 0; i < expected_urls.size(); i++)
1721 EXPECT_EQ(expected_urls[i], tab_strip->GetWebContentsAt(i)->GetURL());
1722
1723 g_browser_process->ReleaseModule();
1724 }
1725
1726 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTriggeredResetTest,
1727 TestTriggeredResetDoesNotShowOnFirstRun) {
1728 StartupBrowserCreator browser_creator;
1729 browser_creator.AddFirstRunTab(GURL("http://new_tab_page"));
1730 browser_creator.AddFirstRunTab(test_server()->GetURL("files/title1.html"));
1731
1732 // Do a process-startup browser launch.
1733 base::CommandLine dummy(base::CommandLine::NO_PROGRAM);
1734 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator,
1735 chrome::startup::IS_FIRST_RUN);
1736 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), true,
1737 browser()->host_desktop_type()));
1738
1739 // This should have created a new browser window.
1740 Browser* new_browser = FindOneOtherBrowser(browser());
1741 ASSERT_TRUE(new_browser);
1742
1743 // Verify that only the first-run tabs are shown.
1744 TabStripModel* tab_strip = new_browser->tab_strip_model();
1745 ASSERT_EQ(2, tab_strip->count());
1746 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
1747 tab_strip->GetWebContentsAt(0)->GetURL());
1748 EXPECT_EQ("title1.html",
1749 tab_strip->GetWebContentsAt(1)->GetURL().ExtractFileName());
1750 }
1751
1752 #endif // defined(OS_WIN)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698