Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(703)

Side by Side Diff: chrome/common/extensions/manifest_tests/extension_manifests_service_worker_unittest.cc

Issue 178253007: Parse manifest file with app.service_worker.script. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
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"
18
19 namespace extensions {
20
21 class ExtensionManifestServiceWorkerTest : public ExtensionManifestTest {};
22
23 // Checks that a service_worker key is ignored without enable-service-worker
24 // switch.
25 TEST_F(ExtensionManifestServiceWorkerTest, ServiceWorkerCommandLineRequired) {
26 CHECK(!CommandLine::ForCurrentProcess()->HasSwitch(
27 ::switches::kEnableServiceWorker));
28 const char* manifest_string =
29 "{"
30 " 'name': '',"
31 " 'manifest_version': 2,"
32 " 'version': '1',"
33 " 'app': {"
34 " 'service_worker': {"
35 " 'script': 'service_worker.js'"
36 " }"
37 " }"
38 "}";
39 LoadAndExpectError(Manifest(base::test::ParseJsonDictionaryWithSingleQuotes(
40 manifest_string).Pass()),
41 manifest_errors::kServiceWorkerRequiresFlag);
42 }
43
44 // Checks that an app manifest with a service_worker key but no script fails.
45 TEST_F(ExtensionManifestServiceWorkerTest, ServiceWorkerEmpty) {
46 CHECK(!CommandLine::ForCurrentProcess()->HasSwitch(
47 ::switches::kEnableServiceWorker));
48 CommandLine::ForCurrentProcess()->AppendSwitch(
49 switches::kEnableServiceWorker);
50 const char* manifest_string =
51 "{"
52 " 'name': '',"
53 " 'manifest_version': 2,"
54 " 'version': '1',"
55 " 'app': {"
56 " 'service_worker': {}" // No script specified.
57 " }"
58 "}";
59 LoadAndExpectError(Manifest(base::test::ParseJsonDictionaryWithSingleQuotes(
60 manifest_string).Pass()),
61 manifest_errors::kBackgroundRequiredForPlatformApps);
62
63 const char* manifest_string2 =
64 "{"
65 " 'name': '',"
66 " 'manifest_version': 2,"
67 " 'version': '1',"
68 " 'app': {"
69 " 'service_worker': {"
70 " 'script': ''" // Empty script.
71 " }"
72 " }"
73 "}";
74 LoadAndExpectError(Manifest(base::test::ParseJsonDictionaryWithSingleQuotes(
75 manifest_string2).Pass()),
76 manifest_errors::kBackgroundRequiredForPlatformApps);
77 }
78
79 // Checks that an app manifest with a single script is loaded.
80 TEST_F(ExtensionManifestServiceWorkerTest, ServiceWorkerScript) {
81 CHECK(!CommandLine::ForCurrentProcess()->HasSwitch(
82 ::switches::kEnableServiceWorker));
83 CommandLine::ForCurrentProcess()->AppendSwitch(
84 switches::kEnableServiceWorker);
85 const char* manifest_string =
86 "{"
87 " 'name': '',"
88 " 'manifest_version': 2,"
89 " 'version': '1',"
90 " 'app': {"
91 " 'service_worker': {"
92 " 'script': 'service_worker.js'"
93 " }"
94 " }"
95 "}";
96 scoped_refptr<Extension> extension(LoadAndExpectSuccess(
97 Manifest(base::test::ParseJsonDictionaryWithSingleQuotes(manifest_string)
98 .Pass())));
Jeffrey Yasskin 2014/03/04 17:29:16 You probably don't need a .Pass() here, since the
scheib 2014/03/04 17:51:24 Done.
99 ASSERT_TRUE(extension.get());
100 EXPECT_EQ("service_worker.js",
101 BackgroundInfo::GetServiceWorkerScript(extension.get()));
102
103 EXPECT_TRUE(BackgroundInfo::HasServiceWorker(extension.get()));
104 }
105
106 // Checks that an app manifest with service worker and background script fails.
107 TEST_F(ExtensionManifestServiceWorkerTest, ServiceWorkerWithBackgroundScript) {
108 CHECK(!CommandLine::ForCurrentProcess()->HasSwitch(
109 ::switches::kEnableServiceWorker));
110 CommandLine::ForCurrentProcess()->AppendSwitch(
111 switches::kEnableServiceWorker);
112 const char* manifest_string =
113 "{"
114 " 'name': '',"
115 " 'manifest_version': 2,"
116 " 'version': '1',"
117 " 'app': {"
118 " 'service_worker': {"
119 " 'script': 'service_worker.js'"
120 " },"
121 " 'background': {"
122 " 'scripts': [ 'background.js' ]"
123 " }"
124 " }"
125 "}";
126 LoadAndExpectError(Manifest(base::test::ParseJsonDictionaryWithSingleQuotes(
127 manifest_string).Pass()),
128 manifest_errors::kInvalidBackgroundCombination);
129 }
130
131 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/manifest_tests/extension_manifest_test.cc ('k') | chrome/common/extensions/manifest_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698