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

Unified Diff: chrome/test/data/extensions/api_test/webrequest/test_unload4.js

Issue 2003593002: Add tests for webRequest events and frame unload (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: battre's nits 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_unload4.js
diff --git a/chrome/test/data/extensions/api_test/webrequest/test_unload4.js b/chrome/test/data/extensions/api_test/webrequest/test_unload4.js
new file mode 100644
index 0000000000000000000000000000000000000000..7183498baeeb5d592ac4aff2297d95fc2d38abe3
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/webrequest/test_unload4.js
@@ -0,0 +1,135 @@
+// 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.
+
+runTests([
+ // Loads a slow image in an iframe and removes it.
+ function loadImageAndRemoveFrame() {
+ const hostname = 'slow-resourcetype-image-remove-frame';
+ const url = getSlowURL(hostname);
+ const mainUrl = getPageWithFrame('empty.html', hostname);
+
+ expect([
+ { label: 'onBeforeRequest',
+ event: 'onBeforeRequest',
+ details: {
+ type: 'image',
+ url,
+ frameId: 1,
+ parentFrameId: 0,
+ frameUrl: 'unknown frame URL',
+ }
+ },
+ { label: 'onBeforeSendHeaders',
+ event: 'onBeforeSendHeaders',
+ details: {
+ type: 'image',
+ url,
+ frameId: 1,
+ parentFrameId: 0,
+ },
+ },
+ { label: 'onSendHeaders',
+ event: 'onSendHeaders',
+ details: {
+ type: 'image',
+ url,
+ frameId: 1,
+ parentFrameId: 0,
+ },
+ },
+ { label: 'onErrorOccurred',
+ event: 'onErrorOccurred',
+ details: {
+ type: 'image',
+ url,
+ frameId: 1,
+ parentFrameId: 0,
+ fromCache: false,
+ error: 'net::ERR_ABORTED',
+ },
+ }],
+ [['onBeforeRequest', 'onBeforeSendHeaders', 'onSendHeaders',
+ 'onErrorOccurred']],
+ {
+ urls: ['<all_urls>'],
+ types: ['image'],
+ });
+
+ waitUntilSendHeaders('image', url, function() {
+ // Cancels load and triggers onErrorOccurred.
+ chrome.tabs.executeScript(tabId, {
+ code: 'document.querySelector("iframe").remove();',
+ });
+ });
+
+ navigateAndWait(mainUrl, function() {
+ chrome.tabs.executeScript(tabId, {
+ allFrames: true,
+ code: `if (top !== window) {
+ var img = new Image();
+ img.src = '${url}';
+ }`
+ });
+ });
+ },
+
+ // Load a slow image in the main frame and close the tab.
+ function loadImageAndRemoveTab() {
+ const hostname = 'slow-resourcetype-image-remove-tab';
+ const url = getSlowURL(hostname);
+ const mainUrl = getServerURL('empty.html', hostname);
+
+ expect([
+ { label: 'onBeforeRequest',
+ event: 'onBeforeRequest',
+ details: {
+ type: 'image',
+ url,
+ frameUrl: 'unknown frame URL',
+ }
+ },
+ { label: 'onBeforeSendHeaders',
+ event: 'onBeforeSendHeaders',
+ details: {
+ type: 'image',
+ url,
+ },
+ },
+ { label: 'onSendHeaders',
+ event: 'onSendHeaders',
+ details: {
+ type: 'image',
+ url,
+ },
+ },
+ { label: 'onErrorOccurred',
+ event: 'onErrorOccurred',
+ details: {
+ type: 'image',
+ url,
+ fromCache: false,
+ error: 'net::ERR_ABORTED',
+ },
+ }],
+ [['onBeforeRequest', 'onBeforeSendHeaders', 'onSendHeaders',
+ 'onErrorOccurred']],
+ {
+ urls: ['<all_urls>'],
+ types: ['image'],
+ });
+
+ var callbackDone = chrome.test.callbackAdded();
+
+ waitUntilSendHeaders('image', url, function() {
+ // Cancels load and triggers onErrorOccurred.
+ chrome.tabs.remove(tabId, callbackDone);
+ }),
+
+ navigateAndWait(mainUrl, function() {
+ chrome.tabs.executeScript(tabId, {
+ code: `var img = new Image(); img.src = '${url}';`
+ });
+ });
+ },
+]);

Powered by Google App Engine
This is Rietveld 408576698