OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 var dirName = "requestBody/"; |
| 6 |
| 7 function sendPost(formFile, ParseableForm) { |
| 8 // The following variables must be updated when files in |dirName| change. |
| 9 var parsedForm = { |
| 10 check: ["option_A"], |
| 11 password: ["password"], |
| 12 radio: ["Yes"], |
| 13 select: ["one"], |
| 14 text1: ["TEST_TEXT_1"], |
| 15 text2: ["TEST_TEXT_2"], |
| 16 text3: ["TEST_TEXT_3"], |
| 17 txtarea: ["Text"] |
| 18 }; |
| 19 var encodedData = |
| 20 "dGV4dDE9VEVTVF9URVhUXzENCnRleHQyPVRFU1RfVEVYVF8yDQp0ZXh0Mz1URVNUX1RFW" |
| 21 + "FRfMw0KcGFzc3dvcmQ9cGFzc3dvcmQNCnJhZGlvPVllcw0KY2hlY2s9b3B0aW9uX0EN" |
| 22 + "CnR4dGFyZWE9VGV4dA0Kc2VsZWN0PW9uZQ=="; |
| 23 return function submitForm() { |
| 24 expect( |
| 25 [ // events |
| 26 { label: "a-onBeforeRequest", |
| 27 event: "onBeforeRequest", |
| 28 details: { |
| 29 method: "GET", |
| 30 type: "main_frame", |
| 31 url: getURL(dirName + formFile), |
| 32 frameUrl: getURL(dirName + formFile) |
| 33 } |
| 34 }, |
| 35 { label: "a-onResponseStarted", |
| 36 event: "onResponseStarted", |
| 37 details: { |
| 38 fromCache: false, |
| 39 method: "GET", |
| 40 statusCode: 200, |
| 41 statusLine: "HTTP/1.1 200 OK", |
| 42 type: "main_frame", |
| 43 url: getURL(dirName + formFile) |
| 44 } |
| 45 }, |
| 46 { label: "a-onCompleted", |
| 47 event: "onCompleted", |
| 48 details: { |
| 49 fromCache: false, |
| 50 method: "GET", |
| 51 statusCode: 200, |
| 52 statusLine: "HTTP/1.1 200 OK", |
| 53 type: "main_frame", |
| 54 url: getURL(dirName + formFile) |
| 55 } |
| 56 }, |
| 57 { label: "s-onBeforeRequest", |
| 58 event: "onBeforeRequest", |
| 59 details: { |
| 60 method: "GET", |
| 61 type: "script", |
| 62 url: getURL("requestBody/submit.js"), |
| 63 frameUrl: getURL(dirName + formFile) |
| 64 } |
| 65 }, |
| 66 { label: "s-onResponseStarted", |
| 67 event: "onResponseStarted", |
| 68 details: { |
| 69 fromCache: false, |
| 70 method: "GET", |
| 71 statusCode: 200, |
| 72 statusLine: "HTTP/1.1 200 OK", |
| 73 type: "script", |
| 74 url: getURL("requestBody/submit.js") |
| 75 } |
| 76 }, |
| 77 { label: "s-onCompleted", |
| 78 event: "onCompleted", |
| 79 details: { |
| 80 fromCache: false, |
| 81 method: "GET", |
| 82 statusCode: 200, |
| 83 statusLine: "HTTP/1.1 200 OK", |
| 84 type: "script", |
| 85 url: getURL("requestBody/submit.js") |
| 86 } |
| 87 }, |
| 88 { label: "b-onBeforeRequest", |
| 89 event: "onBeforeRequest", |
| 90 details: { |
| 91 method: "POST", |
| 92 type: "main_frame", |
| 93 url: getURL("requestBody/nonExistingTarget.html"), |
| 94 frameUrl: getURL("requestBody/nonExistingTarget.html"), |
| 95 body: ParseableForm ? { |
| 96 parsedForm: parsedForm |
| 97 } : { |
| 98 raw: encodedData |
| 99 } |
| 100 } |
| 101 }, |
| 102 { label: "b-onErrorOccurred", |
| 103 event: "onErrorOccurred", |
| 104 details: { |
| 105 error: "net::ERR_FILE_NOT_FOUND", |
| 106 fromCache: false, |
| 107 method: "POST", |
| 108 type: "main_frame", |
| 109 url: getURL("requestBody/nonExistingTarget.html") |
| 110 } |
| 111 } |
| 112 ], |
| 113 [ // event order |
| 114 ["a-onBeforeRequest", "a-onResponseStarted", "a-onCompleted", |
| 115 "s-onBeforeRequest", "s-onResponseStarted", "s-onCompleted", |
| 116 "b-onBeforeRequest", "b-onErrorOccurred"] |
| 117 ], |
| 118 {urls: ["<all_urls>"]}, // filter |
| 119 ["body"]); |
| 120 navigateAndWait(getURL(dirName + formFile)); |
| 121 close(); |
| 122 } |
| 123 } |
| 124 |
| 125 runTests([ |
| 126 // Navigates to a page with a form and submits it, generating a POST request. |
| 127 // First two result in url-encoded form. |
| 128 sendPost('no-enctype.html', true), |
| 129 sendPost('urlencoded.html', true), |
| 130 // Third results in multipart-encoded form. |
| 131 sendPost('multipart.html', true), |
| 132 // Fourth results in unparseable form, and thus raw data string. |
| 133 sendPost('plaintext.html', false), |
| 134 ]); |
OLD | NEW |