| OLD | NEW |
| (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 // Starts an XMLHttpRequest in an iframe and removes the frame. |
| 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 // Starts an XMLHttpRequest in the main frame and immediately remove the tab. |
| 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 ]); |
| OLD | NEW |