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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 chrome.runtime.onConnect.addListener((port) => { 5 chrome.runtime.onConnect.addListener(function listener(port) {
6 port.onMessage.addListener((message) => { 6 port.onMessage.addListener((message) => {
7 chrome.test.assertEq('background page', message); 7 chrome.test.assertEq('background page', message);
8 port.postMessage('content script'); 8 port.postMessage('content script');
9 }); 9 });
10 chrome.runtime.onConnect.removeListener(listener);
11 });
12
13 chrome.runtime.onMessage.addListener(
14 function listener(message, sender, sendResponse) {
15 chrome.test.assertEq('async bounce', message);
16 chrome.runtime.onMessage.removeListener(listener);
17 // Respond asynchronously.
18 setTimeout(() => { sendResponse('bounced'); }, 0);
19 // When returning a result asynchronously, the listener must return true -
20 // otherwise the channel is immediately closed.
21 return true;
10 }); 22 });
11 23
12 chrome.runtime.sendMessage('startFlow', function(response) { 24 chrome.runtime.sendMessage('startFlow', function(response) {
13 chrome.test.assertEq('started', response); 25 chrome.test.assertEq('started', response);
14 }); 26 });
OLDNEW
« 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