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/logging.h" | 5 #include "base/logging.h" |
6 #include "chrome/browser/browser_process.h" | 6 #include "chrome/browser/browser_process.h" |
7 #include "chrome/browser/extensions/apps_promo.h" | 7 #include "chrome/browser/extensions/apps_promo.h" |
8 #include "chrome/browser/prefs/browser_prefs.h" | 8 #include "chrome/browser/prefs/browser_prefs.h" |
9 #include "chrome/browser/ui/webui/ntp/shown_sections_handler.h" | |
10 #include "chrome/common/extensions/extension.h" | 9 #include "chrome/common/extensions/extension.h" |
11 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
12 #include "chrome/test/base/testing_browser_process.h" | 11 #include "chrome/test/base/testing_browser_process.h" |
13 #include "chrome/test/base/testing_pref_service.h" | 12 #include "chrome/test/base/testing_pref_service.h" |
14 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
16 | 15 |
17 namespace { | 16 namespace { |
18 | 17 |
19 const char kPromoId[] = "23123123"; | 18 const char kPromoId[] = "23123123"; |
20 const char kPromoHeader[] = "Get great apps!"; | 19 const char kPromoHeader[] = "Get great apps!"; |
21 const char kPromoButton[] = "Click for apps!"; | 20 const char kPromoButton[] = "Click for apps!"; |
22 const char kPromoLink[] = "http://apps.com"; | 21 const char kPromoLink[] = "http://apps.com"; |
23 const char kPromoLogo[] = "chrome://theme/IDR_WEBSTORE_ICON"; | 22 const char kPromoLogo[] = "chrome://theme/IDR_WEBSTORE_ICON"; |
24 const char kPromoExpire[] = "No thanks."; | 23 const char kPromoExpire[] = "No thanks."; |
25 const int kPromoUserGroup = | 24 const int kPromoUserGroup = |
26 AppsPromo::USERS_NEW | AppsPromo::USERS_EXISTING; | 25 AppsPromo::USERS_NEW | AppsPromo::USERS_EXISTING; |
27 | 26 |
28 void ExpectAppsSectionMaximized(PrefService* prefs, bool maximized) { | |
29 EXPECT_EQ(maximized, | |
30 (ShownSectionsHandler::GetShownSections(prefs) & APPS) != 0); | |
31 EXPECT_EQ(!maximized, | |
32 (ShownSectionsHandler::GetShownSections(prefs) & THUMB) != 0); | |
33 } | |
34 | |
35 void ExpectAppsPromoHidden(PrefService* prefs) { | |
36 // Hiding the promo places the apps section in menu mode and maximizes the | |
37 // most visited section. | |
38 EXPECT_TRUE((ShownSectionsHandler::GetShownSections(prefs) & | |
39 APPS) == 0); | |
40 EXPECT_TRUE((ShownSectionsHandler::GetShownSections(prefs) & | |
41 (MENU_APPS | THUMB)) != 0); | |
42 } | |
43 | |
44 } // namespace | 27 } // namespace |
45 | 28 |
46 class ExtensionAppsPromo : public testing::Test { | 29 class ExtensionAppsPromo : public testing::Test { |
47 public: | 30 public: |
48 TestingPrefService* prefs() { return &prefs_; } | 31 TestingPrefService* prefs() { return &prefs_; } |
49 AppsPromo* apps_promo() { return &apps_promo_; } | 32 AppsPromo* apps_promo() { return &apps_promo_; } |
50 | 33 |
51 protected: | 34 protected: |
52 explicit ExtensionAppsPromo(); | 35 explicit ExtensionAppsPromo(); |
53 | 36 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 EXPECT_TRUE(AppsPromo::IsWebStoreSupportedForLocale()); | 190 EXPECT_TRUE(AppsPromo::IsWebStoreSupportedForLocale()); |
208 AppsPromo::SetWebStoreSupportedForLocale(false); | 191 AppsPromo::SetWebStoreSupportedForLocale(false); |
209 EXPECT_FALSE(AppsPromo::IsWebStoreSupportedForLocale()); | 192 EXPECT_FALSE(AppsPromo::IsWebStoreSupportedForLocale()); |
210 | 193 |
211 // Try setting and getting the source logo URL. | 194 // Try setting and getting the source logo URL. |
212 GURL expected_source("https://www.google.com/images/test.png"); | 195 GURL expected_source("https://www.google.com/images/test.png"); |
213 AppsPromo::SetSourcePromoLogoURL(expected_source); | 196 AppsPromo::SetSourcePromoLogoURL(expected_source); |
214 EXPECT_EQ(expected_source, AppsPromo::GetSourcePromoLogoURL()); | 197 EXPECT_EQ(expected_source, AppsPromo::GetSourcePromoLogoURL()); |
215 } | 198 } |
216 | 199 |
217 // Tests maximizing the promo for USERS_NONE. | |
218 TEST_F(ExtensionAppsPromo, UpdatePromoFocus_UsersNone) { | |
219 // Verify that the apps section is not already maximized. | |
220 ExpectAppsSectionMaximized(prefs(), false); | |
221 | |
222 // The promo shouldn't maximize for anyone. | |
223 AppsPromo::PromoData promo_data(kPromoId, kPromoHeader, kPromoButton, | |
224 GURL(kPromoLink), kPromoExpire, GURL(""), | |
225 AppsPromo::USERS_NONE); | |
226 AppsPromo::SetPromo(promo_data); | |
227 apps_promo()->MaximizeAppsIfNecessary(); | |
228 ExpectAppsSectionMaximized(prefs(), false); | |
229 | |
230 // The promo still shouldn't maximize if we change it's ID. | |
231 promo_data.id = "lkksdf"; | |
232 AppsPromo::SetPromo(promo_data); | |
233 apps_promo()->MaximizeAppsIfNecessary(); | |
234 ExpectAppsSectionMaximized(prefs(), false); | |
235 } | |
236 | |
237 // Tests maximizing the promo for USERS_EXISTING. | |
238 TEST_F(ExtensionAppsPromo, UpdatePromoFocus_UsersExisting) { | |
239 // Verify that the apps section is not already maximized. | |
240 ExpectAppsSectionMaximized(prefs(), false); | |
241 | |
242 // Set the promo content. | |
243 AppsPromo::PromoData promo_data(kPromoId, kPromoHeader, kPromoButton, | |
244 GURL(kPromoLink), kPromoExpire, GURL(""), | |
245 AppsPromo::USERS_EXISTING); | |
246 AppsPromo::SetPromo(promo_data); | |
247 // This is a new user so the apps section shouldn't maximize. | |
248 apps_promo()->MaximizeAppsIfNecessary(); | |
249 ExpectAppsSectionMaximized(prefs(), false); | |
250 | |
251 // Set a new promo and now it should maximize. | |
252 promo_data.id = "lksdf"; | |
253 AppsPromo::SetPromo(promo_data); | |
254 | |
255 apps_promo()->MaximizeAppsIfNecessary(); | |
256 ExpectAppsSectionMaximized(prefs(), true); | |
257 | |
258 apps_promo()->HidePromo(); | |
259 ExpectAppsPromoHidden(prefs()); | |
260 } | |
261 | |
262 // Tests maximizing the promo for USERS_NEW. | |
263 TEST_F(ExtensionAppsPromo, UpdatePromoFocus_UsersNew) { | |
264 // Verify that the apps section is not already maximized. | |
265 ExpectAppsSectionMaximized(prefs(), false); | |
266 | |
267 // The promo should maximize for new users. | |
268 AppsPromo::PromoData promo_data(kPromoId, kPromoHeader, kPromoButton, | |
269 GURL(kPromoLink), kPromoExpire, GURL(""), | |
270 AppsPromo::USERS_NEW); | |
271 AppsPromo::SetPromo(promo_data); | |
272 apps_promo()->MaximizeAppsIfNecessary(); | |
273 ExpectAppsSectionMaximized(prefs(), true); | |
274 | |
275 // Try hiding the promo. | |
276 apps_promo()->HidePromo(); | |
277 ExpectAppsPromoHidden(prefs()); | |
278 | |
279 // The same promo should not maximize twice. | |
280 apps_promo()->MaximizeAppsIfNecessary(); | |
281 ExpectAppsSectionMaximized(prefs(), false); | |
282 | |
283 // Another promo targetting new users should not maximize. | |
284 promo_data.id = "lksdf"; | |
285 AppsPromo::SetPromo(promo_data); | |
286 apps_promo()->MaximizeAppsIfNecessary(); | |
287 ExpectAppsSectionMaximized(prefs(), false); | |
288 } | |
289 | |
290 // Tests maximizing the promo for USERS_NEW | USERS_EXISTING. | |
291 TEST_F(ExtensionAppsPromo, UpdatePromoFocus_UsersAll) { | |
292 // Verify that the apps section is not already maximized. | |
293 ExpectAppsSectionMaximized(prefs(), false); | |
294 | |
295 // The apps section should maximize for all users. | |
296 AppsPromo::PromoData promo_data( | |
297 kPromoId, kPromoHeader, kPromoButton, GURL(kPromoLink), kPromoExpire, | |
298 GURL(""), AppsPromo::USERS_NEW | AppsPromo::USERS_EXISTING); | |
299 AppsPromo::SetPromo(promo_data); | |
300 apps_promo()->MaximizeAppsIfNecessary(); | |
301 ExpectAppsSectionMaximized(prefs(), true); | |
302 | |
303 apps_promo()->HidePromo(); | |
304 ExpectAppsPromoHidden(prefs()); | |
305 | |
306 // The same promo should not maximize twice. | |
307 apps_promo()->MaximizeAppsIfNecessary(); | |
308 ExpectAppsSectionMaximized(prefs(), false); | |
309 | |
310 // A promo with a new ID should maximize though. | |
311 promo_data.id = "lkksdf"; | |
312 AppsPromo::SetPromo(promo_data); | |
313 apps_promo()->MaximizeAppsIfNecessary(); | |
314 ExpectAppsSectionMaximized(prefs(), true); | |
315 } | |
316 | |
317 TEST_F(ExtensionAppsPromo, PromoHiddenByPref) { | 200 TEST_F(ExtensionAppsPromo, PromoHiddenByPref) { |
318 prefs()->SetInteger(prefs::kAppsPromoCounter, 0); | 201 prefs()->SetInteger(prefs::kAppsPromoCounter, 0); |
319 prefs()->SetBoolean(prefs::kDefaultAppsInstalled, true); | 202 prefs()->SetBoolean(prefs::kDefaultAppsInstalled, true); |
320 | 203 |
321 // When the "hide" pref is false, the promo should still appear. | 204 // When the "hide" pref is false, the promo should still appear. |
322 prefs()->SetBoolean(prefs::kNTPHideWebStorePromo, false); | 205 prefs()->SetBoolean(prefs::kNTPHideWebStorePromo, false); |
323 AppsPromo::PromoData promo_data( | 206 AppsPromo::PromoData promo_data( |
324 kPromoId, kPromoHeader, kPromoButton, GURL(kPromoLink), kPromoExpire, | 207 kPromoId, kPromoHeader, kPromoButton, GURL(kPromoLink), kPromoExpire, |
325 GURL(""), AppsPromo::USERS_NEW | AppsPromo::USERS_EXISTING); | 208 GURL(""), AppsPromo::USERS_NEW | AppsPromo::USERS_EXISTING); |
326 AppsPromo::SetPromo(promo_data); | 209 AppsPromo::SetPromo(promo_data); |
327 bool just_expired; | 210 bool just_expired; |
328 bool show_promo = apps_promo()->ShouldShowPromo( | 211 bool show_promo = apps_promo()->ShouldShowPromo( |
329 apps_promo()->old_default_apps(), &just_expired); | 212 apps_promo()->old_default_apps(), &just_expired); |
330 EXPECT_TRUE(show_promo); | 213 EXPECT_TRUE(show_promo); |
331 | 214 |
332 // When the "hide" pref is true, the promo should NOT appear. | 215 // When the "hide" pref is true, the promo should NOT appear. |
333 prefs()->SetBoolean(prefs::kNTPHideWebStorePromo, true); | 216 prefs()->SetBoolean(prefs::kNTPHideWebStorePromo, true); |
334 show_promo = apps_promo()->ShouldShowPromo( | 217 show_promo = apps_promo()->ShouldShowPromo( |
335 apps_promo()->old_default_apps(), &just_expired); | 218 apps_promo()->old_default_apps(), &just_expired); |
336 EXPECT_FALSE(show_promo); | 219 EXPECT_FALSE(show_promo); |
337 } | 220 } |
338 | 221 |
339 #endif // OS_CHROMEOS | 222 #endif // OS_CHROMEOS |
OLD | NEW |