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

Unified Diff: chrome/test/data/extensions/api_test/native_bindings/background.js

Issue 2641863003: [Extensions Bindings] Add a messaging test (Closed)
Patch Set: . Created 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/api_test/native_bindings/background.js
diff --git a/chrome/test/data/extensions/api_test/native_bindings/background.js b/chrome/test/data/extensions/api_test/native_bindings/background.js
index d0ccb14de99674d58b031783a06c12d5831f9ced..bf18b8d4eda2823e45f2d3ed2670eff704bedd02 100644
--- a/chrome/test/data/extensions/api_test/native_bindings/background.js
+++ b/chrome/test/data/extensions/api_test/native_bindings/background.js
@@ -5,6 +5,8 @@
if (!chrome || !chrome.test)
throw new Error('chrome.test is undefined');
+var portNumber;
+
// This is a good end-to-end test for two reasons. The first is obvious - it
// tests a simple API and makes sure it behaves as expected, as well as testing
// that other APIs are unavailable.
@@ -14,7 +16,7 @@ if (!chrome || !chrome.test)
// enters JS) and custom JS bindings (in order to have our runTests, assert*
// methods, etc). If any of these stages failed, the test itself would also
// fail.
-chrome.test.runTests([
+var tests = [
function idleApi() {
chrome.test.assertTrue(!!chrome.idle);
chrome.test.assertTrue(!!chrome.idle.IdleState);
@@ -56,4 +58,39 @@ chrome.test.runTests([
chrome.test.succeed();
});
},
-]);
+ function testMessaging() {
+ var tabId;
+ var createPort = function() {
+ chrome.test.assertTrue(!!tabId);
+ var port = chrome.tabs.connect(tabId);
+ chrome.test.assertTrue(!!port, 'Port does not exist');
+ port.onMessage.addListener(message => {
+ chrome.test.assertEq('content script', message);
+ port.disconnect();
+ chrome.test.succeed();
+ });
+ port.postMessage('background page');
+ };
+
+ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
+ chrome.test.assertEq('startFlow', message);
+ createPort();
+ sendResponse('started');
+ });
+ var url = 'http://localhost:' + portNumber +
+ '/native_bindings/messaging_test.html';
+ chrome.tabs.create({url: url}, function(tab) {
+ chrome.test.assertNoLastError();
+ chrome.test.assertTrue(!!tab);
+ chrome.test.assertTrue(!!tab.id && tab.id >= 0);
+ tabId = tab.id;
+ });
+ },
+];
+
+chrome.test.getConfig(config => {
+ chrome.test.assertTrue(!!config, 'config does not exist');
+ chrome.test.assertTrue(!!config.testServer, 'testServer does not exist');
+ portNumber = config.testServer.port;
+ chrome.test.runTests(tests);
+});

Powered by Google App Engine
This is Rietveld 408576698