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

Side by Side Diff: chrome/test/data/extensions/api_test/native_bindings/extension/background.js

Issue 2921013002: [Extensions Bindings] Return result from event dispatch (Closed)
Patch Set: add listener count todo Created 3 years, 6 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
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/native_bindings/extension/content_script.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 if (!chrome || !chrome.test) 5 if (!chrome || !chrome.test)
6 throw new Error('chrome.test is undefined'); 6 throw new Error('chrome.test is undefined');
7 7
8 var portNumber; 8 var portNumber;
9 9
10 // This is a good end-to-end test for two reasons. The first is obvious - it 10 // This is a good end-to-end test for two reasons. The first is obvious - it
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 }); 53 });
54 }); 54 });
55 Promise.all([createdEvent, createdCallback]).then(res => { 55 Promise.all([createdEvent, createdCallback]).then(res => {
56 chrome.test.assertEq(2, res.length); 56 chrome.test.assertEq(2, res.length);
57 chrome.test.assertEq(res[0], res[1]); 57 chrome.test.assertEq(res[0], res[1]);
58 chrome.test.succeed(); 58 chrome.test.succeed();
59 }); 59 });
60 }, 60 },
61 function testMessaging() { 61 function testMessaging() {
62 var tabId; 62 var tabId;
63
63 var createPort = function() { 64 var createPort = function() {
64 chrome.test.assertTrue(!!tabId); 65 chrome.test.assertTrue(!!tabId);
65 var port = chrome.tabs.connect(tabId); 66 var port = chrome.tabs.connect(tabId);
66 chrome.test.assertTrue(!!port, 'Port does not exist'); 67 chrome.test.assertTrue(!!port, 'Port does not exist');
67 port.onMessage.addListener(message => { 68 port.onMessage.addListener(message => {
68 chrome.test.assertEq('content script', message); 69 chrome.test.assertEq('content script', message);
69 port.disconnect(); 70 port.disconnect();
70 chrome.test.succeed(); 71 chrome.tabs.sendMessage(tabId, 'async bounce', function(response) {
72 chrome.test.assertEq('bounced', response);
73 chrome.test.succeed();
74 });
71 }); 75 });
72 port.postMessage('background page'); 76 port.postMessage('background page');
73 }; 77 };
74 78
75 chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { 79 chrome.runtime.onMessage.addListener(function listener(
80 message, sender, sendResponse) {
76 chrome.test.assertEq('startFlow', message); 81 chrome.test.assertEq('startFlow', message);
77 createPort(); 82 createPort();
78 sendResponse('started'); 83 sendResponse('started');
84 chrome.runtime.onMessage.removeListener(listener);
79 }); 85 });
86
80 var url = 'http://localhost:' + portNumber + 87 var url = 'http://localhost:' + portNumber +
81 '/native_bindings/extension/messaging_test.html'; 88 '/native_bindings/extension/messaging_test.html';
82 chrome.tabs.create({url: url}, function(tab) { 89 chrome.tabs.create({url: url}, function(tab) {
83 chrome.test.assertNoLastError(); 90 chrome.test.assertNoLastError();
84 chrome.test.assertTrue(!!tab); 91 chrome.test.assertTrue(!!tab);
85 chrome.test.assertTrue(!!tab.id && tab.id >= 0); 92 chrome.test.assertTrue(!!tab.id && tab.id >= 0);
86 tabId = tab.id; 93 tabId = tab.id;
87 }); 94 });
88 }, 95 },
89 function castStreaming() { 96 function castStreaming() {
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 }); 324 });
318 }, 325 },
319 ]; 326 ];
320 327
321 chrome.test.getConfig(config => { 328 chrome.test.getConfig(config => {
322 chrome.test.assertTrue(!!config, 'config does not exist'); 329 chrome.test.assertTrue(!!config, 'config does not exist');
323 chrome.test.assertTrue(!!config.testServer, 'testServer does not exist'); 330 chrome.test.assertTrue(!!config.testServer, 'testServer does not exist');
324 portNumber = config.testServer.port; 331 portNumber = config.testServer.port;
325 chrome.test.runTests(tests); 332 chrome.test.runTests(tests);
326 }); 333 });
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/native_bindings/extension/content_script.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698