Index: chrome/browser/extensions/service_worker_apitest.cc |
diff --git a/chrome/browser/extensions/service_worker_apitest.cc b/chrome/browser/extensions/service_worker_apitest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5c0d2c6e16c78858dfa86dd969424c75427d001d |
--- /dev/null |
+++ b/chrome/browser/extensions/service_worker_apitest.cc |
@@ -0,0 +1,50 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/extensions/extension_apitest.h" |
+#include "extensions/test/extension_test_message_listener.h" |
+ |
+namespace extensions { |
+ |
+class ServiceWorkerTest : public ExtensionApiTest { |
+ public: |
+ // Set the channel to "trunk" since service workers are restricted to trunk. |
+ ServiceWorkerTest() |
+ : current_channel_(chrome::VersionInfo::CHANNEL_UNKNOWN) {} |
+ |
+ ~ServiceWorkerTest() override {} |
+ |
+ private: |
+ ScopedCurrentChannel current_channel_; |
+ DISALLOW_COPY_AND_ASSIGN(ServiceWorkerTest); |
+}; |
+ |
+// This should fail because there are changes to be made to |
Devlin
2015/07/13 21:22:11
nit: The "this should fail" almost looks like it's
annekao
2015/07/13 22:21:29
Done.
|
+// successfully register a service worker. |
+IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, RegisterServiceWorkersOnTrunk) { |
+ ExtensionTestMessageListener listener(false); |
+ ASSERT_FALSE(RunExtensionTest("service_worker/register")) << message_; |
+ ASSERT_TRUE(listener.WaitUntilSatisfied()); |
+ ASSERT_EQ( |
+ "SecurityError: Failed to register a ServiceWorker: No URL is " |
+ "associated with the caller's document.", |
+ listener.message()); |
+} |
+ |
+// This feature is restricted to trunk, so on dev it should have existing |
+// behavior - which is for it to fail. |
+IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, CannotRegisterServiceWorkersOnDev) { |
+ ScopedCurrentChannel current_channel_override( |
+ chrome::VersionInfo::CHANNEL_DEV); |
+ ExtensionTestMessageListener listener(false); |
+ ASSERT_FALSE(RunExtensionTest("service_worker/register")) << message_; |
+ ASSERT_TRUE(listener.WaitUntilSatisfied()); |
+ ASSERT_EQ( |
+ "SecurityError: Failed to register a ServiceWorker: The URL " |
+ "protocol of the current origin ('chrome-extension://" + |
+ GetSingleLoadedExtension()->id() + "') is not supported.", |
+ listener.message()); |
+} |
+ |
+} // namespace extensions |