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

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

Issue 1294923003: Add a triggered profile reset mechanism. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: msw feedback Created 5 years, 2 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
« no previous file with comments | « chrome/browser/ui/startup/startup_browser_creator_impl.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/callback_list.h"
6 #include "base/command_line.h"
7 #include "base/macros.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/win/windows_version.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/profile_resetter/triggered_profile_resetter.h"
12 #include "chrome/browser/profile_resetter/triggered_profile_resetter_factory.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_finder.h"
15 #include "chrome/browser/ui/browser_iterator.h"
16 #include "chrome/browser/ui/startup/startup_browser_creator.h"
17 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/common/url_constants.h"
20 #include "chrome/test/base/in_process_browser_test.h"
21 #include "components/keyed_service/content/browser_context_dependency_manager.h"
22 #include "testing/gtest/include/gtest/gtest.h"
23
24 namespace {
25
26 // Check that there are two browsers. Find the one that is not |browser|.
27 Browser* FindOneOtherBrowser(Browser* browser) {
28 // There should only be one other browser.
29 EXPECT_EQ(2u, chrome::GetBrowserCount(browser->profile(),
30 browser->host_desktop_type()));
31
32 // Find the new browser.
33 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
34 if (*it != browser)
35 return *it;
36 }
37
38 return nullptr;
39 }
40
41 class MockTriggeredProfileResetter : public TriggeredProfileResetter {
42 public:
43 MockTriggeredProfileResetter() : TriggeredProfileResetter(nullptr) {}
44
45 void Activate() override {}
46 bool HasResetTrigger() override { return true; }
47
48 private:
49 DISALLOW_COPY_AND_ASSIGN(MockTriggeredProfileResetter);
50 };
51
52 scoped_ptr<KeyedService> BuildMockTriggeredProfileResetter(
53 content::BrowserContext* context) {
54 return make_scoped_ptr(new MockTriggeredProfileResetter);
55 }
56
57 } // namespace
58
59 class StartupBrowserCreatorTriggeredResetTest : public InProcessBrowserTest {
60 public:
61 StartupBrowserCreatorTriggeredResetTest() {}
62
63 protected:
64 void SetUpInProcessBrowserTestFixture() override {
65 will_create_browser_context_services_subscription_ =
66 BrowserContextDependencyManager::GetInstance()
67 ->RegisterWillCreateBrowserContextServicesCallbackForTesting(
68 base::Bind(&StartupBrowserCreatorTriggeredResetTest::
69 OnWillCreateBrowserContextServices,
70 base::Unretained(this)))
71 .Pass();
72 }
73
74 private:
75 void OnWillCreateBrowserContextServices(content::BrowserContext* context) {
76 TriggeredProfileResetterFactory::GetInstance()->SetTestingFactory(
77 context, &BuildMockTriggeredProfileResetter);
78 }
79
80 scoped_ptr<base::CallbackList<void(content::BrowserContext*)>::Subscription>
81 will_create_browser_context_services_subscription_;
82
83 DISALLOW_COPY_AND_ASSIGN(StartupBrowserCreatorTriggeredResetTest);
84 };
85
86 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTriggeredResetTest,
87 TestTriggeredReset) {
88 // Use a couple same-site HTTP URLs.
89 ASSERT_TRUE(test_server()->Start());
90 std::vector<GURL> urls;
91 urls.push_back(test_server()->GetURL("files/title1.html"));
92 urls.push_back(test_server()->GetURL("files/title2.html"));
93
94 Profile* profile = browser()->profile();
95 chrome::HostDesktopType host_desktop_type = browser()->host_desktop_type();
96
97 // Set the startup preference to open these URLs.
98 SessionStartupPref pref(SessionStartupPref::URLS);
99 pref.urls = urls;
100 SessionStartupPref::SetStartupPref(profile, pref);
101
102 // Keep the browser process running while browsers are closed.
103 g_browser_process->AddRefModule();
104
105 // Close the browser.
106 CloseBrowserAsynchronously(browser());
107
108 // Do a simple non-process-startup browser launch.
109 base::CommandLine dummy(base::CommandLine::NO_PROGRAM);
110 StartupBrowserCreatorImpl launch(base::FilePath(), dummy,
111 chrome::startup::IS_NOT_FIRST_RUN);
112 ASSERT_TRUE(
113 launch.Launch(profile, std::vector<GURL>(), false, host_desktop_type));
114
115 // This should have created a new browser window. |browser()| is still
116 // around at this point, even though we've closed its window.
117 Browser* new_browser = FindOneOtherBrowser(browser());
118 ASSERT_TRUE(new_browser);
119
120 std::vector<GURL> expected_urls(urls);
121 if (base::win::GetVersion() >= base::win::VERSION_WIN10)
122 expected_urls.insert(expected_urls.begin(), internals::GetWelcomePageURL());
123 expected_urls.insert(expected_urls.begin(), internals::GetResetSettingsURL());
124
125 TabStripModel* tab_strip = new_browser->tab_strip_model();
126 ASSERT_EQ(static_cast<int>(expected_urls.size()), tab_strip->count());
127 for (size_t i = 0; i < expected_urls.size(); i++)
128 EXPECT_EQ(expected_urls[i], tab_strip->GetWebContentsAt(i)->GetURL());
129
130 g_browser_process->ReleaseModule();
131 }
132
133 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTriggeredResetTest,
134 TestTriggeredResetDoesNotShowWithFirstRunURLs) {
135 // The presence of First Run tabs (in production code, these commonly come
136 // from master_preferences) should suppress the reset UI. Check that this is
137 // the case.
138 StartupBrowserCreator browser_creator;
139 browser_creator.AddFirstRunTab(GURL("http://new_tab_page"));
140 browser_creator.AddFirstRunTab(test_server()->GetURL("files/title1.html"));
141
142 // Do a process-startup browser launch.
143 base::CommandLine dummy(base::CommandLine::NO_PROGRAM);
144 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator,
145 chrome::startup::IS_FIRST_RUN);
146 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), true,
147 browser()->host_desktop_type()));
148
149 // This should have created a new browser window.
150 Browser* new_browser = FindOneOtherBrowser(browser());
151 ASSERT_TRUE(new_browser);
152
153 // Verify that only the first-run tabs are shown.
154 TabStripModel* tab_strip = new_browser->tab_strip_model();
155 ASSERT_EQ(2, tab_strip->count());
156 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL),
157 tab_strip->GetWebContentsAt(0)->GetURL());
158 EXPECT_EQ("title1.html",
159 tab_strip->GetWebContentsAt(1)->GetURL().ExtractFileName());
160 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/startup/startup_browser_creator_impl.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698