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

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

Issue 2768093002: [Reland][Extensions Bindings] Add support for filtered events (Closed)
Patch Set: Fix Created 3 years, 9 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/manifest.json » ('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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 resolve(); 199 resolve();
200 }); 200 });
201 }); 201 });
202 }); 202 });
203 }); 203 });
204 204
205 Promise.all([listenerPromise, methodPromise]).then(() => { 205 Promise.all([listenerPromise, methodPromise]).then(() => {
206 chrome.test.succeed(); 206 chrome.test.succeed();
207 }); 207 });
208 }, 208 },
209 function testWebNavigationAndFilteredEvents() {
210 // Tests unfiltered events, which can be exercised with the webNavigation
211 // API.
212 var unfiltered = new Promise((resolve, reject) => {
213 var sawSimple1 = false;
214 var sawSimple2 = false;
215 chrome.webNavigation.onBeforeNavigate.addListener(
216 function listener(details) {
217 // We create a bunch of tabs in other tests, which can potentially
218 // show up here. If this becomes too much of a problem, we can isolate
219 // these tests further, but for now, just using a unique url should be
220 // sufficient.
221 if (details.url.indexOf('unique') == -1)
222 return;
223 if (details.url.indexOf('simple.html') != -1)
224 sawSimple1 = true;
225 else if (details.url.indexOf('simple2.html') != -1)
226 sawSimple2 = true;
227 else
228 chrome.test.fail(details.url);
229
230 if (sawSimple1 && sawSimple2) {
231 chrome.webNavigation.onBeforeNavigate.removeListener(listener);
232 resolve();
233 }
234 });
235 });
236
237 var filtered = new Promise((resolve, reject) => {
238 chrome.webNavigation.onBeforeNavigate.addListener(
239 function listener(details) {
240 chrome.test.assertTrue(details.url.indexOf('unique') != -1);
241 chrome.test.assertTrue(details.url.indexOf('simple2.html') != -1,
242 details.url);
243 chrome.webNavigation.onBeforeNavigate.removeListener(listener);
244 resolve();
245 }, {url: [{pathContains: 'simple2.html'}]});
246 });
247
248 var url1 =
249 'http://unique.com:' + portNumber + '/native_bindings/simple.html';
250 var url2 =
251 'http://unique.com:' + portNumber + '/native_bindings/simple2.html';
252 chrome.tabs.create({url: url1});
253 chrome.tabs.create({url: url2});
254
255 Promise.all([unfiltered, filtered]).then(() => { chrome.test.succeed(); });
256 },
209 ]; 257 ];
210 258
211 chrome.test.getConfig(config => { 259 chrome.test.getConfig(config => {
212 chrome.test.assertTrue(!!config, 'config does not exist'); 260 chrome.test.assertTrue(!!config, 'config does not exist');
213 chrome.test.assertTrue(!!config.testServer, 'testServer does not exist'); 261 chrome.test.assertTrue(!!config.testServer, 'testServer does not exist');
214 portNumber = config.testServer.port; 262 portNumber = config.testServer.port;
215 chrome.test.runTests(tests); 263 chrome.test.runTests(tests);
216 }); 264 });
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/native_bindings/extension/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698