Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Side by Side Diff: chrome/browser/extensions/default_apps_unittest.cc

Issue 3522015: Implement new strategy for default apps (Closed)
Patch Set: all done Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "chrome/browser/extensions/default_apps.h"
6 #include "chrome/common/extensions/extension.h"
7 #include "chrome/test/testing_pref_service.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 TEST(DefaultApps, Basics) {
11 TestingPrefService pref_service;
12 DefaultApps::RegisterUserPrefs(&pref_service);
13 DefaultApps default_apps(&pref_service);
14
15 ExtensionIdSet default_app_ids = *default_apps.GetAppsToInstall();
16 ASSERT_GT(default_app_ids.size(), 0u);
17 EXPECT_FALSE(default_apps.GetDefaultAppsInstalled());
18 EXPECT_EQ(0, default_apps.GetPromoCounter());
19
20 // The promo should not be shown until the default apps have been installed.
21 ExtensionIdSet installed_app_ids;
22 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_app_ids));
23
24 // Simulate installing the apps one by one and notifying default_apps after
25 // each intallation. Nothing should change until we have installed all the
26 // default apps.
27 ExtensionIdSet extension_id_sets[] = {
28 default_app_ids,
29 default_app_ids,
30 default_app_ids
31 };
32 extension_id_sets[0].clear();
33 extension_id_sets[1].erase(extension_id_sets[1].begin());
34 extension_id_sets[2].erase(extension_id_sets[2].begin(),
35 ++extension_id_sets[2].begin());
36 for (size_t i = 0; i < arraysize(extension_id_sets); ++i) {
37 default_apps.DidInstallApp(extension_id_sets[i]);
38 EXPECT_TRUE(default_app_ids == *default_apps.GetAppsToInstall());
39 EXPECT_FALSE(default_apps.GetDefaultAppsInstalled());
40 EXPECT_FALSE(default_apps.ShouldShowPromo(extension_id_sets[i]));
41 }
42
43 // Simulate all the default apps being installed. Now we should stop getting
44 // default apps to install.
45 default_apps.DidInstallApp(default_app_ids);
46 EXPECT_EQ(NULL, default_apps.GetAppsToInstall());
47 EXPECT_TRUE(default_apps.GetDefaultAppsInstalled());
48
49 // And the promo should become available.
50 EXPECT_TRUE(default_apps.ShouldShowPromo(default_app_ids));
51
52 // The promo should be available up to the max allowed times, then stop.
53 for (int i = 0; i < DefaultApps::kAppsPromoCounterMax; ++i) {
54 EXPECT_TRUE(default_apps.ShouldShowPromo(default_app_ids));
55 default_apps.DidShowPromo();
56 EXPECT_EQ(i + 1, default_apps.GetPromoCounter());
57 }
58 EXPECT_FALSE(default_apps.ShouldShowPromo(default_app_ids));
59 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter());
60 }
61
62 TEST(DefaultApps, HidePromo) {
63 TestingPrefService pref_service;
64 DefaultApps::RegisterUserPrefs(&pref_service);
65 DefaultApps default_apps(&pref_service);
66
67 ExtensionIdSet default_app_ids = *default_apps.GetAppsToInstall();
68 default_apps.DidInstallApp(default_app_ids);
69
70 EXPECT_TRUE(default_apps.ShouldShowPromo(default_app_ids));
71 default_apps.DidShowPromo();
72 EXPECT_EQ(1, default_apps.GetPromoCounter());
73
74 default_apps.SetPromoHidden();
75 EXPECT_FALSE(default_apps.ShouldShowPromo(default_app_ids));
76 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter());
77 }
78
79 TEST(DefaultApps, InstallingAnAppHidesPromo) {
80 TestingPrefService pref_service;
81 DefaultApps::RegisterUserPrefs(&pref_service);
82 DefaultApps default_apps(&pref_service);
83
84 ExtensionIdSet default_app_ids = *default_apps.GetAppsToInstall();
85 ExtensionIdSet installed_app_ids = default_app_ids;
86 default_apps.DidInstallApp(installed_app_ids);
87
88 EXPECT_TRUE(default_apps.ShouldShowPromo(installed_app_ids));
89 default_apps.DidShowPromo();
90 EXPECT_EQ(1, default_apps.GetPromoCounter());
91
92 // Now simulate a new extension being installed. This should cause the promo
93 // to be hidden.
94 installed_app_ids.insert("foo");
95 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_app_ids));
96 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter());
97 }
98
99 TEST(DefaultApps, ManualAppInstalledWhileInstallingDefaultApps) {
100 // It is possible to have apps manually installed while the default apps are
101 // being installed. The network or server might be down, causing the default
102 // app installation to fail. The updater might take awhile to get around to
103 // updating, giving the user a chance to manually intall.
104 //
105 // In these cases, we should keep trying to install default apps until we have
106 // them all, and then stop, even if at that point, we have more apps than just
107 // the default ones.
108 TestingPrefService pref_service;
109 DefaultApps::RegisterUserPrefs(&pref_service);
110 DefaultApps default_apps(&pref_service);
111
112 // Simulate an app getting installed before the complete set of default apps.
113 // This shouldn't affect us installing default apps. We should keep trying.
114 ExtensionIdSet installed_ids;
115 installed_ids.insert("foo");
116 default_apps.DidInstallApp(installed_ids);
117 EXPECT_FALSE(default_apps.GetDefaultAppsInstalled());
118 EXPECT_TRUE(default_apps.GetAppsToInstall());
119
120 // Now add all the default apps in addition to the extra app. We should stop
121 // trying to install default apps.
122 installed_ids = *default_apps.GetAppsToInstall();
123 installed_ids.insert("foo");
124 default_apps.DidInstallApp(installed_ids);
125 EXPECT_TRUE(default_apps.GetDefaultAppsInstalled());
126 EXPECT_FALSE(default_apps.GetAppsToInstall());
127
128 // The promo shouldn't turn on though, because it would look weird with the
129 // user's extra, manually installed extensions.
130 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_ids));
131 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter());
132 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/default_apps.cc ('k') | chrome/browser/extensions/extension_updater.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698