Log Message
Web Inspector: Add tests for Fetch API Network Data (CORs, Opaque Responses, Filtered Headers) https://bugs.webkit.org/show_bug.cgi?id=165683
Reviewed by Brian Burg. * http/tests/inspector/network/fetch-network-data-expected.txt: Added. * http/tests/inspector/network/fetch-network-data.html: Added. * http/tests/inspector/network/resources/cors-data.pl: Added. * http/tests/inspector/resources/inspector-test.js:
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (209733 => 209734)
--- trunk/LayoutTests/ChangeLog 2016-12-12 23:27:13 UTC (rev 209733)
+++ trunk/LayoutTests/ChangeLog 2016-12-12 23:36:09 UTC (rev 209734)
@@ -1,3 +1,15 @@
+2016-12-12 Joseph Pecoraro <[email protected]>
+
+ Web Inspector: Add tests for Fetch API Network Data (CORs, Opaque Responses, Filtered Headers)
+ https://bugs.webkit.org/show_bug.cgi?id=165683
+
+ Reviewed by Brian Burg.
+
+ * http/tests/inspector/network/fetch-network-data-expected.txt: Added.
+ * http/tests/inspector/network/fetch-network-data.html: Added.
+ * http/tests/inspector/network/resources/cors-data.pl: Added.
+ * http/tests/inspector/resources/inspector-test.js:
+
2016-12-12 Jer Noble <[email protected]>
Remove implementation of legacy Mozilla-based Fullscreen API.
Added: trunk/LayoutTests/http/tests/inspector/network/fetch-network-data-expected.txt (0 => 209734)
--- trunk/LayoutTests/http/tests/inspector/network/fetch-network-data-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/network/fetch-network-data-expected.txt 2016-12-12 23:36:09 UTC (rev 209734)
@@ -0,0 +1,41 @@
+Tests for Network data with different types of Fetch requests.
+
+
+== Running test suite: Network.Fetch
+-- Running test case: Network.Fetch.ModeNoCORS.SameOrigin
+PASS: Resource should be Fetch type.
+PASS: Resource should have loaded successfully.
+PASS: MIMEType should be 'application/json'.
+PASS: Status code should be 200.
+PASS: Should be able to see X-Custom-Header.
+
+-- Running test case: Network.Fetch.ModeNoCORS.CrossOrigin
+PASS: Resource should be Fetch type.
+PASS: Resource should have failed to load.
+PASS: Load should have failed.
+PASS: Load should have canceled.
+
+-- Running test case: Network.Fetch.ModeCORS.SameOrigin
+PASS: Resource should be Fetch type.
+PASS: Resource should have loaded successfully.
+PASS: MIMEType should be 'application/json'.
+PASS: Status code should be 200.
+PASS: Should be able to see X-Custom-Header.
+
+-- Running test case: Network.Fetch.ModeCORS.CrossOrigin
+PASS: Resource should be Fetch type.
+PASS: Resource should have loaded successfully.
+PASS: MIMEType should be 'application/json'.
+PASS: Status code should be 200.
+PASS: Should be able to see X-Custom-Header which would have otherwise been filtered.
+
+-- Running test case: Network.Fetch.ModeSameOrigin.SameOrigin
+PASS: Resource should be Fetch type.
+PASS: Resource should have loaded successfully.
+PASS: MIMEType should be 'application/json'.
+PASS: Status code should be 200.
+PASS: Should be able to see X-Custom-Header.
+
+-- Running test case: Network.Fetch.ModeSameOrigin.CrossOrigin
+PASS: Should produce a TypeError.
+
Added: trunk/LayoutTests/http/tests/inspector/network/fetch-network-data.html (0 => 209734)
--- trunk/LayoutTests/http/tests/inspector/network/fetch-network-data.html (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/network/fetch-network-data.html 2016-12-12 23:36:09 UTC (rev 209734)
@@ -0,0 +1,124 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src=""
+<script>
+function test()
+{
+ let suite = InspectorTest.createAsyncSuite("Network.Fetch");
+
+ function addTestCase({name, _expression_, loadedHandler, failedHandler}) {
+ suite.addTestCase({
+ name, test(resolve, reject) {
+ InspectorTest.evaluateInPage(_expression_);
+ WebInspector.Frame.awaitEvent(WebInspector.Frame.Event.ResourceWasAdded).then((event) => {
+ let resource = event.data.resource;
+ InspectorTest.expectEqual(resource.type, WebInspector.Resource.Type.Fetch, "Resource should be Fetch type.");
+ if (loadedHandler) {
+ resource.awaitEvent(WebInspector.Resource.Event.LoadingDidFinish)
+ .then(() => { InspectorTest.pass("Resource should have loaded successfully.") })
+ .then(() => { loadedHandler(resource); })
+ .then(resolve, reject);
+ resource.awaitEvent(WebInspector.Resource.Event.LoadingDidFail)
+ .then(() => { InspectorTest.fail("Resource should not have failed to load.") })
+ .then(reject, reject);
+ } else if (failedHandler) {
+ resource.awaitEvent(WebInspector.Resource.Event.LoadingDidFinish)
+ .then(() => { InspectorTest.fail("Resource should not have loaded successfully.") })
+ .then(resolve, reject);
+ resource.awaitEvent(WebInspector.Resource.Event.LoadingDidFail)
+ .then(() => { InspectorTest.pass("Resource should have failed to load.") })
+ .then(() => { failedHandler(resource); })
+ .then(resolve, reject);
+ }
+ });
+ }
+ });
+ }
+
+ addTestCase({
+ name: "Network.Fetch.ModeNoCORS.SameOrigin",
+ description: "Same Origin 'no-cors' fetch => type 'basic'.",
+ _expression_: `fetch("http://127.0.0.1:8000/inspector/network/resources/cors-data.pl", {mode: "no-cors"})`,
+ loadedHandler(resource) {
+ InspectorTest.expectEqual(resource.mimeType, "application/json", "MIMEType should be 'application/json'.");
+ InspectorTest.expectEqual(resource.statusCode, 200, "Status code should be 200.");
+ InspectorTest.expectEqual(resource.responseHeaders["X-Custom-Header"], "Custom-Header-Value", "Should be able to see X-Custom-Header.");
+ }
+ });
+
+ addTestCase({
+ name: "Network.Fetch.ModeNoCORS.CrossOrigin",
+ description: "Same Origin 'no-cors' fetch => type 'opaque'. Produces an opaque failure.",
+ _expression_: `fetch("http://localhost:8000/inspector/network/resources/cors-data.pl", {mode: "no-cors"})`,
+ failedHandler(resource) {
+ InspectorTest.expectThat(resource.failed, "Load should have failed.");
+ InspectorTest.expectThat(resource.canceled, "Load should have canceled.");
+ }
+ });
+
+ addTestCase({
+ name: "Network.Fetch.ModeCORS.SameOrigin",
+ description: "Same Origin 'cors' fetch => type 'basic'.",
+ _expression_: `fetch("http://127.0.0.1:8000/inspector/network/resources/cors-data.pl", {mode: "cors"})`,
+ loadedHandler(resource) {
+ InspectorTest.expectEqual(resource.mimeType, "application/json", "MIMEType should be 'application/json'.");
+ InspectorTest.expectEqual(resource.statusCode, 200, "Status code should be 200.");
+ InspectorTest.expectEqual(resource.responseHeaders["X-Custom-Header"], "Custom-Header-Value", "Should be able to see X-Custom-Header.");
+ }
+ });
+
+ addTestCase({
+ name: "Network.Fetch.ModeCORS.CrossOrigin",
+ description: "Cross Origin 'cors' fetch => type 'cors'. Produces filtered headers.",
+ _expression_: `fetch("http://localhost:8000/inspector/network/resources/cors-data.pl", {mode: "cors"})`,
+ loadedHandler(resource) {
+ InspectorTest.expectEqual(resource.mimeType, "application/json", "MIMEType should be 'application/json'.");
+ InspectorTest.expectEqual(resource.statusCode, 200, "Status code should be 200.");
+ InspectorTest.expectEqual(resource.responseHeaders["X-Custom-Header"], "Custom-Header-Value", "Should be able to see X-Custom-Header which would have otherwise been filtered.");
+ }
+ });
+
+ addTestCase({
+ name: "Network.Fetch.ModeSameOrigin.SameOrigin",
+ description: "Same Origin 'same-origin' fetch => type 'basic'.",
+ _expression_: `fetch("http://127.0.0.1:8000/inspector/network/resources/cors-data.pl", {mode: "same-origin"})`,
+ loadedHandler(resource) {
+ InspectorTest.expectEqual(resource.mimeType, "application/json", "MIMEType should be 'application/json'.");
+ InspectorTest.expectEqual(resource.statusCode, 200, "Status code should be 200.");
+ InspectorTest.expectEqual(resource.responseHeaders["X-Custom-Header"], "Custom-Header-Value", "Should be able to see X-Custom-Header.");
+ }
+ });
+
+ suite.addTestCase({
+ name: "Network.Fetch.ModeSameOrigin.CrossOrigin",
+ description: "Cross Origin 'same-origin' fetch => Error.",
+ description: "Attempting a fetch with mode: 'same-origin' will immediately TypeError for a cross origin request",
+ test(resolve, reject) {
+ InspectorTest.evaluateInPage(`
+ fetch("http://localhost:8000/inspector/network/resources/cors-data.pl", {mode: "same-origin"}).then(
+ function success() {
+ TestPage.log("FAIL: Should produce a TypeError.");
+ TestPage.dispatchEventToFrontend("Completed");
+ },
+ function error() {
+ TestPage.log("PASS: Should produce a TypeError.");
+ TestPage.dispatchEventToFrontend("Completed");
+ }
+ );
+ `);
+ InspectorTest.singleFireEventListener("Completed", () => {
+ resolve();
+ });
+ }
+ });
+
+ suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body _onload_="runTest()">
+<p>Tests for Network data with different types of Fetch requests.</p>
+</body>
+</html>
Added: trunk/LayoutTests/http/tests/inspector/network/resources/cors-data.pl (0 => 209734)
--- trunk/LayoutTests/http/tests/inspector/network/resources/cors-data.pl (rev 0)
+++ trunk/LayoutTests/http/tests/inspector/network/resources/cors-data.pl 2016-12-12 23:36:09 UTC (rev 209734)
@@ -0,0 +1,9 @@
+#!/usr/bin/perl -wT
+use strict;
+
+print "Content-Type: application/json\n";
+print "Access-Control-Allow-Credentials: true\n";
+print "Access-Control-Allow-Origin: http://127.0.0.1:8000\n";
+print "X-Custom-Header: Custom-Header-Value\n\n";
+
+print "{\"json\": true, \"value\": 42}";
Property changes on: trunk/LayoutTests/http/tests/inspector/network/resources/cors-data.pl
___________________________________________________________________
Added: svn:executable
Modified: trunk/LayoutTests/http/tests/inspector/resources/inspector-test.js (209733 => 209734)
--- trunk/LayoutTests/http/tests/inspector/resources/inspector-test.js 2016-12-12 23:27:13 UTC (rev 209733)
+++ trunk/LayoutTests/http/tests/inspector/resources/inspector-test.js 2016-12-12 23:36:09 UTC (rev 209734)
@@ -139,6 +139,8 @@
this._resultElement.append(text, document.createElement("br"));
}
+TestPage.log = TestPage.addResult;
+
TestPage.dispatchEventToFrontend = function(eventName, data)
{
let dispatchEventCodeString = `InspectorTest.dispatchEventToListeners(${JSON.stringify(eventName)}, ${JSON.stringify(data)});`;
_______________________________________________ webkit-changes mailing list [email protected] https://lists.webkit.org/mailman/listinfo/webkit-changes
