Index: chrome/browser/ui/startup/startup_browser_creator_browsertest.cc |
diff --git a/chrome/browser/ui/startup/startup_browser_creator_browsertest.cc b/chrome/browser/ui/startup/startup_browser_creator_browsertest.cc |
index e5a280543a0d81a9e7706cb24b359618d88ae3db..64352c730617644d767779341a329e8c91d96bf0 100644 |
--- a/chrome/browser/ui/startup/startup_browser_creator_browsertest.cc |
+++ b/chrome/browser/ui/startup/startup_browser_creator_browsertest.cc |
@@ -18,6 +18,8 @@ |
#include "chrome/browser/first_run/first_run.h" |
#include "chrome/browser/infobars/infobar_service.h" |
#include "chrome/browser/prefs/session_startup_pref.h" |
+#include "chrome/browser/profile_resetter/triggered_profile_resetter.h" |
+#include "chrome/browser/profile_resetter/triggered_profile_resetter_factory.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/profiles/profile_impl.h" |
#include "chrome/browser/profiles/profile_manager.h" |
@@ -41,6 +43,7 @@ |
#include "chrome/test/base/in_process_browser_test.h" |
#include "chrome/test/base/test_switches.h" |
#include "chrome/test/base/ui_test_utils.h" |
+#include "components/keyed_service/content/browser_context_dependency_manager.h" |
#include "content/public/browser/web_contents.h" |
#include "content/public/test/test_utils.h" |
#include "extensions/browser/extension_system.h" |
@@ -100,6 +103,23 @@ bool IsWindows10OrNewer() { |
#endif |
} |
+class MockTriggeredProfileResetter : public TriggeredProfileResetter { |
+ public: |
+ MockTriggeredProfileResetter() : TriggeredProfileResetter(nullptr) {} |
+ |
+ void Activate() override {} |
+ bool HasResetTrigger() override { return true; } |
+}; |
+ |
+#if defined(OS_WIN) |
+ |
+scoped_ptr<KeyedService> BuildMockTriggeredProfileResetter( |
+ content::BrowserContext* context) { |
+ return make_scoped_ptr(new MockTriggeredProfileResetter); |
+} |
+ |
+#endif // defined(OS_WIN) |
+ |
} // namespace |
class StartupBrowserCreatorTest : public ExtensionBrowserTest { |
@@ -1633,3 +1653,115 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorFirstRunTest, |
// defined(ENABLE_CONFIGURATION_POLICY) |
#endif // !defined(OS_CHROMEOS) |
+ |
+#if defined(OS_WIN) |
+ |
+class StartupBrowserCreatorTriggeredResetTest : public InProcessBrowserTest { |
msw
2015/09/22 17:44:26
nit: maybe this belongs in its own file?
robertshield
2015/09/24 04:00:40
Done. Note that there's a tiny bit of code duplica
|
+ protected: |
+ void SetUpCommandLine(base::CommandLine* command_line) override; |
msw
2015/09/22 17:44:26
nit: these could be defined inline
robertshield
2015/09/24 04:00:40
Done.
|
+ void SetUpInProcessBrowserTestFixture() override; |
+ |
+ private: |
+ void OnWillCreateBrowserContextServices(content::BrowserContext* context) { |
+ TriggeredProfileResetterFactory::GetInstance()->SetTestingFactory( |
+ context, &BuildMockTriggeredProfileResetter); |
+ } |
+ |
+ scoped_ptr<base::CallbackList<void(content::BrowserContext*)>::Subscription> |
+ will_create_browser_context_services_subscription_; |
+}; |
+ |
+void StartupBrowserCreatorTriggeredResetTest::SetUpCommandLine( |
+ base::CommandLine* command_line) { |
+ command_line->AppendArg("http://www.chromium.org"); |
+} |
+ |
+void StartupBrowserCreatorTriggeredResetTest:: |
+ SetUpInProcessBrowserTestFixture() { |
+ will_create_browser_context_services_subscription_ = |
+ BrowserContextDependencyManager::GetInstance() |
+ ->RegisterWillCreateBrowserContextServicesCallbackForTesting( |
+ base::Bind(&StartupBrowserCreatorTriggeredResetTest:: |
+ OnWillCreateBrowserContextServices, |
+ base::Unretained(this))) |
+ .Pass(); |
msw
2015/09/22 17:44:26
nit: did this pass "git cl format"?
robertshield
2015/09/24 04:00:40
This is git cl format's take on how to arrange thi
|
+} |
+ |
+IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTriggeredResetTest, |
+ TestTriggeredReset) { |
+ // Use a couple same-site HTTP URLs. |
+ ASSERT_TRUE(test_server()->Start()); |
+ std::vector<GURL> urls; |
+ urls.push_back(test_server()->GetURL("files/title1.html")); |
+ urls.push_back(test_server()->GetURL("files/title2.html")); |
+ |
+ Profile* profile = browser()->profile(); |
+ chrome::HostDesktopType host_desktop_type = browser()->host_desktop_type(); |
+ |
+ // Set the startup preference to open these URLs. |
+ SessionStartupPref pref(SessionStartupPref::URLS); |
+ pref.urls = urls; |
+ SessionStartupPref::SetStartupPref(profile, pref); |
+ |
+ // Keep the browser process running while browsers are closed. |
+ g_browser_process->AddRefModule(); |
+ |
+ // Close the browser. |
+ CloseBrowserAsynchronously(browser()); |
+ |
+ // Do a simple non-process-startup browser launch. |
+ base::CommandLine dummy(base::CommandLine::NO_PROGRAM); |
+ chrome::startup::IsFirstRun first_run = |
+ first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN |
msw
2015/09/22 17:44:26
Why isn't this known at compile time (ie. expect/u
robertshield
2015/09/24 04:00:40
That's a good question. I cribbed this from some o
|
+ : chrome::startup::IS_NOT_FIRST_RUN; |
+ { |
+ StartupBrowserCreatorImpl launch(base::FilePath(), dummy, first_run); |
+ ASSERT_TRUE( |
+ launch.Launch(profile, std::vector<GURL>(), false, host_desktop_type)); |
+ } |
+ |
+ // This should have created a new browser window. |browser()| is still |
+ // around at this point, even though we've closed its window. |
+ Browser* new_browser = FindOneOtherBrowser(browser()); |
+ ASSERT_TRUE(new_browser); |
+ |
+ std::vector<GURL> expected_urls(urls); |
+ if (IsWindows10OrNewer()) |
+ expected_urls.insert(expected_urls.begin(), internals::GetWelcomePageURL()); |
+ expected_urls.insert(expected_urls.begin(), internals::GetResetSettingsURL()); |
+ |
+ TabStripModel* tab_strip = new_browser->tab_strip_model(); |
+ ASSERT_EQ(static_cast<int>(expected_urls.size()), tab_strip->count()); |
+ for (size_t i = 0; i < expected_urls.size(); i++) |
+ EXPECT_EQ(expected_urls[i], tab_strip->GetWebContentsAt(i)->GetURL()); |
+ |
+ g_browser_process->ReleaseModule(); |
+} |
+ |
+IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTriggeredResetTest, |
+ TestTriggeredResetDoesNotShowOnFirstRun) { |
+ StartupBrowserCreator browser_creator; |
+ browser_creator.AddFirstRunTab(GURL("http://new_tab_page")); |
+ browser_creator.AddFirstRunTab(test_server()->GetURL("files/title1.html")); |
+ |
+ // Do a process-startup browser launch. |
+ base::CommandLine dummy(base::CommandLine::NO_PROGRAM); |
+ StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator, |
msw
2015/09/22 17:44:26
nit: why no nested block like above? Be consistent
robertshield
2015/09/24 04:00:40
Indeed, that was cribbed from an earlier test and
|
+ chrome::startup::IS_FIRST_RUN); |
+ ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), true, |
+ browser()->host_desktop_type())); |
+ |
+ // This should have created a new browser window. |
+ Browser* new_browser = FindOneOtherBrowser(browser()); |
+ ASSERT_TRUE(new_browser); |
+ |
+ // Verify that only the first-run tabs are shown. |
msw
2015/09/22 17:44:26
Where does StartupBrowserCreatorImpl inhibit the u
robertshield
2015/09/24 04:00:40
In StartupBrowserCreatorImpl::AddStartupURLs(), th
|
+ TabStripModel* tab_strip = new_browser->tab_strip_model(); |
+ ASSERT_EQ(2, tab_strip->count()); |
+ EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), |
+ tab_strip->GetWebContentsAt(0)->GetURL()); |
+ EXPECT_EQ("title1.html", |
+ tab_strip->GetWebContentsAt(1)->GetURL().ExtractFileName()); |
+} |
+ |
+#endif // defined(OS_WIN) |