OLD | NEW |
---|---|
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" |
31 #include "chrome/browser/ui/browser_list_observer.h" | 33 #include "chrome/browser/ui/browser_list_observer.h" |
32 #include "chrome/browser/ui/browser_window.h" | 34 #include "chrome/browser/ui/browser_window.h" |
33 #include "chrome/browser/ui/host_desktop.h" | 35 #include "chrome/browser/ui/host_desktop.h" |
34 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 36 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
35 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" | 37 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" |
36 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 38 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
37 #include "chrome/common/chrome_switches.h" | 39 #include "chrome/common/chrome_switches.h" |
38 #include "chrome/common/extensions/extension_constants.h" | 40 #include "chrome/common/extensions/extension_constants.h" |
39 #include "chrome/common/pref_names.h" | 41 #include "chrome/common/pref_names.h" |
40 #include "chrome/common/url_constants.h" | 42 #include "chrome/common/url_constants.h" |
41 #include "chrome/test/base/in_process_browser_test.h" | 43 #include "chrome/test/base/in_process_browser_test.h" |
42 #include "chrome/test/base/test_switches.h" | 44 #include "chrome/test/base/test_switches.h" |
43 #include "chrome/test/base/ui_test_utils.h" | 45 #include "chrome/test/base/ui_test_utils.h" |
46 #include "components/keyed_service/content/browser_context_dependency_manager.h" | |
44 #include "content/public/browser/web_contents.h" | 47 #include "content/public/browser/web_contents.h" |
45 #include "content/public/test/test_utils.h" | 48 #include "content/public/test/test_utils.h" |
46 #include "extensions/browser/extension_system.h" | 49 #include "extensions/browser/extension_system.h" |
47 #include "testing/gtest/include/gtest/gtest.h" | 50 #include "testing/gtest/include/gtest/gtest.h" |
48 #include "url/gurl.h" | 51 #include "url/gurl.h" |
49 | 52 |
50 #if defined(ENABLE_CONFIGURATION_POLICY) && !defined(OS_CHROMEOS) | 53 #if defined(ENABLE_CONFIGURATION_POLICY) && !defined(OS_CHROMEOS) |
51 #include "base/callback.h" | 54 #include "base/callback.h" |
52 #include "base/run_loop.h" | 55 #include "base/run_loop.h" |
53 #include "base/values.h" | 56 #include "base/values.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 } | 96 } |
94 | 97 |
95 bool IsWindows10OrNewer() { | 98 bool IsWindows10OrNewer() { |
96 #if defined(OS_WIN) | 99 #if defined(OS_WIN) |
97 return base::win::GetVersion() >= base::win::VERSION_WIN10; | 100 return base::win::GetVersion() >= base::win::VERSION_WIN10; |
98 #else | 101 #else |
99 return false; | 102 return false; |
100 #endif | 103 #endif |
101 } | 104 } |
102 | 105 |
106 class MockTriggeredProfileResetter : public TriggeredProfileResetter { | |
107 public: | |
108 MockTriggeredProfileResetter() : TriggeredProfileResetter(nullptr) {} | |
109 | |
110 void Activate() override {} | |
111 bool HasResetTrigger() override { return true; } | |
112 }; | |
113 | |
114 #if defined(OS_WIN) | |
115 | |
116 scoped_ptr<KeyedService> BuildMockTriggeredProfileResetter( | |
117 content::BrowserContext* context) { | |
118 return make_scoped_ptr(new MockTriggeredProfileResetter); | |
119 } | |
120 | |
121 #endif // defined(OS_WIN) | |
122 | |
103 } // namespace | 123 } // namespace |
104 | 124 |
105 class StartupBrowserCreatorTest : public ExtensionBrowserTest { | 125 class StartupBrowserCreatorTest : public ExtensionBrowserTest { |
106 protected: | 126 protected: |
107 StartupBrowserCreatorTest() {} | 127 StartupBrowserCreatorTest() {} |
108 | 128 |
109 bool SetUpUserDataDirectory() override { | 129 bool SetUpUserDataDirectory() override { |
110 return ExtensionBrowserTest::SetUpUserDataDirectory(); | 130 return ExtensionBrowserTest::SetUpUserDataDirectory(); |
111 } | 131 } |
112 | 132 |
(...skipping 1513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1626 ASSERT_EQ(1, tab_strip->count()); | 1646 ASSERT_EQ(1, tab_strip->count()); |
1627 EXPECT_EQ("title1.html", | 1647 EXPECT_EQ("title1.html", |
1628 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName()); | 1648 tab_strip->GetWebContentsAt(0)->GetURL().ExtractFileName()); |
1629 } | 1649 } |
1630 #endif // defined(ENABLE_CONFIGURATION_POLICY) | 1650 #endif // defined(ENABLE_CONFIGURATION_POLICY) |
1631 | 1651 |
1632 #endif // !defined(OS_LINUX) || !defined(GOOGLE_CHROME_BUILD) || | 1652 #endif // !defined(OS_LINUX) || !defined(GOOGLE_CHROME_BUILD) || |
1633 // defined(ENABLE_CONFIGURATION_POLICY) | 1653 // defined(ENABLE_CONFIGURATION_POLICY) |
1634 | 1654 |
1635 #endif // !defined(OS_CHROMEOS) | 1655 #endif // !defined(OS_CHROMEOS) |
1656 | |
1657 #if defined(OS_WIN) | |
1658 | |
1659 class StartupBrowserCreatorTriggeredResetTest : public InProcessBrowserTest { | |
1660 public: | |
1661 void OnWillCreateBrowserContextServices(content::BrowserContext* context) { | |
engedy
2015/09/21 12:56:10
nit: This could be made private. (Not because it h
robertshield
2015/09/21 22:04:30
Done.
| |
1662 TriggeredProfileResetterFactory::GetInstance()->SetTestingFactory( | |
1663 context, &BuildMockTriggeredProfileResetter); | |
1664 } | |
1665 | |
1666 protected: | |
1667 void SetUpCommandLine(base::CommandLine* command_line) override; | |
1668 void SetUpInProcessBrowserTestFixture() override; | |
1669 | |
1670 private: | |
1671 scoped_ptr<base::CallbackList<void(content::BrowserContext*)>::Subscription> | |
1672 will_create_browser_context_services_subscription_; | |
1673 }; | |
1674 | |
1675 void StartupBrowserCreatorTriggeredResetTest::SetUpCommandLine( | |
1676 base::CommandLine* command_line) { | |
1677 command_line->AppendArg("http://www.chromium.org"); | |
1678 } | |
1679 | |
1680 void StartupBrowserCreatorTriggeredResetTest:: | |
1681 SetUpInProcessBrowserTestFixture() { | |
1682 will_create_browser_context_services_subscription_ = | |
1683 BrowserContextDependencyManager::GetInstance() | |
1684 ->RegisterWillCreateBrowserContextServicesCallbackForTesting( | |
1685 base::Bind(&StartupBrowserCreatorTriggeredResetTest:: | |
1686 OnWillCreateBrowserContextServices, | |
1687 base::Unretained(this))) | |
1688 .Pass(); | |
1689 } | |
1690 | |
1691 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTriggeredResetTest, | |
1692 TestTriggeredReset) { | |
1693 // Use a couple same-site HTTP URLs. | |
1694 ASSERT_TRUE(test_server()->Start()); | |
1695 std::vector<GURL> urls; | |
1696 urls.push_back(test_server()->GetURL("files/title1.html")); | |
1697 urls.push_back(test_server()->GetURL("files/title2.html")); | |
1698 | |
1699 Profile* profile = browser()->profile(); | |
1700 chrome::HostDesktopType host_desktop_type = browser()->host_desktop_type(); | |
1701 | |
1702 // Set the startup preference to open these URLs. | |
1703 SessionStartupPref pref(SessionStartupPref::URLS); | |
1704 pref.urls = urls; | |
1705 SessionStartupPref::SetStartupPref(profile, pref); | |
1706 | |
1707 // Keep the browser process running while browsers are closed. | |
1708 g_browser_process->AddRefModule(); | |
1709 | |
1710 // Close the browser. | |
1711 CloseBrowserAsynchronously(browser()); | |
1712 | |
1713 // Do a simple non-process-startup browser launch. | |
1714 base::CommandLine dummy(base::CommandLine::NO_PROGRAM); | |
1715 chrome::startup::IsFirstRun first_run = | |
1716 first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN | |
1717 : chrome::startup::IS_NOT_FIRST_RUN; | |
1718 { | |
1719 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run); | |
1720 ASSERT_TRUE( | |
1721 launch.Launch(profile, std::vector<GURL>(), false, host_desktop_type)); | |
1722 } | |
1723 | |
1724 // This should have created a new browser window. |browser()| is still | |
1725 // around at this point, even though we've closed its window. | |
1726 Browser* new_browser = FindOneOtherBrowser(browser()); | |
1727 ASSERT_TRUE(new_browser); | |
1728 | |
1729 std::vector<GURL> expected_urls(urls); | |
1730 if (IsWindows10OrNewer()) | |
1731 expected_urls.insert(expected_urls.begin(), internals::GetWelcomePageURL()); | |
1732 expected_urls.insert(expected_urls.begin(), internals::GetResetSettingsURL()); | |
1733 | |
1734 TabStripModel* tab_strip = new_browser->tab_strip_model(); | |
1735 ASSERT_EQ(static_cast<int>(expected_urls.size()), tab_strip->count()); | |
1736 for (size_t i = 0; i < expected_urls.size(); i++) | |
1737 EXPECT_EQ(expected_urls[i], tab_strip->GetWebContentsAt(i)->GetURL()); | |
1738 | |
1739 g_browser_process->ReleaseModule(); | |
1740 } | |
1741 | |
1742 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTriggeredResetTest, | |
1743 TestTriggeredResetDoesNotShowOnFirstRun) { | |
1744 StartupBrowserCreator browser_creator; | |
1745 browser_creator.AddFirstRunTab(GURL("http://new_tab_page")); | |
1746 browser_creator.AddFirstRunTab(test_server()->GetURL("files/title1.html")); | |
1747 | |
1748 // Do a process-startup browser launch. | |
1749 base::CommandLine dummy(base::CommandLine::NO_PROGRAM); | |
1750 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator, | |
1751 chrome::startup::IS_FIRST_RUN); | |
1752 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), true, | |
1753 browser()->host_desktop_type())); | |
1754 | |
1755 // This should have created a new browser window. | |
1756 Browser* new_browser = FindOneOtherBrowser(browser()); | |
1757 ASSERT_TRUE(new_browser); | |
1758 | |
1759 // Verify that only the first-run tabs are shown. | |
1760 TabStripModel* tab_strip = new_browser->tab_strip_model(); | |
1761 ASSERT_EQ(2, tab_strip->count()); | |
1762 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), | |
1763 tab_strip->GetWebContentsAt(0)->GetURL()); | |
1764 EXPECT_EQ("title1.html", | |
1765 tab_strip->GetWebContentsAt(1)->GetURL().ExtractFileName()); | |
1766 } | |
1767 | |
1768 #endif // defined(OS_WIN) | |
OLD | NEW |