| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 "base/callback_list.h" | 7 #include "base/callback_list.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/win/windows_version.h" | 11 #include "base/win/windows_version.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/lifetime/keep_alive_types.h" |
| 14 #include "chrome/browser/lifetime/scoped_keep_alive.h" |
| 13 #include "chrome/browser/profile_resetter/triggered_profile_resetter.h" | 15 #include "chrome/browser/profile_resetter/triggered_profile_resetter.h" |
| 14 #include "chrome/browser/profile_resetter/triggered_profile_resetter_factory.h" | 16 #include "chrome/browser/profile_resetter/triggered_profile_resetter_factory.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/browser/signin/signin_promo.h" | 18 #include "chrome/browser/signin/signin_promo.h" |
| 17 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/browser_finder.h" | 20 #include "chrome/browser/ui/browser_finder.h" |
| 19 #include "chrome/browser/ui/browser_list.h" | 21 #include "chrome/browser/ui/browser_list.h" |
| 20 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 22 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
| 21 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" | 23 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" |
| 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 urls.push_back(embedded_test_server()->GetURL("/title2.html")); | 104 urls.push_back(embedded_test_server()->GetURL("/title2.html")); |
| 103 | 105 |
| 104 Profile* profile = browser()->profile(); | 106 Profile* profile = browser()->profile(); |
| 105 | 107 |
| 106 // Set the startup preference to open these URLs. | 108 // Set the startup preference to open these URLs. |
| 107 SessionStartupPref pref(SessionStartupPref::URLS); | 109 SessionStartupPref pref(SessionStartupPref::URLS); |
| 108 pref.urls = urls; | 110 pref.urls = urls; |
| 109 SessionStartupPref::SetStartupPref(profile, pref); | 111 SessionStartupPref::SetStartupPref(profile, pref); |
| 110 | 112 |
| 111 // Keep the browser process running while browsers are closed. | 113 // Keep the browser process running while browsers are closed. |
| 112 g_browser_process->AddRefModule(); | 114 ScopedKeepAlive keep_alive(KeepAliveOrigin::BROWSER, |
| 115 KeepAliveRestartOption::DISABLED); |
| 113 | 116 |
| 114 // Close the browser. | 117 // Close the browser. |
| 115 CloseBrowserAsynchronously(browser()); | 118 CloseBrowserAsynchronously(browser()); |
| 116 | 119 |
| 117 // Prep the next launch to offer a reset prompt. | 120 // Prep the next launch to offer a reset prompt. |
| 118 MockTriggeredProfileResetter::SetHasResetTrigger(true); | 121 MockTriggeredProfileResetter::SetHasResetTrigger(true); |
| 119 | 122 |
| 120 // Do a simple non-process-startup browser launch. | 123 // Do a simple non-process-startup browser launch. |
| 121 base::CommandLine dummy(base::CommandLine::NO_PROGRAM); | 124 base::CommandLine dummy(base::CommandLine::NO_PROGRAM); |
| 122 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, | 125 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, |
| 123 chrome::startup::IS_NOT_FIRST_RUN); | 126 chrome::startup::IS_NOT_FIRST_RUN); |
| 124 ASSERT_TRUE(launch.Launch(profile, std::vector<GURL>(), false)); | 127 ASSERT_TRUE(launch.Launch(profile, std::vector<GURL>(), false)); |
| 125 | 128 |
| 126 // This should have created a new browser window. |browser()| is still | 129 // This should have created a new browser window. |browser()| is still |
| 127 // around at this point, even though we've closed its window. | 130 // around at this point, even though we've closed its window. |
| 128 Browser* new_browser = FindOneOtherBrowser(browser()); | 131 Browser* new_browser = FindOneOtherBrowser(browser()); |
| 129 ASSERT_TRUE(new_browser); | 132 ASSERT_TRUE(new_browser); |
| 130 | 133 |
| 131 std::vector<GURL> expected_urls(urls); | 134 std::vector<GURL> expected_urls(urls); |
| 132 if (base::win::GetVersion() >= base::win::VERSION_WIN10) | 135 if (base::win::GetVersion() >= base::win::VERSION_WIN10) |
| 133 expected_urls.insert(expected_urls.begin(), internals::GetWelcomePageURL()); | 136 expected_urls.insert(expected_urls.begin(), internals::GetWelcomePageURL()); |
| 134 expected_urls.insert(expected_urls.begin(), | 137 expected_urls.insert(expected_urls.begin(), |
| 135 internals::GetTriggeredResetSettingsURL()); | 138 internals::GetTriggeredResetSettingsURL()); |
| 136 | 139 |
| 137 TabStripModel* tab_strip = new_browser->tab_strip_model(); | 140 TabStripModel* tab_strip = new_browser->tab_strip_model(); |
| 138 ASSERT_EQ(static_cast<int>(expected_urls.size()), tab_strip->count()); | 141 ASSERT_EQ(static_cast<int>(expected_urls.size()), tab_strip->count()); |
| 139 for (size_t i = 0; i < expected_urls.size(); i++) | 142 for (size_t i = 0; i < expected_urls.size(); i++) |
| 140 EXPECT_EQ(expected_urls[i], tab_strip->GetWebContentsAt(i)->GetURL()); | 143 EXPECT_EQ(expected_urls[i], tab_strip->GetWebContentsAt(i)->GetURL()); |
| 141 | |
| 142 g_browser_process->ReleaseModule(); | |
| 143 } | 144 } |
| 144 | 145 |
| 145 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTriggeredResetTest, | 146 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTriggeredResetTest, |
| 146 TestTriggeredResetDoesNotShowWithFirstRunURLs) { | 147 TestTriggeredResetDoesNotShowWithFirstRunURLs) { |
| 147 // The presence of First Run tabs (in production code, these commonly come | 148 // The presence of First Run tabs (in production code, these commonly come |
| 148 // from master_preferences) should suppress the reset UI. Check that this is | 149 // from master_preferences) should suppress the reset UI. Check that this is |
| 149 // the case. | 150 // the case. |
| 150 ASSERT_TRUE(embedded_test_server()->Start()); | 151 ASSERT_TRUE(embedded_test_server()->Start()); |
| 151 StartupBrowserCreator browser_creator; | 152 StartupBrowserCreator browser_creator; |
| 152 browser_creator.AddFirstRunTab(GURL("http://new_tab_page")); | 153 browser_creator.AddFirstRunTab(GURL("http://new_tab_page")); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 181 EXPECT_EQ("title1.html", | 182 EXPECT_EQ("title1.html", |
| 182 tab_strip->GetWebContentsAt(1)->GetURL().ExtractFileName()); | 183 tab_strip->GetWebContentsAt(1)->GetURL().ExtractFileName()); |
| 183 } | 184 } |
| 184 | 185 |
| 185 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTriggeredResetTest, | 186 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTriggeredResetTest, |
| 186 TestMultiProfile) { | 187 TestMultiProfile) { |
| 187 SessionStartupPref pref(SessionStartupPref::DEFAULT); | 188 SessionStartupPref pref(SessionStartupPref::DEFAULT); |
| 188 SessionStartupPref::SetStartupPref(browser()->profile(), pref); | 189 SessionStartupPref::SetStartupPref(browser()->profile(), pref); |
| 189 | 190 |
| 190 // Keep the browser process running while browsers are closed. | 191 // Keep the browser process running while browsers are closed. |
| 191 g_browser_process->AddRefModule(); | 192 ScopedKeepAlive keep_alive(KeepAliveOrigin::BROWSER, |
| 193 KeepAliveRestartOption::DISABLED); |
| 192 | 194 |
| 193 // Close the browser. | 195 // Close the browser. |
| 194 CloseBrowserAsynchronously(browser()); | 196 CloseBrowserAsynchronously(browser()); |
| 195 | 197 |
| 196 // Prep the next launch to offer a reset prompt. | 198 // Prep the next launch to offer a reset prompt. |
| 197 MockTriggeredProfileResetter::SetHasResetTrigger(true); | 199 MockTriggeredProfileResetter::SetHasResetTrigger(true); |
| 198 | 200 |
| 199 // Do a simple non-process-startup browser launch. | 201 // Do a simple non-process-startup browser launch. |
| 200 base::CommandLine dummy(base::CommandLine::NO_PROGRAM); | 202 base::CommandLine dummy(base::CommandLine::NO_PROGRAM); |
| 201 { | 203 { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 243 |
| 242 Browser* other_profile_browser = | 244 Browser* other_profile_browser = |
| 243 chrome::FindBrowserWithProfile(other_profile); | 245 chrome::FindBrowserWithProfile(other_profile); |
| 244 ASSERT_NE(nullptr, other_profile_browser); | 246 ASSERT_NE(nullptr, other_profile_browser); |
| 245 | 247 |
| 246 // Check for the expected reset dialog in the second browser too. | 248 // Check for the expected reset dialog in the second browser too. |
| 247 TabStripModel* other_tab_strip = other_profile_browser->tab_strip_model(); | 249 TabStripModel* other_tab_strip = other_profile_browser->tab_strip_model(); |
| 248 ASSERT_LT(0, other_tab_strip->count()); | 250 ASSERT_LT(0, other_tab_strip->count()); |
| 249 EXPECT_EQ(internals::GetTriggeredResetSettingsURL(), | 251 EXPECT_EQ(internals::GetTriggeredResetSettingsURL(), |
| 250 other_tab_strip->GetActiveWebContents()->GetURL()); | 252 other_tab_strip->GetActiveWebContents()->GetURL()); |
| 251 g_browser_process->ReleaseModule(); | |
| 252 } | 253 } |
| OLD | NEW |