| 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(ExtensionDefaultApps, Basics) { | 13 TEST(ExtensionDefaultApps, Basics) { |
| 14 TestingPrefService pref_service; | 14 scoped_ptr<TestingPrefService> pref_service( |
| 15 DefaultApps::RegisterUserPrefs(&pref_service); | 15 TestingPrefService::CreateTestingPrefService()); |
| 16 DefaultApps default_apps(&pref_service); | 16 DefaultApps::RegisterUserPrefs(pref_service.get()); |
| 17 DefaultApps default_apps(pref_service.get()); |
| 17 | 18 |
| 18 ExtensionIdSet default_app_ids = *default_apps.GetAppsToInstall(); | 19 ExtensionIdSet default_app_ids = *default_apps.GetAppsToInstall(); |
| 19 ASSERT_GT(default_app_ids.size(), 0u); | 20 ASSERT_GT(default_app_ids.size(), 0u); |
| 20 EXPECT_FALSE(default_apps.GetDefaultAppsInstalled()); | 21 EXPECT_FALSE(default_apps.GetDefaultAppsInstalled()); |
| 21 EXPECT_EQ(0, default_apps.GetPromoCounter()); | 22 EXPECT_EQ(0, default_apps.GetPromoCounter()); |
| 22 EXPECT_EQ(default_app_ids, *default_apps.GetDefaultApps()); | 23 EXPECT_EQ(default_app_ids, *default_apps.GetDefaultApps()); |
| 23 | 24 |
| 24 // The promo should not be shown until the default apps have been installed. | 25 // The promo should not be shown until the default apps have been installed. |
| 25 ExtensionIdSet installed_app_ids; | 26 ExtensionIdSet installed_app_ids; |
| 26 EXPECT_FALSE(default_apps.CheckShouldShowPromo(installed_app_ids)); | 27 EXPECT_FALSE(default_apps.CheckShouldShowPromo(installed_app_ids)); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 57 for (int i = 0; i < DefaultApps::kAppsPromoCounterMax; ++i) { | 58 for (int i = 0; i < DefaultApps::kAppsPromoCounterMax; ++i) { |
| 58 EXPECT_TRUE(default_apps.CheckShouldShowPromo(default_app_ids)); | 59 EXPECT_TRUE(default_apps.CheckShouldShowPromo(default_app_ids)); |
| 59 default_apps.DidShowPromo(); | 60 default_apps.DidShowPromo(); |
| 60 EXPECT_EQ(i + 1, default_apps.GetPromoCounter()); | 61 EXPECT_EQ(i + 1, default_apps.GetPromoCounter()); |
| 61 } | 62 } |
| 62 EXPECT_FALSE(default_apps.CheckShouldShowPromo(default_app_ids)); | 63 EXPECT_FALSE(default_apps.CheckShouldShowPromo(default_app_ids)); |
| 63 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter()); | 64 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter()); |
| 64 } | 65 } |
| 65 | 66 |
| 66 TEST(ExtensionDefaultApps, HidePromo) { | 67 TEST(ExtensionDefaultApps, HidePromo) { |
| 67 TestingPrefService pref_service; | 68 scoped_ptr<TestingPrefService> pref_service( |
| 68 DefaultApps::RegisterUserPrefs(&pref_service); | 69 TestingPrefService::CreateTestingPrefService()); |
| 69 DefaultApps default_apps(&pref_service); | 70 DefaultApps::RegisterUserPrefs(pref_service.get()); |
| 71 DefaultApps default_apps(pref_service.get()); |
| 70 | 72 |
| 71 ExtensionIdSet default_app_ids = *default_apps.GetAppsToInstall(); | 73 ExtensionIdSet default_app_ids = *default_apps.GetAppsToInstall(); |
| 72 default_apps.DidInstallApp(default_app_ids); | 74 default_apps.DidInstallApp(default_app_ids); |
| 73 | 75 |
| 74 EXPECT_TRUE(default_apps.CheckShouldShowPromo(default_app_ids)); | 76 EXPECT_TRUE(default_apps.CheckShouldShowPromo(default_app_ids)); |
| 75 default_apps.DidShowPromo(); | 77 default_apps.DidShowPromo(); |
| 76 EXPECT_EQ(1, default_apps.GetPromoCounter()); | 78 EXPECT_EQ(1, default_apps.GetPromoCounter()); |
| 77 | 79 |
| 78 default_apps.SetPromoHidden(); | 80 default_apps.SetPromoHidden(); |
| 79 EXPECT_FALSE(default_apps.CheckShouldShowPromo(default_app_ids)); | 81 EXPECT_FALSE(default_apps.CheckShouldShowPromo(default_app_ids)); |
| 80 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter()); | 82 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter()); |
| 81 } | 83 } |
| 82 | 84 |
| 83 TEST(ExtensionDefaultApps, InstallingAnAppHidesPromo) { | 85 TEST(ExtensionDefaultApps, InstallingAnAppHidesPromo) { |
| 84 TestingPrefService pref_service; | 86 scoped_ptr<TestingPrefService> pref_service( |
| 85 DefaultApps::RegisterUserPrefs(&pref_service); | 87 TestingPrefService::CreateTestingPrefService()); |
| 86 DefaultApps default_apps(&pref_service); | 88 DefaultApps::RegisterUserPrefs(pref_service.get()); |
| 89 DefaultApps default_apps(pref_service.get()); |
| 87 | 90 |
| 88 ExtensionIdSet default_app_ids = *default_apps.GetAppsToInstall(); | 91 ExtensionIdSet default_app_ids = *default_apps.GetAppsToInstall(); |
| 89 ExtensionIdSet installed_app_ids = default_app_ids; | 92 ExtensionIdSet installed_app_ids = default_app_ids; |
| 90 default_apps.DidInstallApp(installed_app_ids); | 93 default_apps.DidInstallApp(installed_app_ids); |
| 91 | 94 |
| 92 EXPECT_TRUE(default_apps.CheckShouldShowPromo(installed_app_ids)); | 95 EXPECT_TRUE(default_apps.CheckShouldShowPromo(installed_app_ids)); |
| 93 default_apps.DidShowPromo(); | 96 default_apps.DidShowPromo(); |
| 94 EXPECT_EQ(1, default_apps.GetPromoCounter()); | 97 EXPECT_EQ(1, default_apps.GetPromoCounter()); |
| 95 | 98 |
| 96 // Now simulate a new extension being installed. This should cause the promo | 99 // Now simulate a new extension being installed. This should cause the promo |
| 97 // to be hidden. | 100 // to be hidden. |
| 98 installed_app_ids.insert("foo"); | 101 installed_app_ids.insert("foo"); |
| 99 EXPECT_FALSE(default_apps.CheckShouldShowPromo(installed_app_ids)); | 102 EXPECT_FALSE(default_apps.CheckShouldShowPromo(installed_app_ids)); |
| 100 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter()); | 103 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter()); |
| 101 } | 104 } |
| 102 | 105 |
| 103 TEST(ExtensionDefaultApps, ManualAppInstalledWhileInstallingDefaultApps) { | 106 TEST(ExtensionDefaultApps, ManualAppInstalledWhileInstallingDefaultApps) { |
| 104 // It is possible to have apps manually installed while the default apps are | 107 // 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 | 108 // 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 | 109 // app installation to fail. The updater might take awhile to get around to |
| 107 // updating, giving the user a chance to manually intall. | 110 // updating, giving the user a chance to manually intall. |
| 108 // | 111 // |
| 109 // In these cases, we should keep trying to install default apps until we have | 112 // 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 | 113 // them all, and then stop, even if at that point, we have more apps than just |
| 111 // the default ones. | 114 // the default ones. |
| 112 TestingPrefService pref_service; | 115 scoped_ptr<TestingPrefService> pref_service( |
| 113 DefaultApps::RegisterUserPrefs(&pref_service); | 116 TestingPrefService::CreateTestingPrefService()); |
| 114 DefaultApps default_apps(&pref_service); | 117 DefaultApps::RegisterUserPrefs(pref_service.get()); |
| 118 DefaultApps default_apps(pref_service.get()); |
| 115 | 119 |
| 116 // Simulate an app getting installed before the complete set of default apps. | 120 // Simulate an app getting installed before the complete set of default apps. |
| 117 // This shouldn't affect us installing default apps. We should keep trying. | 121 // This shouldn't affect us installing default apps. We should keep trying. |
| 118 ExtensionIdSet installed_ids; | 122 ExtensionIdSet installed_ids; |
| 119 installed_ids.insert("foo"); | 123 installed_ids.insert("foo"); |
| 120 default_apps.DidInstallApp(installed_ids); | 124 default_apps.DidInstallApp(installed_ids); |
| 121 EXPECT_FALSE(default_apps.GetDefaultAppsInstalled()); | 125 EXPECT_FALSE(default_apps.GetDefaultAppsInstalled()); |
| 122 EXPECT_TRUE(default_apps.GetAppsToInstall()); | 126 EXPECT_TRUE(default_apps.GetAppsToInstall()); |
| 123 | 127 |
| 124 // Now add all the default apps in addition to the extra app. We should stop | 128 // Now add all the default apps in addition to the extra app. We should stop |
| 125 // trying to install default apps. | 129 // trying to install default apps. |
| 126 installed_ids = *default_apps.GetAppsToInstall(); | 130 installed_ids = *default_apps.GetAppsToInstall(); |
| 127 installed_ids.insert("foo"); | 131 installed_ids.insert("foo"); |
| 128 default_apps.DidInstallApp(installed_ids); | 132 default_apps.DidInstallApp(installed_ids); |
| 129 EXPECT_TRUE(default_apps.GetDefaultAppsInstalled()); | 133 EXPECT_TRUE(default_apps.GetDefaultAppsInstalled()); |
| 130 EXPECT_FALSE(default_apps.GetAppsToInstall()); | 134 EXPECT_FALSE(default_apps.GetAppsToInstall()); |
| 131 | 135 |
| 132 // The promo shouldn't turn on though, because it would look weird with the | 136 // The promo shouldn't turn on though, because it would look weird with the |
| 133 // user's extra, manually installed extensions. | 137 // user's extra, manually installed extensions. |
| 134 EXPECT_FALSE(default_apps.CheckShouldShowPromo(installed_ids)); | 138 EXPECT_FALSE(default_apps.CheckShouldShowPromo(installed_ids)); |
| 135 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter()); | 139 EXPECT_EQ(DefaultApps::kAppsPromoCounterMax, default_apps.GetPromoCounter()); |
| 136 } | 140 } |
| 137 #endif // OS_CHROMEOS | 141 #endif // OS_CHROMEOS |
| OLD | NEW |