summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-08 23:14:12 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-08 23:14:12 +0000
commit7a379f0eec9bbaeeb0d68c06de5d3473b18ea50d (patch)
tree6cd83a8c4f7dabeab1eb44afd612a3ec264302d1 /chrome/test
parenta96af9d3a9feb46c463399438d9687c7c10a9451 (diff)
downloadchromium_src-7a379f0eec9bbaeeb0d68c06de5d3473b18ea50d.zip
chromium_src-7a379f0eec9bbaeeb0d68c06de5d3473b18ea50d.tar.gz
chromium_src-7a379f0eec9bbaeeb0d68c06de5d3473b18ea50d.tar.bz2
Move the extension messaging tests to be ExtensionApiTests. Remove the old
tests. Review URL: http://codereview.chromium.org/519087 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35843 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/data/extensions/api_test/messaging/connect/page.js45
-rw-r--r--chrome/test/data/extensions/api_test/messaging/connect/test.html107
-rw-r--r--chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/background.html9
-rw-r--r--chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/manifest.json10
-rw-r--r--chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/toolstrip.html87
-rw-r--r--chrome/test/data/extensions/good/Preferences10
-rw-r--r--chrome/test/data/extensions/ui/create_extension_detail_value_expected_output/good-extension3.json7
7 files changed, 148 insertions, 127 deletions
diff --git a/chrome/test/data/extensions/api_test/messaging/connect/page.js b/chrome/test/data/extensions/api_test/messaging/connect/page.js
index 2f737f70..b876f7e 100644
--- a/chrome/test/data/extensions/api_test/messaging/connect/page.js
+++ b/chrome/test/data/extensions/api_test/messaging/connect/page.js
@@ -1,9 +1,46 @@
-// For test onRequest.
-chrome.extension.sendRequest({step: 1}, function(response) {
- if (response.nextStep)
- chrome.extension.sendRequest({step: 2});
+// For complex connect tests.
+chrome.extension.onConnect.addListener(function(port) {
+ console.log('connected');
+ port.onMessage.addListener(function(msg) {
+ console.log('got ' + msg);
+ if (msg.testPostMessage) {
+ port.postMessage({success: true});
+ } else if (msg.testPostMessageFromTab) {
+ testPostMessageFromTab(port);
+ } else if (msg.testSendRequestFromTab) {
+ testSendRequestFromTab();
+ } else if (msg.testDisconnect) {
+ port.disconnect();
+ } else if (msg.testDisconnectOnClose) {
+ window.location = "about:blank";
+ } else if (msg.testPortName) {
+ port.postMessage({portName:port.name});
+ }
+ });
});
+// Tests that postMessage to the extension and its response works.
+function testPostMessageFromTab(origPort) {
+ var portName = "peter";
+ var port = chrome.extension.connect({name: portName});
+ port.postMessage({testPostMessageFromTab: true});
+ port.onMessage.addListener(function(msg) {
+ origPort.postMessage({success: (msg.success && (msg.portName == portName))});
+ console.log('testPostMessageFromTab sent ' + msg.success);
+ port.disconnect();
+ });
+}
+
+// For test onRequest.
+function testSendRequestFromTab() {
+ chrome.extension.sendRequest({step: 1}, function(response) {
+ if (response.nextStep) {
+ console.log('testSendRequestFromTab sent');
+ chrome.extension.sendRequest({step: 2});
+ }
+ });
+}
+
// For test sendRequest.
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
sendResponse({success: (request.step2 == 1)});
diff --git a/chrome/test/data/extensions/api_test/messaging/connect/test.html b/chrome/test/data/extensions/api_test/messaging/connect/test.html
index b108a8d..3e24916 100644
--- a/chrome/test/data/extensions/api_test/messaging/connect/test.html
+++ b/chrome/test/data/extensions/api_test/messaging/connect/test.html
@@ -1,36 +1,115 @@
<script>
+// Keep track of the tab that we're running tests in, for simplicity.
+var testTab = null;
+
chrome.test.runTests([
+ function setupTestTab() {
+ chrome.test.log("Creating tab...");
+ chrome.tabs.create({
+ url: "http://localhost:1337/files/extensions/test_file.html"
+ }, function(tab) {
+ chrome.tabs.onUpdated.addListener(function listener(tabid, info) {
+ if (tab.id == tabid && info.status == 'complete') {
+ chrome.test.log("Created tab: " + tab.url);
+ chrome.tabs.onUpdated.removeListener(listener);
+ testTab = tab;
+ chrome.test.succeed();
+ }
+ });
+ });
+ },
+
+ // Tests that postMessage to the tab and its response works.
+ function postMessage() {
+ var port = chrome.tabs.connect(testTab.id);
+ port.postMessage({testPostMessage: true});
+ port.onMessage.addListener(function(msg) {
+ port.disconnect();
+ chrome.test.succeed();
+ });
+ },
+
+ // Tests that port name is sent & received correctly.
+ function portName() {
+ var portName = "lemonjello";
+ var port = chrome.tabs.connect(testTab.id, {name: portName});
+ port.postMessage({testPortName: true});
+ port.onMessage.addListener(function(msg) {
+ chrome.test.assertEq(msg.portName, portName);
+ port.disconnect();
+ chrome.test.succeed();
+ });
+ },
+
+ // Tests that postMessage from the tab and its response works.
+ function postMessageFromTab() {
+ chrome.extension.onConnect.addListener(function(port) {
+ port.onMessage.addListener(function(msg) {
+ chrome.test.assertTrue(msg.testPostMessageFromTab);
+ port.postMessage({success: true, portName: port.name});
+ chrome.test.log("postMessageFromTab: got message from tab");
+ });
+ });
+
+ var port = chrome.tabs.connect(testTab.id);
+ port.postMessage({testPostMessageFromTab: true});
+ chrome.test.log("postMessageFromTab: sent first message to tab");
+ port.onMessage.addListener(function(msg) {
+ port.disconnect();
+ chrome.test.succeed();
+ });
+ },
+
// Tests receiving a request from a content script and responding.
- function onRequest() {
+ function sendRequestFromTab() {
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
chrome.test.assertTrue("url" in sender.tab, "no tab available.");
chrome.test.assertEq(sender.id, location.host);
if (request.step == 1) {
// Step 1: Page should send another request for step 2.
+ chrome.test.log("sendRequestFromTab: got step 1");
sendResponse({nextStep: true});
} else {
// Step 2.
chrome.test.assertEq(request.step, 2);
- sendResponse({});
+ sendResponse();
chrome.test.succeed();
}
- });
+ });
+
+ var port = chrome.tabs.connect(testTab.id);
+ port.postMessage({testSendRequestFromTab: true});
+ port.disconnect();
+ chrome.test.log("sendRequestFromTab: sent first message to tab");
},
+
// Tests sending a request to a tab and receiving a response.
function sendRequest() {
- chrome.tabs.getSelected(null, function(tab) {
- chrome.test.log("Selected tab: " + tab.url);
- chrome.tabs.sendRequest(tab.id, {step2: 1}, function(response) {
- chrome.test.assertTrue(response.success);
- chrome.test.succeed();
- });
+ chrome.tabs.sendRequest(testTab.id, {step2: 1}, function(response) {
+ chrome.test.assertTrue(response.success);
+ chrome.test.succeed();
});
- }
+ },
+
+ // Tests that we get the disconnect event when the tab disconnect.
+ function disconnect() {
+ var port = chrome.tabs.connect(testTab.id);
+ port.postMessage({testDisconnect: true});
+ port.onDisconnect.addListener(function() {
+ chrome.test.succeed();
+ });
+ },
+
+ // Tests that we get the disconnect event when the tab context closes.
+ function disconnectOnClose() {
+ var port = chrome.tabs.connect(testTab.id);
+ port.postMessage({testDisconnectOnClose: true});
+ port.onDisconnect.addListener(function() {
+ chrome.test.succeed();
+ testTab = null; // the tab is about:blank now.
+ });
+ },
]);
-chrome.test.log("Creating tab...");
-chrome.tabs.create({
- url: "http://localhost:1337/files/extensions/test_file.html"
-});
</script>
diff --git a/chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/background.html b/chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/background.html
new file mode 100644
index 0000000..4f8dda3
--- /dev/null
+++ b/chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/background.html
@@ -0,0 +1,9 @@
+<script>
+chrome.extension.onConnectExternal.addListener(function(port) {
+ port.onMessage.addListener(function(msg) {
+ if (msg.testConnectExternal) {
+ port.postMessage({success: true, senderId: port.sender.id});
+ }
+ });
+});
+</script>
diff --git a/chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/manifest.json b/chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/manifest.json
index d87557c..37b7cd5 100644
--- a/chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/manifest.json
+++ b/chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/manifest.json
@@ -2,12 +2,6 @@
"key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDRS2GUBOUAO5VZ2CMRId/eRR8/e9V42nUvY5XG+0sZ+JDHEjIQdq8qQy7HqdqEpCXKPMSPuMiC2t2HE9/hpL89SblNn3mwYPtSJGQdZvAzuv6SB0oA6jZ66V7+h/k0noGD3Tcu+Ko/vfkt5wCx2uHVK29k5JR/vGr0klaoVezGlwIDAQAB",
"version": "1.0",
"name": "My extension 3",
- "toolstrips": ["toolstrip.html"],
- "permissions": ["tabs"],
- "content_scripts": [
- {
- "matches": ["http://localhost/*"],
- "js": ["page.js"]
- }
- ]
+ "background_page": "background.html",
+ "permissions": ["tabs"]
}
diff --git a/chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/toolstrip.html b/chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/toolstrip.html
deleted file mode 100644
index fb4c2eb..0000000
--- a/chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/toolstrip.html
+++ /dev/null
@@ -1,87 +0,0 @@
-<script>
-window.onload = function() {
- chrome.extension.onConnect.addListener(function(port) {
- console.log('onConnect');
- port.onMessage.addListener(function(msg) {
- console.log('got message');
- if (msg.testPostMessageFromTab) {
- port.postMessage({success: true, portName: port.name});
- console.log('sent success');
- }
- // Ignore other messages since they are from us.
- });
- });
- chrome.extension.onConnectExternal.addListener(function(port) {
- port.onMessage.addListener(function(msg) {
- if (msg.testConnectExternal) {
- port.postMessage({success: true, senderId: port.sender.id});
- }
- });
- });
-};
-
-// Tests that postMessage to the tab and its response works.
-function testPostMessage() {
- chrome.tabs.getSelected(null, function(tab) {
- var port = chrome.tabs.connect(tab.id);
- console.log('connect to ' + tab.id);
- port.postMessage({testPostMessage: true});
- port.onMessage.addListener(function(msg) {
- window.domAutomationController.send(msg.success);
- port.disconnect();
- });
- });
-}
-
-// Tests that port name is sent & received correctly.
-function testPortName() {
- chrome.tabs.getSelected(null, function(tab) {
- var portName = "lemonjello";
- var port = chrome.tabs.connect(tab.id, {name: portName});
- console.log('naming port ' + portName);
- port.postMessage({testPortName: true});
- port.onMessage.addListener(function(msg) {
- console.log('got name ' + msg.portName);
- window.domAutomationController.send(msg.portName == portName);
- port.disconnect();
- });
- });
-}
-
-// Tests that postMessage from the tab and its response works.
-function testPostMessageFromTab() {
- chrome.tabs.getSelected(null, function(tab) {
- var port = chrome.tabs.connect(tab.id);
- console.log('connect to ' + tab.id);
- port.postMessage({testPostMessageFromTab: true});
- port.onMessage.addListener(function(msg) {
- window.domAutomationController.send(msg.success);
- port.disconnect();
- });
- });
-}
-
-// Tests that we get the disconnect event when the tab disconnect.
-function testDisconnect() {
- chrome.tabs.getSelected(null, function(tab) {
- var port = chrome.tabs.connect(tab.id);
- console.log('connect to ' + tab.id);
- port.postMessage({testDisconnect: true});
- port.onDisconnect.addListener(function() {
- window.domAutomationController.send(true);
- });
- });
-}
-
-// Tests that we get the disconnect event when the tab context closes.
-function testDisconnectOnClose() {
- chrome.tabs.getSelected(null, function(tab) {
- var port = chrome.tabs.connect(tab.id);
- console.log('connect to ' + tab.id);
- port.postMessage({testDisconnectOnClose: true});
- port.onDisconnect.addListener(function() {
- window.domAutomationController.send(true);
- });
- });
-}
-</script>
diff --git a/chrome/test/data/extensions/good/Preferences b/chrome/test/data/extensions/good/Preferences
index 42a2713..7aad8c2 100644
--- a/chrome/test/data/extensions/good/Preferences
+++ b/chrome/test/data/extensions/good/Preferences
@@ -46,14 +46,8 @@
"key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDRS2GUBOUAO5VZ2CMRId/eRR8/e9V42nUvY5XG+0sZ+JDHEjIQdq8qQy7HqdqEpCXKPMSPuMiC2t2HE9/hpL89SblNn3mwYPtSJGQdZvAzuv6SB0oA6jZ66V7+h/k0noGD3Tcu+Ko/vfkt5wCx2uHVK29k5JR/vGr0klaoVezGlwIDAQAB",
"version": "1.0",
"name": "My extension 3",
- "toolstrips": ["toolstrip.html"],
- "permissions": ["tabs"],
- "content_scripts": [
- {
- "matches": ["file://*"],
- "js": ["page.js"]
- }
- ]
+ "background_page": "background.html",
+ "permissions": ["tabs"]
}
},
"hpiknbiabeeppbpihjehijgoemciehgk": {
diff --git a/chrome/test/data/extensions/ui/create_extension_detail_value_expected_output/good-extension3.json b/chrome/test/data/extensions/ui/create_extension_detail_value_expected_output/good-extension3.json
index bbf69cd..564053a 100644
--- a/chrome/test/data/extensions/ui/create_extension_detail_value_expected_output/good-extension3.json
+++ b/chrome/test/data/extensions/ui/create_extension_detail_value_expected_output/good-extension3.json
@@ -7,11 +7,6 @@
"permissions": [],
"allow_reload": false,
"order": 2,
- "content_scripts": [
- {
- "matches": ["http://localhost/*"],
- "js": ["page.js"]
- }
- ],
+ "content_scripts": [],
"views": []
}