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 18 matching lines...) Expand all Loading... | |
29 #include "content/public/browser/navigation_controller.h" | 29 #include "content/public/browser/navigation_controller.h" |
30 #include "content/public/browser/navigation_entry.h" | 30 #include "content/public/browser/navigation_entry.h" |
31 #include "content/public/browser/service_worker_context.h" | 31 #include "content/public/browser/service_worker_context.h" |
32 #include "content/public/browser/storage_partition.h" | 32 #include "content/public/browser/storage_partition.h" |
33 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
34 #include "content/public/common/content_switches.h" | 34 #include "content/public/common/content_switches.h" |
35 #include "content/public/common/origin_util.h" | 35 #include "content/public/common/origin_util.h" |
36 #include "content/public/common/page_type.h" | 36 #include "content/public/common/page_type.h" |
37 #include "content/public/test/background_sync_test_util.h" | 37 #include "content/public/test/background_sync_test_util.h" |
38 #include "content/public/test/browser_test_utils.h" | 38 #include "content/public/test/browser_test_utils.h" |
39 #include "content/public/test/service_worker_test_helpers.h" | |
39 #include "extensions/browser/extension_host.h" | 40 #include "extensions/browser/extension_host.h" |
40 #include "extensions/browser/extension_registry.h" | 41 #include "extensions/browser/extension_registry.h" |
41 #include "extensions/browser/process_manager.h" | 42 #include "extensions/browser/process_manager.h" |
42 #include "extensions/test/background_page_watcher.h" | 43 #include "extensions/test/background_page_watcher.h" |
43 #include "extensions/test/extension_test_message_listener.h" | 44 #include "extensions/test/extension_test_message_listener.h" |
44 #include "net/dns/mock_host_resolver.h" | 45 #include "net/dns/mock_host_resolver.h" |
45 #include "net/test/embedded_test_server/embedded_test_server.h" | 46 #include "net/test/embedded_test_server/embedded_test_server.h" |
47 #include "url/url_constants.h" | |
46 | 48 |
47 namespace extensions { | 49 namespace extensions { |
48 | 50 |
49 namespace { | 51 namespace { |
50 | 52 |
51 // Pass into ServiceWorkerTest::StartTestFromBackgroundPage to indicate that | 53 // Pass into ServiceWorkerTest::StartTestFromBackgroundPage to indicate that |
52 // registration is expected to succeed. | 54 // registration is expected to succeed. |
53 std::string* const kExpectSuccess = nullptr; | 55 std::string* const kExpectSuccess = nullptr; |
54 | 56 |
55 void DoNothingWithBool(bool b) {} | 57 void DoNothingWithBool(bool b) {} |
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
675 ui_test_utils::NavigateToURL(browser(), | 677 ui_test_utils::NavigateToURL(browser(), |
676 extension->GetResourceURL("page.html")); | 678 extension->GetResourceURL("page.html")); |
677 content::WebContents* web_contents = | 679 content::WebContents* web_contents = |
678 browser()->tab_strip_model()->GetActiveWebContents(); | 680 browser()->tab_strip_model()->GetActiveWebContents(); |
679 std::string result; | 681 std::string result; |
680 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 682 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
681 web_contents, "window.runEventTest()", &result)); | 683 web_contents, "window.runEventTest()", &result)); |
682 ASSERT_EQ("chrome.tabs.onUpdated callback", result); | 684 ASSERT_EQ("chrome.tabs.onUpdated callback", result); |
683 } | 685 } |
684 | 686 |
687 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, EventsToStoppedWorker) { | |
688 // Extensions APIs from SW are only enabled on trunk. | |
689 ScopedCurrentChannel current_channel_override(version_info::Channel::UNKNOWN); | |
690 const Extension* extension = LoadExtensionWithFlags( | |
691 test_data_dir_.AppendASCII("service_worker/events_to_stopped_worker"), | |
692 kFlagNone); | |
693 ASSERT_TRUE(extension); | |
694 ui_test_utils::NavigateToURL(browser(), | |
695 extension->GetResourceURL("page.html")); | |
696 content::WebContents* web_contents = | |
697 browser()->tab_strip_model()->GetActiveWebContents(); | |
698 { | |
699 std::string result; | |
700 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
701 web_contents, "window.runServiceWorker()", &result)); | |
702 ASSERT_EQ("ready", result); | |
703 | |
704 { | |
Devlin
2017/06/20 20:31:19
nit: do these scopes need to be nested?
lazyboy
2017/06/22 02:46:56
Done.
| |
705 base::RunLoop stop_called_run_loop; | |
Devlin
2017/06/20 20:31:19
nit: this is a bit weird, since the run loop isn't
lazyboy
2017/06/22 02:46:56
Done.
| |
706 content::StoragePartition* storage_partition = | |
707 content::BrowserContext::GetDefaultStoragePartition( | |
708 browser()->profile()); | |
709 content::StopServiceWorkerAtOrigin( | |
710 storage_partition->GetServiceWorkerContext(), | |
711 // The service worker is registered at the top level scope. | |
712 extension->url(), stop_called_run_loop.QuitClosure()); | |
713 stop_called_run_loop.Run(); | |
714 } | |
715 } | |
716 | |
717 std::string result; | |
718 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
719 web_contents, "window.createTabThenUpdate()", &result)); | |
720 ASSERT_EQ("chrome.tabs.onUpdated callback", result); | |
721 } | |
722 | |
685 // Tests that worker ref count increments while extension API function is | 723 // Tests that worker ref count increments while extension API function is |
686 // active. | 724 // active. |
687 | 725 |
688 // Flaky on Linux and ChromeOS, https://crbug.com/702126 | 726 // Flaky on Linux and ChromeOS, https://crbug.com/702126 |
689 #if defined(OS_LINUX) | 727 #if defined(OS_LINUX) |
690 #define MAYBE_WorkerRefCount DISABLED_WorkerRefCount | 728 #define MAYBE_WorkerRefCount DISABLED_WorkerRefCount |
691 #else | 729 #else |
692 #define MAYBE_WorkerRefCount WorkerRefCount | 730 #define MAYBE_WorkerRefCount WorkerRefCount |
693 #endif | 731 #endif |
694 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, MAYBE_WorkerRefCount) { | 732 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, MAYBE_WorkerRefCount) { |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
898 message.sender_id = "1234567890"; | 936 message.sender_id = "1234567890"; |
899 message.raw_data = "testdata"; | 937 message.raw_data = "testdata"; |
900 message.decrypted = true; | 938 message.decrypted = true; |
901 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure()); | 939 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure()); |
902 push_service()->OnMessage(app_identifier.app_id(), message); | 940 push_service()->OnMessage(app_identifier.app_id(), message); |
903 EXPECT_TRUE(push_message_listener.WaitUntilSatisfied()); | 941 EXPECT_TRUE(push_message_listener.WaitUntilSatisfied()); |
904 run_loop.Run(); // Wait until the message is handled by push service. | 942 run_loop.Run(); // Wait until the message is handled by push service. |
905 } | 943 } |
906 | 944 |
907 } // namespace extensions | 945 } // namespace extensions |
OLD | NEW |