Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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/logging.h" | |
| 5 #include "chrome/browser/extensions/default_apps.h" | 6 #include "chrome/browser/extensions/default_apps.h" |
| 6 #include "chrome/common/extensions/extension.h" | 7 #include "chrome/common/extensions/extension.h" |
| 7 #include "chrome/test/testing_pref_service.h" | 8 #include "chrome/test/testing_pref_service.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 10 |
| 10 // TODO(dpolukhin): On Chrome OS all apps are installed via external extensions, | 11 // TODO(dpolukhin): On Chrome OS all apps are installed via external extensions, |
| 11 // and the web store promo is never shown. | 12 // and the web store promo is never shown. |
| 12 #if !defined(OS_CHROMEOS) | 13 #if !defined(OS_CHROMEOS) |
| 13 TEST(ExtensionDefaultApps, Basics) { | 14 TEST(ExtensionDefaultApps, HappyPath) { |
| 14 TestingPrefService pref_service; | 15 TestingPrefService pref_service; |
| 15 DefaultApps::RegisterUserPrefs(&pref_service); | 16 DefaultApps::RegisterUserPrefs(&pref_service); |
| 16 DefaultApps default_apps(&pref_service); | 17 DefaultApps default_apps(&pref_service, "en-US"); |
| 17 | 18 |
| 18 ExtensionIdSet default_app_ids = *default_apps.GetAppsToInstall(); | 19 const ExtensionIdSet& default_app_ids = default_apps.default_apps(); |
| 19 ASSERT_GT(default_app_ids.size(), 0u); | 20 ASSERT_GT(default_app_ids.size(), 0u); |
| 20 EXPECT_FALSE(default_apps.GetDefaultAppsInstalled()); | 21 EXPECT_FALSE(default_apps.GetDefaultAppsInstalled()); |
| 21 EXPECT_EQ(0, default_apps.GetPromoCounter()); | 22 EXPECT_EQ(0, default_apps.GetPromoCounter()); |
| 22 EXPECT_EQ(default_app_ids, *default_apps.GetDefaultApps()); | 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 installed . | |
|
Erik does not do reviews
2011/01/03 22:01:30
nit: 80 cols
| |
| 29 EXPECT_FALSE(default_apps.ShouldShowAppLauncher(installed_app_ids)); | |
| 23 | 30 |
| 24 // The promo should not be shown until the default apps have been installed. | 31 // The promo should not be shown until the default apps have been installed. |
| 25 ExtensionIdSet installed_app_ids; | 32 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_app_ids)); |
| 26 EXPECT_FALSE(default_apps.CheckShouldShowPromo(installed_app_ids)); | |
| 27 | 33 |
| 28 // Simulate installing the apps one by one and notifying default_apps after | 34 // Simulate installing the apps one by one and notifying default_apps after |
| 29 // each intallation. Nothing should change until we have installed all the | 35 // each intallation. Nothing should change until we have installed all the |
| 30 // default apps. | 36 // default apps. |
| 31 ExtensionIdSet extension_id_sets[] = { | 37 for (size_t i = 0; i < default_app_ids.size() - 1; ++i) { |
| 32 default_app_ids, | 38 ExtensionIdSet::const_iterator iter = default_app_ids.begin(); |
| 33 default_app_ids, | 39 for (size_t j = 0; j <= i; ++j) |
| 34 default_app_ids | 40 ++iter; |
| 35 }; | 41 installed_app_ids.insert(*iter); |
| 36 extension_id_sets[0].clear(); | 42 default_apps.DidInstallApp(installed_app_ids); |
| 37 extension_id_sets[1].erase(extension_id_sets[1].begin()); | |
| 38 extension_id_sets[2].erase(extension_id_sets[2].begin(), | |
| 39 ++extension_id_sets[2].begin()); | |
| 40 for (size_t i = 0; i < arraysize(extension_id_sets); ++i) { | |
| 41 default_apps.DidInstallApp(extension_id_sets[i]); | |
| 42 EXPECT_TRUE(default_app_ids == *default_apps.GetAppsToInstall()); | |
| 43 EXPECT_FALSE(default_apps.GetDefaultAppsInstalled()); | 43 EXPECT_FALSE(default_apps.GetDefaultAppsInstalled()); |
| 44 EXPECT_FALSE(default_apps.CheckShouldShowPromo(extension_id_sets[i])); | 44 EXPECT_TRUE(default_apps.ShouldInstallDefaultApps(installed_app_ids)); |
| 45 EXPECT_FALSE(default_apps.ShouldShowAppLauncher(installed_app_ids)); | |
| 46 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_app_ids)); | |
| 45 } | 47 } |
| 46 | 48 |
| 47 // Simulate all the default apps being installed. Now we should stop getting | 49 // Simulate all the default apps being installed. Now we should stop getting |
| 48 // default apps to install. | 50 // default apps to install. |
| 49 default_apps.DidInstallApp(default_app_ids); | 51 installed_app_ids = default_app_ids; |
| 50 EXPECT_EQ(NULL, default_apps.GetAppsToInstall()); | 52 default_apps.DidInstallApp(installed_app_ids); |
| 51 EXPECT_TRUE(default_apps.GetDefaultAppsInstalled()); | 53 EXPECT_TRUE(default_apps.GetDefaultAppsInstalled()); |
| 54 EXPECT_FALSE(default_apps.ShouldInstallDefaultApps(installed_app_ids)); | |
| 52 | 55 |
| 53 // And the promo should become available. | 56 // And the promo and launcher should become available. |
| 54 EXPECT_TRUE(default_apps.CheckShouldShowPromo(default_app_ids)); | 57 EXPECT_TRUE(default_apps.ShouldShowAppLauncher(installed_app_ids)); |
| 58 EXPECT_TRUE(default_apps.ShouldShowPromo(installed_app_ids)); | |
| 55 | 59 |
| 56 // The promo should be available up to the max allowed times, then stop. | 60 // The promo should be available up to the max allowed times, then stop. |
| 57 for (int i = 0; i < DefaultApps::kAppsPromoCounterMax; ++i) { | 61 for (int i = 0; i < DefaultApps::kAppsPromoCounterMax; ++i) { |
| 58 EXPECT_TRUE(default_apps.CheckShouldShowPromo(default_app_ids)); | 62 EXPECT_TRUE(default_apps.ShouldShowPromo(installed_app_ids)); |
| 59 default_apps.DidShowPromo(); | 63 default_apps.DidShowPromo(); |
| 60 EXPECT_EQ(i + 1, default_apps.GetPromoCounter()); | 64 EXPECT_EQ(i + 1, default_apps.GetPromoCounter()); |
| 61 } | 65 } |
| 62 EXPECT_FALSE(default_apps.CheckShouldShowPromo(default_app_ids)); | 66 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_app_ids)); |
| 63 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter()); | 67 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter()); |
| 68 | |
| 69 // Even if all the apps are subsequently removed, the apps section should | |
| 70 // remain. | |
| 71 installed_app_ids.clear(); | |
| 72 EXPECT_FALSE(default_apps.ShouldInstallDefaultApps(installed_app_ids)); | |
| 73 EXPECT_TRUE(default_apps.ShouldShowAppLauncher(installed_app_ids)); | |
| 74 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_app_ids)); | |
| 75 } | |
| 76 | |
| 77 TEST(ExtensionDefaultApps, UnsupportedLocale) { | |
| 78 TestingPrefService pref_service; | |
| 79 DefaultApps::RegisterUserPrefs(&pref_service); | |
| 80 DefaultApps default_apps(&pref_service, "fr"); | |
| 81 | |
| 82 const ExtensionIdSet& default_app_ids = default_apps.default_apps(); | |
| 83 EXPECT_GT(default_app_ids.size(), 0u); | |
| 84 | |
| 85 // Since the store only supports en-US at the moment, we don't install default | |
| 86 // apps or promote the store. | |
| 87 ExtensionIdSet installed_ids; | |
| 88 EXPECT_FALSE(default_apps.ShouldInstallDefaultApps(installed_ids)); | |
| 89 EXPECT_FALSE(default_apps.ShouldShowAppLauncher(installed_ids)); | |
| 90 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_ids)); | |
| 91 | |
| 92 // If the user installs an app manually, then we show the apps section, but | |
| 93 // no promotion or default apps. | |
| 94 installed_ids.insert(*(default_app_ids.begin())); | |
| 95 EXPECT_FALSE(default_apps.ShouldInstallDefaultApps(installed_ids)); | |
| 96 EXPECT_TRUE(default_apps.ShouldShowAppLauncher(installed_ids)); | |
| 97 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_ids)); | |
| 98 | |
| 99 // Even if the user installs the exact set of default apps, we don't show the | |
| 100 // promo. | |
| 101 installed_ids = default_app_ids; | |
| 102 EXPECT_FALSE(default_apps.ShouldInstallDefaultApps(installed_ids)); | |
| 103 EXPECT_TRUE(default_apps.ShouldShowAppLauncher(installed_ids)); | |
| 104 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_ids)); | |
| 105 | |
| 106 // If the user uninstalls the apps again, we go back to not showing the | |
| 107 // apps section. | |
| 108 installed_ids.clear(); | |
| 109 EXPECT_FALSE(default_apps.ShouldInstallDefaultApps(installed_ids)); | |
| 110 EXPECT_FALSE(default_apps.ShouldShowAppLauncher(installed_ids)); | |
| 111 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_ids)); | |
| 64 } | 112 } |
| 65 | 113 |
| 66 TEST(ExtensionDefaultApps, HidePromo) { | 114 TEST(ExtensionDefaultApps, HidePromo) { |
| 67 TestingPrefService pref_service; | 115 TestingPrefService pref_service; |
| 68 DefaultApps::RegisterUserPrefs(&pref_service); | 116 DefaultApps::RegisterUserPrefs(&pref_service); |
| 69 DefaultApps default_apps(&pref_service); | 117 DefaultApps default_apps(&pref_service, "en-US"); |
| 70 | 118 |
| 71 ExtensionIdSet default_app_ids = *default_apps.GetAppsToInstall(); | 119 const ExtensionIdSet& default_app_ids = default_apps.default_apps(); |
| 72 default_apps.DidInstallApp(default_app_ids); | 120 default_apps.DidInstallApp(default_app_ids); |
| 73 | 121 |
| 74 EXPECT_TRUE(default_apps.CheckShouldShowPromo(default_app_ids)); | 122 EXPECT_TRUE(default_apps.ShouldShowPromo(default_app_ids)); |
| 75 default_apps.DidShowPromo(); | 123 default_apps.DidShowPromo(); |
| 76 EXPECT_EQ(1, default_apps.GetPromoCounter()); | 124 EXPECT_EQ(1, default_apps.GetPromoCounter()); |
| 77 | 125 |
| 78 default_apps.SetPromoHidden(); | 126 default_apps.SetPromoHidden(); |
| 79 EXPECT_FALSE(default_apps.CheckShouldShowPromo(default_app_ids)); | 127 EXPECT_FALSE(default_apps.ShouldShowPromo(default_app_ids)); |
| 80 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter()); | 128 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter()); |
| 81 } | 129 } |
| 82 | 130 |
| 83 TEST(ExtensionDefaultApps, InstallingAnAppHidesPromo) { | 131 TEST(ExtensionDefaultApps, InstallingAnAppHidesPromo) { |
| 84 TestingPrefService pref_service; | 132 TestingPrefService pref_service; |
| 85 DefaultApps::RegisterUserPrefs(&pref_service); | 133 DefaultApps::RegisterUserPrefs(&pref_service); |
| 86 DefaultApps default_apps(&pref_service); | 134 DefaultApps default_apps(&pref_service, "en-US"); |
| 87 | 135 |
| 88 ExtensionIdSet default_app_ids = *default_apps.GetAppsToInstall(); | 136 const ExtensionIdSet& default_app_ids = default_apps.default_apps(); |
| 89 ExtensionIdSet installed_app_ids = default_app_ids; | 137 ExtensionIdSet installed_app_ids = default_app_ids; |
| 90 default_apps.DidInstallApp(installed_app_ids); | 138 default_apps.DidInstallApp(installed_app_ids); |
| 91 | 139 |
| 92 EXPECT_TRUE(default_apps.CheckShouldShowPromo(installed_app_ids)); | 140 EXPECT_TRUE(default_apps.ShouldShowPromo(installed_app_ids)); |
| 93 default_apps.DidShowPromo(); | 141 default_apps.DidShowPromo(); |
| 94 EXPECT_EQ(1, default_apps.GetPromoCounter()); | 142 EXPECT_EQ(1, default_apps.GetPromoCounter()); |
| 95 | 143 |
| 96 // Now simulate a new extension being installed. This should cause the promo | 144 // Now simulate a new extension being installed. This should cause the promo |
| 97 // to be hidden. | 145 // to be hidden. |
| 98 installed_app_ids.insert("foo"); | 146 installed_app_ids.insert("foo"); |
| 99 EXPECT_FALSE(default_apps.CheckShouldShowPromo(installed_app_ids)); | 147 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_app_ids)); |
| 100 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter()); | 148 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter()); |
| 101 } | 149 } |
| 102 | 150 |
| 103 TEST(ExtensionDefaultApps, ManualAppInstalledWhileInstallingDefaultApps) { | 151 TEST(ExtensionDefaultApps, ManualAppInstalledWhileInstallingDefaultApps) { |
| 104 // It is possible to have apps manually installed while the default apps are | 152 // It is possible to have apps manually installed while the default apps are |
| 105 // being installed. The network or server might be down, causing the default | 153 // being installed. The network or server might be down, causing the default |
| 106 // app installation to fail. The updater might take awhile to get around to | 154 // app installation to fail. The updater might take awhile to get around to |
| 107 // updating, giving the user a chance to manually intall. | 155 // updating, giving the user a chance to manually intall. |
| 108 // | 156 // |
| 109 // In these cases, we should keep trying to install default apps until we have | 157 // In these cases, we should keep trying to install default apps until we have |
| 110 // them all, and then stop, even if at that point, we have more apps than just | 158 // them all, and then stop, even if at that point, we have more apps than just |
| 111 // the default ones. | 159 // the default ones. |
| 112 TestingPrefService pref_service; | 160 TestingPrefService pref_service; |
| 113 DefaultApps::RegisterUserPrefs(&pref_service); | 161 DefaultApps::RegisterUserPrefs(&pref_service); |
| 114 DefaultApps default_apps(&pref_service); | 162 DefaultApps default_apps(&pref_service, "en-US"); |
| 115 | 163 |
| 116 // Simulate an app getting installed before the complete set of default apps. | 164 // Simulate an app getting installed before the complete set of default apps. |
| 117 // This shouldn't affect us installing default apps. We should keep trying. | 165 // This should stop the default apps from trying to be installed. The launcher |
|
Erik does not do reviews
2011/01/03 22:01:30
Doesn't this put us in a weird state? They could
Aaron Boodman
2011/01/04 20:59:35
It does.
This code was mainly intended to handle
| |
| 166 // should also immediately show up. | |
| 118 ExtensionIdSet installed_ids; | 167 ExtensionIdSet installed_ids; |
| 119 installed_ids.insert("foo"); | 168 installed_ids.insert("foo"); |
| 120 default_apps.DidInstallApp(installed_ids); | 169 EXPECT_FALSE(default_apps.ShouldInstallDefaultApps(installed_ids)); |
| 121 EXPECT_FALSE(default_apps.GetDefaultAppsInstalled()); | |
| 122 EXPECT_TRUE(default_apps.GetAppsToInstall()); | |
| 123 | |
| 124 // Now add all the default apps in addition to the extra app. We should stop | |
| 125 // trying to install default apps. | |
| 126 installed_ids = *default_apps.GetAppsToInstall(); | |
| 127 installed_ids.insert("foo"); | |
| 128 default_apps.DidInstallApp(installed_ids); | |
| 129 EXPECT_TRUE(default_apps.GetDefaultAppsInstalled()); | 170 EXPECT_TRUE(default_apps.GetDefaultAppsInstalled()); |
| 130 EXPECT_FALSE(default_apps.GetAppsToInstall()); | 171 EXPECT_TRUE(default_apps.ShouldShowAppLauncher(installed_ids)); |
| 131 | 172 |
| 132 // The promo shouldn't turn on though, because it would look weird with the | 173 // The promo shouldn't turn on though, because it would look weird with the |
| 133 // user's extra, manually installed extensions. | 174 // user's extra, manually installed extensions. |
| 134 EXPECT_FALSE(default_apps.CheckShouldShowPromo(installed_ids)); | 175 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_ids)); |
| 135 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter()); | 176 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter()); |
| 177 | |
| 178 // Going back to a subset of the default apps shouldn't allow the default app | |
| 179 // install to continue. | |
| 180 installed_ids.clear(); | |
| 181 EXPECT_FALSE(default_apps.ShouldInstallDefaultApps(installed_ids)); | |
| 182 EXPECT_TRUE(default_apps.GetDefaultAppsInstalled()); | |
| 183 EXPECT_TRUE(default_apps.ShouldShowAppLauncher(installed_ids)); | |
| 184 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_ids)); | |
| 185 | |
| 186 // Going to the exact set of default apps shouldn't show the promo. | |
| 187 EXPECT_FALSE(default_apps.ShouldShowPromo(default_apps.default_apps())); | |
| 136 } | 188 } |
| 137 #endif // OS_CHROMEOS | 189 #endif // OS_CHROMEOS |
| OLD | NEW |