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

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

Issue 314113010: Remove deprecated permissions functions from Extension (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
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_unittest.h" 18 #include "chrome/browser/extensions/extension_service_unittest.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/common/extension.h" 24 #include "extensions/common/extension.h"
25 #include "extensions/common/manifest_constants.h" 25 #include "extensions/common/manifest_constants.h"
26 #include "extensions/common/permissions/api_permission.h" 26 #include "extensions/common/permissions/api_permission.h"
27 #include "extensions/common/permissions/permission_set.h" 27 #include "extensions/common/permissions/permission_set.h"
28 #include "extensions/common/permissions/permissions_data.h"
28 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
29 30
30 // This value is used to seed the PRNG at the beginning of a sequence of 31 // This value is used to seed the PRNG at the beginning of a sequence of
31 // operations to produce a repeatable sequence. 32 // operations to produce a repeatable sequence.
32 #define RANDOM_SEED (0x33F7A7A7) 33 #define RANDOM_SEED (0x33F7A7A7)
33 34
34 using extensions::APIPermission; 35 using extensions::APIPermission;
35 using extensions::Extension; 36 using extensions::Extension;
36 37
37 // For ExtensionService interface when it requires a path that is not used. 38 // For ExtensionService interface when it requires a path that is not used.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 void AddBackgroundPermission(ExtensionService* service, 133 void AddBackgroundPermission(ExtensionService* service,
133 Extension* extension) { 134 Extension* extension) {
134 if (BackgroundApplicationListModel::IsBackgroundApp(*extension, 135 if (BackgroundApplicationListModel::IsBackgroundApp(*extension,
135 service->profile())) { 136 service->profile())) {
136 return; 137 return;
137 } 138 }
138 139
139 scoped_refptr<Extension> temporary = 140 scoped_refptr<Extension> temporary =
140 CreateExtension(GenerateUniqueExtensionName(), true); 141 CreateExtension(GenerateUniqueExtensionName(), true);
141 scoped_refptr<const extensions::PermissionSet> permissions = 142 scoped_refptr<const extensions::PermissionSet> permissions =
142 temporary->GetActivePermissions(); 143 temporary->permissions_data()->active_permissions();
143 extensions::PermissionsUpdater(service->profile()).AddPermissions( 144 extensions::PermissionsUpdater(service->profile()).AddPermissions(
144 extension, permissions.get()); 145 extension, permissions.get());
145 } 146 }
146 147
147 void RemoveBackgroundPermission(ExtensionService* service, 148 void RemoveBackgroundPermission(ExtensionService* service,
148 Extension* extension) { 149 Extension* extension) {
149 if (!BackgroundApplicationListModel::IsBackgroundApp(*extension, 150 if (!BackgroundApplicationListModel::IsBackgroundApp(*extension,
150 service->profile())) { 151 service->profile())) {
151 return; 152 return;
152 } 153 }
153 extensions::PermissionsUpdater(service->profile()) 154 extensions::PermissionsUpdater(service->profile()).RemovePermissions(
154 .RemovePermissions(extension, extension->GetActivePermissions().get()); 155 extension, extension->permissions_data()->active_permissions().get());
155 } 156 }
156 } // namespace 157 } // namespace
157 158
158 // Crashes on Mac tryslaves. 159 // Crashes on Mac tryslaves.
159 // http://crbug.com/165458 160 // http://crbug.com/165458
160 #if defined(OS_MACOSX) || defined(OS_LINUX) 161 #if defined(OS_MACOSX) || defined(OS_LINUX)
161 #define MAYBE_ExplicitTest DISABLED_ExplicitTest 162 #define MAYBE_ExplicitTest DISABLED_ExplicitTest
162 #else 163 #else
163 #define MAYBE_ExplicitTest ExplicitTest 164 #define MAYBE_ExplicitTest ExplicitTest
164 #endif 165 #endif
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 extension_service(); 313 extension_service();
313 ASSERT_TRUE(service); 314 ASSERT_TRUE(service);
314 ASSERT_TRUE(service->is_ready()); 315 ASSERT_TRUE(service->is_ready());
315 ASSERT_TRUE(service->extensions()); 316 ASSERT_TRUE(service->extensions());
316 ASSERT_TRUE(service->extensions()->is_empty()); 317 ASSERT_TRUE(service->extensions()->is_empty());
317 scoped_ptr<BackgroundApplicationListModel> model( 318 scoped_ptr<BackgroundApplicationListModel> model(
318 new BackgroundApplicationListModel(profile_.get())); 319 new BackgroundApplicationListModel(profile_.get()));
319 ASSERT_EQ(0U, model->size()); 320 ASSERT_EQ(0U, model->size());
320 321
321 scoped_refptr<Extension> ext = CreateExtension("extension", false); 322 scoped_refptr<Extension> ext = CreateExtension("extension", false);
322 ASSERT_FALSE(ext->HasAPIPermission(APIPermission::kBackground)); 323 ASSERT_FALSE(
324 ext->permissions_data()->HasAPIPermission(APIPermission::kBackground));
323 scoped_refptr<Extension> bgapp = CreateExtension("application", true); 325 scoped_refptr<Extension> bgapp = CreateExtension("application", true);
324 ASSERT_TRUE(bgapp->HasAPIPermission(APIPermission::kBackground)); 326 ASSERT_TRUE(
327 bgapp->permissions_data()->HasAPIPermission(APIPermission::kBackground));
325 ASSERT_TRUE(service->extensions() != NULL); 328 ASSERT_TRUE(service->extensions() != NULL);
326 ASSERT_EQ(0U, service->extensions()->size()); 329 ASSERT_EQ(0U, service->extensions()->size());
327 ASSERT_EQ(0U, model->size()); 330 ASSERT_EQ(0U, model->size());
328 331
329 // Add one (non-background) extension and one background application 332 // Add one (non-background) extension and one background application
330 ASSERT_FALSE(IsBackgroundApp(*ext.get())); 333 ASSERT_FALSE(IsBackgroundApp(*ext.get()));
331 service->AddExtension(ext.get()); 334 service->AddExtension(ext.get());
332 ASSERT_EQ(1U, service->extensions()->size()); 335 ASSERT_EQ(1U, service->extensions()->size());
333 ASSERT_EQ(0U, model->size()); 336 ASSERT_EQ(0U, model->size());
334 ASSERT_TRUE(IsBackgroundApp(*bgapp.get())); 337 ASSERT_TRUE(IsBackgroundApp(*bgapp.get()));
335 service->AddExtension(bgapp.get()); 338 service->AddExtension(bgapp.get());
336 ASSERT_EQ(2U, service->extensions()->size()); 339 ASSERT_EQ(2U, service->extensions()->size());
337 ASSERT_EQ(1U, model->size()); 340 ASSERT_EQ(1U, model->size());
338 341
339 // Change permissions back and forth 342 // Change permissions back and forth
340 AddBackgroundPermission(service, ext.get()); 343 AddBackgroundPermission(service, ext.get());
341 ASSERT_TRUE(ext->HasAPIPermission(APIPermission::kBackground)); 344 ASSERT_TRUE(
345 ext->permissions_data()->HasAPIPermission(APIPermission::kBackground));
342 ASSERT_EQ(2U, service->extensions()->size()); 346 ASSERT_EQ(2U, service->extensions()->size());
343 ASSERT_EQ(2U, model->size()); 347 ASSERT_EQ(2U, model->size());
344 RemoveBackgroundPermission(service, bgapp.get()); 348 RemoveBackgroundPermission(service, bgapp.get());
345 ASSERT_FALSE(bgapp->HasAPIPermission(APIPermission::kBackground)); 349 ASSERT_FALSE(
350 bgapp->permissions_data()->HasAPIPermission(APIPermission::kBackground));
346 ASSERT_EQ(2U, service->extensions()->size()); 351 ASSERT_EQ(2U, service->extensions()->size());
347 ASSERT_EQ(1U, model->size()); 352 ASSERT_EQ(1U, model->size());
348 RemoveBackgroundPermission(service, ext.get()); 353 RemoveBackgroundPermission(service, ext.get());
349 ASSERT_FALSE(ext->HasAPIPermission(APIPermission::kBackground)); 354 ASSERT_FALSE(
355 ext->permissions_data()->HasAPIPermission(APIPermission::kBackground));
350 ASSERT_EQ(2U, service->extensions()->size()); 356 ASSERT_EQ(2U, service->extensions()->size());
351 ASSERT_EQ(0U, model->size()); 357 ASSERT_EQ(0U, model->size());
352 AddBackgroundPermission(service, bgapp.get()); 358 AddBackgroundPermission(service, bgapp.get());
353 ASSERT_TRUE(bgapp->HasAPIPermission(APIPermission::kBackground)); 359 ASSERT_TRUE(
360 bgapp->permissions_data()->HasAPIPermission(APIPermission::kBackground));
354 ASSERT_EQ(2U, service->extensions()->size()); 361 ASSERT_EQ(2U, service->extensions()->size());
355 ASSERT_EQ(1U, model->size()); 362 ASSERT_EQ(1U, model->size());
356 } 363 }
357 364
358 typedef std::set<scoped_refptr<Extension> > ExtensionCollection; 365 typedef std::set<scoped_refptr<Extension> > ExtensionCollection;
359 366
360 namespace { 367 namespace {
361 void AddExtension(ExtensionService* service, 368 void AddExtension(ExtensionService* service,
362 ExtensionCollection* extensions, 369 ExtensionCollection* extensions,
363 BackgroundApplicationListModel* model, 370 BackgroundApplicationListModel* model,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 break; 490 break;
484 case 2: 491 case 2:
485 TogglePermission(service, &extensions, model.get(), &expected, &count); 492 TogglePermission(service, &extensions, model.get(), &expected, &count);
486 break; 493 break;
487 default: 494 default:
488 NOTREACHED(); 495 NOTREACHED();
489 break; 496 break;
490 } 497 }
491 } 498 }
492 } 499 }
OLDNEW
« no previous file with comments | « chrome/browser/background/background_application_list_model.cc ('k') | chrome/browser/chrome_content_browser_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698