OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 "chrome/browser/ui/startup/startup_browser_creator_impl.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "chrome/browser/ui/startup/startup_tab_provider.h" | |
9 #include "chrome/common/url_constants.cc" | |
10 #include "testing/gtest/include/gtest/gtest.h" | |
11 | |
12 class StartupBrowserCreatorImplTest : public testing::Test {}; | |
grt (UTC plus 2)
2016/09/26 20:11:14
i believe this is unused since you're using TEST r
| |
13 | |
14 // Bits for FakeStartupTabProvider options. | |
grt (UTC plus 2)
2016/09/26 20:11:14
nit: wrap lines 14-77 in an unnamed namespace
| |
15 constexpr uint32_t kOnboardingTabs = 0x01; | |
16 constexpr uint32_t kDistributionFirstRunTabs = 0x02; | |
17 constexpr uint32_t kResetTriggerTabs = 0x04; | |
18 constexpr uint32_t kPinnedTabs = 0x08; | |
19 constexpr uint32_t kPreferencesTabs = 0x10; | |
20 | |
21 class FakeStartupTabProvider : public StartupTabProvider { | |
22 public: | |
23 // For each option passed, the corresponding adder below will add a sentinel | |
24 // tab and return true. For options not passed, the adder will return false. | |
25 explicit FakeStartupTabProvider(uint32_t options) : options_(options) {} | |
26 | |
27 bool AddOnboardingTabs(StartupTabs* tabs) const override { | |
28 if (options_ & kOnboardingTabs) { | |
29 tabs->push_back(StartupTab(GURL("https://onboarding"), false)); | |
30 return true; | |
31 } | |
32 return false; | |
33 } | |
34 | |
35 bool AddDistributionFirstRunTabs(StartupBrowserCreator* browser_creator, | |
36 StartupTabs* tabs) const override { | |
37 if (options_ & kDistributionFirstRunTabs) { | |
38 tabs->push_back(StartupTab(GURL("https://distribution"), false)); | |
39 return true; | |
40 } | |
41 return false; | |
42 } | |
43 | |
44 bool AddResetTriggerTabs(Profile* profile, StartupTabs* tabs) const override { | |
45 if (options_ & kResetTriggerTabs) { | |
46 tabs->push_back(StartupTab(GURL("https://reset-trigger"), false)); | |
47 return true; | |
48 } | |
49 return false; | |
50 } | |
51 | |
52 bool AddPinnedTabs(StartupTabs* tabs) const override { | |
53 if (options_ & kPinnedTabs) { | |
54 tabs->push_back(StartupTab(GURL("https://pinned"), true)); | |
55 return true; | |
56 } | |
57 return false; | |
58 } | |
59 | |
60 bool AddPreferencesTabs(StartupTabs* tabs) const override { | |
61 if (options_ & kPreferencesTabs) { | |
62 tabs->push_back(StartupTab(GURL("https://prefs"), false)); | |
63 return true; | |
64 } | |
65 return false; | |
66 } | |
67 | |
68 private: | |
69 const uint32_t options_; | |
70 }; | |
71 | |
72 StartupTabs GetSentinelCommandLineTabs() { | |
73 StartupTabs cmd_line_tabs; | |
74 cmd_line_tabs.push_back(StartupTab(GURL("https://cmd-line"), false)); | |
75 return cmd_line_tabs; | |
76 } | |
77 | |
78 // "Standard" case: Tabs specified in onboarding, reset trigger, pinned tabs, or | |
79 // preferences shouldn't interfere with each other. Nothing specified on the | |
80 // command line. Reset trigger always appears first. | |
81 TEST(StartupBrowserCreatorImplTest, DetermineStartupTabs) { | |
82 FakeStartupTabProvider provider(kOnboardingTabs | kResetTriggerTabs | | |
83 kPinnedTabs | kPreferencesTabs); | |
84 StartupBrowserCreatorImpl impl( | |
85 base::FilePath(), base::CommandLine(base::CommandLine::NO_PROGRAM), | |
86 chrome::startup::IS_FIRST_RUN); | |
87 StartupTabs no_tabs; | |
88 | |
89 StartupTabs output = | |
90 impl.DetermineStartupTabs(provider, no_tabs, false, false); | |
91 ASSERT_EQ(4U, output.size()); | |
92 EXPECT_EQ("reset-trigger", output[0].url.host()); | |
93 EXPECT_EQ("onboarding", output[1].url.host()); | |
94 EXPECT_EQ("prefs", output[2].url.host()); | |
95 EXPECT_EQ("pinned", output[3].url.host()); | |
96 } | |
97 | |
98 // All content is blocked in Incognito mode, or when recovering from a crash. | |
99 // Only the New Tab Page should appear in either case. | |
100 TEST(StartupBrowserCreatorImplTest, DetermineStartupTabs_IncognitoOrCrash) { | |
101 FakeStartupTabProvider provider(kOnboardingTabs | kDistributionFirstRunTabs | | |
102 kResetTriggerTabs | kPinnedTabs | | |
103 kPreferencesTabs); | |
104 StartupBrowserCreatorImpl impl( | |
105 base::FilePath(), base::CommandLine(base::CommandLine::NO_PROGRAM), | |
106 chrome::startup::IS_FIRST_RUN); | |
107 StartupTabs no_tabs; | |
108 | |
109 // Incognito | |
110 StartupTabs output = | |
111 impl.DetermineStartupTabs(provider, no_tabs, true, false); | |
112 ASSERT_EQ(1U, output.size()); | |
113 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL).host(), output[0].url.host()); | |
114 | |
115 // Crash Recovery | |
116 output = impl.DetermineStartupTabs(provider, no_tabs, false, true); | |
117 ASSERT_EQ(1U, output.size()); | |
118 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL).host(), output[0].url.host()); | |
119 } | |
120 | |
121 // If Master Preferences specifies content, this should block all other | |
122 // policies. The only exception is command line URLs, tested below. | |
123 TEST(StartupBrowserCreatorImplTest, DetermineStartupTabs_MasterPrefs) { | |
124 FakeStartupTabProvider provider(kOnboardingTabs | kDistributionFirstRunTabs | | |
125 kResetTriggerTabs | kPinnedTabs | | |
126 kPreferencesTabs); | |
127 StartupBrowserCreatorImpl impl( | |
128 base::FilePath(), base::CommandLine(base::CommandLine::NO_PROGRAM), | |
129 chrome::startup::IS_FIRST_RUN); | |
130 StartupTabs no_tabs; | |
131 | |
132 StartupTabs output = | |
133 impl.DetermineStartupTabs(provider, no_tabs, false, false); | |
134 ASSERT_EQ(1U, output.size()); | |
135 EXPECT_EQ("distribution", output[0].url.host()); | |
136 } | |
137 | |
138 // URLs specified on the command line should always appear, and should block | |
139 // all other tabs except the Reset Trigger tab. | |
140 TEST(StartupBrowserCreatorImplTest, DetermineStartupTabs_CommandLine) { | |
141 FakeStartupTabProvider provider(kOnboardingTabs | kDistributionFirstRunTabs | | |
142 kResetTriggerTabs | kPinnedTabs | | |
143 kPreferencesTabs); | |
144 StartupBrowserCreatorImpl impl( | |
145 base::FilePath(), base::CommandLine(base::CommandLine::NO_PROGRAM), | |
146 chrome::startup::IS_FIRST_RUN); | |
147 | |
148 StartupTabs cmd_line_tabs = GetSentinelCommandLineTabs(); | |
149 | |
150 StartupTabs output = | |
151 impl.DetermineStartupTabs(provider, cmd_line_tabs, false, false); | |
152 ASSERT_EQ(2U, output.size()); | |
153 EXPECT_EQ("reset-trigger", output[0].url.host()); | |
154 EXPECT_EQ("cmd-line", output[1].url.host()); | |
155 | |
156 // Also test that both incognito and crash recovery don't interfere with | |
157 // command line tabs. | |
158 | |
159 // Incognito | |
160 output = impl.DetermineStartupTabs(provider, cmd_line_tabs, true, false); | |
161 ASSERT_EQ(1U, output.size()); | |
162 EXPECT_EQ("cmd-line", output[0].url.host()); | |
163 | |
164 // Crash Recovery | |
165 output = impl.DetermineStartupTabs(provider, cmd_line_tabs, false, true); | |
166 ASSERT_EQ(1U, output.size()); | |
167 EXPECT_EQ("cmd-line", output[0].url.host()); | |
168 } | |
169 | |
170 // New Tab Page should appear alongside pinned tabs and the reset trigger, but | |
171 // should be superseded by onboarding tabs and by tabs specified in preferences. | |
172 TEST(StartupBrowserCreatorImplTest, DetermineStartupTabs_NewTabPage) { | |
173 FakeStartupTabProvider provider_allows_ntp(kPinnedTabs | kResetTriggerTabs); | |
174 StartupBrowserCreatorImpl impl( | |
175 base::FilePath(), base::CommandLine(base::CommandLine::NO_PROGRAM), | |
176 chrome::startup::IS_FIRST_RUN); | |
177 StartupTabs no_tabs; | |
178 | |
179 StartupTabs output = | |
180 impl.DetermineStartupTabs(provider_allows_ntp, no_tabs, false, false); | |
181 ASSERT_EQ(3U, output.size()); | |
182 EXPECT_EQ("reset-trigger", output[0].url.host()); | |
183 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL).host(), output[1].url.host()); | |
184 EXPECT_EQ("pinned", output[2].url.host()); | |
185 } | |
OLD | NEW |