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

Unified Diff: chrome/test/data/extensions/api_test/native_bindings/extension/content_script.js

Issue 2921013002: [Extensions Bindings] Return result from event dispatch (Closed)
Patch Set: add listener count todo Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/api_test/native_bindings/extension/content_script.js
diff --git a/chrome/test/data/extensions/api_test/native_bindings/extension/content_script.js b/chrome/test/data/extensions/api_test/native_bindings/extension/content_script.js
index b837db3abb141fd75d01caf83b2993ec8f099526..1a0d5407d26329fea9d37af8f3bbcdba87e99cb4 100644
--- a/chrome/test/data/extensions/api_test/native_bindings/extension/content_script.js
+++ b/chrome/test/data/extensions/api_test/native_bindings/extension/content_script.js
@@ -2,11 +2,23 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-chrome.runtime.onConnect.addListener((port) => {
+chrome.runtime.onConnect.addListener(function listener(port) {
port.onMessage.addListener((message) => {
chrome.test.assertEq('background page', message);
port.postMessage('content script');
});
+ chrome.runtime.onConnect.removeListener(listener);
+});
+
+chrome.runtime.onMessage.addListener(
+ function listener(message, sender, sendResponse) {
+ chrome.test.assertEq('async bounce', message);
+ chrome.runtime.onMessage.removeListener(listener);
+ // Respond asynchronously.
+ setTimeout(() => { sendResponse('bounced'); }, 0);
+ // When returning a result asynchronously, the listener must return true -
+ // otherwise the channel is immediately closed.
+ return true;
});
chrome.runtime.sendMessage('startFlow', function(response) {
« no previous file with comments | « chrome/test/data/extensions/api_test/native_bindings/extension/background.js ('k') | extensions/renderer/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698