| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var pass = chrome.test.callbackPass; | 5 var pass = chrome.test.callbackPass; |
| 6 | 6 |
| 7 // Constants as functions, not to be called until after runTests. | 7 // Constants as functions, not to be called until after runTests. |
| 8 function getURLEchoUserAgent() { | 8 function getURLEchoUserAgent() { |
| 9 return getServerURL('echoheader?User-Agent'); | 9 return getServerURL('echoheader?User-Agent'); |
| 10 } | 10 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 [ // event order | 118 [ // event order |
| 119 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders", | 119 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders", |
| 120 "onHeadersReceived", "onErrorOccurred"] | 120 "onHeadersReceived", "onErrorOccurred"] |
| 121 ], | 121 ], |
| 122 {urls: ["<all_urls>"]}, // filter | 122 {urls: ["<all_urls>"]}, // filter |
| 123 ["blocking"]); | 123 ["blocking"]); |
| 124 navigateAndWait(getURLHttpSimpleLoad()); | 124 navigateAndWait(getURLHttpSimpleLoad()); |
| 125 }, | 125 }, |
| 126 | 126 |
| 127 // Navigates to a page and provides invalid header information. The request | 127 // Navigates to a page and provides invalid header information. The request |
| 128 // gets canceled. | 128 // should continue as if the headers were not changed. |
| 129 function simpleLoadCancelledOnReceiveHeadersInvalidHeaders() { | 129 function simpleLoadIgnoreOnBeforeSendHeadersInvalidHeaders() { |
| 130 expect( | 130 expect( |
| 131 [ // events | 131 [ // events |
| 132 { label: "onBeforeRequest", | 132 { label: "onBeforeRequest", |
| 133 event: "onBeforeRequest", | 133 event: "onBeforeRequest", |
| 134 details: { | 134 details: { |
| 135 method: "GET", | 135 method: "GET", |
| 136 type: "main_frame", | 136 type: "main_frame", |
| 137 url: getURLHttpSimpleLoad(), | 137 url: getURLHttpSimpleLoad(), |
| 138 frameUrl: getURLHttpSimpleLoad() | 138 frameUrl: getURLHttpSimpleLoad() |
| 139 }, | 139 }, |
| 140 }, | 140 }, |
| 141 { label: "onBeforeSendHeaders", | 141 { label: "onBeforeSendHeaders", |
| 142 event: "onBeforeSendHeaders", | 142 event: "onBeforeSendHeaders", |
| 143 details: { | 143 details: { |
| 144 url: getURLHttpSimpleLoad(), | 144 url: getURLHttpSimpleLoad(), |
| 145 // Note: no requestHeaders because we don't ask for them. | 145 requestHeadersValid: true |
| 146 }, | 146 }, |
| 147 retval: {requestHeaders: [{name: "User-Agent"}]} | 147 retval: {requestHeaders: [{name: "User-Agent"}]} |
| 148 }, | 148 }, |
| 149 // Cancelling is considered an error. | 149 // The headers were invalid, so they should not be modified. |
| 150 { label: "onErrorOccurred", | 150 // TODO(robwu): Test whether an error is logged to the console. |
| 151 event: "onErrorOccurred", | 151 { label: "onSendHeaders", |
| 152 event: "onSendHeaders", |
| 153 details: { |
| 154 url: getURLHttpSimpleLoad(), |
| 155 requestHeadersValid: true |
| 156 } |
| 157 }, |
| 158 { label: "onHeadersReceived", |
| 159 event: "onHeadersReceived", |
| 160 details: { |
| 161 url: getURLHttpSimpleLoad(), |
| 162 statusLine: "HTTP/1.1 200 OK", |
| 163 } |
| 164 }, |
| 165 { label: "onResponseStarted", |
| 166 event: "onResponseStarted", |
| 152 details: { | 167 details: { |
| 153 url: getURLHttpSimpleLoad(), | 168 url: getURLHttpSimpleLoad(), |
| 154 fromCache: false, | 169 fromCache: false, |
| 155 error: "net::ERR_BLOCKED_BY_CLIENT" | 170 statusCode: 200, |
| 156 // Request to chrome-extension:// url has no IP. | 171 ip: "127.0.0.1", |
| 172 statusLine: "HTTP/1.1 200 OK", |
| 173 } |
| 174 }, |
| 175 { label: "onCompleted", |
| 176 event: "onCompleted", |
| 177 details: { |
| 178 url: getURLHttpSimpleLoad(), |
| 179 fromCache: false, |
| 180 statusCode: 200, |
| 181 ip: "127.0.0.1", |
| 182 statusLine: "HTTP/1.1 200 OK", |
| 157 } | 183 } |
| 158 }, | 184 }, |
| 159 ], | 185 ], |
| 160 [ // event order | 186 [ // event order |
| 161 ["onBeforeRequest", "onBeforeSendHeaders", "onErrorOccurred"] | 187 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders", |
| 188 "onHeadersReceived", "onResponseStarted", "onCompleted"] |
| 162 ], | 189 ], |
| 163 {urls: ["<all_urls>"]}, // filter | 190 {urls: ["<all_urls>"]}, // filter |
| 164 ["blocking"]); | 191 ["blocking", "requestHeaders"]); |
| 165 navigateAndWait(getURLHttpSimpleLoad()); | 192 navigateAndWait(getURLHttpSimpleLoad()); |
| 166 }, | 193 }, |
| 167 | 194 |
| 168 // Navigates to a page and provides invalid header information. The request | 195 // Navigates to a page and provides invalid header information. The request |
| 169 // gets canceled. | 196 // should continue as if the headers were not changed. |
| 170 function simpleLoadCancelledOnReceiveHeadersInvalidResponse() { | 197 function simpleLoadIgnoreOnBeforeSendHeadersInvalidResponse() { |
| 171 expect( | 198 expect( |
| 172 [ // events | 199 [ // events |
| 173 { label: "onBeforeRequest", | 200 { label: "onBeforeRequest", |
| 174 event: "onBeforeRequest", | 201 event: "onBeforeRequest", |
| 175 details: { | 202 details: { |
| 176 method: "GET", | 203 method: "GET", |
| 177 type: "main_frame", | 204 type: "main_frame", |
| 178 url: getURLHttpSimpleLoad(), | 205 url: getURLHttpSimpleLoad(), |
| 179 frameUrl: getURLHttpSimpleLoad() | 206 frameUrl: getURLHttpSimpleLoad() |
| 180 }, | 207 }, |
| 181 }, | 208 }, |
| 182 { label: "onBeforeSendHeaders", | 209 { label: "onBeforeSendHeaders", |
| 183 event: "onBeforeSendHeaders", | 210 event: "onBeforeSendHeaders", |
| 184 details: { | 211 details: { |
| 185 url: getURLHttpSimpleLoad(), | 212 url: getURLHttpSimpleLoad(), |
| 186 // Note: no requestHeaders because we don't ask for them. | 213 requestHeadersValid: true |
| 187 }, | 214 }, |
| 188 retval: {foo: "bar"} | 215 retval: {foo: "bar"} |
| 189 }, | 216 }, |
| 190 // Cancelling is considered an error. | 217 // TODO(robwu): Test whether an error is logged to the console. |
| 191 { label: "onErrorOccurred", | 218 { label: "onSendHeaders", |
| 192 event: "onErrorOccurred", | 219 event: "onSendHeaders", |
| 220 details: { |
| 221 url: getURLHttpSimpleLoad(), |
| 222 requestHeadersValid: true |
| 223 } |
| 224 }, |
| 225 { label: "onHeadersReceived", |
| 226 event: "onHeadersReceived", |
| 227 details: { |
| 228 url: getURLHttpSimpleLoad(), |
| 229 statusLine: "HTTP/1.1 200 OK", |
| 230 } |
| 231 }, |
| 232 { label: "onResponseStarted", |
| 233 event: "onResponseStarted", |
| 193 details: { | 234 details: { |
| 194 url: getURLHttpSimpleLoad(), | 235 url: getURLHttpSimpleLoad(), |
| 195 fromCache: false, | 236 fromCache: false, |
| 196 error: "net::ERR_BLOCKED_BY_CLIENT" | 237 statusCode: 200, |
| 197 // Request to chrome-extension:// url has no IP. | 238 ip: "127.0.0.1", |
| 239 statusLine: "HTTP/1.1 200 OK", |
| 240 } |
| 241 }, |
| 242 { label: "onCompleted", |
| 243 event: "onCompleted", |
| 244 details: { |
| 245 url: getURLHttpSimpleLoad(), |
| 246 fromCache: false, |
| 247 statusCode: 200, |
| 248 ip: "127.0.0.1", |
| 249 statusLine: "HTTP/1.1 200 OK", |
| 198 } | 250 } |
| 199 }, | 251 }, |
| 200 ], | 252 ], |
| 201 [ // event order | 253 [ // event order |
| 202 ["onBeforeRequest", "onBeforeSendHeaders", "onErrorOccurred"] | 254 ["onBeforeRequest", "onBeforeSendHeaders", "onSendHeaders", |
| 255 "onHeadersReceived", "onResponseStarted", "onCompleted"] |
| 203 ], | 256 ], |
| 204 {urls: ["<all_urls>"]}, // filter | 257 {urls: ["<all_urls>"]}, // filter |
| 205 ["blocking"]); | 258 ["blocking", "requestHeaders"]); |
| 206 navigateAndWait(getURLHttpSimpleLoad()); | 259 navigateAndWait(getURLHttpSimpleLoad()); |
| 207 }, | 260 }, |
| 208 | 261 |
| 209 // Navigates to a page with a blocking handler that redirects to a different | 262 // Navigates to a page with a blocking handler that redirects to a different |
| 210 // page. | 263 // page. |
| 211 function complexLoadRedirected() { | 264 function complexLoadRedirected() { |
| 212 expect( | 265 expect( |
| 213 [ // events | 266 [ // events |
| 214 { label: "onBeforeRequest-1", | 267 { label: "onBeforeRequest-1", |
| 215 event: "onBeforeRequest", | 268 event: "onBeforeRequest", |
| (...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 // Check the page content for our modified User-Agent string. | 984 // Check the page content for our modified User-Agent string. |
| 932 navigateAndWait(getURL("simpleLoad/a.html"), function() { | 985 navigateAndWait(getURL("simpleLoad/a.html"), function() { |
| 933 var req = new XMLHttpRequest(); | 986 var req = new XMLHttpRequest(); |
| 934 var asynchronous = true; | 987 var asynchronous = true; |
| 935 req.open("GET", getURLHttpXHRData(), asynchronous); | 988 req.open("GET", getURLHttpXHRData(), asynchronous); |
| 936 req.send(null); | 989 req.send(null); |
| 937 navigateAndWait(getURL("complexLoad/b.jpg")); | 990 navigateAndWait(getURL("complexLoad/b.jpg")); |
| 938 }); | 991 }); |
| 939 }, | 992 }, |
| 940 ]); | 993 ]); |
| OLD | NEW |