OLD | NEW |
---|---|
(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/memory/scoped_ptr.h" | |
8 #include "base/win/windows_version.h" | |
9 #include "chrome/browser/browser_process.h" | |
10 #include "chrome/browser/profile_resetter/triggered_profile_resetter.h" | |
11 #include "chrome/browser/profile_resetter/triggered_profile_resetter_factory.h" | |
12 #include "chrome/browser/ui/browser.h" | |
13 #include "chrome/browser/ui/browser_finder.h" | |
14 #include "chrome/browser/ui/browser_iterator.h" | |
15 #include "chrome/browser/ui/startup/startup_browser_creator.h" | |
16 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" | |
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
18 #include "chrome/common/url_constants.h" | |
19 #include "chrome/test/base/in_process_browser_test.h" | |
20 #include "components/keyed_service/content/browser_context_dependency_manager.h" | |
21 #include "testing/gtest/include/gtest/gtest.h" | |
22 | |
23 namespace { | |
24 | |
25 // Check that there are two browsers. Find the one that is not |browser|. | |
26 Browser* FindOneOtherBrowser(Browser* browser) { | |
27 // There should only be one other browser. | |
28 EXPECT_EQ(2u, chrome::GetBrowserCount(browser->profile(), | |
29 browser->host_desktop_type())); | |
30 | |
31 // Find the new browser. | |
32 Browser* other_browser = NULL; | |
msw
2015/09/24 17:15:32
nit: nullptr (okay as-is if you'd rather straight
robertshield
2015/09/25 00:39:19
Done.
| |
33 for (chrome::BrowserIterator it; !it.done() && !other_browser; it.Next()) { | |
msw
2015/09/24 17:15:32
nit: no curlies needed, afaik (ditto ignore if dup
robertshield
2015/09/25 00:39:19
I could drop them if I make the if statement singl
msw
2015/09/25 01:55:42
Second is fine, I thought that simply without curl
| |
34 if (*it != browser) | |
35 other_browser = *it; | |
msw
2015/09/24 17:15:31
nit: just return *it here and remove |other_browse
robertshield
2015/09/25 00:39:19
Done.
| |
36 } | |
37 return other_browser; | |
38 } | |
39 | |
40 class MockTriggeredProfileResetter : public TriggeredProfileResetter { | |
41 public: | |
42 MockTriggeredProfileResetter() : TriggeredProfileResetter(nullptr) {} | |
43 | |
44 void Activate() override {} | |
45 bool HasResetTrigger() override { return true; } | |
46 }; | |
msw
2015/09/24 17:15:32
nit: DISALLOW_COPY_AND_ASSIGN?
robertshield
2015/09/25 00:39:19
Done.
| |
47 | |
48 scoped_ptr<KeyedService> BuildMockTriggeredProfileResetter( | |
49 content::BrowserContext* context) { | |
50 return make_scoped_ptr(new MockTriggeredProfileResetter); | |
51 } | |
52 | |
53 } // namespace | |
54 | |
55 class StartupBrowserCreatorTriggeredResetTest : public InProcessBrowserTest { | |
56 protected: | |
57 void SetUpCommandLine(base::CommandLine* command_line) override { | |
58 command_line->AppendArg("http://www.chromium.org"); | |
msw
2015/09/24 17:15:31
q: Where does this come into play? Is the SetUpCom
robertshield
2015/09/25 00:39:19
Hrm, actually no, all the tab setup happens in the
| |
59 }; | |
msw
2015/09/24 17:15:32
nit: no semicolon to close function
robertshield
2015/09/25 00:39:19
ah, copy/paste, you fail me again!
| |
60 | |
61 void SetUpInProcessBrowserTestFixture() override { | |
62 will_create_browser_context_services_subscription_ = | |
63 BrowserContextDependencyManager::GetInstance() | |
64 ->RegisterWillCreateBrowserContextServicesCallbackForTesting( | |
65 base::Bind(&StartupBrowserCreatorTriggeredResetTest:: | |
66 OnWillCreateBrowserContextServices, | |
67 base::Unretained(this))) | |
68 .Pass(); | |
69 }; | |
msw
2015/09/24 17:15:31
ditto nit: no semicolon to close function
robertshield
2015/09/25 00:39:19
Done.
| |
70 | |
71 private: | |
72 void OnWillCreateBrowserContextServices(content::BrowserContext* context) { | |
73 TriggeredProfileResetterFactory::GetInstance()->SetTestingFactory( | |
74 context, &BuildMockTriggeredProfileResetter); | |
75 } | |
76 | |
77 scoped_ptr<base::CallbackList<void(content::BrowserContext*)>::Subscription> | |
78 will_create_browser_context_services_subscription_; | |
79 }; | |
msw
2015/09/24 17:15:32
nit: DISALLOW_COPY_AND_ASSIGN?
robertshield
2015/09/25 00:39:19
Done.
| |
80 | |
81 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTriggeredResetTest, | |
82 TestTriggeredReset) { | |
83 // Use a couple same-site HTTP URLs. | |
84 ASSERT_TRUE(test_server()->Start()); | |
85 std::vector<GURL> urls; | |
86 urls.push_back(test_server()->GetURL("files/title1.html")); | |
87 urls.push_back(test_server()->GetURL("files/title2.html")); | |
88 | |
89 Profile* profile = browser()->profile(); | |
90 chrome::HostDesktopType host_desktop_type = browser()->host_desktop_type(); | |
91 | |
92 // Set the startup preference to open these URLs. | |
93 SessionStartupPref pref(SessionStartupPref::URLS); | |
94 pref.urls = urls; | |
95 SessionStartupPref::SetStartupPref(profile, pref); | |
96 | |
97 // Keep the browser process running while browsers are closed. | |
98 g_browser_process->AddRefModule(); | |
99 | |
100 // Close the browser. | |
101 CloseBrowserAsynchronously(browser()); | |
102 | |
103 // Do a simple non-process-startup browser launch. | |
104 base::CommandLine dummy(base::CommandLine::NO_PROGRAM); | |
105 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, | |
106 chrome::startup::IS_NOT_FIRST_RUN); | |
107 ASSERT_TRUE( | |
108 launch.Launch(profile, std::vector<GURL>(), false, host_desktop_type)); | |
109 | |
110 // This should have created a new browser window. |browser()| is still | |
111 // around at this point, even though we've closed its window. | |
112 Browser* new_browser = FindOneOtherBrowser(browser()); | |
113 ASSERT_TRUE(new_browser); | |
114 | |
115 std::vector<GURL> expected_urls(urls); | |
116 if (base::win::GetVersion() >= base::win::VERSION_WIN10) | |
117 expected_urls.insert(expected_urls.begin(), internals::GetWelcomePageURL()); | |
msw
2015/09/24 17:15:31
q: *should* we get the welcome page on non-first-r
robertshield
2015/09/25 00:39:19
Yes, the welcome page isn't displayed only at firs
msw
2015/09/25 01:55:42
Acknowledged.
| |
118 expected_urls.insert(expected_urls.begin(), internals::GetResetSettingsURL()); | |
119 | |
120 TabStripModel* tab_strip = new_browser->tab_strip_model(); | |
121 ASSERT_EQ(static_cast<int>(expected_urls.size()), tab_strip->count()); | |
122 for (size_t i = 0; i < expected_urls.size(); i++) | |
123 EXPECT_EQ(expected_urls[i], tab_strip->GetWebContentsAt(i)->GetURL()); | |
124 | |
125 g_browser_process->ReleaseModule(); | |
126 } | |
127 | |
128 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTriggeredResetTest, | |
129 TestTriggeredResetDoesNotShowWithFirstRunURLs) { | |
130 // The presence of First Run tabs (in production code, these commonly come | |
131 // from master_preferences) should suppress the reset UI. Check that this is | |
132 // the case. | |
133 StartupBrowserCreator browser_creator; | |
134 browser_creator.AddFirstRunTab(GURL("http://new_tab_page")); | |
135 browser_creator.AddFirstRunTab(test_server()->GetURL("files/title1.html")); | |
136 | |
137 // Do a process-startup browser launch. | |
138 base::CommandLine dummy(base::CommandLine::NO_PROGRAM); | |
139 StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator, | |
140 chrome::startup::IS_NOT_FIRST_RUN); | |
msw
2015/09/24 17:15:31
nit: it's odd that AddFirstRunTab is respected for
robertshield
2015/09/25 00:39:19
Hrm, yes, I actually meant to make this IS_FIRST_R
msw
2015/09/25 01:55:42
Acknowledged.
| |
141 ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), true, | |
142 browser()->host_desktop_type())); | |
143 | |
144 // This should have created a new browser window. | |
145 Browser* new_browser = FindOneOtherBrowser(browser()); | |
146 ASSERT_TRUE(new_browser); | |
147 | |
148 // Verify that only the first-run tabs are shown. | |
msw
2015/09/24 17:15:32
q: *shouldn't* we show the profile reset even with
robertshield
2015/09/25 00:39:19
I had intentionally made it so that profile reset
msw
2015/09/25 01:55:42
Fair enough, maybe run that by a PM interested in
| |
149 TabStripModel* tab_strip = new_browser->tab_strip_model(); | |
150 ASSERT_EQ(2, tab_strip->count()); | |
151 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), | |
152 tab_strip->GetWebContentsAt(0)->GetURL()); | |
153 EXPECT_EQ("title1.html", | |
154 tab_strip->GetWebContentsAt(1)->GetURL().ExtractFileName()); | |
155 } | |
OLD | NEW |