OLD | NEW |
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/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/extension_system.h" |
20 #include "chrome/browser/extensions/permissions_updater.h" | 21 #include "chrome/browser/extensions/permissions_updater.h" |
21 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
22 #include "chrome/common/extensions/extension_manifest_constants.h" | 23 #include "chrome/common/extensions/extension_manifest_constants.h" |
23 #include "chrome/common/extensions/permissions/api_permission.h" | 24 #include "chrome/common/extensions/permissions/api_permission.h" |
24 #include "chrome/common/extensions/permissions/permission_set.h" | 25 #include "chrome/common/extensions/permissions/permission_set.h" |
25 #include "chrome/test/base/testing_profile.h" | 26 #include "chrome/test/base/testing_profile.h" |
26 #include "content/public/browser/notification_registrar.h" | 27 #include "content/public/browser/notification_registrar.h" |
27 #include "content/public/browser/notification_types.h" | 28 #include "content/public/browser/notification_types.h" |
28 #include "content/public/test/test_browser_thread.h" | 29 #include "content/public/test/test_browser_thread.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 } | 116 } |
116 extensions::PermissionsUpdater(service->profile()).RemovePermissions( | 117 extensions::PermissionsUpdater(service->profile()).RemovePermissions( |
117 extension, extension->GetActivePermissions()); | 118 extension, extension->GetActivePermissions()); |
118 } | 119 } |
119 } // namespace | 120 } // namespace |
120 | 121 |
121 // With minimal test logic, verifies behavior over an explicit set of | 122 // With minimal test logic, verifies behavior over an explicit set of |
122 // extensions, of which some are Background Apps and others are not. | 123 // extensions, of which some are Background Apps and others are not. |
123 TEST_F(BackgroundApplicationListModelTest, ExplicitTest) { | 124 TEST_F(BackgroundApplicationListModelTest, ExplicitTest) { |
124 InitializeAndLoadEmptyExtensionService(); | 125 InitializeAndLoadEmptyExtensionService(); |
125 ExtensionService* service = profile_->GetExtensionService(); | 126 ExtensionService* service = extensions::ExtensionSystem::Get(profile_.get())-> |
| 127 extension_service(); |
126 ASSERT_TRUE(service); | 128 ASSERT_TRUE(service); |
127 ASSERT_TRUE(service->is_ready()); | 129 ASSERT_TRUE(service->is_ready()); |
128 ASSERT_TRUE(service->extensions()); | 130 ASSERT_TRUE(service->extensions()); |
129 ASSERT_TRUE(service->extensions()->is_empty()); | 131 ASSERT_TRUE(service->extensions()->is_empty()); |
130 scoped_ptr<BackgroundApplicationListModel> model( | 132 scoped_ptr<BackgroundApplicationListModel> model( |
131 new BackgroundApplicationListModel(profile_.get())); | 133 new BackgroundApplicationListModel(profile_.get())); |
132 ASSERT_EQ(0U, model->size()); | 134 ASSERT_EQ(0U, model->size()); |
133 | 135 |
134 scoped_refptr<Extension> ext1 = CreateExtension("alpha", false); | 136 scoped_refptr<Extension> ext1 = CreateExtension("alpha", false); |
135 scoped_refptr<Extension> ext2 = CreateExtension("bravo", false); | 137 scoped_refptr<Extension> ext2 = CreateExtension("bravo", false); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 ASSERT_EQ(0U, model->size()); | 183 ASSERT_EQ(0U, model->size()); |
182 ASSERT_FALSE(IsBackgroundApp(*ext3)); | 184 ASSERT_FALSE(IsBackgroundApp(*ext3)); |
183 service->UninstallExtension(ext3->id(), false, NULL); | 185 service->UninstallExtension(ext3->id(), false, NULL); |
184 ASSERT_EQ(0U, service->extensions()->size()); | 186 ASSERT_EQ(0U, service->extensions()->size()); |
185 ASSERT_EQ(0U, model->size()); | 187 ASSERT_EQ(0U, model->size()); |
186 } | 188 } |
187 | 189 |
188 // With minimal test logic, verifies behavior with dynamic permissions. | 190 // With minimal test logic, verifies behavior with dynamic permissions. |
189 TEST_F(BackgroundApplicationListModelTest, AddRemovePermissionsTest) { | 191 TEST_F(BackgroundApplicationListModelTest, AddRemovePermissionsTest) { |
190 InitializeAndLoadEmptyExtensionService(); | 192 InitializeAndLoadEmptyExtensionService(); |
191 ExtensionService* service = profile_->GetExtensionService(); | 193 ExtensionService* service = extensions::ExtensionSystem::Get(profile_.get())-> |
| 194 extension_service(); |
192 ASSERT_TRUE(service); | 195 ASSERT_TRUE(service); |
193 ASSERT_TRUE(service->is_ready()); | 196 ASSERT_TRUE(service->is_ready()); |
194 ASSERT_TRUE(service->extensions()); | 197 ASSERT_TRUE(service->extensions()); |
195 ASSERT_TRUE(service->extensions()->is_empty()); | 198 ASSERT_TRUE(service->extensions()->is_empty()); |
196 scoped_ptr<BackgroundApplicationListModel> model( | 199 scoped_ptr<BackgroundApplicationListModel> model( |
197 new BackgroundApplicationListModel(profile_.get())); | 200 new BackgroundApplicationListModel(profile_.get())); |
198 ASSERT_EQ(0U, model->size()); | 201 ASSERT_EQ(0U, model->size()); |
199 | 202 |
200 scoped_refptr<Extension> ext = CreateExtension("extension", false); | 203 scoped_refptr<Extension> ext = CreateExtension("extension", false); |
201 ASSERT_FALSE(ext->HasAPIPermission(APIPermission::kBackground)); | 204 ASSERT_FALSE(ext->HasAPIPermission(APIPermission::kBackground)); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 ASSERT_EQ(*expected, model->size()); | 333 ASSERT_EQ(*expected, model->size()); |
331 } | 334 } |
332 } | 335 } |
333 } | 336 } |
334 } // namespace | 337 } // namespace |
335 | 338 |
336 // Verifies behavior with a pseudo-randomly generated set of actions: Adding and | 339 // Verifies behavior with a pseudo-randomly generated set of actions: Adding and |
337 // removing extensions, of which some are Background Apps and others are not. | 340 // removing extensions, of which some are Background Apps and others are not. |
338 TEST_F(BackgroundApplicationListModelTest, RandomTest) { | 341 TEST_F(BackgroundApplicationListModelTest, RandomTest) { |
339 InitializeAndLoadEmptyExtensionService(); | 342 InitializeAndLoadEmptyExtensionService(); |
340 ExtensionService* service = profile_->GetExtensionService(); | 343 ExtensionService* service = extensions::ExtensionSystem::Get(profile_.get())-> |
| 344 extension_service(); |
341 ASSERT_TRUE(service); | 345 ASSERT_TRUE(service); |
342 ASSERT_TRUE(service->is_ready()); | 346 ASSERT_TRUE(service->is_ready()); |
343 ASSERT_TRUE(service->extensions()); | 347 ASSERT_TRUE(service->extensions()); |
344 ASSERT_TRUE(service->extensions()->is_empty()); | 348 ASSERT_TRUE(service->extensions()->is_empty()); |
345 scoped_ptr<BackgroundApplicationListModel> model( | 349 scoped_ptr<BackgroundApplicationListModel> model( |
346 new BackgroundApplicationListModel(profile_.get())); | 350 new BackgroundApplicationListModel(profile_.get())); |
347 ASSERT_EQ(0U, model->size()); | 351 ASSERT_EQ(0U, model->size()); |
348 | 352 |
349 static const int kIterations = 500; | 353 static const int kIterations = 500; |
350 ExtensionCollection extensions; | 354 ExtensionCollection extensions; |
(...skipping 10 matching lines...) Expand all Loading... |
361 break; | 365 break; |
362 case 2: | 366 case 2: |
363 TogglePermission(service, &extensions, model.get(), &expected, &count); | 367 TogglePermission(service, &extensions, model.get(), &expected, &count); |
364 break; | 368 break; |
365 default: | 369 default: |
366 NOTREACHED(); | 370 NOTREACHED(); |
367 break; | 371 break; |
368 } | 372 } |
369 } | 373 } |
370 } | 374 } |
OLD | NEW |