Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/http/tests/inspector-protocol/cookies-protocol-test.html |
| diff --git a/third_party/WebKit/LayoutTests/http/tests/inspector-protocol/cookies-protocol-test.html b/third_party/WebKit/LayoutTests/http/tests/inspector-protocol/cookies-protocol-test.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..03aec500ffa45b60c32a196460b4f474381cb587 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/http/tests/inspector-protocol/cookies-protocol-test.html |
| @@ -0,0 +1,138 @@ |
| +<!DOCTYPE html> |
| +<html> |
| +<head> |
| +<script src="inspector-protocol-test.js"></script> |
| +<script> |
| +function test() |
| +{ |
| + InspectorTest.log("Test started"); |
| + |
| + var testCookies = [ |
| + function simpleCookieAdd(done) |
| + { |
| + setCookie({url: "http://127.0.0.1", name: "foo", value: "bar1"}, done); |
| + }, |
| + |
| + function simpleCookieChange(done) |
| + { |
| + setCookie({url: "http://127.0.0.1", name: "foo", value: "second bar2"}, done); |
| + }, |
| + |
| + function anotherSimpleCookieAdd(done) |
| + { |
| + setCookie({url: "http://127.0.0.1", name: "foo2", value: "bar1"}, done); |
| + }, |
| + |
| + function simpleCookieDelete(done) |
| + { |
| + deleteCookie({url: "http://127.0.0.1", cookieName: "foo"}, done); |
| + }, |
| + |
| + deleteAllCookies, |
| + |
| + function sessionCookieAdd(done) |
| + { |
| + setCookie({url: "http://127.0.0.1", name: "foo", value: "bar4", expirationDate: undefined}, done); |
| + }, |
| + |
| + deleteAllCookies, |
| + |
| + function nonSessionCookieZeroAdd(done) |
| + { |
| + setCookie({url: "http://127.0.0.1", name: "foo", value: "bar5", expirationDate: 0}, done); |
| + }, |
| + |
| + deleteAllCookies, |
| + |
| + function nonSessionCookieAdd(done) |
| + { |
| + setCookie({url: "http://127.0.0.1", name: "foo", value: "bar6", expirationDate: new Date().getTime() + 1000000}, done); |
| + }, |
| + |
| + deleteAllCookies, |
| + |
| + function differentOriginCookieAdd(done) |
| + { |
| + // Will result in success but not show up |
| + setCookie({url: "http://example.com", name: "foo", value: "bar7"}, done); |
| + }, |
| + |
| + function invalidCookieAddDomain(done) |
| + { |
| + setCookie({url: "ht2tp://127.0.0.1", name: "foo", value: "bar8"}, done); |
| + }, |
| + |
| + function invalidCookieAddName(done) |
| + { |
| + setCookie({url: "http://127.0.0.1", name: "foo\0\r\na", value: "bar9"}, done); |
|
dgozman
2016/08/16 18:56:59
Let's also exercise passing domain, path, secure,
allada
2016/08/16 21:30:56
Done.
|
| + } |
| + |
| + ]; |
| + |
| + enableNetwork(); |
| + |
| + function enableNetwork() |
| + { |
| + InspectorTest.log("Enabling network"); |
| + InspectorTest.sendCommandOrDie("Network.enable", {}, InspectorTest.runTestSuite(testCookies)); |
| + } |
| + |
| + function setCookie(cookie, done) |
| + { |
| + InspectorTest.log("Setting Cookie"); |
| + InspectorTest.sendCommandOrDie("Network.setCookie", cookie, (response) => logCookies(done, response.success)); |
| + } |
| + |
| + function deleteCookie(cookie, done) |
| + { |
| + InspectorTest.log("Deleting Cookie"); |
| + InspectorTest.sendCommandOrDie("Network.deleteCookie", cookie, () => logCookies(done)); |
| + } |
| + |
| + function deleteAllCookies(done) |
| + { |
| + InspectorTest.log("Removing All Cookies"); |
| + InspectorTest.sendCommandOrDie("Network.getCookies", {}, gotCookiesForDelete.bind(null, done)); |
| + } |
| + |
| + function gotCookiesForDelete(done, data) |
| + { |
| + var promises = []; |
| + for (var cookie of data.cookies) { |
| + var url = "http://" + cookie.domain + "/" + cookie.path; |
| + promises.push(InspectorTest.sendCommandPromise("Network.deleteCookie", {url: url, cookieName: cookie.name})); |
| + } |
| + |
| + Promise.all(promises).then(logCookies.bind(null, done, undefined)); |
| + } |
| + |
| + function logCookies(done, success) |
| + { |
| + |
| + InspectorTest.log("Logging Cookies"); |
| + if (success !== undefined) |
| + InspectorTest.log("Success: " + success); |
| + InspectorTest.sendCommandOrDie("Network.getCookies", {}, logReceivedGetCookies.bind(null, done)); |
| + } |
| + function logReceivedGetCookies(done, data) |
| + { |
| + InspectorTest.log("Num of cookies " + data.cookies.length); |
| + for (var cookie of data.cookies) { |
| + InspectorTest.log(" Cookie: "); |
| + InspectorTest.log(" Domain: " + cookie.domain); |
| + InspectorTest.log(" Name: " + cookie.name); |
| + InspectorTest.log(" Value: " + cookie.value); |
| + InspectorTest.log(" Path: " + cookie.path); |
| + InspectorTest.log(" HttpOnly: " + cookie.httpOnly); |
| + InspectorTest.log(" Secure: " + cookie.secure); |
| + InspectorTest.log(" Session: " + cookie.session); |
| + } |
| + done(); |
| + } |
| +} |
| +</script> |
| +</head> |
| +<body onload="runTest();"> |
| +<p>Tests that cookies are set, updated and removed.</p> |
| +</body> |
| +</html> |