Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: chrome/browser/extensions/service_worker_apitest.cc

Issue 1532633003: Extension SW: Add tests that serve web_accessible_resources from a SW. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: foo Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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(
574 "service_worker/web_accessible_resources/fetch/", "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
581 // controls the extension. Further requests to the same resource as before
582 // should now be served by the Service Worker.
583 // This test also verifies that if the requested resource exists in the manifest
584 // but is not present in the extension directory, the Service Worker can still
585 // serve the resource file.
586 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, WebAccessibleResourcesIframeSrc) {
587 const Extension* extension = LoadExtensionWithFlags(
588 test_data_dir_.AppendASCII(
589 "service_worker/web_accessible_resources/iframe_src"),
590 kFlagNone);
591 ASSERT_TRUE(extension);
592 ASSERT_TRUE(StartEmbeddedTestServer());
593 GURL page_url = embedded_test_server()->GetURL(
594 "/extensions/api_test/service_worker/web_accessible_resources/"
595 "webpage.html");
596
597 content::WebContents* web_contents = AddTab(browser(), page_url);
598 std::string result;
599 // webpage.html will create an iframe pointing to a resource from |extension|.
600 // Expect the resource to be served by the extension.
601 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
602 web_contents, base::StringPrintf("window.testIframe('%s', 'iframe.html')",
603 extension->id().c_str()),
604 &result));
605 EXPECT_EQ("FROM_EXTENSION_RESOURCE", result);
606
607 ExtensionTestMessageListener service_worker_ready_listener("SW_READY", false);
608 EXPECT_TRUE(ExecuteScriptInBackgroundPageNoWait(
609 extension->id(), "window.registerServiceWorker()"));
610 EXPECT_TRUE(service_worker_ready_listener.WaitUntilSatisfied());
611
612 result.clear();
613 // webpage.html will create another iframe pointing to a resource from
614 // |extension| as before. But this time, the resource should be be served
615 // from the Service Worker.
616 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
617 web_contents, base::StringPrintf("window.testIframe('%s', 'iframe.html')",
618 extension->id().c_str()),
619 &result));
620 EXPECT_EQ("FROM_SW_RESOURCE", result);
621
622 result.clear();
623 // webpage.html will create yet another iframe pointing to a resource that
624 // exists in the extension manifest's web_accessible_resources, but is not
625 // present in the extension directory. Expect the resources of the iframe to
626 // be served by the Service Worker.
627 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
628 web_contents,
629 base::StringPrintf("window.testIframe('%s', 'iframe_non_existent.html')",
630 extension->id().c_str()),
631 &result));
632 EXPECT_EQ("FROM_SW_RESOURCE", result);
633 }
634
572 IN_PROC_BROWSER_TEST_F(ServiceWorkerBackgroundSyncTest, Sync) { 635 IN_PROC_BROWSER_TEST_F(ServiceWorkerBackgroundSyncTest, Sync) {
573 const Extension* extension = LoadExtensionWithFlags( 636 const Extension* extension = LoadExtensionWithFlags(
574 test_data_dir_.AppendASCII("service_worker/sync"), kFlagNone); 637 test_data_dir_.AppendASCII("service_worker/sync"), kFlagNone);
575 ASSERT_TRUE(extension); 638 ASSERT_TRUE(extension);
576 ui_test_utils::NavigateToURL(browser(), 639 ui_test_utils::NavigateToURL(browser(),
577 extension->GetResourceURL("page.html")); 640 extension->GetResourceURL("page.html"));
578 content::WebContents* web_contents = 641 content::WebContents* web_contents =
579 browser()->tab_strip_model()->GetActiveWebContents(); 642 browser()->tab_strip_model()->GetActiveWebContents();
580 643
581 // Prevent firing by going offline. 644 // Prevent firing by going offline.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 push_message_listener.set_failure_message("FAIL"); 709 push_message_listener.set_failure_message("FAIL");
647 gcm::IncomingMessage message; 710 gcm::IncomingMessage message;
648 message.sender_id = "1234567890"; 711 message.sender_id = "1234567890";
649 message.raw_data = "testdata"; 712 message.raw_data = "testdata";
650 message.decrypted = true; 713 message.decrypted = true;
651 push_service()->OnMessage(app_identifier.app_id(), message); 714 push_service()->OnMessage(app_identifier.app_id(), message);
652 EXPECT_TRUE(push_message_listener.WaitUntilSatisfied()); 715 EXPECT_TRUE(push_message_listener.WaitUntilSatisfied());
653 } 716 }
654 717
655 } // namespace extensions 718 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698