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 {}; |
| 13 |
| 14 // Bits for FakeStartupTabProvider options. |
| 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 // "Standard" case: Tabs specified in onboarding, reset trigger, pinned tabs, or |
| 73 // preferences shouldn't interfere with other content. Pinned tabs appear first. |
| 74 TEST(StartupBrowserCreatorImplTest, DetermineStartupTabs) { |
| 75 FakeStartupTabProvider provider(kOnboardingTabs | kResetTriggerTabs | |
| 76 kPinnedTabs | kPreferencesTabs); |
| 77 StartupBrowserCreatorImpl impl( |
| 78 base::FilePath(), base::CommandLine(base::CommandLine::NO_PROGRAM), |
| 79 chrome::startup::IS_FIRST_RUN); |
| 80 |
| 81 StartupTabs output = impl.DetermineStartupTabs(provider, false, false); |
| 82 ASSERT_EQ(4U, output.size()); |
| 83 EXPECT_EQ("pinned", output[0].url.host()); |
| 84 EXPECT_EQ("onboarding", output[1].url.host()); |
| 85 EXPECT_EQ("reset-trigger", output[2].url.host()); |
| 86 EXPECT_EQ("prefs", output[3].url.host()); |
| 87 } |
| 88 |
| 89 // All content is blocked in Incognito mode, or when recovering from a crash. |
| 90 // Only the New Tab Page should appear in either case. |
| 91 TEST(StartupBrowserCreatorImplTest, DetermineStartupTabs_IncognitoOrCrash) { |
| 92 FakeStartupTabProvider provider(kOnboardingTabs | kDistributionFirstRunTabs | |
| 93 kResetTriggerTabs | kPinnedTabs | |
| 94 kPreferencesTabs); |
| 95 StartupBrowserCreatorImpl impl( |
| 96 base::FilePath(), base::CommandLine(base::CommandLine::NO_PROGRAM), |
| 97 chrome::startup::IS_FIRST_RUN); |
| 98 |
| 99 // Incognito |
| 100 StartupTabs output = impl.DetermineStartupTabs(provider, true, false); |
| 101 ASSERT_EQ(1U, output.size()); |
| 102 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL).host(), output[0].url.host()); |
| 103 |
| 104 // Crash Recovery |
| 105 output = impl.DetermineStartupTabs(provider, false, true); |
| 106 ASSERT_EQ(1U, output.size()); |
| 107 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL).host(), output[0].url.host()); |
| 108 } |
| 109 |
| 110 // If Master Preferences specifies content, this should block all other |
| 111 // policies. |
| 112 TEST(StartupBrowserCreatorImplTest, DetermineStartupTabs_MasterPrefs) { |
| 113 FakeStartupTabProvider provider(kOnboardingTabs | kDistributionFirstRunTabs | |
| 114 kResetTriggerTabs | kPinnedTabs | |
| 115 kPreferencesTabs); |
| 116 StartupBrowserCreatorImpl impl( |
| 117 base::FilePath(), base::CommandLine(base::CommandLine::NO_PROGRAM), |
| 118 chrome::startup::IS_FIRST_RUN); |
| 119 |
| 120 StartupTabs output = impl.DetermineStartupTabs(provider, false, false); |
| 121 ASSERT_EQ(1U, output.size()); |
| 122 EXPECT_EQ("distribution", output[0].url.host()); |
| 123 } |
OLD | NEW |