Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve fetch #853

Merged
merged 5 commits into from
Sep 30, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 18 additions & 40 deletions js/fetch_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,13 @@ testPerm({ net: true }, async function fetchBlob() {
// sure pass mostly header basic test
/* tslint:disable-next-line:max-line-length */
// ref: https://github.com/web-platform-tests/wpt/blob/7c50c216081d6ea3c9afe553ee7b64534020a1b2/fetch/api/headers/headers-basic.html
// tslint:disable:only-arrow-functions
test(function() {
/* tslint:disable:no-unused-expression */
test(function newHeaderTest() {
new Headers();
new Headers(undefined);
new Headers({});
try {
const h = new Headers();
} catch (e) {
assert(false, "Create headers from no parameter failed");
}
});

test(function() {
try {
const h = new Headers(undefined);
} catch (e) {
assert(false, "Create headers from undefined parameter failed");
}
});

test(function() {
try {
const h = new Headers({});
} catch (e) {
assert(false, "Create headers from empty object failed");
}
});

test(function() {
try {
const h = new Headers(null);
new Headers(null);
} catch (e) {
assertEqual(e.message, "Failed to construct 'Headers': Invalid value");
}
Expand All @@ -93,30 +72,30 @@ for (const name in headerDict) {
headerSeq.push([name, headerDict[name]]);
}

test(function() {
test(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs name

const headers = new Headers(headerSeq);
for (const name in headerDict) {
assertEqual(headers.get(name), String(headerDict[name]));
}
assertEqual(headers.get("length"), null);
});

test(function() {
test(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs name

const headers = new Headers(headerDict);
for (const name in headerDict) {
assertEqual(headers.get(name), String(headerDict[name]));
}
});

test(function() {
test(() => {
const headers = new Headers(headerDict);
const headers2 = new Headers(headers);
for (const name in headerDict) {
assertEqual(headers2.get(name), String(headerDict[name]));
}
});

test(function() {
test(() => {
const headers = new Headers();
for (const name in headerDict) {
headers.append(name, headerDict[name]);
Expand All @@ -125,25 +104,24 @@ test(function() {
}
});

test(function() {
test(() => {
const headers = new Headers();
for (const name in headerDict) {
headers.set(name, headerDict[name]);
assertEqual(headers.get(name), String(headerDict[name]));
}
});

test(function() {
test(() => {
const headers = new Headers(headerDict);
for (const name in headerDict) {
assert(headers.has(name), "headers has name " + name);
/* tslint:disable-next-line:max-line-length */
assert(!headers.has("nameNotInHeaders"), "headers do not have header: nameNotInHeaders");
}

});

test(function() {
test(() => {
const headers = new Headers(headerDict);
for (const name in headerDict) {
assert(headers.has(name), "headers have a header: " + name);
Expand All @@ -152,7 +130,7 @@ test(function() {
}
});

test(function() {
test(() => {
const headers = new Headers(headerDict);
for (const name in headerDict) {
assertEqual(headers.get(name), String(headerDict[name]));
Expand All @@ -169,16 +147,16 @@ const headerEntriesDict = {
"Content-Types": "value6"
};

test(function() {
test(() => {
const headers = new Headers(headerEntriesDict);
const keys = Object.keys(headerEntriesDict);
keys.forEach(key => {
const value = headerEntriesDict[key];
const newkey = key.toLowerCase();
headerEntriesDict[newkey] = value;
});
headers.forEach(function(value, key, container) {
assertEqual(headers, container);
assertEqual(value, headerEntriesDict[key]);
headers.forEach((value, key, container) => {
assertEqual(headers, container);
assertEqual(value, headerEntriesDict[key]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if forEach does not call the callback at all?

let call_num = 0;
headers.forEach((value, key, container) => {
  ++call_num;
  ..
});
assertEqual(call_num, keys.length)

});
});