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

Side by Side Diff: chrome/test/data/extensions/api_test/messaging/connect/page.js

Issue 1413543005: Use FrameTreeNode ID as frameId in extension APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/:/ / Created 4 years, 11 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 (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.";
11 }; 11 };
12 12
13 Array.prototype.toJSON = function() { 13 Array.prototype.toJSON = function() {
14 return "Array.prototype.toJSON clobbered by content script."; 14 return "Array.prototype.toJSON clobbered by content script.";
15 }; 15 };
16 16
17 Object.prototype.toJSON = function() { 17 Object.prototype.toJSON = function() {
18 return "Object.prototype.toJSON clobbered by content script."; 18 return "Object.prototype.toJSON clobbered by content script.";
19 }; 19 };
20 20
21 // For complex connect tests. 21 // For complex connect tests.
22 chrome.runtime.onConnect.addListener(function(port) { 22 chrome.runtime.onConnect.addListener(function onConnect(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) { 32 } else if (msg.testSendMessageFromFrame) {
33 testSendMessageFromFrame(); 33 testSendMessageFromFrame();
34 } else if (msg.testSendMessageToFrame) { 34 } else if (msg.testSendMessageToFrame) {
35 port.postMessage('from_main'); 35 port.postMessage('from_main');
36 } else if (msg.testDisconnect) { 36 } else if (msg.testDisconnect) {
37 port.disconnect(); 37 port.disconnect();
38 } else if (msg.testConnectChildFrameAndNavigateSetup) {
39 chrome.runtime.onConnect.removeListener(onConnect);
40 chrome.test.assertFalse(chrome.runtime.onConnect.hasListeners());
41 testConnectChildFrameAndNavigateSetup();
38 } else if (msg.testDisconnectOnClose) { 42 } else if (msg.testDisconnectOnClose) {
39 window.location = "about:blank"; 43 window.location = "about:blank";
40 } else if (msg.testPortName) { 44 } else if (msg.testPortName) {
41 port.postMessage({portName:port.name}); 45 port.postMessage({portName:port.name});
42 } else if (msg.testSendMessageFromTabError) { 46 } else if (msg.testSendMessageFromTabError) {
43 testSendMessageFromTabError(); 47 testSendMessageFromTabError();
44 } else if (msg.testConnectFromTabError) { 48 } else if (msg.testConnectFromTabError) {
45 testConnectFromTabError(); 49 testConnectFromTabError();
46 } 50 }
47 }); 51 });
(...skipping 26 matching lines...) Expand all
74 // runs in frames whose URL matches ?testSendMessageFromFrame. 78 // runs in frames whose URL matches ?testSendMessageFromFrame.
75 // frame.js sends a message to the background page, which checks that 79 // frame.js sends a message to the background page, which checks that
76 // sender.frameId exists and is different for both frames. 80 // sender.frameId exists and is different for both frames.
77 for (var i = 0; i < 2; ++i) { 81 for (var i = 0; i < 2; ++i) {
78 var f = document.createElement('iframe'); 82 var f = document.createElement('iframe');
79 f.src = '?testSendMessageFromFrame' + i; 83 f.src = '?testSendMessageFromFrame' + i;
80 document.body.appendChild(f); 84 document.body.appendChild(f);
81 } 85 }
82 } 86 }
83 87
88 function testConnectChildFrameAndNavigateSetup() {
89 var frames = document.querySelectorAll('iframe');
90 for (var i = 0; i < frames.length; ++i) {
91 frames[i].remove();
92 }
93 var f = document.createElement('iframe');
94 f.src = '?testConnectChildFrameAndNavigateSetup';
95 document.body.appendChild(f);
96 // Test will continue in frame.js
97 }
98
84 // Tests sendMessage to an invalid extension. 99 // Tests sendMessage to an invalid extension.
85 function testSendMessageFromTabError() { 100 function testSendMessageFromTabError() {
86 // try sending a request to a bad extension id 101 // try sending a request to a bad extension id
87 chrome.runtime.sendMessage("bad-extension-id", {m: 1}, function(response) { 102 chrome.runtime.sendMessage("bad-extension-id", {m: 1}, function(response) {
88 var success = (response === undefined && chrome.runtime.lastError); 103 var success = (response === undefined && chrome.runtime.lastError);
89 chrome.runtime.sendMessage({success: success}); 104 chrome.runtime.sendMessage({success: success});
90 }); 105 });
91 } 106 }
92 107
93 // Tests connecting to an invalid extension. 108 // Tests connecting to an invalid extension.
94 function testConnectFromTabError() { 109 function testConnectFromTabError() {
95 var port = chrome.runtime.connect("bad-extension-id"); 110 var port = chrome.runtime.connect("bad-extension-id");
96 port.onDisconnect.addListener(function() { 111 port.onDisconnect.addListener(function() {
97 var success = (chrome.runtime.lastError ? true : false); 112 var success = (chrome.runtime.lastError ? true : false);
98 chrome.runtime.sendMessage({success: success}); 113 chrome.runtime.sendMessage({success: success});
99 }); 114 });
100 } 115 }
101 116
102 // For test sendMessage. 117 // For test sendMessage.
103 chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { 118 chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
104 chrome.test.assertEq({id: chrome.runtime.id}, sender); 119 chrome.test.assertEq({id: chrome.runtime.id}, sender);
105 sendResponse({success: (request.step2 == 1)}); 120 sendResponse({success: (request.step2 == 1)});
106 }); 121 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698