| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 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/logging.h" | |
| 6 #include "chrome/browser/extensions/default_apps.h" | |
| 7 #include "chrome/common/extensions/extension.h" | |
| 8 #include "chrome/test/testing_pref_service.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 // TODO(dpolukhin): On Chrome OS all apps are installed via external extensions, | |
| 12 // and the web store promo is never shown. | |
| 13 #if !defined(OS_CHROMEOS) | |
| 14 TEST(ExtensionDefaultApps, HappyPath) { | |
| 15 TestingPrefService pref_service; | |
| 16 DefaultApps::RegisterUserPrefs(&pref_service); | |
| 17 DefaultApps default_apps(&pref_service, "en-US"); | |
| 18 | |
| 19 const ExtensionIdSet& default_app_ids = default_apps.default_apps(); | |
| 20 ASSERT_GT(default_app_ids.size(), 0u); | |
| 21 EXPECT_FALSE(default_apps.GetDefaultAppsInstalled()); | |
| 22 EXPECT_EQ(0, default_apps.GetPromoCounter()); | |
| 23 | |
| 24 // If no apps are installed, the default apps should be installed. | |
| 25 ExtensionIdSet installed_app_ids; | |
| 26 EXPECT_TRUE(default_apps.ShouldInstallDefaultApps(installed_app_ids)); | |
| 27 | |
| 28 // The launcher should not be shown until the default apps have been | |
| 29 // installed. | |
| 30 EXPECT_FALSE(default_apps.ShouldShowAppLauncher(installed_app_ids)); | |
| 31 | |
| 32 // The promo should not be shown until the default apps have been installed. | |
| 33 bool promo_just_expired = false; | |
| 34 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_app_ids, | |
| 35 &promo_just_expired)); | |
| 36 EXPECT_FALSE(promo_just_expired); | |
| 37 | |
| 38 // Simulate installing the apps one by one and notifying default_apps after | |
| 39 // each intallation. Nothing should change until we have installed all the | |
| 40 // default apps. | |
| 41 for (size_t i = 0; i < default_app_ids.size() - 1; ++i) { | |
| 42 ExtensionIdSet::const_iterator iter = default_app_ids.begin(); | |
| 43 for (size_t j = 0; j <= i; ++j) | |
| 44 ++iter; | |
| 45 installed_app_ids.insert(*iter); | |
| 46 default_apps.DidInstallApp(installed_app_ids); | |
| 47 EXPECT_FALSE(default_apps.GetDefaultAppsInstalled()); | |
| 48 EXPECT_TRUE(default_apps.ShouldInstallDefaultApps(installed_app_ids)); | |
| 49 EXPECT_FALSE(default_apps.ShouldShowAppLauncher(installed_app_ids)); | |
| 50 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_app_ids, | |
| 51 &promo_just_expired)); | |
| 52 EXPECT_FALSE(promo_just_expired); | |
| 53 } | |
| 54 | |
| 55 // Simulate all the default apps being installed. Now we should stop getting | |
| 56 // default apps to install. | |
| 57 installed_app_ids = default_app_ids; | |
| 58 default_apps.DidInstallApp(installed_app_ids); | |
| 59 EXPECT_TRUE(default_apps.GetDefaultAppsInstalled()); | |
| 60 EXPECT_FALSE(default_apps.ShouldInstallDefaultApps(installed_app_ids)); | |
| 61 | |
| 62 // And the promo and launcher should become available. | |
| 63 EXPECT_TRUE(default_apps.ShouldShowAppLauncher(installed_app_ids)); | |
| 64 EXPECT_TRUE(default_apps.ShouldShowPromo(installed_app_ids, | |
| 65 &promo_just_expired)); | |
| 66 EXPECT_FALSE(promo_just_expired); | |
| 67 | |
| 68 // The promo should be available up to the max allowed times, then stop. | |
| 69 // We start counting at 1 because of the call to ShouldShowPromo() above. | |
| 70 for (int i = 1; i < DefaultApps::kAppsPromoCounterMax; ++i) { | |
| 71 EXPECT_TRUE(default_apps.ShouldShowPromo(installed_app_ids, | |
| 72 &promo_just_expired)); | |
| 73 EXPECT_FALSE(promo_just_expired); | |
| 74 EXPECT_EQ(i + 1, default_apps.GetPromoCounter()); | |
| 75 } | |
| 76 | |
| 77 // The first time, should_show_promo should flip to true, then back to false. | |
| 78 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_app_ids, | |
| 79 &promo_just_expired)); | |
| 80 EXPECT_TRUE(promo_just_expired); | |
| 81 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax + 1, | |
| 82 default_apps.GetPromoCounter()); | |
| 83 | |
| 84 // Even if all the apps are subsequently removed, the apps section should | |
| 85 // remain. | |
| 86 installed_app_ids.clear(); | |
| 87 EXPECT_FALSE(default_apps.ShouldInstallDefaultApps(installed_app_ids)); | |
| 88 EXPECT_TRUE(default_apps.ShouldShowAppLauncher(installed_app_ids)); | |
| 89 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_app_ids, | |
| 90 &promo_just_expired)); | |
| 91 EXPECT_FALSE(promo_just_expired); | |
| 92 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax + 1, | |
| 93 default_apps.GetPromoCounter()); | |
| 94 } | |
| 95 | |
| 96 TEST(ExtensionDefaultApps, UnsupportedLocale) { | |
| 97 TestingPrefService pref_service; | |
| 98 DefaultApps::RegisterUserPrefs(&pref_service); | |
| 99 DefaultApps default_apps(&pref_service, "fr"); | |
| 100 | |
| 101 const ExtensionIdSet& default_app_ids = default_apps.default_apps(); | |
| 102 EXPECT_GT(default_app_ids.size(), 0u); | |
| 103 | |
| 104 // Since the store only supports en-US at the moment, we don't install default | |
| 105 // apps or promote the store. | |
| 106 ExtensionIdSet installed_ids; | |
| 107 EXPECT_FALSE(default_apps.ShouldInstallDefaultApps(installed_ids)); | |
| 108 EXPECT_FALSE(default_apps.ShouldShowAppLauncher(installed_ids)); | |
| 109 | |
| 110 bool promo_just_expired = false; | |
| 111 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_ids, | |
| 112 &promo_just_expired)); | |
| 113 EXPECT_FALSE(promo_just_expired); | |
| 114 | |
| 115 // If the user installs an app manually, then we show the apps section, but | |
| 116 // no promotion or default apps. | |
| 117 installed_ids.insert(*(default_app_ids.begin())); | |
| 118 EXPECT_FALSE(default_apps.ShouldInstallDefaultApps(installed_ids)); | |
| 119 EXPECT_TRUE(default_apps.ShouldShowAppLauncher(installed_ids)); | |
| 120 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_ids, | |
| 121 &promo_just_expired)); | |
| 122 EXPECT_FALSE(promo_just_expired); | |
| 123 | |
| 124 // Even if the user installs the exact set of default apps, we don't show the | |
| 125 // promo. | |
| 126 installed_ids = default_app_ids; | |
| 127 EXPECT_FALSE(default_apps.ShouldInstallDefaultApps(installed_ids)); | |
| 128 EXPECT_TRUE(default_apps.ShouldShowAppLauncher(installed_ids)); | |
| 129 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_ids, | |
| 130 &promo_just_expired)); | |
| 131 EXPECT_FALSE(promo_just_expired); | |
| 132 | |
| 133 // If the user uninstalls the apps again, we go back to not showing the | |
| 134 // apps section. | |
| 135 installed_ids.clear(); | |
| 136 EXPECT_FALSE(default_apps.ShouldInstallDefaultApps(installed_ids)); | |
| 137 EXPECT_FALSE(default_apps.ShouldShowAppLauncher(installed_ids)); | |
| 138 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_ids, | |
| 139 &promo_just_expired)); | |
| 140 EXPECT_FALSE(promo_just_expired); | |
| 141 } | |
| 142 | |
| 143 TEST(ExtensionDefaultApps, HidePromo) { | |
| 144 TestingPrefService pref_service; | |
| 145 DefaultApps::RegisterUserPrefs(&pref_service); | |
| 146 DefaultApps default_apps(&pref_service, "en-US"); | |
| 147 | |
| 148 const ExtensionIdSet& default_app_ids = default_apps.default_apps(); | |
| 149 default_apps.DidInstallApp(default_app_ids); | |
| 150 | |
| 151 bool promo_just_expired = false; | |
| 152 EXPECT_TRUE(default_apps.ShouldShowPromo(default_app_ids, | |
| 153 &promo_just_expired)); | |
| 154 EXPECT_FALSE(promo_just_expired); | |
| 155 EXPECT_EQ(1, default_apps.GetPromoCounter()); | |
| 156 | |
| 157 default_apps.SetPromoHidden(); | |
| 158 EXPECT_FALSE(default_apps.ShouldShowPromo(default_app_ids, | |
| 159 &promo_just_expired)); | |
| 160 EXPECT_FALSE(promo_just_expired); | |
| 161 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax + 1, | |
| 162 default_apps.GetPromoCounter()); | |
| 163 } | |
| 164 | |
| 165 TEST(ExtensionDefaultApps, InstallingAnAppHidesPromo) { | |
| 166 TestingPrefService pref_service; | |
| 167 DefaultApps::RegisterUserPrefs(&pref_service); | |
| 168 DefaultApps default_apps(&pref_service, "en-US"); | |
| 169 | |
| 170 const ExtensionIdSet& default_app_ids = default_apps.default_apps(); | |
| 171 ExtensionIdSet installed_app_ids = default_app_ids; | |
| 172 default_apps.DidInstallApp(installed_app_ids); | |
| 173 | |
| 174 bool promo_just_expired = false; | |
| 175 EXPECT_TRUE(default_apps.ShouldShowPromo(installed_app_ids, | |
| 176 &promo_just_expired)); | |
| 177 EXPECT_FALSE(promo_just_expired); | |
| 178 EXPECT_EQ(1, default_apps.GetPromoCounter()); | |
| 179 | |
| 180 // Now simulate a new extension being installed. This should cause the promo | |
| 181 // to be hidden. | |
| 182 installed_app_ids.insert("foo"); | |
| 183 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_app_ids, | |
| 184 &promo_just_expired)); | |
| 185 EXPECT_FALSE(promo_just_expired); | |
| 186 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax + 1, | |
| 187 default_apps.GetPromoCounter()); | |
| 188 } | |
| 189 | |
| 190 TEST(ExtensionDefaultApps, ManualAppInstalledWhileInstallingDefaultApps) { | |
| 191 // It is possible to have apps manually installed while the default apps are | |
| 192 // being installed. The network or server might be down, causing the default | |
| 193 // app installation to fail. The updater might take awhile to get around to | |
| 194 // updating, giving the user a chance to manually intall. | |
| 195 // | |
| 196 // In these cases, we should keep trying to install default apps until we have | |
| 197 // them all, and then stop, even if at that point, we have more apps than just | |
| 198 // the default ones. | |
| 199 TestingPrefService pref_service; | |
| 200 DefaultApps::RegisterUserPrefs(&pref_service); | |
| 201 DefaultApps default_apps(&pref_service, "en-US"); | |
| 202 | |
| 203 // Simulate an app getting installed before the complete set of default apps. | |
| 204 // This should stop the default apps from trying to be installed. The launcher | |
| 205 // should also immediately show up. | |
| 206 ExtensionIdSet installed_ids; | |
| 207 installed_ids.insert("foo"); | |
| 208 EXPECT_FALSE(default_apps.ShouldInstallDefaultApps(installed_ids)); | |
| 209 EXPECT_TRUE(default_apps.GetDefaultAppsInstalled()); | |
| 210 EXPECT_TRUE(default_apps.ShouldShowAppLauncher(installed_ids)); | |
| 211 | |
| 212 // The promo shouldn't turn on though, because it would look weird with the | |
| 213 // user's extra, manually installed extensions. | |
| 214 bool promo_just_expired = false; | |
| 215 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_ids, | |
| 216 &promo_just_expired)); | |
| 217 EXPECT_FALSE(promo_just_expired); | |
| 218 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax + 1, | |
| 219 default_apps.GetPromoCounter()); | |
| 220 | |
| 221 // Going back to a subset of the default apps shouldn't allow the default app | |
| 222 // install to continue. | |
| 223 installed_ids.clear(); | |
| 224 EXPECT_FALSE(default_apps.ShouldInstallDefaultApps(installed_ids)); | |
| 225 EXPECT_TRUE(default_apps.GetDefaultAppsInstalled()); | |
| 226 EXPECT_TRUE(default_apps.ShouldShowAppLauncher(installed_ids)); | |
| 227 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_ids, | |
| 228 &promo_just_expired)); | |
| 229 EXPECT_FALSE(promo_just_expired); | |
| 230 | |
| 231 // Going to the exact set of default apps shouldn't show the promo. | |
| 232 EXPECT_FALSE(default_apps.ShouldShowPromo(default_apps.default_apps(), | |
| 233 &promo_just_expired)); | |
| 234 EXPECT_FALSE(promo_just_expired); | |
| 235 } | |
| 236 #endif // OS_CHROMEOS | |
| OLD | NEW |