Chromium Code Reviews| 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 13 matching lines...) Expand all Loading... | |
| 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/test/background_page_watcher.h" | 32 #include "extensions/test/background_page_watcher.h" |
| 33 #include "extensions/test/extension_test_message_listener.h" | 33 #include "extensions/test/extension_test_message_listener.h" |
| 34 #include "net/dns/mock_host_resolver.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. |
| 42 std::string* const kExpectSuccess = nullptr; | 43 std::string* const kExpectSuccess = nullptr; |
| 43 | 44 |
| (...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 667 // present in the extension directory. Expect the resources of the iframe to | 668 // present in the extension directory. Expect the resources of the iframe to |
| 668 // be served by the Service Worker. | 669 // be served by the Service Worker. |
| 669 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 670 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| 670 web_contents, | 671 web_contents, |
| 671 base::StringPrintf("window.testIframe('%s', 'iframe_non_existent.html')", | 672 base::StringPrintf("window.testIframe('%s', 'iframe_non_existent.html')", |
| 672 extension->id().c_str()), | 673 extension->id().c_str()), |
| 673 &result)); | 674 &result)); |
| 674 EXPECT_EQ("FROM_SW_RESOURCE", result); | 675 EXPECT_EQ("FROM_SW_RESOURCE", result); |
| 675 } | 676 } |
| 676 | 677 |
| 678 // Tests that service worker serves resources even if they are embedded in an | |
| 679 // insecure context. | |
| 680 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, | |
| 681 WebAccessibleResourcesInsecureIframe) { | |
| 682 const Extension* extension = LoadExtensionWithFlags( | |
| 683 test_data_dir_.AppendASCII( | |
| 684 "service_worker/web_accessible_resources/iframe_src"), | |
| 685 kFlagNone); | |
| 686 ASSERT_TRUE(extension); | |
| 687 ASSERT_TRUE(StartEmbeddedTestServer()); | |
| 688 host_resolver()->AddRule("a.com", "127.0.0.1"); | |
| 689 GURL page_url = | |
| 690 embedded_test_server()->GetURL("a.com", | |
| 691 "/extensions/api_test/service_worker/" | |
| 692 "web_accessible_resources/webpage.html"); | |
| 693 GURL::Replacements replace_host_and_scheme; | |
| 694 replace_host_and_scheme.SetHostStr("a.com"); | |
| 695 replace_host_and_scheme.SetSchemeStr("http"); | |
| 696 page_url = page_url.ReplaceComponents(replace_host_and_scheme); | |
|
falken
2016/06/06 06:38:13
Oops, I meant to delete the use of GURL::Replaceme
| |
| 697 | |
| 698 content::WebContents* web_contents = AddTab(browser(), page_url); | |
| 699 std::string result; | |
| 700 // webpage.html will create an iframe pointing to a resource from |extension|. | |
| 701 // Expect the resource to be served by the extension. | |
| 702 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | |
| 703 web_contents, base::StringPrintf("window.testIframe('%s', 'iframe.html')", | |
| 704 extension->id().c_str()), | |
| 705 &result)); | |
| 706 EXPECT_EQ("FROM_EXTENSION_RESOURCE", result); | |
| 707 | |
| 708 ExtensionTestMessageListener service_worker_ready_listener("SW_READY", false); | |
| 709 EXPECT_TRUE(ExecuteScriptInBackgroundPageNoWait( | |
| 710 extension->id(), "window.registerServiceWorker()")); | |
| 711 EXPECT_TRUE(service_worker_ready_listener.WaitUntilSatisfied()); | |
| 712 | |
| 713 result.clear(); | |
| 714 // webpage.html will create another iframe pointing to a resource from | |
| 715 // |extension| as before. But this time, the resource should be be served | |
| 716 // from the Service Worker. | |
| 717 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | |
| 718 web_contents, base::StringPrintf("window.testIframe('%s', 'iframe.html')", | |
| 719 extension->id().c_str()), | |
| 720 &result)); | |
| 721 EXPECT_EQ("FROM_SW_RESOURCE", result); | |
| 722 | |
| 723 result.clear(); | |
| 724 // webpage.html will create yet another iframe pointing to a resource that | |
| 725 // exists in the extension manifest's web_accessible_resources, but is not | |
| 726 // present in the extension directory. Expect the resources of the iframe to | |
| 727 // be served by the Service Worker. | |
| 728 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | |
| 729 web_contents, | |
| 730 base::StringPrintf("window.testIframe('%s', 'iframe_non_existent.html')", | |
| 731 extension->id().c_str()), | |
| 732 &result)); | |
| 733 EXPECT_EQ("FROM_SW_RESOURCE", result); | |
| 734 } | |
| 735 | |
| 677 IN_PROC_BROWSER_TEST_F(ServiceWorkerBackgroundSyncTest, Sync) { | 736 IN_PROC_BROWSER_TEST_F(ServiceWorkerBackgroundSyncTest, Sync) { |
| 678 const Extension* extension = LoadExtensionWithFlags( | 737 const Extension* extension = LoadExtensionWithFlags( |
| 679 test_data_dir_.AppendASCII("service_worker/sync"), kFlagNone); | 738 test_data_dir_.AppendASCII("service_worker/sync"), kFlagNone); |
| 680 ASSERT_TRUE(extension); | 739 ASSERT_TRUE(extension); |
| 681 ui_test_utils::NavigateToURL(browser(), | 740 ui_test_utils::NavigateToURL(browser(), |
| 682 extension->GetResourceURL("page.html")); | 741 extension->GetResourceURL("page.html")); |
| 683 content::WebContents* web_contents = | 742 content::WebContents* web_contents = |
| 684 browser()->tab_strip_model()->GetActiveWebContents(); | 743 browser()->tab_strip_model()->GetActiveWebContents(); |
| 685 | 744 |
| 686 // Prevent firing by going offline. | 745 // Prevent firing by going offline. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 754 message.sender_id = "1234567890"; | 813 message.sender_id = "1234567890"; |
| 755 message.raw_data = "testdata"; | 814 message.raw_data = "testdata"; |
| 756 message.decrypted = true; | 815 message.decrypted = true; |
| 757 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure()); | 816 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure()); |
| 758 push_service()->OnMessage(app_identifier.app_id(), message); | 817 push_service()->OnMessage(app_identifier.app_id(), message); |
| 759 EXPECT_TRUE(push_message_listener.WaitUntilSatisfied()); | 818 EXPECT_TRUE(push_message_listener.WaitUntilSatisfied()); |
| 760 run_loop.Run(); // Wait until the message is handled by push service. | 819 run_loop.Run(); // Wait until the message is handled by push service. |
| 761 } | 820 } |
| 762 | 821 |
| 763 } // namespace extensions | 822 } // namespace extensions |
| OLD | NEW |