Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / common / extensions / manifest_tests / extension_manifests_service_worker_unittest.cc
blob10f4de83bf0405d068a822f6d68108c33f8fea98
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
3 // found in the LICENSE file.
5 #include "base/command_line.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "base/test/values_test_util.h"
8 #include "base/values.h"
9 #include "chrome/common/extensions/features/feature_channel.h"
10 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
11 #include "content/public/common/content_switches.h"
12 #include "extensions/common/constants.h"
13 #include "extensions/common/error_utils.h"
14 #include "extensions/common/extension.h"
15 #include "extensions/common/manifest_constants.h"
16 #include "extensions/common/manifest_handlers/background_info.h"
17 #include "testing/gtest/include/gtest/gtest.h"
19 namespace extensions {
21 class ExtensionManifestServiceWorkerTest : public ExtensionManifestTest {
22 public:
23 ExtensionManifestServiceWorkerTest()
24 : trunk_channel_(chrome::VersionInfo::CHANNEL_UNKNOWN) {}
26 void AddServiceWorkerCommandLineSwitch() {
27 CHECK(!CommandLine::ForCurrentProcess()->HasSwitch(
28 switches::kEnableServiceWorker));
29 CommandLine::ForCurrentProcess()->AppendSwitch(
30 switches::kEnableServiceWorker);
33 // "app.service_worker" is restricted to trunk in _manifest_features.json.
34 extensions::ScopedCurrentChannel trunk_channel_;
37 // Checks that a service_worker key is ignored without enable-service-worker
38 // switch. When service workers are enabled by default please remove this
39 // test.
40 TEST_F(ExtensionManifestServiceWorkerTest, ServiceWorkerCommandLineRequired) {
41 CHECK(!CommandLine::ForCurrentProcess()->HasSwitch(
42 ::switches::kEnableServiceWorker));
43 LoadFromStringAndExpectError(
44 "{"
45 " 'name': '',"
46 " 'manifest_version': 2,"
47 " 'version': '1',"
48 " 'app': {"
49 " 'service_worker': {"
50 " 'script': 'service_worker.js'"
51 " }"
52 " }"
53 "}",
54 manifest_errors::kServiceWorkerRequiresFlag);
57 // Checks that an app manifest with a service_worker key but no script fails.
58 TEST_F(ExtensionManifestServiceWorkerTest, ServiceWorkerEmpty) {
59 AddServiceWorkerCommandLineSwitch();
60 LoadFromStringAndExpectError(
61 "{"
62 " 'name': '',"
63 " 'manifest_version': 2,"
64 " 'version': '1',"
65 " 'app': {"
66 " 'service_worker': {}" // No script specified.
67 " }"
68 "}",
69 manifest_errors::kBackgroundRequiredForPlatformApps);
71 LoadFromStringAndExpectError(
72 "{"
73 " 'name': '',"
74 " 'manifest_version': 2,"
75 " 'version': '1',"
76 " 'app': {"
77 " 'service_worker': {"
78 " 'script': ''" // Empty script.
79 " }"
80 " }"
81 "}",
82 manifest_errors::kBackgroundRequiredForPlatformApps);
85 // Checks that an app manifest with a single script is loaded.
86 TEST_F(ExtensionManifestServiceWorkerTest, ServiceWorkerScript) {
87 AddServiceWorkerCommandLineSwitch();
88 scoped_refptr<Extension> extension(LoadFromStringAndExpectSuccess(
89 "{"
90 " 'name': '',"
91 " 'manifest_version': 2,"
92 " 'version': '1',"
93 " 'app': {"
94 " 'service_worker': {"
95 " 'script': 'service_worker.js'"
96 " }"
97 " }"
98 "}"));
99 ASSERT_TRUE(extension.get());
100 // "app.service_worker" key exists and access is permitted.
101 EXPECT_TRUE(extension->manifest()->HasPath("app.service_worker"));
102 EXPECT_EQ("service_worker.js",
103 BackgroundInfo::GetServiceWorkerScript(extension.get()));
105 EXPECT_TRUE(BackgroundInfo::HasServiceWorker(extension.get()));
108 // Checks that an app manifest with service worker and background script fails.
109 TEST_F(ExtensionManifestServiceWorkerTest, ServiceWorkerWithBackgroundScript) {
110 AddServiceWorkerCommandLineSwitch();
111 LoadFromStringAndExpectError(
113 " 'name': '',"
114 " 'manifest_version': 2,"
115 " 'version': '1',"
116 " 'app': {"
117 " 'service_worker': {"
118 " 'script': 'service_worker.js'"
119 " },"
120 " 'background': {"
121 " 'scripts': [ 'background.js' ]"
122 " }"
123 " }"
124 "}",
125 manifest_errors::kInvalidBackgroundCombination);
128 } // namespace extensions