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 cannot trigger background mode. | |
334 TEST_F(BackgroundApplicationListModelTest, EphemeralAppTest) { | |
335 InitializeAndLoadEmptyExtensionService(); | |
336 ExtensionService* service = extensions::ExtensionSystem::Get(profile_.get())-> | |
337 extension_service(); | |
338 ASSERT_TRUE(service); | |
339 ASSERT_TRUE(service->is_ready()); | |
340 ASSERT_TRUE(service->extensions()); | |
341 ASSERT_TRUE(service->extensions()->is_empty()); | |
342 scoped_ptr<BackgroundApplicationListModel> model( | |
343 new BackgroundApplicationListModel(profile_.get())); | |
344 ASSERT_EQ(0U, model->size()); | |
318 | 345 |
346 scoped_refptr<Extension> installed = | |
347 CreateExtensionBase("installed", false, PUSH_MESSAGING_PERMISSION); | |
348 scoped_refptr<Extension> ephemeral = | |
349 CreateExtensionBase("ephemeral", false, PUSH_MESSAGING_PERMISSION); | |
350 scoped_refptr<Extension> background = CreateExtension("background", true); | |
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 // An ephemeral app with the background permission should not trigger | |
364 // background mode. | |
365 AddEphemeralApp(background.get(), service); | |
366 ASSERT_FALSE(IsBackgroundApp(*background.get())); | |
367 ASSERT_EQ(3U, service->extensions()->size()); | |
368 ASSERT_EQ(1U, model->size()); | |
369 | |
370 // If the ephemeral app becomes promoted to an installed app, it can now | |
371 // trigger background mode. | |
372 service->PromoteEphemeralApp(ephemeral.get(), false /*from sync*/); | |
Andrew T Wilson (Slow)
2014/07/23 13:34:32
Ideally, we'd also have a BackgroundModeManagerTes
| |
373 ASSERT_TRUE(IsBackgroundApp(*ephemeral.get())); | |
374 ASSERT_EQ(3U, service->extensions()->size()); | |
375 ASSERT_EQ(2U, model->size()); | |
376 } | |
319 | 377 |
320 // With minimal test logic, verifies behavior with dynamic permissions. | 378 // With minimal test logic, verifies behavior with dynamic permissions. |
321 TEST_F(BackgroundApplicationListModelTest, AddRemovePermissionsTest) { | 379 TEST_F(BackgroundApplicationListModelTest, AddRemovePermissionsTest) { |
322 InitializeAndLoadEmptyExtensionService(); | 380 InitializeAndLoadEmptyExtensionService(); |
323 ExtensionService* service = extensions::ExtensionSystem::Get(profile_.get())-> | 381 ExtensionService* service = extensions::ExtensionSystem::Get(profile_.get())-> |
324 extension_service(); | 382 extension_service(); |
325 ASSERT_TRUE(service); | 383 ASSERT_TRUE(service); |
326 ASSERT_TRUE(service->is_ready()); | 384 ASSERT_TRUE(service->is_ready()); |
327 ASSERT_TRUE(service->extensions()); | 385 ASSERT_TRUE(service->extensions()); |
328 ASSERT_TRUE(service->extensions()->is_empty()); | 386 ASSERT_TRUE(service->extensions()->is_empty()); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
502 break; | 560 break; |
503 case 2: | 561 case 2: |
504 TogglePermission(service, &extensions, model.get(), &expected, &count); | 562 TogglePermission(service, &extensions, model.get(), &expected, &count); |
505 break; | 563 break; |
506 default: | 564 default: |
507 NOTREACHED(); | 565 NOTREACHED(); |
508 break; | 566 break; |
509 } | 567 } |
510 } | 568 } |
511 } | 569 } |
OLD | NEW |