| OLD | NEW |
| 1 // Copyright (c) 2011 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/file_path.h" | 13 #include "base/file_path.h" |
| 14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
| 17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 18 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
| 19 #include "chrome/browser/extensions/extension_service_unittest.h" | 19 #include "chrome/browser/extensions/extension_service_unittest.h" |
| 20 #include "chrome/browser/extensions/permissions_updater.h" |
| 20 #include "chrome/common/extensions/extension.h" | 21 #include "chrome/common/extensions/extension.h" |
| 21 #include "chrome/test/base/testing_profile.h" | 22 #include "chrome/test/base/testing_profile.h" |
| 22 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
| 23 #include "content/public/browser/notification_types.h" | 24 #include "content/public/browser/notification_types.h" |
| 24 #include "content/test/test_browser_thread.h" | 25 #include "content/test/test_browser_thread.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 27 |
| 27 // This value is used to seed the PRNG at the beginning of a sequence of | 28 // This value is used to seed the PRNG at the beginning of a sequence of |
| 28 // operations to produce a repeatable sequence. | 29 // operations to produce a repeatable sequence. |
| 29 #define RANDOM_SEED (0x33F7A7A7) | 30 #define RANDOM_SEED (0x33F7A7A7) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 } | 82 } |
| 82 | 83 |
| 83 void AddBackgroundPermission(ExtensionService* service, | 84 void AddBackgroundPermission(ExtensionService* service, |
| 84 Extension* extension) { | 85 Extension* extension) { |
| 85 if (BackgroundApplicationListModel::IsBackgroundApp(*extension)) return; | 86 if (BackgroundApplicationListModel::IsBackgroundApp(*extension)) return; |
| 86 | 87 |
| 87 static scoped_refptr<Extension> temporary = | 88 static scoped_refptr<Extension> temporary = |
| 88 CreateExtension(GenerateUniqueExtensionName(), true); | 89 CreateExtension(GenerateUniqueExtensionName(), true); |
| 89 scoped_refptr<const ExtensionPermissionSet> permissions = | 90 scoped_refptr<const ExtensionPermissionSet> permissions = |
| 90 temporary->GetActivePermissions(); | 91 temporary->GetActivePermissions(); |
| 91 ExtensionPermissionsManager(service).AddPermissions( | 92 extensions::PermissionsUpdater(service->profile()).AddPermissions( |
| 92 extension, permissions.get()); | 93 extension, permissions.get()); |
| 93 } | 94 } |
| 94 | 95 |
| 95 void RemoveBackgroundPermission(ExtensionService* service, | 96 void RemoveBackgroundPermission(ExtensionService* service, |
| 96 Extension* extension) { | 97 Extension* extension) { |
| 97 if (!BackgroundApplicationListModel::IsBackgroundApp(*extension)) return; | 98 if (!BackgroundApplicationListModel::IsBackgroundApp(*extension)) return; |
| 98 ExtensionPermissionsManager(service).RemovePermissions( | 99 extensions::PermissionsUpdater(service->profile()).RemovePermissions( |
| 99 extension, extension->GetActivePermissions()); | 100 extension, extension->GetActivePermissions()); |
| 100 } | 101 } |
| 101 } // namespace | 102 } // namespace |
| 102 | 103 |
| 103 // With minimal test logic, verifies behavior over an explicit set of | 104 // With minimal test logic, verifies behavior over an explicit set of |
| 104 // extensions, of which some are Background Apps and others are not. | 105 // extensions, of which some are Background Apps and others are not. |
| 105 TEST_F(BackgroundApplicationListModelTest, ExplicitTest) { | 106 TEST_F(BackgroundApplicationListModelTest, ExplicitTest) { |
| 106 InitializeAndLoadEmptyExtensionService(); | 107 InitializeAndLoadEmptyExtensionService(); |
| 107 ExtensionService* service = profile_->GetExtensionService(); | 108 ExtensionService* service = profile_->GetExtensionService(); |
| 108 ASSERT_TRUE(service); | 109 ASSERT_TRUE(service); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 extensions->erase(cursor); | 262 extensions->erase(cursor); |
| 262 --*count; | 263 --*count; |
| 263 ASSERT_EQ(*count, extensions->size()); | 264 ASSERT_EQ(*count, extensions->size()); |
| 264 service->UninstallExtension(extension->id(), false, NULL); | 265 service->UninstallExtension(extension->id(), false, NULL); |
| 265 ASSERT_EQ(*count, service->extensions()->size()); | 266 ASSERT_EQ(*count, service->extensions()->size()); |
| 266 ASSERT_EQ(*expected, model->size()); | 267 ASSERT_EQ(*expected, model->size()); |
| 267 } | 268 } |
| 268 } | 269 } |
| 269 | 270 |
| 270 void TogglePermission(ExtensionService* service, | 271 void TogglePermission(ExtensionService* service, |
| 271 ExtensionCollection* extensions, | 272 ExtensionCollection* extensions, |
| 272 BackgroundApplicationListModel* model, | 273 BackgroundApplicationListModel* model, |
| 273 size_t* expected, | 274 size_t* expected, |
| 274 size_t* count) { | 275 size_t* count) { |
| 275 ExtensionCollection::iterator cursor = extensions->begin(); | 276 ExtensionCollection::iterator cursor = extensions->begin(); |
| 276 if (cursor == extensions->end()) { | 277 if (cursor == extensions->end()) { |
| 277 // Nothing to toggle. Just verify accounting. | 278 // Nothing to toggle. Just verify accounting. |
| 278 ASSERT_EQ(0U, *count); | 279 ASSERT_EQ(0U, *count); |
| 279 ASSERT_EQ(0U, *expected); | 280 ASSERT_EQ(0U, *expected); |
| 280 ASSERT_EQ(0U, service->extensions()->size()); | 281 ASSERT_EQ(0U, service->extensions()->size()); |
| 281 ASSERT_EQ(0U, model->size()); | 282 ASSERT_EQ(0U, model->size()); |
| 282 } else { | 283 } else { |
| 283 // Randomly select which extension to toggle. | 284 // Randomly select which extension to toggle. |
| 284 if (extensions->size() > 1) { | 285 if (extensions->size() > 1) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 break; | 334 break; |
| 334 case 2: | 335 case 2: |
| 335 TogglePermission(service, &extensions, model.get(), &expected, &count); | 336 TogglePermission(service, &extensions, model.get(), &expected, &count); |
| 336 break; | 337 break; |
| 337 default: | 338 default: |
| 338 NOTREACHED(); | 339 NOTREACHED(); |
| 339 break; | 340 break; |
| 340 } | 341 } |
| 341 } | 342 } |
| 342 } | 343 } |
| OLD | NEW |