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

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: remove unused var Created 4 years, 11 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
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/service_worker/web_accessible_resources/fetch/data_for_extension » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 // should fail. 565 // should fail.
566 // Note that this also tests that service workers can be registered from tabs. 566 // Note that this also tests that service workers can be registered from tabs.
567 EXPECT_TRUE(RunExtensionSubtest("service_worker/no_background", "page.html")); 567 EXPECT_TRUE(RunExtensionSubtest("service_worker/no_background", "page.html"));
568 } 568 }
569 569
570 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, NotificationAPI) { 570 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, NotificationAPI) {
571 EXPECT_TRUE(RunExtensionSubtest("service_worker/notifications/has_permission", 571 EXPECT_TRUE(RunExtensionSubtest("service_worker/notifications/has_permission",
572 "page.html")); 572 "page.html"));
573 } 573 }
574 574
575 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, WebAccessibleResourcesFetch) {
576 EXPECT_TRUE(RunExtensionSubtest(
577 "service_worker/web_accessible_resources/fetch/", "page.html"));
578 }
579
580 // This test loads a web page that has an iframe pointing to a
581 // chrome-extension:// URL. The URL is listed in the extension's
582 // web_accessible_resources. Initially the iframe is served from the extension's
583 // resource file. After verifying that, we register a Service Worker that
584 // controls the extension. Further requests to the same resource as before
585 // should now be served by the Service Worker.
586 // This test also verifies that if the requested resource exists in the manifest
587 // but is not present in the extension directory, the Service Worker can still
588 // serve the resource file.
589 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, WebAccessibleResourcesIframeSrc) {
590 const Extension* extension = LoadExtensionWithFlags(
591 test_data_dir_.AppendASCII(
592 "service_worker/web_accessible_resources/iframe_src"),
593 kFlagNone);
594 ASSERT_TRUE(extension);
595 ASSERT_TRUE(StartEmbeddedTestServer());
596 GURL page_url = embedded_test_server()->GetURL(
597 "/extensions/api_test/service_worker/web_accessible_resources/"
598 "webpage.html");
599
600 content::WebContents* web_contents = AddTab(browser(), page_url);
601 std::string result;
602 // webpage.html will create an iframe pointing to a resource from |extension|.
603 // Expect the resource to be served by the extension.
604 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
605 web_contents, base::StringPrintf("window.testIframe('%s', 'iframe.html')",
606 extension->id().c_str()),
607 &result));
608 EXPECT_EQ("FROM_EXTENSION_RESOURCE", result);
609
610 ExtensionTestMessageListener service_worker_ready_listener("SW_READY", false);
611 EXPECT_TRUE(ExecuteScriptInBackgroundPageNoWait(
612 extension->id(), "window.registerServiceWorker()"));
613 EXPECT_TRUE(service_worker_ready_listener.WaitUntilSatisfied());
614
615 result.clear();
616 // webpage.html will create another iframe pointing to a resource from
617 // |extension| as before. But this time, the resource should be be served
618 // from the Service Worker.
619 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
620 web_contents, base::StringPrintf("window.testIframe('%s', 'iframe.html')",
621 extension->id().c_str()),
622 &result));
623 EXPECT_EQ("FROM_SW_RESOURCE", result);
624
625 result.clear();
626 // webpage.html will create yet another iframe pointing to a resource that
627 // exists in the extension manifest's web_accessible_resources, but is not
628 // present in the extension directory. Expect the resources of the iframe to
629 // be served by the Service Worker.
630 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
631 web_contents,
632 base::StringPrintf("window.testIframe('%s', 'iframe_non_existent.html')",
633 extension->id().c_str()),
634 &result));
635 EXPECT_EQ("FROM_SW_RESOURCE", result);
636 }
637
575 IN_PROC_BROWSER_TEST_F(ServiceWorkerBackgroundSyncTest, Sync) { 638 IN_PROC_BROWSER_TEST_F(ServiceWorkerBackgroundSyncTest, Sync) {
576 const Extension* extension = LoadExtensionWithFlags( 639 const Extension* extension = LoadExtensionWithFlags(
577 test_data_dir_.AppendASCII("service_worker/sync"), kFlagNone); 640 test_data_dir_.AppendASCII("service_worker/sync"), kFlagNone);
578 ASSERT_TRUE(extension); 641 ASSERT_TRUE(extension);
579 ui_test_utils::NavigateToURL(browser(), 642 ui_test_utils::NavigateToURL(browser(),
580 extension->GetResourceURL("page.html")); 643 extension->GetResourceURL("page.html"));
581 content::WebContents* web_contents = 644 content::WebContents* web_contents =
582 browser()->tab_strip_model()->GetActiveWebContents(); 645 browser()->tab_strip_model()->GetActiveWebContents();
583 646
584 // Prevent firing by going offline. 647 // Prevent firing by going offline.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 push_message_listener.set_failure_message("FAIL"); 712 push_message_listener.set_failure_message("FAIL");
650 gcm::IncomingMessage message; 713 gcm::IncomingMessage message;
651 message.sender_id = "1234567890"; 714 message.sender_id = "1234567890";
652 message.raw_data = "testdata"; 715 message.raw_data = "testdata";
653 message.decrypted = true; 716 message.decrypted = true;
654 push_service()->OnMessage(app_identifier.app_id(), message); 717 push_service()->OnMessage(app_identifier.app_id(), message);
655 EXPECT_TRUE(push_message_listener.WaitUntilSatisfied()); 718 EXPECT_TRUE(push_message_listener.WaitUntilSatisfied());
656 } 719 }
657 720
658 } // namespace extensions 721 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/service_worker/web_accessible_resources/fetch/data_for_extension » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698