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

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

Issue 2943583002: [extension SW] Support lazy events from extension service workers. (Closed)
Patch Set: sync @tott Created 3 years, 5 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/renderer/chrome_content_renderer_client.h » ('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 18 matching lines...) Expand all
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
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 base::RunLoop run_loop;
705 content::StoragePartition* storage_partition =
706 content::BrowserContext::GetDefaultStoragePartition(
707 browser()->profile());
708 content::StopServiceWorkerForPattern(
709 storage_partition->GetServiceWorkerContext(),
710 // The service worker is registered at the top level scope.
711 extension->url(), run_loop.QuitClosure());
712 run_loop.Run();
713 }
714
715 std::string result;
716 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
717 web_contents, "window.createTabThenUpdate()", &result));
718 ASSERT_EQ("chrome.tabs.onUpdated callback", result);
719 }
720
685 // Tests that worker ref count increments while extension API function is 721 // Tests that worker ref count increments while extension API function is
686 // active. 722 // active.
687 723
688 // Flaky on Linux and ChromeOS, https://crbug.com/702126 724 // Flaky on Linux and ChromeOS, https://crbug.com/702126
689 #if defined(OS_LINUX) 725 #if defined(OS_LINUX)
690 #define MAYBE_WorkerRefCount DISABLED_WorkerRefCount 726 #define MAYBE_WorkerRefCount DISABLED_WorkerRefCount
691 #else 727 #else
692 #define MAYBE_WorkerRefCount WorkerRefCount 728 #define MAYBE_WorkerRefCount WorkerRefCount
693 #endif 729 #endif
694 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, MAYBE_WorkerRefCount) { 730 IN_PROC_BROWSER_TEST_F(ServiceWorkerTest, MAYBE_WorkerRefCount) {
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 message.sender_id = "1234567890"; 935 message.sender_id = "1234567890";
900 message.raw_data = "testdata"; 936 message.raw_data = "testdata";
901 message.decrypted = true; 937 message.decrypted = true;
902 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure()); 938 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure());
903 push_service()->OnMessage(app_identifier.app_id(), message); 939 push_service()->OnMessage(app_identifier.app_id(), message);
904 EXPECT_TRUE(push_message_listener.WaitUntilSatisfied()); 940 EXPECT_TRUE(push_message_listener.WaitUntilSatisfied());
905 run_loop.Run(); // Wait until the message is handled by push service. 941 run_loop.Run(); // Wait until the message is handled by push service.
906 } 942 }
907 943
908 } // namespace extensions 944 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/renderer/chrome_content_renderer_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698