From a1ecd476b867180002a51e6c61154dfad0aebad0 Mon Sep 17 00:00:00 2001 From: Andres Rey Date: Sun, 11 Dec 2016 12:22:14 +0000 Subject: Adjusted more result test cases --- test/test-pages/002/expected.html | 51 ++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 17 deletions(-) (limited to 'test/test-pages/002') diff --git a/test/test-pages/002/expected.html b/test/test-pages/002/expected.html index 25820a5..964d7d6 100644 --- a/test/test-pages/002/expected.html +++ b/test/test-pages/002/expected.html @@ -29,7 +29,8 @@

The most useful, high-level part of the Fetch API is the fetch() function. In its simplest form it takes a URL and returns a promise that resolves to the response. The response is captured as a Response object.

-
fetch("/data.json").then(function(res) {
+                        
+
fetch("/data.json").then(function(res) {
   // res instanceof Response == true.
   if (res.ok) {
     res.json().then(function(data) {
@@ -44,7 +45,8 @@
                                         

Submitting some parameters, it would look like this:

-
fetch("http://www.example.org/submit.php", {
+            
+
fetch("http://www.example.org/submit.php", {
   method: "POST",
   headers: {
     "Content-Type": "application/x-www-form-urlencoded"
@@ -76,7 +78,8 @@
                 

supporting CORS rules and ensuring cookies aren’t readable by third parties.

The Headers interface is a simple multi-map of names to values:

-
var content = "Hello World";
+            
+
var content = "Hello World";
 var reqHeaders = new Headers();
 reqHeaders.append("Content-Type", "text/plain"
 reqHeaders.append("Content-Length", content.length.toString());
@@ -86,7 +89,8 @@ reqHeaders.append
reqHeaders = new Headers({
+            
+
reqHeaders = new Headers({
   "Content-Type": "text/plain",
   "Content-Length": content.length.toString(),
   "X-Custom-Header": "ProcessThisImmediately",
@@ -94,7 +98,8 @@ reqHeaders.append
console.log(reqHeaders.has("Content-Type")); // true
+            
+
console.log(reqHeaders.has("Content-Type")); // true
 console.log(reqHeaders.has("Set-Cookie")); // false
 reqHeaders.set("Content-Type", "text/html");
 reqHeaders.append("X-Custom-Header", "AnotherValue");
@@ -130,7 +135,8 @@ console.log(<
             

All of the Headers methods throw TypeError if name is not a valid HTTP Header name. The mutation operations will throw TypeError if there is an immutable guard. Otherwise they fail silently. For example:

-
var res = Response.error();
+            
+
var res = Response.error();
 try {
   res.headers.set("Origin", "http://mybank.com");
 } catch(e) {
@@ -146,7 +152,8 @@ console.log(<
             a body, a request mode, credentials and cache hints.

The simplest Request is of course, just a URL, as you may do to GET a resource.

-
var req = new Request("/index.html");
+        
+ @@ -156,7 +163,8 @@ console.log(<

(This is not the same as calling the clone() method, which is covered in

the “Reading bodies” section.).

-
var req = new Request("/index.html");
 console.log(req.method); // "GET"
 console.log(req.url); // "http://example.com/index.html"
var copy = new Request(req);
+        
+ @@ -165,7 +173,8 @@ console.log(<

The non-URL attributes of the Request can only be set by passing initial

values as a second argument to the constructor. This argument is a dictionary.

-
var copy = new Request(req);
 console.log(copy.method); // "GET"
 console.log(copy.url); // "http://example.com/index.html"
var uploadReq = new Request("/uploadImage", {
+        
+
var uploadReq = new Request("/uploadImage", {
   method: "POST",
   headers: {
     "Content-Type": "image/png",
@@ -182,7 +191,8 @@ console.log(<
                 origin with this mode set, the result is simply an error. You could use
                 this to ensure that
                 

a request is always being made to your origin.

-
var arbitraryUrl = document.getElementById("url-input").value;
+            
+
var arbitraryUrl = document.getElementById("url-input").value;
 fetch(arbitraryUrl, { mode: "same-origin" }).then(function(res) {
   console.log("Response succeeded?", res.ok);
 }, function(e) {
@@ -207,7 +217,8 @@ fetch(arbitraryUrlmost interesting photos
                 today like this:

-
var u = new URLSearchParams();
+            
+
var u = new URLSearchParams();
 u.append('method', 'flickr.interestingness.getList');
 u.append('api_key', '<insert api key here>');
 u.append('format', 'json');
@@ -230,7 +241,8 @@ apiCall.then(
             

You may not read out the “Date” header since Flickr does not allow it via

Access-Control-Expose-Headers.

-
response.headers.get("Date"); // null
+
+
response.headers.get("Date"); // null

The credentials enumeration determines if cookies for the other @@ -284,7 +296,8 @@ apiCall.then( The

idiomatic way to return a Response to an intercepted request in ServiceWorkers is:

-
addEventListener('fetch', function(event) {
+            
+
addEventListener('fetch', function(event) {
   event.respondWith(new Response("Response body", {
     headers: { "Content-Type" : "text/plain" }
   });
@@ -334,7 +347,8 @@ apiCall.then(
             

This is a significant improvement over XHR in terms of ease of use of non-text data!

Request bodies can be set by passing body parameters:

-
var form = new FormData(document.getElementById('login-form'));
+            
+
var form = new FormData(document.getElementById('login-form'));
 fetch("/login", {
   method: "POST",
   body: form
@@ -342,7 +356,8 @@ fetch("/login
                             

Responses take the first argument as the body.

-
var res = new Response(new File(["chunk", "chunk"], "archive.zip",
+                
+
var res = new Response(new File(["chunk", "chunk"], "archive.zip",
                        { type: "application/zip" }));
@@ -356,7 +371,8 @@ fetch("/login

It is important to realise that Request and Response bodies can only be read once! Both interfaces have a boolean attribute bodyUsed to determine if it is safe to read or not.

-
var res = new Response("one time use");
+                
+
var res = new Response("one time use");
 console.log(res.bodyUsed); // false
 res.text().then(function(v) {
   console.log(res.bodyUsed); // true
@@ -381,7 +397,8 @@ res.text(clone() MUST
                     be called before the body of the corresponding object has been used. That
                     is, clone() first, read later.

-
addEventListener('fetch', function(evt) {
+                
+
addEventListener('fetch', function(evt) {
   var sheep = new Response("Dolly");
   console.log(sheep.bodyUsed); // false
   var clone = sheep.clone();
-- 
cgit v1.2.3