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