OLD | NEW |
---|---|
(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 const char* manifest_string = | |
27 "{" | |
28 " 'name': ''," | |
29 " 'manifest_version': 2," | |
30 " 'version': '1'," | |
31 " 'app': {" | |
32 " 'service_worker': {" | |
33 " 'script': 'service_worker.js'" | |
34 " }" | |
35 " }" | |
36 "}"; | |
37 LoadAndExpectError(Manifest(base::test::ParseJsonDictionaryWithSingleQuotes( | |
38 manifest_string).Pass(), | |
39 ""), | |
40 manifest_errors::kServiceWorkerRequiresFlag); | |
41 } | |
42 | |
43 // Checks that an app manifest with a service_worker key but no script fails. | |
44 TEST_F(ExtensionManifestServiceWorkerTest, ServiceWorkerEmpty) { | |
45 CommandLine::ForCurrentProcess()->AppendSwitch( | |
Jeffrey Yasskin
2014/03/04 01:41:48
You have to remove the flag again at the end of th
scheib
2014/03/04 15:34:31
Wonderfully this is no longer the case, base::test
Jeffrey Yasskin
2014/03/04 17:29:15
Oh, great! I will forget that pitfall then. :)
| |
46 switches::kEnableServiceWorker); | |
47 const char* manifest_string = | |
48 "{" | |
49 " 'name': ''," | |
50 " 'manifest_version': 2," | |
51 " 'version': '1'," | |
52 " 'app': {" | |
53 " 'service_worker': {}" // No script specified. | |
54 " }" | |
55 "}"; | |
56 LoadAndExpectError(Manifest(base::test::ParseJsonDictionaryWithSingleQuotes( | |
57 manifest_string).Pass(), | |
58 ""), | |
59 manifest_errors::kBackgroundRequiredForPlatformApps); | |
60 | |
61 const char* manifest_string2 = | |
62 "{" | |
63 " 'name': ''," | |
64 " 'manifest_version': 2," | |
65 " 'version': '1'," | |
66 " 'app': {" | |
67 " 'service_worker': {" | |
68 " 'script': ''" // Empty script. | |
69 " }" | |
70 " }" | |
71 "}"; | |
72 LoadAndExpectError(Manifest(base::test::ParseJsonDictionaryWithSingleQuotes( | |
73 manifest_string2).Pass(), | |
74 ""), | |
75 manifest_errors::kBackgroundRequiredForPlatformApps); | |
76 } | |
77 | |
78 // Checks that an app manifest with a single script is loaded. | |
79 TEST_F(ExtensionManifestServiceWorkerTest, ServiceWorkerScript) { | |
80 CommandLine::ForCurrentProcess()->AppendSwitch( | |
81 switches::kEnableServiceWorker); | |
82 const char* manifest_string = | |
83 "{" | |
84 " 'name': ''," | |
85 " 'manifest_version': 2," | |
86 " 'version': '1'," | |
87 " 'app': {" | |
88 " 'service_worker': {" | |
89 " 'script': 'service_worker.js'" | |
90 " }" | |
91 " }" | |
92 "}"; | |
93 scoped_refptr<Extension> extension(LoadAndExpectSuccess(Manifest( | |
94 base::test::ParseJsonDictionaryWithSingleQuotes(manifest_string).Pass(), | |
95 ""))); | |
96 ASSERT_TRUE(extension.get()); | |
97 EXPECT_EQ("service_worker.js", | |
98 BackgroundInfo::GetServiceWorkerScript(extension.get())); | |
99 | |
100 EXPECT_TRUE(BackgroundInfo::HasServiceWorker(extension.get())); | |
101 } | |
102 | |
103 // Checks that an app manifest with service worker and background script fails. | |
104 TEST_F(ExtensionManifestServiceWorkerTest, ServiceWorkerWithBackgroundScript) { | |
105 CommandLine::ForCurrentProcess()->AppendSwitch( | |
106 switches::kEnableServiceWorker); | |
107 const char* manifest_string = | |
108 "{" | |
109 " 'name': ''," | |
110 " 'manifest_version': 2," | |
111 " 'version': '1'," | |
112 " 'app': {" | |
113 " 'service_worker': {" | |
114 " 'script': 'service_worker.js'" | |
115 " }," | |
not at google - send to devlin
2014/03/03 19:56:07
when do you plan on adding the parsing logic for j
scheib
2014/03/03 20:25:46
After we have a hello world app working.
https://
not at google - send to devlin
2014/03/03 20:34:22
Why? It seems like minimal effort to add it right
scheib
2014/03/03 21:38:00
Discussed offline - it's not lots of work, but it'
| |
116 " 'background': {" | |
117 " 'scripts': [ 'background.js' ]" | |
118 " }" | |
119 " }" | |
120 "}"; | |
121 LoadAndExpectError(Manifest(base::test::ParseJsonDictionaryWithSingleQuotes( | |
122 manifest_string).Pass(), | |
123 ""), | |
124 manifest_errors::kInvalidBackgroundCombination); | |
125 } | |
126 | |
127 } // namespace extensions | |
OLD | NEW |