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

Side by Side Diff: chrome/test/data/extensions/api_test/webrequest/test_unload5.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 runTests([
6 // Start a XMLHttpRequest in an frame and remove the frame.
battre 2016/05/23 11:17:08 nit: a frame
robwu 2016/05/23 11:51:03 Done.
7 // Unlike the previous tests (test_unload1, 2, 3, 4), this test doesn't wait
8 // for a server response and immediately removes the frame after issuing an
9 // asynchronous request.
10 function startXMLHttpRequestAndRemoveFrame() {
11 const hostname = 'slow-resourcetype-xhr-immediately-remove-frame';
12 const url = getSlowURL(hostname);
13 const mainUrl = getPageWithFrame('empty.html', hostname);
14
15 expect([
16 { label: 'onBeforeRequest',
17 event: 'onBeforeRequest',
18 details: {
19 type: 'xmlhttprequest',
20 url,
21 frameId: 1,
22 parentFrameId: 0,
23 frameUrl: 'unknown frame URL',
24 }
25 },
26 { label: 'onBeforeSendHeaders',
27 event: 'onBeforeSendHeaders',
28 details: {
29 type: 'xmlhttprequest',
30 url,
31 frameId: 1,
32 parentFrameId: 0,
33 },
34 },
35 { label: 'onSendHeaders',
36 event: 'onSendHeaders',
37 details: {
38 type: 'xmlhttprequest',
39 url,
40 frameId: 1,
41 parentFrameId: 0,
42 },
43 },
44 { label: 'onErrorOccurred',
45 event: 'onErrorOccurred',
46 details: {
47 type: 'xmlhttprequest',
48 url,
49 frameId: 1,
50 parentFrameId: 0,
51 fromCache: false,
52 error: 'net::ERR_ABORTED',
53 },
54 }],
55 [['onBeforeRequest', 'onBeforeSendHeaders', 'onSendHeaders',
56 'onErrorOccurred']],
57 {
58 urls: ['<all_urls>'],
59 types: ['xmlhttprequest'],
60 });
61
62 navigateAndWait(mainUrl, function() {
63 chrome.tabs.executeScript(tabId, {
64 allFrames: true,
65 code: `if (top !== window) {
66 var x = new XMLHttpRequest();
67 x.open('GET', '${url}', true);
68 x.send();
69 frameElement.remove();
70 }`
71 });
72 });
73 },
74
75 // Start a XMLHttpRequest in the main frame and immediately remove the tab.
battre 2016/05/23 11:17:08 nit: "an XMLHttpRequest"
robwu 2016/05/23 11:51:03 Done.
76 function startXMLHttpRequestAndRemoveTab() {
77 const hostname = 'slow-resourcetype-xhr-immediately-remove-tab';
78 const url = getSlowURL(hostname);
79 const mainUrl = getServerURL('empty.html', hostname);
80
81 expect([
82 { label: 'onBeforeRequest',
83 event: 'onBeforeRequest',
84 details: {
85 type: 'xmlhttprequest',
86 url,
87 frameUrl: 'unknown frame URL',
88 tabId: 1,
89 }
90 },
91 { label: 'onBeforeSendHeaders',
92 event: 'onBeforeSendHeaders',
93 details: {
94 type: 'xmlhttprequest',
95 url,
96 tabId: 1,
97 },
98 },
99 { label: 'onSendHeaders',
100 event: 'onSendHeaders',
101 details: {
102 type: 'xmlhttprequest',
103 url,
104 tabId: 1,
105 },
106 },
107 { label: 'onErrorOccurred',
108 event: 'onErrorOccurred',
109 details: {
110 type: 'xmlhttprequest',
111 url,
112 fromCache: false,
113 error: 'net::ERR_ABORTED',
114 tabId: 1,
115 },
116 }],
117 [['onBeforeRequest', 'onBeforeSendHeaders', 'onSendHeaders',
118 'onErrorOccurred']],
119 {
120 urls: ['<all_urls>'],
121 types: ['xmlhttprequest'],
122 });
123
124 var callbackDone = chrome.test.callbackAdded();
125
126 // Creating a new tab instead of re-using the tab from the test framework
127 // because a page can only close itself if it has no navigation history.
128 chrome.tabs.create({
129 url: mainUrl,
130 }, function(tab) {
131 chrome.tabs.executeScript(tab.id, {
132 code: `
133 var x = new XMLHttpRequest();
134 x.open('GET', '${url}', true);
135 x.send();
136 window.close();
137 // Closing the tab should not be blocked. If it does, then the slow
138 // request will eventually complete and cause a test failure.
139 `
140 }, callbackDone);
141 });
142 },
143 ]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698