| OLD | NEW |
| 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 }); |
| OLD | NEW |