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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/api_test/webrequest/test_unload.js
diff --git a/chrome/test/data/extensions/api_test/webrequest/test_unload.js b/chrome/test/data/extensions/api_test/webrequest/test_unload.js
new file mode 100644
index 0000000000000000000000000000000000000000..51d33ce551c269001f7b76201647b51b20cb0f70
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/webrequest/test_unload.js
@@ -0,0 +1,65 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Returns a URL of a page that generates a response after waiting for a long
+// 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.
+// |hostname| can be set to make sure that the frame is created in a new process
+// if site isolation is enabled.
+function getSlowURL(hostname) {
+ // Waiting for 10 seconds should be more than sufficient.
+ return getServerURL('slow?10', hostname);
+}
+
+// Get the URL of a page that inserts a frame with the given URL upon load.
+function getPageWithFrame(frameUrl, hostname) {
+ return getServerURL('extensions/api_test/webrequest/unload/load_frame.html?' +
+ encodeURIComponent(frameUrl), hostname);
+}
+
+// Invokes |callback| when when the onSendHeaders event occurs. When used with
+// 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.
+// there won't be any webRequest events for a long while.
+// This allows the test to deterministically cancel the request, which should
+// trigger onErrorOccurred.
+function waitUntilSendHeaders(type, url, callback) {
+ chrome.test.assertTrue(/^https?:.+\/slow\?/.test(url),
+ 'Must be a slow URL, but was ' + url);
+
+ chrome.webRequest.onSendHeaders.addListener(function listener() {
+ chrome.webRequest.onSendHeaders.removeListener(listener);
+ callback();
+ }, {
+ types: [type],
+ urls: [url],
+ });
+}
+
+(function() {
+ // Load the actual test file.
+ var id = location.search.slice(1);
+ chrome.test.assertTrue(/^\d+$/.test(id),
+ 'Page URL should end with digits, but got ' + id);
+ console.log('Running test_unload ' + id);
+
+ var s = document.createElement('script');
+ // test_unload1.js, test_unload2.js, ..., etc.
+ // These tests are in separate files to make sure that the tests are
+ // independent of each other. If they were put in one file, then the tabId
+ // of one test would depend on the number of tabs from the previous tests.
+ s.src = 'test_unload' + id + '.js';
+ s.onerror = function() {
+ chrome.test.fail('Failed to load test ' + s.src);
+ };
+
+ // At the next test, a call to RunExtensionSubtest causes the extension to
+ // reload. As a result, all extension pages are closed. If the extension page
+ // was the only tab in the browser, then the browser would exit and cause the
+ // test to end too early. To avoid this problem, create an extra non-extension
+ // tab before starting tests.
+ chrome.tabs.create({
+ url: 'data:,'
+ }, function() {
+ document.body.appendChild(s);
+ });
+})();

Powered by Google App Engine
This is Rietveld 408576698