OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/compiler_specific.h" | 5 #include "base/compiler_specific.h" |
6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/strings/utf_string_conversions.h" |
8 #include "base/test/scoped_path_override.h" | 9 #include "base/test/scoped_path_override.h" |
9 #include "base/values.h" | 10 #include "base/values.h" |
10 #include "chrome/browser/first_run/first_run.h" | 11 #include "chrome/browser/first_run/first_run.h" |
11 #include "chrome/browser/first_run/first_run_internal.h" | 12 #include "chrome/browser/first_run/first_run_internal.h" |
12 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
| 14 #include "chrome/common/url_constants.h" |
13 #include "chrome/installer/util/master_preferences.h" | 15 #include "chrome/installer/util/master_preferences.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "url/gurl.h" |
15 | 18 |
16 namespace first_run { | 19 namespace first_run { |
17 | 20 |
18 class FirstRunTest : public testing::Test { | 21 class FirstRunTest : public testing::Test { |
19 protected: | 22 protected: |
20 FirstRunTest() : user_data_dir_override_(chrome::DIR_USER_DATA) {} | 23 FirstRunTest() : user_data_dir_override_(chrome::DIR_USER_DATA) {} |
21 ~FirstRunTest() override {} | 24 ~FirstRunTest() override {} |
22 | 25 |
23 private: | 26 private: |
24 base::ScopedPathOverride user_data_dir_override_; | 27 base::ScopedPathOverride user_data_dir_override_; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 82 |
80 TEST_F(FirstRunTest, | 83 TEST_F(FirstRunTest, |
81 SetupMasterPrefsFromInstallPrefs_WelcomePageOnOSUpgradeDisabled) { | 84 SetupMasterPrefsFromInstallPrefs_WelcomePageOnOSUpgradeDisabled) { |
82 installer::MasterPreferences install_prefs( | 85 installer::MasterPreferences install_prefs( |
83 "{\"distribution\":{\"welcome_page_on_os_upgrade_enabled\": false}}"); | 86 "{\"distribution\":{\"welcome_page_on_os_upgrade_enabled\": false}}"); |
84 MasterPrefs out_prefs; | 87 MasterPrefs out_prefs; |
85 internal::SetupMasterPrefsFromInstallPrefs(install_prefs, &out_prefs); | 88 internal::SetupMasterPrefsFromInstallPrefs(install_prefs, &out_prefs); |
86 EXPECT_FALSE(out_prefs.welcome_page_on_os_upgrade_enabled); | 89 EXPECT_FALSE(out_prefs.welcome_page_on_os_upgrade_enabled); |
87 } | 90 } |
88 | 91 |
| 92 TEST_F(FirstRunTest, ProcessMasterPrefsTabs) { |
| 93 std::vector<GURL> input; |
| 94 input.push_back(GURL(base::ASCIIToUTF16("https://new_tab_page"))); |
| 95 input.push_back(GURL(base::ASCIIToUTF16("https://www.google.com"))); |
| 96 input.push_back(GURL(base::ASCIIToUTF16("https://welcome_page"))); |
| 97 std::vector<GURL> output = ProcessMasterPrefsTabs(input); |
| 98 ASSERT_EQ(3U, output.size()); |
| 99 EXPECT_EQ(GURL(chrome::kChromeUINewTabURL).host(), output[0].host()); |
| 100 EXPECT_EQ("www.google.com", output[1].host()); |
| 101 EXPECT_EQ(GetWelcomePageURL().host(), output[2].host()); |
| 102 } |
| 103 |
| 104 // No flags, no sentinel present. Welcome should be surfaced. |
| 105 TEST_F(FirstRunTest, GetOnboardingTabs_StandardFirstRun) { |
| 106 FirstRunSystemStatus status; |
| 107 status.os_class = FirstRunSystemStatus::OperatingSystemClass::STANDARD; |
| 108 status.is_sentinel_present = false; |
| 109 status.is_force_flag_on = false; |
| 110 status.is_suppress_flag_on = false; |
| 111 |
| 112 std::vector<GURL> output = GetOnboardingTabs(status); |
| 113 |
| 114 ASSERT_EQ(1U, output.size()); |
| 115 EXPECT_EQ(GetWelcomePageURL().host(), output[0].host()); |
| 116 } |
| 117 |
| 118 // Sentinel present, no flags. Nothing should be shown. |
| 119 TEST_F(FirstRunTest, GetOnboardingTabs_StandardWithSentinel) { |
| 120 FirstRunSystemStatus status; |
| 121 status.os_class = FirstRunSystemStatus::OperatingSystemClass::STANDARD; |
| 122 status.is_sentinel_present = true; |
| 123 status.is_force_flag_on = false; |
| 124 status.is_suppress_flag_on = true; |
| 125 |
| 126 std::vector<GURL> output = GetOnboardingTabs(status); |
| 127 |
| 128 EXPECT_EQ(0U, output.size()); |
| 129 } |
| 130 |
| 131 // Even without sentinel, the suppress flag means no tabs come back. |
| 132 TEST_F(FirstRunTest, GetOnboardingTabs_StandardSuppressed) { |
| 133 FirstRunSystemStatus status; |
| 134 status.os_class = FirstRunSystemStatus::OperatingSystemClass::STANDARD; |
| 135 status.is_sentinel_present = false; |
| 136 status.is_force_flag_on = false; |
| 137 status.is_suppress_flag_on = true; |
| 138 |
| 139 std::vector<GURL> output = GetOnboardingTabs(status); |
| 140 |
| 141 EXPECT_EQ(0U, output.size()); |
| 142 } |
| 143 |
| 144 // Force First Run flag overrides both the presence of the sentinel file and |
| 145 // the suppress flag, and the welcome page is still shown. |
| 146 TEST_F(FirstRunTest, GetOnboardingTabs_StandardForced) { |
| 147 FirstRunSystemStatus status; |
| 148 status.os_class = FirstRunSystemStatus::OperatingSystemClass::STANDARD; |
| 149 status.is_sentinel_present = true; |
| 150 status.is_force_flag_on = true; |
| 151 status.is_suppress_flag_on = true; |
| 152 |
| 153 std::vector<GURL> output = GetOnboardingTabs(status); |
| 154 |
| 155 ASSERT_EQ(1U, output.size()); |
| 156 EXPECT_EQ(GetWelcomePageURL().host(), output[0].host()); |
| 157 } |
| 158 |
89 } // namespace first_run | 159 } // namespace first_run |
OLD | NEW |