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/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_prefs.h" |
23 #include "extensions/browser/extension_system.h" | 24 #include "extensions/browser/extension_system.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. |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 149 |
149 void RemoveBackgroundPermission(ExtensionService* service, | 150 void RemoveBackgroundPermission(ExtensionService* service, |
150 Extension* extension) { | 151 Extension* extension) { |
151 if (!BackgroundApplicationListModel::IsBackgroundApp(*extension, | 152 if (!BackgroundApplicationListModel::IsBackgroundApp(*extension, |
152 service->profile())) { | 153 service->profile())) { |
153 return; | 154 return; |
154 } | 155 } |
155 extensions::PermissionsUpdater(service->profile()).RemovePermissions( | 156 extensions::PermissionsUpdater(service->profile()).RemovePermissions( |
156 extension, extension->permissions_data()->active_permissions().get()); | 157 extension, extension->permissions_data()->active_permissions().get()); |
157 } | 158 } |
| 159 |
| 160 void AddEphemeralApp(const Extension* extension, ExtensionService* service) { |
| 161 extensions::ExtensionPrefs* prefs = |
| 162 extensions::ExtensionPrefs::Get(service->profile()); |
| 163 ASSERT_TRUE(prefs); |
| 164 prefs->OnExtensionInstalled(extension, |
| 165 extensions::Extension::ENABLED, |
| 166 syncer::StringOrdinal(), |
| 167 extensions::kInstallFlagIsEphemeral, |
| 168 std::string()); |
| 169 |
| 170 service->AddExtension(extension); |
| 171 } |
| 172 |
158 } // namespace | 173 } // namespace |
159 | 174 |
160 // Crashes on Mac tryslaves. | 175 // Crashes on Mac tryslaves. |
161 // http://crbug.com/165458 | 176 // http://crbug.com/165458 |
162 #if defined(OS_MACOSX) || defined(OS_LINUX) | 177 #if defined(OS_MACOSX) || defined(OS_LINUX) |
163 #define MAYBE_ExplicitTest DISABLED_ExplicitTest | 178 #define MAYBE_ExplicitTest DISABLED_ExplicitTest |
164 #else | 179 #else |
165 #define MAYBE_ExplicitTest ExplicitTest | 180 #define MAYBE_ExplicitTest ExplicitTest |
166 #endif | 181 #endif |
167 // With minimal test logic, verifies behavior over an explicit set of | 182 // With minimal test logic, verifies behavior over an explicit set of |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 bgapp2->id(), ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL); | 323 bgapp2->id(), ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL); |
309 ASSERT_EQ(1U, service->extensions()->size()); | 324 ASSERT_EQ(1U, service->extensions()->size()); |
310 ASSERT_EQ(1U, model->size()); | 325 ASSERT_EQ(1U, model->size()); |
311 ASSERT_TRUE(IsBackgroundApp(*bgapp3.get())); | 326 ASSERT_TRUE(IsBackgroundApp(*bgapp3.get())); |
312 service->UninstallExtension( | 327 service->UninstallExtension( |
313 bgapp3->id(), ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL); | 328 bgapp3->id(), ExtensionService::UNINSTALL_REASON_FOR_TESTING, NULL); |
314 ASSERT_EQ(0U, service->extensions()->size()); | 329 ASSERT_EQ(0U, service->extensions()->size()); |
315 ASSERT_EQ(0U, model->size()); | 330 ASSERT_EQ(0U, model->size()); |
316 } | 331 } |
317 | 332 |
| 333 // Verifies that an ephemeral app with push messaging permissions cannot trigger |
| 334 // background mode. |
| 335 TEST_F(BackgroundApplicationListModelTest, EphemeralAppTest) { |
| 336 InitializeAndLoadEmptyExtensionService(); |
| 337 ExtensionService* service = extensions::ExtensionSystem::Get(profile_.get())-> |
| 338 extension_service(); |
| 339 ASSERT_TRUE(service); |
| 340 ASSERT_TRUE(service->is_ready()); |
| 341 ASSERT_TRUE(service->extensions()); |
| 342 ASSERT_TRUE(service->extensions()->is_empty()); |
| 343 scoped_ptr<BackgroundApplicationListModel> model( |
| 344 new BackgroundApplicationListModel(profile_.get())); |
| 345 ASSERT_EQ(0U, model->size()); |
318 | 346 |
| 347 scoped_refptr<Extension> installed = |
| 348 CreateExtensionBase("installed", false, PUSH_MESSAGING_PERMISSION); |
| 349 scoped_refptr<Extension> ephemeral = |
| 350 CreateExtensionBase("ephemeral", false, PUSH_MESSAGING_PERMISSION); |
| 351 |
| 352 // Installed app with push messaging permissions can trigger background mode. |
| 353 ASSERT_TRUE(IsBackgroundApp(*installed.get())); |
| 354 service->AddExtension(installed.get()); |
| 355 ASSERT_EQ(1U, service->extensions()->size()); |
| 356 ASSERT_EQ(1U, model->size()); |
| 357 // An ephemeral app with push messaging permissions should not trigger |
| 358 // background mode. |
| 359 AddEphemeralApp(ephemeral.get(), service); |
| 360 ASSERT_FALSE(IsBackgroundApp(*ephemeral.get())); |
| 361 ASSERT_EQ(2U, service->extensions()->size()); |
| 362 ASSERT_EQ(1U, model->size()); |
| 363 |
| 364 // If the ephemeral app becomes promoted to an installed app, it can now |
| 365 // trigger background mode. |
| 366 service->PromoteEphemeralApp(ephemeral.get(), false /*from sync*/); |
| 367 ASSERT_TRUE(IsBackgroundApp(*ephemeral.get())); |
| 368 ASSERT_EQ(2U, service->extensions()->size()); |
| 369 ASSERT_EQ(2U, model->size()); |
| 370 } |
319 | 371 |
320 // With minimal test logic, verifies behavior with dynamic permissions. | 372 // With minimal test logic, verifies behavior with dynamic permissions. |
321 TEST_F(BackgroundApplicationListModelTest, AddRemovePermissionsTest) { | 373 TEST_F(BackgroundApplicationListModelTest, AddRemovePermissionsTest) { |
322 InitializeAndLoadEmptyExtensionService(); | 374 InitializeAndLoadEmptyExtensionService(); |
323 ExtensionService* service = extensions::ExtensionSystem::Get(profile_.get())-> | 375 ExtensionService* service = extensions::ExtensionSystem::Get(profile_.get())-> |
324 extension_service(); | 376 extension_service(); |
325 ASSERT_TRUE(service); | 377 ASSERT_TRUE(service); |
326 ASSERT_TRUE(service->is_ready()); | 378 ASSERT_TRUE(service->is_ready()); |
327 ASSERT_TRUE(service->extensions()); | 379 ASSERT_TRUE(service->extensions()); |
328 ASSERT_TRUE(service->extensions()->is_empty()); | 380 ASSERT_TRUE(service->extensions()->is_empty()); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 break; | 554 break; |
503 case 2: | 555 case 2: |
504 TogglePermission(service, &extensions, model.get(), &expected, &count); | 556 TogglePermission(service, &extensions, model.get(), &expected, &count); |
505 break; | 557 break; |
506 default: | 558 default: |
507 NOTREACHED(); | 559 NOTREACHED(); |
508 break; | 560 break; |
509 } | 561 } |
510 } | 562 } |
511 } | 563 } |
OLD | NEW |