annekao | 3868550 | 2015-07-14 17:46:39 | [diff] [blame^] | 1 | // Copyright 2015 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 "chrome/browser/extensions/extension_apitest.h" |
| 6 | #include "extensions/test/extension_test_message_listener.h" |
| 7 | |
| 8 | namespace extensions { |
| 9 | |
| 10 | class ServiceWorkerTest : public ExtensionApiTest { |
| 11 | public: |
| 12 | // Set the channel to "trunk" since service workers are restricted to trunk. |
| 13 | ServiceWorkerTest() |
| 14 | : current_channel_(chrome::VersionInfo::CHANNEL_UNKNOWN) {} |
| 15 | |
| 16 | ~ServiceWorkerTest() override {} |
| 17 | |
| 18 | private: |
| 19 | ScopedCurrentChannel current_channel_; |
| 20 | DISALLOW_COPY_AND_ASSIGN(ServiceWorkerTest); |
| 21 | }; |
| 22 | |
| 23 | IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, RegisterServiceWorkersOnTrunk) { |
| 24 | ExtensionTestMessageListener listener(false); |
| 25 | // This should fail because there are changes to be made to |
| 26 | // successfully register a service worker. |
| 27 | ASSERT_FALSE(RunExtensionTest("service_worker/register")) << message_; |
| 28 | ASSERT_TRUE(listener.WaitUntilSatisfied()); |
| 29 | ASSERT_EQ( |
| 30 | "SecurityError: Failed to register a ServiceWorker: No URL is " |
| 31 | "associated with the caller's document.", |
| 32 | listener.message()); |
| 33 | } |
| 34 | |
| 35 | // This feature is restricted to trunk, so on dev it should have existing |
| 36 | // behavior - which is for it to fail. |
| 37 | IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, CannotRegisterServiceWorkersOnDev) { |
| 38 | ScopedCurrentChannel current_channel_override( |
| 39 | chrome::VersionInfo::CHANNEL_DEV); |
| 40 | ExtensionTestMessageListener listener(false); |
| 41 | ASSERT_FALSE(RunExtensionTest("service_worker/register")) << message_; |
| 42 | ASSERT_TRUE(listener.WaitUntilSatisfied()); |
| 43 | ASSERT_EQ( |
| 44 | "SecurityError: Failed to register a ServiceWorker: The URL " |
| 45 | "protocol of the current origin ('chrome-extension://" + |
| 46 | GetSingleLoadedExtension()->id() + "') is not supported.", |
| 47 | listener.message()); |
| 48 | } |
| 49 | |
| 50 | } // namespace extensions |