OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 #include "content/public/browser/navigation_controller.h" | 22 #include "content/public/browser/navigation_controller.h" |
23 #include "content/public/browser/navigation_entry.h" | 23 #include "content/public/browser/navigation_entry.h" |
24 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
25 #include "content/public/common/content_switches.h" | 25 #include "content/public/common/content_switches.h" |
26 #include "content/public/common/page_type.h" | 26 #include "content/public/common/page_type.h" |
27 #include "content/public/test/background_sync_test_util.h" | 27 #include "content/public/test/background_sync_test_util.h" |
28 #include "content/public/test/browser_test_utils.h" | 28 #include "content/public/test/browser_test_utils.h" |
29 #include "extensions/browser/extension_host.h" | 29 #include "extensions/browser/extension_host.h" |
30 #include "extensions/browser/extension_registry.h" | 30 #include "extensions/browser/extension_registry.h" |
31 #include "extensions/browser/process_manager.h" | 31 #include "extensions/browser/process_manager.h" |
32 #include "extensions/common/features/feature_util.h" | |
32 #include "extensions/test/background_page_watcher.h" | 33 #include "extensions/test/background_page_watcher.h" |
33 #include "extensions/test/extension_test_message_listener.h" | 34 #include "extensions/test/extension_test_message_listener.h" |
34 #include "net/test/embedded_test_server/embedded_test_server.h" | 35 #include "net/test/embedded_test_server/embedded_test_server.h" |
35 | 36 |
36 namespace extensions { | 37 namespace extensions { |
37 | 38 |
38 namespace { | 39 namespace { |
39 | 40 |
40 // Pass into ServiceWorkerTest::StartTestFromBackgroundPage to indicate that | 41 // Pass into ServiceWorkerTest::StartTestFromBackgroundPage to indicate that |
41 // registration is expected to succeed. | 42 // registration is expected to succeed. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 if (message_loop_runner_) | 74 if (message_loop_runner_) |
74 message_loop_runner_->Quit(); | 75 message_loop_runner_->Quit(); |
75 } | 76 } |
76 | 77 |
77 bool load_stop_observed_; | 78 bool load_stop_observed_; |
78 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 79 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
79 | 80 |
80 DISALLOW_COPY_AND_ASSIGN(WebContentsLoadStopObserver); | 81 DISALLOW_COPY_AND_ASSIGN(WebContentsLoadStopObserver); |
81 }; | 82 }; |
82 | 83 |
84 class ScopedExtensionAPIInServiceWorkerEnabler { | |
85 public: | |
86 ScopedExtensionAPIInServiceWorkerEnabler() | |
87 : current_value_( | |
88 feature_util::ExtensionAPIEnabledInExtensionServiceWorkers()) { | |
89 feature_util::SetExtensionAPIEnabledInExtensionServiceWorkers(true); | |
90 } | |
91 ~ScopedExtensionAPIInServiceWorkerEnabler() { | |
92 feature_util::SetExtensionAPIEnabledInExtensionServiceWorkers( | |
93 current_value_); | |
94 } | |
95 | |
96 private: | |
97 bool current_value_; | |
98 DISALLOW_COPY_AND_ASSIGN(ScopedExtensionAPIInServiceWorkerEnabler); | |
99 }; | |
100 | |
83 } // namespace | 101 } // namespace |
84 | 102 |
85 class ServiceWorkerTest : public ExtensionApiTest { | 103 class ServiceWorkerTest : public ExtensionApiTest { |
86 public: | 104 public: |
87 ServiceWorkerTest() : current_channel_(version_info::Channel::DEV) {} | 105 ServiceWorkerTest() : current_channel_(version_info::Channel::DEV) {} |
88 | 106 |
89 ~ServiceWorkerTest() override {} | 107 ~ServiceWorkerTest() override {} |
90 | 108 |
91 protected: | 109 protected: |
92 // Returns the ProcessManager for the test's profile. | 110 // Returns the ProcessManager for the test's profile. |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
597 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, NotificationAPI) { | 615 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, NotificationAPI) { |
598 EXPECT_TRUE(RunExtensionSubtest("service_worker/notifications/has_permission", | 616 EXPECT_TRUE(RunExtensionSubtest("service_worker/notifications/has_permission", |
599 "page.html")); | 617 "page.html")); |
600 } | 618 } |
601 | 619 |
602 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, WebAccessibleResourcesFetch) { | 620 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, WebAccessibleResourcesFetch) { |
603 EXPECT_TRUE(RunExtensionSubtest( | 621 EXPECT_TRUE(RunExtensionSubtest( |
604 "service_worker/web_accessible_resources/fetch/", "page.html")); | 622 "service_worker/web_accessible_resources/fetch/", "page.html")); |
605 } | 623 } |
606 | 624 |
625 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, TabsCreate) { | |
626 ScopedExtensionAPIInServiceWorkerEnabler enabler; | |
627 const Extension* extension = LoadExtensionWithFlags( | |
628 test_data_dir_.AppendASCII("service_worker/tabs_create"), kFlagNone); | |
629 ASSERT_TRUE(extension); | |
630 ui_test_utils::NavigateToURL(browser(), | |
631 extension->GetResourceURL("page.html")); | |
632 content::WebContents* web_contents = | |
633 browser()->tab_strip_model()->GetActiveWebContents(); | |
634 | |
635 int starting_tab_count = browser()->tab_strip_model()->count(); | |
636 std::string result; | |
637 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
638 web_contents, "window.runServiceWorker()", &result)); | |
Devlin
2016/04/14 22:34:52
Shouldn't we check |result|?
lazyboy
2016/04/15 00:57:47
Wow, this got deleted somehow.
Fixed.
| |
639 EXPECT_EQ(starting_tab_count + 1, browser()->tab_strip_model()->count()); | |
640 | |
641 // Check extension shutdown path. | |
642 UnloadExtension(extension->id()); | |
643 EXPECT_EQ(starting_tab_count, browser()->tab_strip_model()->count()); | |
644 } | |
645 | |
607 // This test loads a web page that has an iframe pointing to a | 646 // This test loads a web page that has an iframe pointing to a |
608 // chrome-extension:// URL. The URL is listed in the extension's | 647 // chrome-extension:// URL. The URL is listed in the extension's |
609 // web_accessible_resources. Initially the iframe is served from the extension's | 648 // web_accessible_resources. Initially the iframe is served from the extension's |
610 // resource file. After verifying that, we register a Service Worker that | 649 // resource file. After verifying that, we register a Service Worker that |
611 // controls the extension. Further requests to the same resource as before | 650 // controls the extension. Further requests to the same resource as before |
612 // should now be served by the Service Worker. | 651 // should now be served by the Service Worker. |
613 // This test also verifies that if the requested resource exists in the manifest | 652 // This test also verifies that if the requested resource exists in the manifest |
614 // but is not present in the extension directory, the Service Worker can still | 653 // but is not present in the extension directory, the Service Worker can still |
615 // serve the resource file. | 654 // serve the resource file. |
616 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, WebAccessibleResourcesIframeSrc) { | 655 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, WebAccessibleResourcesIframeSrc) { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
739 push_message_listener.set_failure_message("FAIL"); | 778 push_message_listener.set_failure_message("FAIL"); |
740 gcm::IncomingMessage message; | 779 gcm::IncomingMessage message; |
741 message.sender_id = "1234567890"; | 780 message.sender_id = "1234567890"; |
742 message.raw_data = "testdata"; | 781 message.raw_data = "testdata"; |
743 message.decrypted = true; | 782 message.decrypted = true; |
744 push_service()->OnMessage(app_identifier.app_id(), message); | 783 push_service()->OnMessage(app_identifier.app_id(), message); |
745 EXPECT_TRUE(push_message_listener.WaitUntilSatisfied()); | 784 EXPECT_TRUE(push_message_listener.WaitUntilSatisfied()); |
746 } | 785 } |
747 | 786 |
748 } // namespace extensions | 787 } // namespace extensions |
OLD | NEW |