OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 JSON.parse = function() { | 5 JSON.parse = function() { |
6 return "JSON.parse clobbered by content script."; | 6 return "JSON.parse clobbered by content script."; |
7 }; | 7 }; |
8 | 8 |
9 JSON.stringify = function() { | 9 JSON.stringify = function() { |
10 return "JSON.stringify clobbered by content script."; | 10 return "JSON.stringify clobbered by content script."; |
(...skipping 11 matching lines...) Expand all Loading... | |
22 chrome.runtime.onConnect.addListener(function(port) { | 22 chrome.runtime.onConnect.addListener(function(port) { |
23 console.log('connected'); | 23 console.log('connected'); |
24 port.onMessage.addListener(function(msg) { | 24 port.onMessage.addListener(function(msg) { |
25 console.log('got ' + msg); | 25 console.log('got ' + msg); |
26 if (msg.testPostMessage) { | 26 if (msg.testPostMessage) { |
27 port.postMessage({success: true}); | 27 port.postMessage({success: true}); |
28 } else if (msg.testPostMessageFromTab) { | 28 } else if (msg.testPostMessageFromTab) { |
29 testPostMessageFromTab(port); | 29 testPostMessageFromTab(port); |
30 } else if (msg.testSendMessageFromTab) { | 30 } else if (msg.testSendMessageFromTab) { |
31 testSendMessageFromTab(); | 31 testSendMessageFromTab(); |
32 } else if (msg.testSendMessageFromFrame) { | |
33 testSendMessageFromFrame(); | |
32 } else if (msg.testDisconnect) { | 34 } else if (msg.testDisconnect) { |
33 port.disconnect(); | 35 port.disconnect(); |
34 } else if (msg.testDisconnectOnClose) { | 36 } else if (msg.testDisconnectOnClose) { |
35 window.location = "about:blank"; | 37 window.location = "about:blank"; |
36 } else if (msg.testPortName) { | 38 } else if (msg.testPortName) { |
37 port.postMessage({portName:port.name}); | 39 port.postMessage({portName:port.name}); |
38 } else if (msg.testSendMessageFromTabError) { | 40 } else if (msg.testSendMessageFromTabError) { |
39 testSendMessageFromTabError(); | 41 testSendMessageFromTabError(); |
40 } else if (msg.testConnectFromTabError) { | 42 } else if (msg.testConnectFromTabError) { |
41 testConnectFromTabError(); | 43 testConnectFromTabError(); |
(...skipping 16 matching lines...) Expand all Loading... | |
58 // For test onMessage. | 60 // For test onMessage. |
59 function testSendMessageFromTab() { | 61 function testSendMessageFromTab() { |
60 chrome.runtime.sendMessage({step: 1}, function(response) { | 62 chrome.runtime.sendMessage({step: 1}, function(response) { |
61 if (response.nextStep) { | 63 if (response.nextStep) { |
62 console.log('testSendMessageFromTab sent'); | 64 console.log('testSendMessageFromTab sent'); |
63 chrome.runtime.sendMessage({step: 2}); | 65 chrome.runtime.sendMessage({step: 2}); |
64 } | 66 } |
65 }); | 67 }); |
66 } | 68 } |
67 | 69 |
70 function testSendMessageFromFrame() { | |
71 var f = document.createElement('iframe'); | |
72 f.src = '?frame_test'; | |
not at google - send to devlin
2014/11/10 18:36:42
Where is this 'frame_test' used?
robwu
2014/11/10 21:43:07
In frame.js. I've clarified the comment two lines
| |
73 document.body.appendChild(f); | |
74 // The test will continue in frame.js. | |
75 } | |
76 | |
68 // Tests sendMessage to an invalid extension. | 77 // Tests sendMessage to an invalid extension. |
69 function testSendMessageFromTabError() { | 78 function testSendMessageFromTabError() { |
70 // try sending a request to a bad extension id | 79 // try sending a request to a bad extension id |
71 chrome.runtime.sendMessage("bad-extension-id", {m: 1}, function(response) { | 80 chrome.runtime.sendMessage("bad-extension-id", {m: 1}, function(response) { |
72 var success = (response === undefined && chrome.runtime.lastError); | 81 var success = (response === undefined && chrome.runtime.lastError); |
73 chrome.runtime.sendMessage({success: success}); | 82 chrome.runtime.sendMessage({success: success}); |
74 }); | 83 }); |
75 } | 84 } |
76 | 85 |
77 // Tests connecting to an invalid extension. | 86 // Tests connecting to an invalid extension. |
78 function testConnectFromTabError() { | 87 function testConnectFromTabError() { |
79 var port = chrome.runtime.connect("bad-extension-id"); | 88 var port = chrome.runtime.connect("bad-extension-id"); |
80 port.onDisconnect.addListener(function() { | 89 port.onDisconnect.addListener(function() { |
81 var success = (chrome.runtime.lastError ? true : false); | 90 var success = (chrome.runtime.lastError ? true : false); |
82 chrome.runtime.sendMessage({success: success}); | 91 chrome.runtime.sendMessage({success: success}); |
83 }); | 92 }); |
84 } | 93 } |
85 | 94 |
86 // For test sendMessage. | 95 // For test sendMessage. |
87 chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { | 96 chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { |
88 chrome.test.assertEq({id: chrome.runtime.id}, sender); | 97 chrome.test.assertEq({id: chrome.runtime.id}, sender); |
89 sendResponse({success: (request.step2 == 1)}); | 98 sendResponse({success: (request.step2 == 1)}); |
90 }); | 99 }); |
OLD | NEW |