OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <script src="inspector-protocol-test.js"></script> |
| 5 <script> |
| 6 function test() |
| 7 { |
| 8 InspectorTest.log("Test started"); |
| 9 |
| 10 var testCookies = [ |
| 11 function simpleCookieAdd(done) |
| 12 { |
| 13 setCookie({url: "http://127.0.0.1", name: "foo", value: "bar1"}, don
e); |
| 14 }, |
| 15 |
| 16 function simpleCookieChange(done) |
| 17 { |
| 18 setCookie({url: "http://127.0.0.1", name: "foo", value: "second bar2
"}, done); |
| 19 }, |
| 20 |
| 21 function anotherSimpleCookieAdd(done) |
| 22 { |
| 23 setCookie({url: "http://127.0.0.1", name: "foo2", value: "bar1"}, do
ne); |
| 24 }, |
| 25 |
| 26 function simpleCookieDelete(done) |
| 27 { |
| 28 deleteCookie({url: "http://127.0.0.1", cookieName: "foo"}, done); |
| 29 }, |
| 30 |
| 31 deleteAllCookies, |
| 32 |
| 33 function sessionCookieAdd(done) |
| 34 { |
| 35 setCookie({url: "http://127.0.0.1", name: "foo", value: "bar4", expi
rationDate: undefined}, done); |
| 36 }, |
| 37 |
| 38 deleteAllCookies, |
| 39 |
| 40 function nonSessionCookieZeroAdd(done) |
| 41 { |
| 42 setCookie({url: "http://127.0.0.1", name: "foo", value: "bar5", expi
rationDate: 0}, done); |
| 43 }, |
| 44 |
| 45 deleteAllCookies, |
| 46 |
| 47 function nonSessionCookieAdd(done) |
| 48 { |
| 49 setCookie({url: "http://127.0.0.1", name: "foo", value: "bar6", expi
rationDate: new Date().getTime() + 1000000}, done); |
| 50 }, |
| 51 |
| 52 deleteAllCookies, |
| 53 |
| 54 function differentOriginCookieAdd(done) |
| 55 { |
| 56 // Will result in success but not show up |
| 57 setCookie({url: "http://example.com", name: "foo", value: "bar7"}, d
one); |
| 58 }, |
| 59 |
| 60 function invalidCookieAddDomain(done) |
| 61 { |
| 62 setCookie({url: "ht2tp://127.0.0.1", name: "foo", value: "bar8"}, do
ne); |
| 63 }, |
| 64 |
| 65 function invalidCookieAddName(done) |
| 66 { |
| 67 setCookie({url: "http://127.0.0.1", name: "foo\0\r\na", value: "bar9
"}, done); |
| 68 } |
| 69 |
| 70 ]; |
| 71 |
| 72 enableNetwork(); |
| 73 |
| 74 function enableNetwork() |
| 75 { |
| 76 InspectorTest.log("Enabling network"); |
| 77 InspectorTest.sendCommandOrDie("Network.enable", {}, InspectorTest.runTe
stSuite(testCookies)); |
| 78 } |
| 79 |
| 80 function setCookie(cookie, done) |
| 81 { |
| 82 InspectorTest.log("Setting Cookie"); |
| 83 InspectorTest.sendCommandOrDie("Network.setCookie", cookie, (response) =
> logCookies(done, response.success)); |
| 84 } |
| 85 |
| 86 function deleteCookie(cookie, done) |
| 87 { |
| 88 InspectorTest.log("Deleting Cookie"); |
| 89 InspectorTest.sendCommandOrDie("Network.deleteCookie", cookie, () => log
Cookies(done)); |
| 90 } |
| 91 |
| 92 function deleteAllCookies(done) |
| 93 { |
| 94 InspectorTest.log("Removing All Cookies"); |
| 95 InspectorTest.sendCommandOrDie("Network.getCookies", {}, gotCookiesForDe
lete.bind(null, done)); |
| 96 } |
| 97 |
| 98 function gotCookiesForDelete(done, data) |
| 99 { |
| 100 var promises = []; |
| 101 for (var cookie of data.cookies) { |
| 102 var url = "http://" + cookie.domain + "/" + cookie.path; |
| 103 promises.push(InspectorTest.sendCommandPromise("Network.deleteCookie
", {url: url, cookieName: cookie.name})); |
| 104 } |
| 105 |
| 106 Promise.all(promises).then(logCookies.bind(null, done, undefined)); |
| 107 } |
| 108 |
| 109 function logCookies(done, success) |
| 110 { |
| 111 |
| 112 InspectorTest.log("Logging Cookies"); |
| 113 if (success !== undefined) |
| 114 InspectorTest.log("Success: " + success); |
| 115 InspectorTest.sendCommandOrDie("Network.getCookies", {}, logReceivedGetC
ookies.bind(null, done)); |
| 116 } |
| 117 function logReceivedGetCookies(done, data) |
| 118 { |
| 119 InspectorTest.log("Num of cookies " + data.cookies.length); |
| 120 for (var cookie of data.cookies) { |
| 121 InspectorTest.log(" Cookie: "); |
| 122 InspectorTest.log(" Domain: " + cookie.domain); |
| 123 InspectorTest.log(" Name: " + cookie.name); |
| 124 InspectorTest.log(" Value: " + cookie.value); |
| 125 InspectorTest.log(" Path: " + cookie.path); |
| 126 InspectorTest.log(" HttpOnly: " + cookie.httpOnly); |
| 127 InspectorTest.log(" Secure: " + cookie.secure); |
| 128 InspectorTest.log(" Session: " + cookie.session); |
| 129 } |
| 130 done(); |
| 131 } |
| 132 } |
| 133 </script> |
| 134 </head> |
| 135 <body onload="runTest();"> |
| 136 <p>Tests that cookies are set, updated and removed.</p> |
| 137 </body> |
| 138 </html> |
OLD | NEW |