OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 var testPort = chrome.runtime.connect({ |
| 6 name: 'port from interstitial' |
| 7 }); |
| 8 |
| 9 var currentTest; |
| 10 testPort.onMessage.addListener(function(msg) { |
| 11 console.assert(!currentTest, 'Should only run one test at a time'); |
| 12 currentTest = msg; |
| 13 |
| 14 if (msg === 'testSendMessage') { |
| 15 testSendMessage(); |
| 16 } else if (msg === 'testDisconnectByBackground') { |
| 17 testDisconnectByBackground(); |
| 18 } else if (msg === 'testDisconnectByInterstitial') { |
| 19 testDisconnectByInterstitial(); |
| 20 } else { |
| 21 done('Unexpected test: ' + msg); |
| 22 } |
| 23 }); |
| 24 |
| 25 function done(test) { |
| 26 console.assert(test === currentTest, 'test name should match current test'); |
| 27 currentTest = null; |
| 28 testPort.postMessage(test); |
| 29 } |
| 30 |
| 31 function testSendMessage() { |
| 32 chrome.runtime.sendMessage('First from interstitial', function(msg) { |
| 33 chrome.runtime.sendMessage('interstitial received: ' + msg); |
| 34 done('testSendMessage'); |
| 35 }); |
| 36 } |
| 37 |
| 38 function testDisconnectByBackground() { |
| 39 var port = chrome.runtime.connect({ |
| 40 name: 'disconnect by background' |
| 41 }); |
| 42 port.onDisconnect.addListener(function() { |
| 43 done('testDisconnectByBackground'); |
| 44 }); |
| 45 } |
| 46 |
| 47 function testDisconnectByInterstitial() { |
| 48 var port = chrome.runtime.connect({ |
| 49 name: 'disconnect by interstitial' |
| 50 }); |
| 51 port.disconnect(); |
| 52 done('testDisconnectByInterstitial'); |
| 53 } |
OLD | NEW |