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/extensions/apps_promo.h" | 6 #include "chrome/browser/extensions/apps_promo.h" |
7 #include "chrome/browser/prefs/browser_prefs.h" | 7 #include "chrome/browser/prefs/browser_prefs.h" |
8 #include "chrome/browser/ui/webui/ntp/shown_sections_handler.h" | 8 #include "chrome/browser/ui/webui/ntp/shown_sections_handler.h" |
9 #include "chrome/common/extensions/extension.h" | 9 #include "chrome/common/extensions/extension.h" |
10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 EXPECT_EQ(maximized, | 28 EXPECT_EQ(maximized, |
29 (ShownSectionsHandler::GetShownSections(prefs) & APPS) != 0); | 29 (ShownSectionsHandler::GetShownSections(prefs) & APPS) != 0); |
30 EXPECT_EQ(!maximized, | 30 EXPECT_EQ(!maximized, |
31 (ShownSectionsHandler::GetShownSections(prefs) & THUMB) != 0); | 31 (ShownSectionsHandler::GetShownSections(prefs) & THUMB) != 0); |
32 } | 32 } |
33 | 33 |
34 void ExpectAppsPromoHidden(PrefService* prefs) { | 34 void ExpectAppsPromoHidden(PrefService* prefs) { |
35 // Hiding the promo places the apps section in menu mode and maximizes the | 35 // Hiding the promo places the apps section in menu mode and maximizes the |
36 // most visited section. | 36 // most visited section. |
37 EXPECT_TRUE((ShownSectionsHandler::GetShownSections(prefs) & | 37 EXPECT_TRUE((ShownSectionsHandler::GetShownSections(prefs) & |
| 38 APPS) == 0); |
| 39 EXPECT_TRUE((ShownSectionsHandler::GetShownSections(prefs) & |
38 (MENU_APPS | THUMB)) != 0); | 40 (MENU_APPS | THUMB)) != 0); |
39 } | 41 } |
40 | 42 |
41 } // namespace | 43 } // namespace |
42 | 44 |
43 class ExtensionAppsPromo : public TestingBrowserProcessTest { | 45 class ExtensionAppsPromo : public TestingBrowserProcessTest { |
44 public: | 46 public: |
45 TestingPrefService* prefs() { return &prefs_; } | 47 TestingPrefService* prefs() { return &prefs_; } |
46 AppsPromo* apps_promo() { return &apps_promo_; } | 48 AppsPromo* apps_promo() { return &apps_promo_; } |
47 | 49 |
(...skipping 14 matching lines...) Expand all Loading... |
62 apps_promo_(&prefs_) { | 64 apps_promo_(&prefs_) { |
63 } | 65 } |
64 | 66 |
65 void ExtensionAppsPromo::SetUp() { | 67 void ExtensionAppsPromo::SetUp() { |
66 browser::RegisterUserPrefs(&prefs_); | 68 browser::RegisterUserPrefs(&prefs_); |
67 } | 69 } |
68 | 70 |
69 // TODO(dpolukhin): On Chrome OS all apps are installed via external extensions, | 71 // TODO(dpolukhin): On Chrome OS all apps are installed via external extensions, |
70 // and the web store promo is never shown. | 72 // and the web store promo is never shown. |
71 #if !defined(OS_CHROMEOS) | 73 #if !defined(OS_CHROMEOS) |
| 74 |
72 TEST_F(ExtensionAppsPromo, HappyPath) { | 75 TEST_F(ExtensionAppsPromo, HappyPath) { |
73 const ExtensionIdSet& default_app_ids = apps_promo()->old_default_apps(); | 76 const ExtensionIdSet& default_app_ids = apps_promo()->old_default_apps(); |
74 | 77 |
75 EXPECT_GT(default_app_ids.size(), 0u); | 78 EXPECT_GT(default_app_ids.size(), 0u); |
76 | 79 |
77 // The promo counter should default to the max, since we only use the counter | 80 // The promo counter should default to the max, since we only use the counter |
78 // if they were installed from older versions of Chrome. | 81 // if they were installed from older versions of Chrome. |
79 EXPECT_EQ(AppsPromo::kDefaultAppsCounterMax + 1, | 82 EXPECT_EQ(AppsPromo::kDefaultAppsCounterMax + 1, |
80 apps_promo()->GetPromoCounter()); | 83 apps_promo()->GetPromoCounter()); |
81 | 84 |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 ExpectAppsSectionMaximized(prefs(), false); | 306 ExpectAppsSectionMaximized(prefs(), false); |
304 | 307 |
305 // A promo with a new ID should maximize though. | 308 // A promo with a new ID should maximize though. |
306 AppsPromo::SetPromo("lkksdf", kPromoHeader, kPromoButton, | 309 AppsPromo::SetPromo("lkksdf", kPromoHeader, kPromoButton, |
307 GURL(kPromoLink), kPromoExpire, GURL(""), | 310 GURL(kPromoLink), kPromoExpire, GURL(""), |
308 AppsPromo::USERS_NEW | AppsPromo::USERS_EXISTING); | 311 AppsPromo::USERS_NEW | AppsPromo::USERS_EXISTING); |
309 apps_promo()->MaximizeAppsIfNecessary(); | 312 apps_promo()->MaximizeAppsIfNecessary(); |
310 ExpectAppsSectionMaximized(prefs(), true); | 313 ExpectAppsSectionMaximized(prefs(), true); |
311 } | 314 } |
312 | 315 |
313 #endif // OS_CHROMEOS | 316 TEST_F(ExtensionAppsPromo, PromoHiddenByPref) { |
| 317 prefs()->SetInteger(prefs::kAppsPromoCounter, 0); |
| 318 prefs()->SetBoolean(prefs::kDefaultAppsInstalled, true); |
| 319 |
| 320 // When the "hide" pref is false, the promo should still appear. |
| 321 prefs()->SetBoolean(prefs::kNTPHideWebStorePromo, false); |
| 322 AppsPromo::SetPromo(kPromoId, kPromoHeader, kPromoButton, |
| 323 GURL(kPromoLink), kPromoExpire, GURL(""), |
| 324 AppsPromo::USERS_NEW | AppsPromo::USERS_EXISTING); |
| 325 bool just_expired; |
| 326 bool show_promo = apps_promo()->ShouldShowPromo( |
| 327 apps_promo()->old_default_apps(), &just_expired); |
| 328 EXPECT_TRUE(show_promo); |
| 329 |
| 330 // When the "hide" pref is true, the promo should NOT appear. |
| 331 prefs()->SetBoolean(prefs::kNTPHideWebStorePromo, true); |
| 332 show_promo = apps_promo()->ShouldShowPromo( |
| 333 apps_promo()->old_default_apps(), &just_expired); |
| 334 EXPECT_FALSE(show_promo); |
| 335 } |
| 336 |
| 337 #endif // OS_CHROMEOS |
OLD | NEW |