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

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

Issue 398083002: Add "UninstallReason" parameter to ExtensionRegistryObserver::OnExtensionUninstalled. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix header file. Created 6 years, 5 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
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"
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "chrome/browser/extensions/extension_service.h" 17 #include "chrome/browser/extensions/extension_service.h"
18 #include "chrome/browser/extensions/extension_service_test_base.h" 18 #include "chrome/browser/extensions/extension_service_test_base.h"
19 #include "chrome/browser/extensions/permissions_updater.h" 19 #include "chrome/browser/extensions/permissions_updater.h"
20 #include "chrome/test/base/testing_profile.h" 20 #include "chrome/test/base/testing_profile.h"
21 #include "content/public/browser/notification_registrar.h" 21 #include "content/public/browser/notification_registrar.h"
22 #include "content/public/browser/notification_types.h" 22 #include "content/public/browser/notification_types.h"
23 #include "extensions/browser/extension_system.h" 23 #include "extensions/browser/extension_system.h"
24 #include "extensions/browser/uninstall_reason.h"
24 #include "extensions/common/extension.h" 25 #include "extensions/common/extension.h"
25 #include "extensions/common/manifest_constants.h" 26 #include "extensions/common/manifest_constants.h"
26 #include "extensions/common/permissions/api_permission.h" 27 #include "extensions/common/permissions/api_permission.h"
27 #include "extensions/common/permissions/permission_set.h" 28 #include "extensions/common/permissions/permission_set.h"
28 #include "extensions/common/permissions/permissions_data.h" 29 #include "extensions/common/permissions/permissions_data.h"
29 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
30 31
31 // This value is used to seed the PRNG at the beginning of a sequence of 32 // This value is used to seed the PRNG at the beginning of a sequence of
32 // operations to produce a repeatable sequence. 33 // operations to produce a repeatable sequence.
33 #define RANDOM_SEED (0x33F7A7A7) 34 #define RANDOM_SEED (0x33F7A7A7)
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 ASSERT_EQ(4U, service->extensions()->size()); 206 ASSERT_EQ(4U, service->extensions()->size());
206 ASSERT_EQ(2U, model->size()); 207 ASSERT_EQ(2U, model->size());
207 ASSERT_FALSE(IsBackgroundApp(*ext3.get())); 208 ASSERT_FALSE(IsBackgroundApp(*ext3.get()));
208 service->AddExtension(ext3.get()); 209 service->AddExtension(ext3.get());
209 ASSERT_EQ(5U, service->extensions()->size()); 210 ASSERT_EQ(5U, service->extensions()->size());
210 ASSERT_EQ(2U, model->size()); 211 ASSERT_EQ(2U, model->size());
211 212
212 // Remove in FIFO order. 213 // Remove in FIFO order.
213 ASSERT_FALSE(IsBackgroundApp(*ext1.get())); 214 ASSERT_FALSE(IsBackgroundApp(*ext1.get()));
214 service->UninstallExtension( 215 service->UninstallExtension(
215 ext1->id(), ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL); 216 ext1->id(), extensions::UNINSTALL_REASON_FOR_TESTING, NULL);
216 ASSERT_EQ(4U, service->extensions()->size()); 217 ASSERT_EQ(4U, service->extensions()->size());
217 ASSERT_EQ(2U, model->size()); 218 ASSERT_EQ(2U, model->size());
218 ASSERT_TRUE(IsBackgroundApp(*bgapp1.get())); 219 ASSERT_TRUE(IsBackgroundApp(*bgapp1.get()));
219 service->UninstallExtension( 220 service->UninstallExtension(
220 bgapp1->id(), ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL); 221 bgapp1->id(), extensions::UNINSTALL_REASON_FOR_TESTING, NULL);
221 ASSERT_EQ(3U, service->extensions()->size()); 222 ASSERT_EQ(3U, service->extensions()->size());
222 ASSERT_EQ(1U, model->size()); 223 ASSERT_EQ(1U, model->size());
223 ASSERT_FALSE(IsBackgroundApp(*ext2.get())); 224 ASSERT_FALSE(IsBackgroundApp(*ext2.get()));
224 service->UninstallExtension( 225 service->UninstallExtension(
225 ext2->id(), ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL); 226 ext2->id(), extensions::UNINSTALL_REASON_FOR_TESTING, NULL);
226 ASSERT_EQ(2U, service->extensions()->size()); 227 ASSERT_EQ(2U, service->extensions()->size());
227 ASSERT_EQ(1U, model->size()); 228 ASSERT_EQ(1U, model->size());
228 ASSERT_TRUE(IsBackgroundApp(*bgapp2.get())); 229 ASSERT_TRUE(IsBackgroundApp(*bgapp2.get()));
229 service->UninstallExtension( 230 service->UninstallExtension(
230 bgapp2->id(), ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL); 231 bgapp2->id(), extensions::UNINSTALL_REASON_FOR_TESTING, NULL);
231 ASSERT_EQ(1U, service->extensions()->size()); 232 ASSERT_EQ(1U, service->extensions()->size());
232 ASSERT_EQ(0U, model->size()); 233 ASSERT_EQ(0U, model->size());
233 ASSERT_FALSE(IsBackgroundApp(*ext3.get())); 234 ASSERT_FALSE(IsBackgroundApp(*ext3.get()));
234 service->UninstallExtension( 235 service->UninstallExtension(
235 ext3->id(), ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL); 236 ext3->id(), extensions::UNINSTALL_REASON_FOR_TESTING, NULL);
236 ASSERT_EQ(0U, service->extensions()->size()); 237 ASSERT_EQ(0U, service->extensions()->size());
237 ASSERT_EQ(0U, model->size()); 238 ASSERT_EQ(0U, model->size());
238 } 239 }
239 240
240 // Verifies that pushMessaging also triggers background detection, except 241 // Verifies that pushMessaging also triggers background detection, except
241 // when extension is in a whitelist. 242 // when extension is in a whitelist.
242 TEST_F(BackgroundApplicationListModelTest, PushMessagingTest) { 243 TEST_F(BackgroundApplicationListModelTest, PushMessagingTest) {
243 InitializeAndLoadEmptyExtensionService(); 244 InitializeAndLoadEmptyExtensionService();
244 ExtensionService* service = extensions::ExtensionSystem::Get(profile_.get())-> 245 ExtensionService* service = extensions::ExtensionSystem::Get(profile_.get())->
245 extension_service(); 246 extension_service();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 service->AddExtension(ext2.get()); 278 service->AddExtension(ext2.get());
278 ASSERT_EQ(3U, service->extensions()->size()); 279 ASSERT_EQ(3U, service->extensions()->size());
279 ASSERT_EQ(1U, model->size()); 280 ASSERT_EQ(1U, model->size());
280 ASSERT_TRUE(IsBackgroundApp(*bgapp2.get())); 281 ASSERT_TRUE(IsBackgroundApp(*bgapp2.get()));
281 service->AddExtension(bgapp2.get()); 282 service->AddExtension(bgapp2.get());
282 ASSERT_EQ(4U, service->extensions()->size()); 283 ASSERT_EQ(4U, service->extensions()->size());
283 ASSERT_EQ(2U, model->size()); 284 ASSERT_EQ(2U, model->size());
284 // Need to remove ext2 because it uses same id as bgapp3. 285 // Need to remove ext2 because it uses same id as bgapp3.
285 ASSERT_FALSE(IsBackgroundApp(*ext2.get())); 286 ASSERT_FALSE(IsBackgroundApp(*ext2.get()));
286 service->UninstallExtension( 287 service->UninstallExtension(
287 ext2->id(), ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL); 288 ext2->id(), extensions::UNINSTALL_REASON_FOR_TESTING, NULL);
288 ASSERT_EQ(3U, service->extensions()->size()); 289 ASSERT_EQ(3U, service->extensions()->size());
289 ASSERT_EQ(2U, model->size()); 290 ASSERT_EQ(2U, model->size());
290 ASSERT_TRUE(IsBackgroundApp(*bgapp3.get())); 291 ASSERT_TRUE(IsBackgroundApp(*bgapp3.get()));
291 service->AddExtension(bgapp3.get()); 292 service->AddExtension(bgapp3.get());
292 ASSERT_EQ(4U, service->extensions()->size()); 293 ASSERT_EQ(4U, service->extensions()->size());
293 ASSERT_EQ(3U, model->size()); 294 ASSERT_EQ(3U, model->size());
294 295
295 // Remove in FIFO order. 296 // Remove in FIFO order.
296 ASSERT_FALSE(IsBackgroundApp(*ext1.get())); 297 ASSERT_FALSE(IsBackgroundApp(*ext1.get()));
297 service->UninstallExtension( 298 service->UninstallExtension(
298 ext1->id(), ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL); 299 ext1->id(), extensions::UNINSTALL_REASON_FOR_TESTING, NULL);
299 ASSERT_EQ(3U, service->extensions()->size()); 300 ASSERT_EQ(3U, service->extensions()->size());
300 ASSERT_EQ(3U, model->size()); 301 ASSERT_EQ(3U, model->size());
301 ASSERT_TRUE(IsBackgroundApp(*bgapp1.get())); 302 ASSERT_TRUE(IsBackgroundApp(*bgapp1.get()));
302 service->UninstallExtension( 303 service->UninstallExtension(
303 bgapp1->id(), ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL); 304 bgapp1->id(), extensions::UNINSTALL_REASON_FOR_TESTING, NULL);
304 ASSERT_EQ(2U, service->extensions()->size()); 305 ASSERT_EQ(2U, service->extensions()->size());
305 ASSERT_EQ(2U, model->size()); 306 ASSERT_EQ(2U, model->size());
306 ASSERT_TRUE(IsBackgroundApp(*bgapp2.get())); 307 ASSERT_TRUE(IsBackgroundApp(*bgapp2.get()));
307 service->UninstallExtension( 308 service->UninstallExtension(
308 bgapp2->id(), ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL); 309 bgapp2->id(), extensions::UNINSTALL_REASON_FOR_TESTING, NULL);
309 ASSERT_EQ(1U, service->extensions()->size()); 310 ASSERT_EQ(1U, service->extensions()->size());
310 ASSERT_EQ(1U, model->size()); 311 ASSERT_EQ(1U, model->size());
311 ASSERT_TRUE(IsBackgroundApp(*bgapp3.get())); 312 ASSERT_TRUE(IsBackgroundApp(*bgapp3.get()));
312 service->UninstallExtension( 313 service->UninstallExtension(
313 bgapp3->id(), ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL); 314 bgapp3->id(), extensions::UNINSTALL_REASON_FOR_TESTING, NULL);
314 ASSERT_EQ(0U, service->extensions()->size()); 315 ASSERT_EQ(0U, service->extensions()->size());
315 ASSERT_EQ(0U, model->size()); 316 ASSERT_EQ(0U, model->size());
316 } 317 }
317 318
318 319
319 320
320 // With minimal test logic, verifies behavior with dynamic permissions. 321 // With minimal test logic, verifies behavior with dynamic permissions.
321 TEST_F(BackgroundApplicationListModelTest, AddRemovePermissionsTest) { 322 TEST_F(BackgroundApplicationListModelTest, AddRemovePermissionsTest) {
322 InitializeAndLoadEmptyExtensionService(); 323 InitializeAndLoadEmptyExtensionService();
323 ExtensionService* service = extensions::ExtensionSystem::Get(profile_.get())-> 324 ExtensionService* service = extensions::ExtensionSystem::Get(profile_.get())->
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 scoped_refptr<Extension> extension = cursor->get(); 422 scoped_refptr<Extension> extension = cursor->get();
422 std::string id = extension->id(); 423 std::string id = extension->id();
423 if (BackgroundApplicationListModel::IsBackgroundApp(*extension.get(), 424 if (BackgroundApplicationListModel::IsBackgroundApp(*extension.get(),
424 service->profile())) { 425 service->profile())) {
425 --*expected; 426 --*expected;
426 } 427 }
427 extensions->erase(cursor); 428 extensions->erase(cursor);
428 --*count; 429 --*count;
429 ASSERT_EQ(*count, extensions->size()); 430 ASSERT_EQ(*count, extensions->size());
430 service->UninstallExtension( 431 service->UninstallExtension(
431 extension->id(), ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL); 432 extension->id(), extensions::UNINSTALL_REASON_FOR_TESTING, NULL);
432 ASSERT_EQ(*count, service->extensions()->size()); 433 ASSERT_EQ(*count, service->extensions()->size());
433 ASSERT_EQ(*expected, model->size()); 434 ASSERT_EQ(*expected, model->size());
434 } 435 }
435 } 436 }
436 437
437 void TogglePermission(ExtensionService* service, 438 void TogglePermission(ExtensionService* service,
438 ExtensionCollection* extensions, 439 ExtensionCollection* extensions,
439 BackgroundApplicationListModel* model, 440 BackgroundApplicationListModel* model,
440 size_t* expected, 441 size_t* expected,
441 size_t* count) { 442 size_t* count) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 break; 503 break;
503 case 2: 504 case 2:
504 TogglePermission(service, &extensions, model.get(), &expected, &count); 505 TogglePermission(service, &extensions, model.get(), &expected, &count);
505 break; 506 break;
506 default: 507 default:
507 NOTREACHED(); 508 NOTREACHED();
508 break; 509 break;
509 } 510 }
510 } 511 }
511 } 512 }
OLDNEW
« no previous file with comments | « chrome/browser/apps/shortcut_manager.cc ('k') | chrome/browser/extensions/activity_log/activity_log.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698