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 "chrome/browser/extensions/default_apps.h" | 5 #include "chrome/browser/extensions/default_apps.h" |
6 #include "chrome/common/extensions/extension.h" | 6 #include "chrome/common/extensions/extension.h" |
7 #include "chrome/test/testing_pref_service.h" | 7 #include "chrome/test/testing_pref_service.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 // TODO(dpolukhin): On Chrome OS all apps are installed via external extensions, | 10 // TODO(dpolukhin): On Chrome OS all apps are installed via external extensions, |
11 // and the web store promo is never shown. | 11 // and the web store promo is never shown. |
12 #if !defined(OS_CHROMEOS) | 12 #if !defined(OS_CHROMEOS) |
13 TEST(DefaultApps, Basics) { | 13 TEST(ExtensionDefaultApps, Basics) { |
14 TestingPrefService pref_service; | 14 TestingPrefService pref_service; |
15 DefaultApps::RegisterUserPrefs(&pref_service); | 15 DefaultApps::RegisterUserPrefs(&pref_service); |
16 DefaultApps default_apps(&pref_service); | 16 DefaultApps default_apps(&pref_service); |
17 | 17 |
18 ExtensionIdSet default_app_ids = *default_apps.GetAppsToInstall(); | 18 ExtensionIdSet default_app_ids = *default_apps.GetAppsToInstall(); |
19 ASSERT_GT(default_app_ids.size(), 0u); | 19 ASSERT_GT(default_app_ids.size(), 0u); |
20 EXPECT_FALSE(default_apps.GetDefaultAppsInstalled()); | 20 EXPECT_FALSE(default_apps.GetDefaultAppsInstalled()); |
21 EXPECT_EQ(0, default_apps.GetPromoCounter()); | 21 EXPECT_EQ(0, default_apps.GetPromoCounter()); |
22 EXPECT_EQ(default_app_ids, *default_apps.GetDefaultApps()); | 22 EXPECT_EQ(default_app_ids, *default_apps.GetDefaultApps()); |
23 | 23 |
24 // The promo should not be shown until the default apps have been installed. | 24 // The promo should not be shown until the default apps have been installed. |
25 ExtensionIdSet installed_app_ids; | 25 ExtensionIdSet installed_app_ids; |
26 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_app_ids)); | 26 EXPECT_FALSE(default_apps.CheckShouldShowPromo(installed_app_ids)); |
27 | 27 |
28 // Simulate installing the apps one by one and notifying default_apps after | 28 // Simulate installing the apps one by one and notifying default_apps after |
29 // each intallation. Nothing should change until we have installed all the | 29 // each intallation. Nothing should change until we have installed all the |
30 // default apps. | 30 // default apps. |
31 ExtensionIdSet extension_id_sets[] = { | 31 ExtensionIdSet extension_id_sets[] = { |
32 default_app_ids, | 32 default_app_ids, |
33 default_app_ids, | 33 default_app_ids, |
34 default_app_ids | 34 default_app_ids |
35 }; | 35 }; |
36 extension_id_sets[0].clear(); | 36 extension_id_sets[0].clear(); |
37 extension_id_sets[1].erase(extension_id_sets[1].begin()); | 37 extension_id_sets[1].erase(extension_id_sets[1].begin()); |
38 extension_id_sets[2].erase(extension_id_sets[2].begin(), | 38 extension_id_sets[2].erase(extension_id_sets[2].begin(), |
39 ++extension_id_sets[2].begin()); | 39 ++extension_id_sets[2].begin()); |
40 for (size_t i = 0; i < arraysize(extension_id_sets); ++i) { | 40 for (size_t i = 0; i < arraysize(extension_id_sets); ++i) { |
41 default_apps.DidInstallApp(extension_id_sets[i]); | 41 default_apps.DidInstallApp(extension_id_sets[i]); |
42 EXPECT_TRUE(default_app_ids == *default_apps.GetAppsToInstall()); | 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.ShouldShowPromo(extension_id_sets[i])); | 44 EXPECT_FALSE(default_apps.CheckShouldShowPromo(extension_id_sets[i])); |
45 } | 45 } |
46 | 46 |
47 // Simulate all the default apps being installed. Now we should stop getting | 47 // Simulate all the default apps being installed. Now we should stop getting |
48 // default apps to install. | 48 // default apps to install. |
49 default_apps.DidInstallApp(default_app_ids); | 49 default_apps.DidInstallApp(default_app_ids); |
50 EXPECT_EQ(NULL, default_apps.GetAppsToInstall()); | 50 EXPECT_EQ(NULL, default_apps.GetAppsToInstall()); |
51 EXPECT_TRUE(default_apps.GetDefaultAppsInstalled()); | 51 EXPECT_TRUE(default_apps.GetDefaultAppsInstalled()); |
52 | 52 |
53 // And the promo should become available. | 53 // And the promo should become available. |
54 EXPECT_TRUE(default_apps.ShouldShowPromo(default_app_ids)); | 54 EXPECT_TRUE(default_apps.CheckShouldShowPromo(default_app_ids)); |
55 | 55 |
56 // The promo should be available up to the max allowed times, then stop. | 56 // The promo should be available up to the max allowed times, then stop. |
57 for (int i = 0; i < DefaultApps::kAppsPromoCounterMax; ++i) { | 57 for (int i = 0; i < DefaultApps::kAppsPromoCounterMax; ++i) { |
58 EXPECT_TRUE(default_apps.ShouldShowPromo(default_app_ids)); | 58 EXPECT_TRUE(default_apps.CheckShouldShowPromo(default_app_ids)); |
59 default_apps.DidShowPromo(); | 59 default_apps.DidShowPromo(); |
60 EXPECT_EQ(i + 1, default_apps.GetPromoCounter()); | 60 EXPECT_EQ(i + 1, default_apps.GetPromoCounter()); |
61 } | 61 } |
62 EXPECT_FALSE(default_apps.ShouldShowPromo(default_app_ids)); | 62 EXPECT_FALSE(default_apps.CheckShouldShowPromo(default_app_ids)); |
63 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter()); | 63 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter()); |
64 } | 64 } |
65 | 65 |
66 TEST(DefaultApps, HidePromo) { | 66 TEST(ExtensionDefaultApps, HidePromo) { |
67 TestingPrefService pref_service; | 67 TestingPrefService pref_service; |
68 DefaultApps::RegisterUserPrefs(&pref_service); | 68 DefaultApps::RegisterUserPrefs(&pref_service); |
69 DefaultApps default_apps(&pref_service); | 69 DefaultApps default_apps(&pref_service); |
70 | 70 |
71 ExtensionIdSet default_app_ids = *default_apps.GetAppsToInstall(); | 71 ExtensionIdSet default_app_ids = *default_apps.GetAppsToInstall(); |
72 default_apps.DidInstallApp(default_app_ids); | 72 default_apps.DidInstallApp(default_app_ids); |
73 | 73 |
74 EXPECT_TRUE(default_apps.ShouldShowPromo(default_app_ids)); | 74 EXPECT_TRUE(default_apps.CheckShouldShowPromo(default_app_ids)); |
75 default_apps.DidShowPromo(); | 75 default_apps.DidShowPromo(); |
76 EXPECT_EQ(1, default_apps.GetPromoCounter()); | 76 EXPECT_EQ(1, default_apps.GetPromoCounter()); |
77 | 77 |
78 default_apps.SetPromoHidden(); | 78 default_apps.SetPromoHidden(); |
79 EXPECT_FALSE(default_apps.ShouldShowPromo(default_app_ids)); | 79 EXPECT_FALSE(default_apps.CheckShouldShowPromo(default_app_ids)); |
80 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter()); | 80 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter()); |
81 } | 81 } |
82 | 82 |
83 TEST(DefaultApps, InstallingAnAppHidesPromo) { | 83 TEST(ExtensionDefaultApps, InstallingAnAppHidesPromo) { |
84 TestingPrefService pref_service; | 84 TestingPrefService pref_service; |
85 DefaultApps::RegisterUserPrefs(&pref_service); | 85 DefaultApps::RegisterUserPrefs(&pref_service); |
86 DefaultApps default_apps(&pref_service); | 86 DefaultApps default_apps(&pref_service); |
87 | 87 |
88 ExtensionIdSet default_app_ids = *default_apps.GetAppsToInstall(); | 88 ExtensionIdSet default_app_ids = *default_apps.GetAppsToInstall(); |
89 ExtensionIdSet installed_app_ids = default_app_ids; | 89 ExtensionIdSet installed_app_ids = default_app_ids; |
90 default_apps.DidInstallApp(installed_app_ids); | 90 default_apps.DidInstallApp(installed_app_ids); |
91 | 91 |
92 EXPECT_TRUE(default_apps.ShouldShowPromo(installed_app_ids)); | 92 EXPECT_TRUE(default_apps.CheckShouldShowPromo(installed_app_ids)); |
93 default_apps.DidShowPromo(); | 93 default_apps.DidShowPromo(); |
94 EXPECT_EQ(1, default_apps.GetPromoCounter()); | 94 EXPECT_EQ(1, default_apps.GetPromoCounter()); |
95 | 95 |
96 // Now simulate a new extension being installed. This should cause the promo | 96 // Now simulate a new extension being installed. This should cause the promo |
97 // to be hidden. | 97 // to be hidden. |
98 installed_app_ids.insert("foo"); | 98 installed_app_ids.insert("foo"); |
99 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_app_ids)); | 99 EXPECT_FALSE(default_apps.CheckShouldShowPromo(installed_app_ids)); |
100 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter()); | 100 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter()); |
101 } | 101 } |
102 | 102 |
103 TEST(DefaultApps, ManualAppInstalledWhileInstallingDefaultApps) { | 103 TEST(ExtensionDefaultApps, ManualAppInstalledWhileInstallingDefaultApps) { |
104 // It is possible to have apps manually installed while the default apps are | 104 // 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 | 105 // 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 | 106 // app installation to fail. The updater might take awhile to get around to |
107 // updating, giving the user a chance to manually intall. | 107 // updating, giving the user a chance to manually intall. |
108 // | 108 // |
109 // In these cases, we should keep trying to install default apps until we have | 109 // 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 | 110 // them all, and then stop, even if at that point, we have more apps than just |
111 // the default ones. | 111 // the default ones. |
112 TestingPrefService pref_service; | 112 TestingPrefService pref_service; |
113 DefaultApps::RegisterUserPrefs(&pref_service); | 113 DefaultApps::RegisterUserPrefs(&pref_service); |
(...skipping 10 matching lines...) Expand all Loading... |
124 // Now add all the default apps in addition to the extra app. We should stop | 124 // Now add all the default apps in addition to the extra app. We should stop |
125 // trying to install default apps. | 125 // trying to install default apps. |
126 installed_ids = *default_apps.GetAppsToInstall(); | 126 installed_ids = *default_apps.GetAppsToInstall(); |
127 installed_ids.insert("foo"); | 127 installed_ids.insert("foo"); |
128 default_apps.DidInstallApp(installed_ids); | 128 default_apps.DidInstallApp(installed_ids); |
129 EXPECT_TRUE(default_apps.GetDefaultAppsInstalled()); | 129 EXPECT_TRUE(default_apps.GetDefaultAppsInstalled()); |
130 EXPECT_FALSE(default_apps.GetAppsToInstall()); | 130 EXPECT_FALSE(default_apps.GetAppsToInstall()); |
131 | 131 |
132 // The promo shouldn't turn on though, because it would look weird with the | 132 // The promo shouldn't turn on though, because it would look weird with the |
133 // user's extra, manually installed extensions. | 133 // user's extra, manually installed extensions. |
134 EXPECT_FALSE(default_apps.ShouldShowPromo(installed_ids)); | 134 EXPECT_FALSE(default_apps.CheckShouldShowPromo(installed_ids)); |
135 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter()); | 135 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter()); |
136 } | 136 } |
137 #endif // OS_CHROMEOS | 137 #endif // OS_CHROMEOS |
OLD | NEW |