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

Side by Side Diff: chrome/browser/background/background_application_list_model_unittest.cc

Issue 1497193002: Remove all the ephemeral apps code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tests Created 5 years 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // TODO(rickcam): Bug 73183: Add unit tests for image loading 5 // TODO(rickcam): Bug 73183: Add unit tests for image loading
6 6
7 #include <cstdlib> 7 #include <cstdlib>
8 #include <set> 8 #include <set>
9 9
10 #include "chrome/browser/background/background_application_list_model.h" 10 #include "chrome/browser/background/background_application_list_model.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 void RemoveBackgroundPermission(ExtensionService* service, 125 void RemoveBackgroundPermission(ExtensionService* service,
126 Extension* extension) { 126 Extension* extension) {
127 if (!BackgroundApplicationListModel::IsBackgroundApp(*extension, 127 if (!BackgroundApplicationListModel::IsBackgroundApp(*extension,
128 service->profile())) { 128 service->profile())) {
129 return; 129 return;
130 } 130 }
131 extensions::PermissionsUpdater(service->profile()) 131 extensions::PermissionsUpdater(service->profile())
132 .RemovePermissionsUnsafe( 132 .RemovePermissionsUnsafe(
133 extension, extension->permissions_data()->active_permissions()); 133 extension, extension->permissions_data()->active_permissions());
134 } 134 }
135
136 void AddEphemeralApp(const Extension* extension, ExtensionService* service) {
137 extensions::ExtensionPrefs* prefs =
138 extensions::ExtensionPrefs::Get(service->profile());
139 ASSERT_TRUE(prefs);
140 prefs->OnExtensionInstalled(extension,
141 extensions::Extension::ENABLED,
142 syncer::StringOrdinal(),
143 extensions::kInstallFlagIsEphemeral,
144 std::string());
145
146 service->AddExtension(extension);
147 }
148
149 } // namespace 135 } // namespace
150 136
151 // Crashes on Mac tryslaves. 137 // Crashes on Mac tryslaves.
152 // http://crbug.com/165458 138 // http://crbug.com/165458
153 #if defined(OS_MACOSX) || defined(OS_LINUX) 139 #if defined(OS_MACOSX) || defined(OS_LINUX)
154 #define MAYBE_ExplicitTest DISABLED_ExplicitTest 140 #define MAYBE_ExplicitTest DISABLED_ExplicitTest
155 #else 141 #else
156 #define MAYBE_ExplicitTest ExplicitTest 142 #define MAYBE_ExplicitTest ExplicitTest
157 #endif 143 #endif
158 // With minimal test logic, verifies behavior over an explicit set of 144 // With minimal test logic, verifies behavior over an explicit set of
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 ASSERT_EQ(1U, registry()->enabled_extensions().size()); 207 ASSERT_EQ(1U, registry()->enabled_extensions().size());
222 ASSERT_EQ(0U, model->size()); 208 ASSERT_EQ(0U, model->size());
223 ASSERT_FALSE(IsBackgroundApp(*ext3.get())); 209 ASSERT_FALSE(IsBackgroundApp(*ext3.get()));
224 service()->UninstallExtension(ext3->id(), 210 service()->UninstallExtension(ext3->id(),
225 extensions::UNINSTALL_REASON_FOR_TESTING, 211 extensions::UNINSTALL_REASON_FOR_TESTING,
226 base::Bind(&base::DoNothing), NULL); 212 base::Bind(&base::DoNothing), NULL);
227 ASSERT_EQ(0U, registry()->enabled_extensions().size()); 213 ASSERT_EQ(0U, registry()->enabled_extensions().size());
228 ASSERT_EQ(0U, model->size()); 214 ASSERT_EQ(0U, model->size());
229 } 215 }
230 216
231 // Verifies that an ephemeral app cannot trigger background mode.
232 TEST_F(BackgroundApplicationListModelTest, EphemeralAppTest) {
233 InitializeAndLoadEmptyExtensionService();
234 ASSERT_TRUE(service()->is_ready());
235 ASSERT_TRUE(registry()->enabled_extensions().is_empty());
236 scoped_ptr<BackgroundApplicationListModel> model(
237 new BackgroundApplicationListModel(profile_.get()));
238 ASSERT_EQ(0U, model->size());
239
240 scoped_refptr<Extension> background = CreateExtension("background", true);
241
242 // An ephemeral app with the background permission should not trigger
243 // background mode.
244 AddEphemeralApp(background.get(), service());
245 ASSERT_FALSE(IsBackgroundApp(*background.get()));
246 ASSERT_EQ(1U, registry()->enabled_extensions().size());
247 ASSERT_EQ(0U, model->size());
248
249 // If the ephemeral app becomes promoted to an installed app, it can now
250 // trigger background mode.
251 service()->PromoteEphemeralApp(background.get(), false /*from sync*/);
252 ASSERT_TRUE(IsBackgroundApp(*background.get()));
253 ASSERT_EQ(1U, registry()->enabled_extensions().size());
254 ASSERT_EQ(1U, model->size());
255 }
256
257 // With minimal test logic, verifies behavior with dynamic permissions. 217 // With minimal test logic, verifies behavior with dynamic permissions.
258 TEST_F(BackgroundApplicationListModelTest, AddRemovePermissionsTest) { 218 TEST_F(BackgroundApplicationListModelTest, AddRemovePermissionsTest) {
259 InitializeAndLoadEmptyExtensionService(); 219 InitializeAndLoadEmptyExtensionService();
260 ASSERT_TRUE(service()->is_ready()); 220 ASSERT_TRUE(service()->is_ready());
261 ASSERT_TRUE(registry()->enabled_extensions().is_empty()); 221 ASSERT_TRUE(registry()->enabled_extensions().is_empty());
262 scoped_ptr<BackgroundApplicationListModel> model( 222 scoped_ptr<BackgroundApplicationListModel> model(
263 new BackgroundApplicationListModel(profile_.get())); 223 new BackgroundApplicationListModel(profile_.get()));
264 ASSERT_EQ(0U, model->size()); 224 ASSERT_EQ(0U, model->size());
265 225
266 scoped_refptr<Extension> ext = CreateExtension("extension", false); 226 scoped_refptr<Extension> ext = CreateExtension("extension", false);
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 case 2: 395 case 2:
436 TogglePermission(service(), &extensions, model.get(), &expected, 396 TogglePermission(service(), &extensions, model.get(), &expected,
437 &count); 397 &count);
438 break; 398 break;
439 default: 399 default:
440 NOTREACHED(); 400 NOTREACHED();
441 break; 401 break;
442 } 402 }
443 } 403 }
444 } 404 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698