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

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: Moved test utils out of base 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 public:
23 void AddServiceWorkerCommandLineSwitch() {
24 CHECK(!CommandLine::ForCurrentProcess()->HasSwitch(
25 switches::kEnableServiceWorker));
26 CommandLine::ForCurrentProcess()->AppendSwitch(
27 switches::kEnableServiceWorker);
28 }
29 };
30
31 // Checks that a service_worker key is ignored without enable-service-worker
32 // switch. When service workers are enabled by default please remove this
33 // test.
34 TEST_F(ExtensionManifestServiceWorkerTest, ServiceWorkerCommandLineRequired) {
35 CHECK(!CommandLine::ForCurrentProcess()->HasSwitch(
36 ::switches::kEnableServiceWorker));
37 LoadFromStringAndExpectError(
38 "{"
39 " 'name': '',"
40 " 'manifest_version': 2,"
41 " 'version': '1',"
42 " 'app': {"
43 " 'service_worker': {"
44 " 'script': 'service_worker.js'"
45 " }"
46 " }"
47 "}",
48 manifest_errors::kServiceWorkerRequiresFlag);
49 }
50
51 // Checks that an app manifest with a service_worker key but no script fails.
52 TEST_F(ExtensionManifestServiceWorkerTest, ServiceWorkerEmpty) {
53 AddServiceWorkerCommandLineSwitch();
54 LoadFromStringAndExpectError(
55 "{"
56 " 'name': '',"
57 " 'manifest_version': 2,"
58 " 'version': '1',"
59 " 'app': {"
60 " 'service_worker': {}" // No script specified.
61 " }"
62 "}",
63 manifest_errors::kBackgroundRequiredForPlatformApps);
64
65 LoadFromStringAndExpectError(
66 "{"
67 " 'name': '',"
68 " 'manifest_version': 2,"
69 " 'version': '1',"
70 " 'app': {"
71 " 'service_worker': {"
72 " 'script': ''" // Empty script.
73 " }"
74 " }"
75 "}",
76 manifest_errors::kBackgroundRequiredForPlatformApps);
77 }
78
79 // Checks that an app manifest with a single script is loaded.
80 TEST_F(ExtensionManifestServiceWorkerTest, ServiceWorkerScript) {
81 AddServiceWorkerCommandLineSwitch();
82 scoped_refptr<Extension> extension(LoadFromStringAndExpectSuccess(
83 "{"
84 " 'name': '',"
85 " 'manifest_version': 2,"
86 " 'version': '1',"
87 " 'app': {"
88 " 'service_worker': {"
89 " 'script': 'service_worker.js'"
90 " }"
91 " }"
92 "}"));
93 ASSERT_TRUE(extension.get());
94 EXPECT_EQ("service_worker.js",
95 BackgroundInfo::GetServiceWorkerScript(extension.get()));
96
97 EXPECT_TRUE(BackgroundInfo::HasServiceWorker(extension.get()));
98 }
99
100 // Checks that an app manifest with service worker and background script fails.
101 TEST_F(ExtensionManifestServiceWorkerTest, ServiceWorkerWithBackgroundScript) {
102 AddServiceWorkerCommandLineSwitch();
103 LoadFromStringAndExpectError(
104 "{"
105 " 'name': '',"
106 " 'manifest_version': 2,"
107 " 'version': '1',"
108 " 'app': {"
109 " 'service_worker': {"
110 " 'script': 'service_worker.js'"
111 " },"
112 " 'background': {"
113 " 'scripts': [ 'background.js' ]"
114 " }"
115 " }"
116 "}",
117 manifest_errors::kInvalidBackgroundCombination);
118 }
119
120 } // 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