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 "base/bind_helpers.h" | 5 #include "base/bind_helpers.h" |
| 6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 10 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 562 // should fail. | 562 // should fail. |
| 563 // Note that this also tests that service workers can be registered from tabs. | 563 // Note that this also tests that service workers can be registered from tabs. |
| 564 EXPECT_TRUE(RunExtensionSubtest("service_worker/no_background", "page.html")); | 564 EXPECT_TRUE(RunExtensionSubtest("service_worker/no_background", "page.html")); |
| 565 } | 565 } |
| 566 | 566 |
| 567 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, NotificationAPI) { | 567 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, NotificationAPI) { |
| 568 EXPECT_TRUE(RunExtensionSubtest("service_worker/notifications/has_permission", | 568 EXPECT_TRUE(RunExtensionSubtest("service_worker/notifications/has_permission", |
| 569 "page.html")); | 569 "page.html")); |
| 570 } | 570 } |
| 571 | 571 |
| 572 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, WebAccessibleResourcesFetch) { | |
| 573 EXPECT_TRUE(RunExtensionSubtest("service_worker/web_accessible_resources", | |
| 574 "page.html")); | |
| 575 } | |
| 576 | |
| 577 // This test loads a web page that has an iframe pointing to a | |
| 578 // chrome-extension:// URL. The URL is listed in the extension's | |
| 579 // web_accessible_resources. Initially the iframe is served from the extension's | |
| 580 // resource file. After verifying that, we register a Service Worker that | |
|
Devlin
2015/12/17 17:37:34
Do we actually need a real resource file here? I'
lazyboy
2015/12/17 19:27:22
No, we don't.
I'm envisioning the use case of
| |
| 581 // controls the extension. Further requests to the same resource as before | |
| 582 // should now be served by the Service Worker. | |
| 583 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, WebAccessibleResourcesIframeSrc) { | |
| 584 const Extension* extension = LoadExtensionWithFlags( | |
| 585 test_data_dir_.AppendASCII("service_worker/web_accessible_resources"), | |
|
Devlin
2015/12/17 17:37:34
it looks like maybe these should be two separate e
lazyboy
2015/12/17 19:27:22
Done.
| |
| 586 kFlagNone); | |
| 587 ASSERT_TRUE(extension); | |
| 588 ASSERT_TRUE(StartEmbeddedTestServer()); | |
| 589 GURL page_url = embedded_test_server()->GetURL( | |
| 590 "/extensions/api_test/service_worker/web_accessible_resources/" | |
| 591 "webpage.html"); | |
| 592 | |
| 593 content::WebContents* web_contents = AddTab(browser(), page_url); | |
| 594 std::string result; | |
| 595 // webpage.html will create an iframe pointing to a resource from |extension|. | |
| 596 // Expect the resource to be served by the extension. | |
| 597 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
| 598 web_contents, | |
| 599 base::StringPrintf("window.testIframe('%s')", extension->id().c_str()), | |
| 600 &result)); | |
| 601 ASSERT_EQ("FROM_EXTENSION_RESOURCE", result); | |
| 602 | |
| 603 // Now, register a Service Worker from the extension. | |
| 604 content::WebContents* extension_page_web_contents = | |
| 605 AddTab(browser(), extension->GetResourceURL("sw_register_page.html")); | |
| 606 ExtensionTestMessageListener service_worker_ready_listener("SW_READY", false); | |
| 607 service_worker_ready_listener.set_failure_message("SW_FAILED"); | |
| 608 EXPECT_TRUE(content::ExecuteScript(extension_page_web_contents, | |
| 609 "window.registerServiceWorker()")); | |
| 610 ASSERT_TRUE(service_worker_ready_listener.WaitUntilSatisfied()); | |
| 611 | |
| 612 // webpage.html will create another iframe pointing to a resource from | |
| 613 // |extension| as before. But this time, the resource should be be served | |
| 614 // from the Service Worker. | |
| 615 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
| 616 web_contents, | |
| 617 base::StringPrintf("window.testIframe('%s')", extension->id().c_str()), | |
| 618 &result)); | |
| 619 ASSERT_EQ("FROM_SW_RESOURCE", result); | |
| 620 } | |
| 621 | |
| 572 IN_PROC_BROWSER_TEST_F(ServiceWorkerBackgroundSyncTest, Sync) { | 622 IN_PROC_BROWSER_TEST_F(ServiceWorkerBackgroundSyncTest, Sync) { |
| 573 const Extension* extension = LoadExtensionWithFlags( | 623 const Extension* extension = LoadExtensionWithFlags( |
| 574 test_data_dir_.AppendASCII("service_worker/sync"), kFlagNone); | 624 test_data_dir_.AppendASCII("service_worker/sync"), kFlagNone); |
| 575 ASSERT_TRUE(extension); | 625 ASSERT_TRUE(extension); |
| 576 ui_test_utils::NavigateToURL(browser(), | 626 ui_test_utils::NavigateToURL(browser(), |
| 577 extension->GetResourceURL("page.html")); | 627 extension->GetResourceURL("page.html")); |
| 578 content::WebContents* web_contents = | 628 content::WebContents* web_contents = |
| 579 browser()->tab_strip_model()->GetActiveWebContents(); | 629 browser()->tab_strip_model()->GetActiveWebContents(); |
| 580 | 630 |
| 581 // Prevent firing by going offline. | 631 // Prevent firing by going offline. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 646 push_message_listener.set_failure_message("FAIL"); | 696 push_message_listener.set_failure_message("FAIL"); |
| 647 gcm::IncomingMessage message; | 697 gcm::IncomingMessage message; |
| 648 message.sender_id = "1234567890"; | 698 message.sender_id = "1234567890"; |
| 649 message.raw_data = "testdata"; | 699 message.raw_data = "testdata"; |
| 650 message.decrypted = true; | 700 message.decrypted = true; |
| 651 push_service()->OnMessage(app_identifier.app_id(), message); | 701 push_service()->OnMessage(app_identifier.app_id(), message); |
| 652 EXPECT_TRUE(push_message_listener.WaitUntilSatisfied()); | 702 EXPECT_TRUE(push_message_listener.WaitUntilSatisfied()); |
| 653 } | 703 } |
| 654 | 704 |
| 655 } // namespace extensions | 705 } // namespace extensions |
| OLD | NEW |