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

Side by Side Diff: chrome/test/data/extensions/api_test/webrequest/test_unload.js

Issue 2003593002: Add tests for webRequest events and frame unload (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 // Returns a URL of a page that generates a response after waiting for a long
6 // while. You should try to cancel the request as soon as reasonably possible.
battre 2016/05/23 11:17:07 The comment "You should try..." does not seem to b
robwu 2016/05/23 11:51:03 Reworded and added a small file-level comment.
7 // |hostname| can be set to make sure that the frame is created in a new process
8 // if site isolation is enabled.
9 function getSlowURL(hostname) {
10 // Waiting for 10 seconds should be more than sufficient.
11 return getServerURL('slow?10', hostname);
12 }
13
14 // Get the URL of a page that inserts a frame with the given URL upon load.
15 function getPageWithFrame(frameUrl, hostname) {
16 return getServerURL('extensions/api_test/webrequest/unload/load_frame.html?' +
17 encodeURIComponent(frameUrl), hostname);
18 }
19
20 // Invokes |callback| when when the onSendHeaders event occurs. When used with
21 // getNewSlowURL(), this signals when the request has been processed and that
battre 2016/05/23 11:17:07 I guess you have renamed getNewSlowURL to getSlowU
robwu 2016/05/23 11:51:03 Done.
22 // there won't be any webRequest events for a long while.
23 // This allows the test to deterministically cancel the request, which should
24 // trigger onErrorOccurred.
25 function waitUntilSendHeaders(type, url, callback) {
26 chrome.test.assertTrue(/^https?:.+\/slow\?/.test(url),
27 'Must be a slow URL, but was ' + url);
28
29 chrome.webRequest.onSendHeaders.addListener(function listener() {
30 chrome.webRequest.onSendHeaders.removeListener(listener);
31 callback();
32 }, {
33 types: [type],
34 urls: [url],
35 });
36 }
37
38 (function() {
39 // Load the actual test file.
40 var id = location.search.slice(1);
41 chrome.test.assertTrue(/^\d+$/.test(id),
42 'Page URL should end with digits, but got ' + id);
43 console.log('Running test_unload ' + id);
44
45 var s = document.createElement('script');
46 // test_unload1.js, test_unload2.js, ..., etc.
47 // These tests are in separate files to make sure that the tests are
48 // independent of each other. If they were put in one file, then the tabId
49 // of one test would depend on the number of tabs from the previous tests.
50 s.src = 'test_unload' + id + '.js';
51 s.onerror = function() {
52 chrome.test.fail('Failed to load test ' + s.src);
53 };
54
55 // At the next test, a call to RunExtensionSubtest causes the extension to
56 // reload. As a result, all extension pages are closed. If the extension page
57 // was the only tab in the browser, then the browser would exit and cause the
58 // test to end too early. To avoid this problem, create an extra non-extension
59 // tab before starting tests.
60 chrome.tabs.create({
61 url: 'data:,'
62 }, function() {
63 document.body.appendChild(s);
64 });
65 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698