OLD | NEW |
(Empty) | |
| 1 <script src="framework.js"> |
| 2 </script> |
| 3 <script> |
| 4 // Constants as functions, not to be called until after runTests. |
| 5 function getURLEchoUserAgent() { |
| 6 return getServerURL('echoheader?User-Agent'); |
| 7 } |
| 8 |
| 9 runTests([ |
| 10 // Navigates to a page with subresources, with a blocking handler that |
| 11 // cancels the page request. The page will not load, and we should not |
| 12 // see the subresources. |
| 13 function complexLoadCancelled() { |
| 14 expect( |
| 15 [ // events |
| 16 { label: "onBeforeRequest", |
| 17 event: "onBeforeRequest", |
| 18 details: { |
| 19 method: "GET", |
| 20 tabId: tabId, |
| 21 type: "main_frame", |
| 22 url: getURL("complexLoad/a.html"), |
| 23 frameUrl: getURL("complexLoad/a.html") |
| 24 }, |
| 25 retval: {cancel: true} |
| 26 }, |
| 27 // Cancelling is considered an error. |
| 28 { label: "onErrorOccurred", |
| 29 event: "onErrorOccurred", |
| 30 details: { |
| 31 url: getURL("complexLoad/a.html"), |
| 32 fromCache: false, |
| 33 error: "net::ERR_EMPTY_RESPONSE" |
| 34 // Request to chrome-extension:// url has no IP. |
| 35 } |
| 36 }, |
| 37 ], |
| 38 [ // event order |
| 39 ["onBeforeRequest"] |
| 40 ], |
| 41 {}, // filter |
| 42 ["blocking"]); |
| 43 console.log("load canc: navigating to a"); |
| 44 navigateAndWait(getURL("complexLoad/a.html")); |
| 45 }, |
| 46 |
| 47 // Navigates to a page with a blocking handler that redirects to a different |
| 48 // page. |
| 49 // TODO(mpcomplete): We should see an onBeforeRedirect as well, but our |
| 50 // process switching logic cancels the original redirect request and |
| 51 // starts a new one instead. See http://crbug.com/79520. |
| 52 function complexLoadRedirected() { |
| 53 expect( |
| 54 [ // events |
| 55 { label: "onBeforeRequest-1", |
| 56 event: "onBeforeRequest", |
| 57 details: { |
| 58 method: "GET", |
| 59 tabId: tabId, |
| 60 type: "main_frame", |
| 61 url: getURL("complexLoad/a.html"), |
| 62 frameUrl: getURL("complexLoad/a.html") |
| 63 }, |
| 64 retval: {redirectUrl: getURL("simpleLoad/a.html")} |
| 65 }, |
| 66 { label: "onErrorOccurred-1", |
| 67 event: "onErrorOccurred", |
| 68 details: { |
| 69 url: getURL("complexLoad/a.html"), |
| 70 fromCache: false, |
| 71 error: "net::ERR_ABORTED" |
| 72 // Request to chrome-extension:// url has no IP. |
| 73 } |
| 74 }, |
| 75 { label: "onBeforeRequest-2", |
| 76 event: "onBeforeRequest", |
| 77 details: { |
| 78 method: "GET", |
| 79 tabId: tabId, |
| 80 type: "main_frame", |
| 81 url: getURL("simpleLoad/a.html"), |
| 82 frameUrl: getURL("simpleLoad/a.html"), |
| 83 }, |
| 84 }, |
| 85 { label: "onResponseStarted", |
| 86 event: "onResponseStarted", |
| 87 details: { |
| 88 url: getURL("simpleLoad/a.html"), |
| 89 fromCache: false, |
| 90 statusCode: 200 |
| 91 // Request to chrome-extension:// url has no IP. |
| 92 } |
| 93 }, |
| 94 { label: "onCompleted", |
| 95 event: "onCompleted", |
| 96 details: { |
| 97 url: getURL("simpleLoad/a.html"), |
| 98 fromCache: false, |
| 99 statusCode: 200 |
| 100 // Request to chrome-extension:// url has no IP. |
| 101 } |
| 102 }, |
| 103 ], |
| 104 [ // event order |
| 105 ["onBeforeRequest-1", "onErrorOccurred-1", "onBeforeRequest-2", |
| 106 "onResponseStarted", "onCompleted"], |
| 107 ], |
| 108 {}, // filter |
| 109 ["blocking"]); |
| 110 console.log("load redir: navigating"); |
| 111 navigateAndWait(getURL("complexLoad/a.html")); |
| 112 }, |
| 113 |
| 114 // Loads a testserver page that echoes the User-Agent header that was |
| 115 // sent to fetch it. We modify the outgoing User-Agent in |
| 116 // onBeforeSendHeaders, so we should see that modified version. |
| 117 function modifyRequestHeaders() { |
| 118 expect( |
| 119 [ // events |
| 120 { label: "onBeforeRequest", |
| 121 event: "onBeforeRequest", |
| 122 details: { |
| 123 method: "GET", |
| 124 tabId: tabId, |
| 125 type: "main_frame", |
| 126 url: getURLEchoUserAgent(), |
| 127 frameUrl: getURLEchoUserAgent() |
| 128 } |
| 129 }, |
| 130 { label: "onBeforeSendHeaders", |
| 131 event: "onBeforeSendHeaders", |
| 132 details: { |
| 133 url: getURLEchoUserAgent(), |
| 134 // Note: no requestHeaders because we don't ask for them. |
| 135 }, |
| 136 retval: {requestHeaders: [{name: "User-Agent", value: "FoobarUA"}]} |
| 137 }, |
| 138 { label: "onSendHeaders", |
| 139 event: "onSendHeaders", |
| 140 details: { |
| 141 url: getURLEchoUserAgent() |
| 142 } |
| 143 }, |
| 144 { label: "onResponseStarted", |
| 145 event: "onResponseStarted", |
| 146 details: { |
| 147 url: getURLEchoUserAgent(), |
| 148 fromCache: false, |
| 149 statusCode: 200, |
| 150 ip: "127.0.0.1" |
| 151 } |
| 152 }, |
| 153 { label: "onCompleted", |
| 154 event: "onCompleted", |
| 155 details: { |
| 156 url: getURLEchoUserAgent(), |
| 157 fromCache: false, |
| 158 statusCode: 200, |
| 159 ip: "127.0.0.1" |
| 160 } |
| 161 }, |
| 162 ], |
| 163 [ // event order |
| 164 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders", |
| 165 "onResponseStarted", "onCompleted"] |
| 166 ], |
| 167 {}, ["blocking"]); |
| 168 // Check the page content for our modified User-Agent string. |
| 169 console.log("mod headers: 1"); |
| 170 navigateAndWait(getURLEchoUserAgent(), function() { |
| 171 console.log("mod headers: 2"); |
| 172 chrome.test.listenOnce(chrome.extension.onRequest, function(request) { |
| 173 console.log("mod headers: 2.1"); |
| 174 chrome.test.assertTrue(request.pass, "Request header was not set."); |
| 175 }); |
| 176 console.log("mod headers: 3"); |
| 177 chrome.tabs.executeScript(tabId, |
| 178 { |
| 179 code: "chrome.extension.sendRequest(" + |
| 180 "{pass: document.body.innerText.indexOf('FoobarUA') >= 0});" |
| 181 }); |
| 182 }); |
| 183 }, |
| 184 ]); |
| 185 </script> |
OLD | NEW |