diff --git a/dom/fetch/Headers.h b/dom/fetch/Headers.h index a3810baa42b3..d52a25c222e8 100644 --- a/dom/fetch/Headers.h +++ b/dom/fetch/Headers.h @@ -102,6 +102,19 @@ public: mInternalHeaders->Set(aName, aValue, aRv); } + uint32_t GetIterableLength() const + { + return mInternalHeaders->GetIterableLength(); + } + const nsString GetKeyAtIndex(unsigned aIndex) const + { + return mInternalHeaders->GetKeyAtIndex(aIndex); + } + const nsString GetValueAtIndex(unsigned aIndex) const + { + return mInternalHeaders->GetValueAtIndex(aIndex); + } + // ChromeOnly HeadersGuardEnum Guard() const { diff --git a/dom/fetch/InternalHeaders.h b/dom/fetch/InternalHeaders.h index 9e11a1e102ec..d62b46fb57aa 100644 --- a/dom/fetch/InternalHeaders.h +++ b/dom/fetch/InternalHeaders.h @@ -70,6 +70,21 @@ public: bool Has(const nsACString& aName, ErrorResult& aRv) const; void Set(const nsACString& aName, const nsACString& aValue, ErrorResult& aRv); + uint32_t GetIterableLength() const + { + return mList.Length(); + } + const NS_ConvertASCIItoUTF16 GetKeyAtIndex(unsigned aIndex) const + { + MOZ_ASSERT(aIndex < mList.Length()); + return NS_ConvertASCIItoUTF16(mList[aIndex].mName); + } + const NS_ConvertASCIItoUTF16 GetValueAtIndex(unsigned aIndex) const + { + MOZ_ASSERT(aIndex < mList.Length()); + return NS_ConvertASCIItoUTF16(mList[aIndex].mValue); + } + void Clear(); HeadersGuardEnum Guard() const { return mGuard; } diff --git a/dom/tests/mochitest/fetch/test_headers_common.js b/dom/tests/mochitest/fetch/test_headers_common.js index fca547bfcaeb..b82e5e224439 100644 --- a/dom/tests/mochitest/fetch/test_headers_common.js +++ b/dom/tests/mochitest/fetch/test_headers_common.js @@ -13,16 +13,27 @@ function shouldThrow(func, expected, msg) { } } +function recursiveArrayCompare(actual, expected) { + is(Array.isArray(actual), Array.isArray(expected), "Both should either be arrays, or not"); + if (Array.isArray(actual) && Array.isArray(expected)) { + var diff = actual.length !== expected.length; + + for (var i = 0, n = actual.length; !diff && i < n; ++i) { + diff = recursiveArrayCompare(actual[i], expected[i]); + } + + return diff; + } else { + return actual !== expected; + } +} + function arrayEquals(actual, expected, msg) { if (actual === expected) { return; } - var diff = actual.length !== expected.length; - - for (var i = 0, n = actual.length; !diff && i < n; ++i) { - diff = actual[i] !== expected[i]; - } + var diff = recursiveArrayCompare(actual, expected); ok(!diff, msg); if (diff) { @@ -169,8 +180,60 @@ function TestFilledHeaders() { }, TypeError, "Fill with non-tuple sequence should throw TypeError."); } +function iterate(iter) { + var result = []; + for (var val = iter.next(); !val.done;) { + result.push(val.value); + val = iter.next(); + } + return result; +} + +function iterateForOf(iter) { + var result = []; + for (var value of iter) { + result.push(value); + } + return result; +} + +function byteInflate(str) { + var encoder = new TextEncoder("utf-8"); + var encoded = encoder.encode(str); + var result = ""; + for (var i = 0; i < encoded.length; ++i) { + result += String.fromCharCode(encoded[i]); + } + return result +} + +function TestHeadersIterator() { + var ehsanInflated = byteInflate("احسان"); + var headers = new Headers(); + headers.set("foo0", "bar0"); + headers.append("foo", "bar"); + headers.append("foo", ehsanInflated); + headers.append("Foo2", "bar2"); + headers.set("Foo2", "baz2"); + headers.set("foo3", "bar3"); + headers.delete("foo0"); + headers.delete("foo3"); + + var key_iter = headers.keys(); + var value_iter = headers.values(); + var entries_iter = headers.entries(); + + arrayEquals(iterate(key_iter), ["foo", "foo", "foo2"], "Correct key iterator"); + arrayEquals(iterate(value_iter), ["bar", ehsanInflated, "baz2"], "Correct value iterator"); + arrayEquals(iterate(entries_iter), [["foo", "bar"], ["foo", ehsanInflated], ["foo2", "baz2"]], "Correct entries iterator"); + + arrayEquals(iterateForOf(headers), [["foo", "bar"], ["foo", ehsanInflated], ["foo2", "baz2"]], "Correct entries iterator"); + arrayEquals(iterateForOf(new Headers(headers)), [["foo", "bar"], ["foo", ehsanInflated], ["foo2", "baz2"]], "Correct entries iterator"); +} + function runTest() { TestEmptyHeaders(); TestFilledHeaders(); + TestHeadersIterator(); return Promise.resolve(); } diff --git a/dom/webidl/Headers.webidl b/dom/webidl/Headers.webidl index f27a1ec05411..38b0a3a2042b 100644 --- a/dom/webidl/Headers.webidl +++ b/dom/webidl/Headers.webidl @@ -27,6 +27,7 @@ interface Headers { [Throws] sequence getAll(ByteString name); [Throws] boolean has(ByteString name); [Throws] void set(ByteString name, ByteString value); + iterable; // Used to test different guard states from mochitest. // Note: Must be set prior to populating headers or will throw. diff --git a/testing/web-platform/meta/service-workers/cache-storage/serviceworker/__dir__.ini b/testing/web-platform/meta/service-workers/cache-storage/serviceworker/__dir__.ini new file mode 100644 index 000000000000..e05911f92d2a --- /dev/null +++ b/testing/web-platform/meta/service-workers/cache-storage/serviceworker/__dir__.ini @@ -0,0 +1 @@ +prefs: [dom.serviceWorkers.enabled: true, dom.serviceWorkers.interception.enabled: true, dom.serviceWorkers.exemptFromPerDomainMax:true, dom.caches.enabled:true] diff --git a/testing/web-platform/meta/service-workers/cache-storage/serviceworker/cache-add.https.html.ini b/testing/web-platform/meta/service-workers/cache-storage/serviceworker/cache-add.https.html.ini deleted file mode 100644 index 2dc41a01c86e..000000000000 --- a/testing/web-platform/meta/service-workers/cache-storage/serviceworker/cache-add.https.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[cache-add.https.html] - type: testharness - prefs: [dom.serviceWorkers.enabled: true, dom.serviceWorkers.interception.enabled: true, dom.serviceWorkers.exemptFromPerDomainMax:true, dom.caches.enabled:true] diff --git a/testing/web-platform/meta/service-workers/cache-storage/serviceworker/cache-delete.https.html.ini b/testing/web-platform/meta/service-workers/cache-storage/serviceworker/cache-delete.https.html.ini deleted file mode 100644 index 4deb7c866746..000000000000 --- a/testing/web-platform/meta/service-workers/cache-storage/serviceworker/cache-delete.https.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[cache-delete.https.html] - type: testharness - prefs: [dom.serviceWorkers.enabled: true, dom.serviceWorkers.interception.enabled: true, dom.serviceWorkers.exemptFromPerDomainMax:true, dom.caches.enabled:true] diff --git a/testing/web-platform/meta/service-workers/cache-storage/serviceworker/cache-match.https.html.ini b/testing/web-platform/meta/service-workers/cache-storage/serviceworker/cache-match.https.html.ini deleted file mode 100644 index 55794621d5db..000000000000 --- a/testing/web-platform/meta/service-workers/cache-storage/serviceworker/cache-match.https.html.ini +++ /dev/null @@ -1,54 +0,0 @@ -[cache-match.https.html] - type: testharness - prefs: [dom.serviceWorkers.enabled: true, dom.serviceWorkers.interception.enabled: true, dom.serviceWorkers.exemptFromPerDomainMax:true, dom.caches.enabled:true] - [Cache.match and Cache.matchAll] - bug: https://github.com/w3c/web-platform-tests/issues/2098 - - [Cache.matchAll with URL] - expected: FAIL - - [Cache.match with URL] - expected: FAIL - - [Cache.matchAll with Request] - expected: FAIL - - [Cache.match with Request] - expected: FAIL - - [Cache.matchAll with new Request] - expected: FAIL - - [Cache.match with new Request] - expected: FAIL - - [Cache.matchAll with ignoreSearch option (request with no search parameters)] - expected: FAIL - - [Cache.match with ignoreSearch option (request with no search parameters)] - expected: FAIL - - [Cache.matchAll with ignoreSearch option (request with search parameter)] - expected: FAIL - - [Cache.match with ignoreSearch option (request with search parameter)] - expected: FAIL - - [Cache.matchAll with URL containing fragment] - expected: FAIL - - [Cache.match with URL containing fragment] - expected: FAIL - - [Cache.matchAll with responses containing "Vary" header] - expected: FAIL - - [Cache.match with responses containing "Vary" header] - expected: FAIL - - [Cache.matchAll with "ignoreVary" parameter] - expected: FAIL - - [Cache.match with Request and Response objects with different URLs] - expected: FAIL - diff --git a/testing/web-platform/meta/service-workers/cache-storage/serviceworker/cache-put.https.html.ini b/testing/web-platform/meta/service-workers/cache-storage/serviceworker/cache-put.https.html.ini deleted file mode 100644 index 5bf731c6eda0..000000000000 --- a/testing/web-platform/meta/service-workers/cache-storage/serviceworker/cache-put.https.html.ini +++ /dev/null @@ -1,25 +0,0 @@ -[cache-put.https.html] - type: testharness - prefs: [dom.serviceWorkers.enabled: true, dom.serviceWorkers.interception.enabled: true, dom.serviceWorkers.exemptFromPerDomainMax:true, dom.caches.enabled:true] - [Cache.put with request URLs containing embedded credentials] - expected: FAIL - bug: https://github.com/w3c/web-platform-tests/issues/2098 - - [Cache.put called with Request and Response from fetch()] - expected: FAIL - - [Cache.put with a Response containing an empty URL] - expected: FAIL - - [Cache.put with HTTP 500 response] - expected: FAIL - - [Cache.put called twice with matching Requests and different Responses] - expected: FAIL - - [Cache.put called twice with request URLs that differ only by a fragment] - expected: FAIL - - [Cache.put with a relative URL] - expected: FAIL - diff --git a/testing/web-platform/meta/service-workers/cache-storage/serviceworker/cache-storage-keys.https.html.ini b/testing/web-platform/meta/service-workers/cache-storage/serviceworker/cache-storage-keys.https.html.ini deleted file mode 100644 index bfd50d10e300..000000000000 --- a/testing/web-platform/meta/service-workers/cache-storage/serviceworker/cache-storage-keys.https.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[cache-storage-keys.https.html] - type: testharness - prefs: [dom.serviceWorkers.enabled: true, dom.serviceWorkers.interception.enabled: true, dom.serviceWorkers.exemptFromPerDomainMax:true, dom.caches.enabled:true] diff --git a/testing/web-platform/meta/service-workers/cache-storage/serviceworker/cache-storage-match.https.html.ini b/testing/web-platform/meta/service-workers/cache-storage/serviceworker/cache-storage-match.https.html.ini deleted file mode 100644 index bcb1dbd46d26..000000000000 --- a/testing/web-platform/meta/service-workers/cache-storage/serviceworker/cache-storage-match.https.html.ini +++ /dev/null @@ -1,15 +0,0 @@ -[cache-storage-match.https.html] - type: testharness - prefs: [dom.serviceWorkers.enabled: true, dom.serviceWorkers.interception.enabled: true, dom.serviceWorkers.exemptFromPerDomainMax:true, dom.caches.enabled:true] - [CacheStorageMatch with no cache name provided] - expected: FAIL - - [CacheStorageMatch from one of many caches] - expected: FAIL - - [CacheStorageMatch from one of many caches by name] - expected: FAIL - - [CacheStorageMatch a string request] - expected: FAIL - diff --git a/testing/web-platform/meta/service-workers/cache-storage/serviceworker/cache-storage.https.html.ini b/testing/web-platform/meta/service-workers/cache-storage/serviceworker/cache-storage.https.html.ini deleted file mode 100644 index f651f5610ba9..000000000000 --- a/testing/web-platform/meta/service-workers/cache-storage/serviceworker/cache-storage.https.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[cache-storage.https.html] - type: testharness - prefs: [dom.serviceWorkers.enabled: true, dom.serviceWorkers.interception.enabled: true, dom.serviceWorkers.exemptFromPerDomainMax:true, dom.caches.enabled:true] diff --git a/testing/web-platform/meta/service-workers/cache-storage/window/cache-match.https.html.ini b/testing/web-platform/meta/service-workers/cache-storage/window/cache-match.https.html.ini deleted file mode 100644 index 564897b348fb..000000000000 --- a/testing/web-platform/meta/service-workers/cache-storage/window/cache-match.https.html.ini +++ /dev/null @@ -1,52 +0,0 @@ -[cache-match.https.html] - type: testharness - prefs: [dom.caches.enabled:true] - bug: https://github.com/w3c/web-platform-tests/issues/2098 - [Cache.matchAll with URL] - expected: FAIL - - [Cache.match with URL] - expected: FAIL - - [Cache.matchAll with Request] - expected: FAIL - - [Cache.match with Request] - expected: FAIL - - [Cache.matchAll with new Request] - expected: FAIL - - [Cache.match with new Request] - expected: FAIL - - [Cache.matchAll with ignoreSearch option (request with no search parameters)] - expected: FAIL - - [Cache.match with ignoreSearch option (request with no search parameters)] - expected: FAIL - - [Cache.matchAll with ignoreSearch option (request with search parameter)] - expected: FAIL - - [Cache.match with ignoreSearch option (request with search parameter)] - expected: FAIL - - [Cache.matchAll with URL containing fragment] - expected: FAIL - - [Cache.match with URL containing fragment] - expected: FAIL - - [Cache.matchAll with responses containing "Vary" header] - expected: FAIL - - [Cache.match with responses containing "Vary" header] - expected: FAIL - - [Cache.matchAll with "ignoreVary" parameter] - expected: FAIL - - [Cache.match with Request and Response objects with different URLs] - expected: FAIL - diff --git a/testing/web-platform/meta/service-workers/cache-storage/window/cache-put.https.html.ini b/testing/web-platform/meta/service-workers/cache-storage/window/cache-put.https.html.ini deleted file mode 100644 index f019ecc17cd5..000000000000 --- a/testing/web-platform/meta/service-workers/cache-storage/window/cache-put.https.html.ini +++ /dev/null @@ -1,25 +0,0 @@ -[cache-put.https.html] - type: testharness - prefs: [dom.caches.enabled:true] - [Cache.put with request URLs containing embedded credentials] - expected: FAIL - bug: https://github.com/w3c/web-platform-tests/issues/2098 - - [Cache.put called with Request and Response from fetch()] - expected: FAIL - - [Cache.put with a Response containing an empty URL] - expected: FAIL - - [Cache.put with HTTP 500 response] - expected: FAIL - - [Cache.put called twice with matching Requests and different Responses] - expected: FAIL - - [Cache.put called twice with request URLs that differ only by a fragment] - expected: FAIL - - [Cache.put with a relative URL] - expected: FAIL - diff --git a/testing/web-platform/meta/service-workers/cache-storage/window/cache-storage-match.https.html.ini b/testing/web-platform/meta/service-workers/cache-storage/window/cache-storage-match.https.html.ini deleted file mode 100644 index 94db1d3279aa..000000000000 --- a/testing/web-platform/meta/service-workers/cache-storage/window/cache-storage-match.https.html.ini +++ /dev/null @@ -1,15 +0,0 @@ -[cache-storage-match.https.html] - type: testharness - prefs: [dom.caches.enabled:true] - [CacheStorageMatch with no cache name provided] - expected: FAIL - - [CacheStorageMatch from one of many caches] - expected: FAIL - - [CacheStorageMatch from one of many caches by name] - expected: FAIL - - [CacheStorageMatch a string request] - expected: FAIL - diff --git a/testing/web-platform/meta/service-workers/cache-storage/worker/__dir__.ini b/testing/web-platform/meta/service-workers/cache-storage/worker/__dir__.ini new file mode 100644 index 000000000000..9f3cfaa25a0b --- /dev/null +++ b/testing/web-platform/meta/service-workers/cache-storage/worker/__dir__.ini @@ -0,0 +1 @@ +prefs: [dom.caches.enabled:true] diff --git a/testing/web-platform/meta/service-workers/cache-storage/worker/cache-add.https.html.ini b/testing/web-platform/meta/service-workers/cache-storage/worker/cache-add.https.html.ini deleted file mode 100644 index f85c725a2220..000000000000 --- a/testing/web-platform/meta/service-workers/cache-storage/worker/cache-add.https.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[cache-add.https.html] - type: testharness - prefs: [dom.caches.enabled:true] diff --git a/testing/web-platform/meta/service-workers/cache-storage/worker/cache-delete.https.html.ini b/testing/web-platform/meta/service-workers/cache-storage/worker/cache-delete.https.html.ini deleted file mode 100644 index 76859c63f047..000000000000 --- a/testing/web-platform/meta/service-workers/cache-storage/worker/cache-delete.https.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[cache-delete.https.html] - type: testharness - prefs: [dom.caches.enabled:true] diff --git a/testing/web-platform/meta/service-workers/cache-storage/worker/cache-match.https.html.ini b/testing/web-platform/meta/service-workers/cache-storage/worker/cache-match.https.html.ini deleted file mode 100644 index 564897b348fb..000000000000 --- a/testing/web-platform/meta/service-workers/cache-storage/worker/cache-match.https.html.ini +++ /dev/null @@ -1,52 +0,0 @@ -[cache-match.https.html] - type: testharness - prefs: [dom.caches.enabled:true] - bug: https://github.com/w3c/web-platform-tests/issues/2098 - [Cache.matchAll with URL] - expected: FAIL - - [Cache.match with URL] - expected: FAIL - - [Cache.matchAll with Request] - expected: FAIL - - [Cache.match with Request] - expected: FAIL - - [Cache.matchAll with new Request] - expected: FAIL - - [Cache.match with new Request] - expected: FAIL - - [Cache.matchAll with ignoreSearch option (request with no search parameters)] - expected: FAIL - - [Cache.match with ignoreSearch option (request with no search parameters)] - expected: FAIL - - [Cache.matchAll with ignoreSearch option (request with search parameter)] - expected: FAIL - - [Cache.match with ignoreSearch option (request with search parameter)] - expected: FAIL - - [Cache.matchAll with URL containing fragment] - expected: FAIL - - [Cache.match with URL containing fragment] - expected: FAIL - - [Cache.matchAll with responses containing "Vary" header] - expected: FAIL - - [Cache.match with responses containing "Vary" header] - expected: FAIL - - [Cache.matchAll with "ignoreVary" parameter] - expected: FAIL - - [Cache.match with Request and Response objects with different URLs] - expected: FAIL - diff --git a/testing/web-platform/meta/service-workers/cache-storage/worker/cache-put.https.html.ini b/testing/web-platform/meta/service-workers/cache-storage/worker/cache-put.https.html.ini deleted file mode 100644 index f019ecc17cd5..000000000000 --- a/testing/web-platform/meta/service-workers/cache-storage/worker/cache-put.https.html.ini +++ /dev/null @@ -1,25 +0,0 @@ -[cache-put.https.html] - type: testharness - prefs: [dom.caches.enabled:true] - [Cache.put with request URLs containing embedded credentials] - expected: FAIL - bug: https://github.com/w3c/web-platform-tests/issues/2098 - - [Cache.put called with Request and Response from fetch()] - expected: FAIL - - [Cache.put with a Response containing an empty URL] - expected: FAIL - - [Cache.put with HTTP 500 response] - expected: FAIL - - [Cache.put called twice with matching Requests and different Responses] - expected: FAIL - - [Cache.put called twice with request URLs that differ only by a fragment] - expected: FAIL - - [Cache.put with a relative URL] - expected: FAIL - diff --git a/testing/web-platform/meta/service-workers/cache-storage/worker/cache-storage-keys.https.html.ini b/testing/web-platform/meta/service-workers/cache-storage/worker/cache-storage-keys.https.html.ini deleted file mode 100644 index 823b5708433c..000000000000 --- a/testing/web-platform/meta/service-workers/cache-storage/worker/cache-storage-keys.https.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[cache-storage-keys.https.html] - type: testharness - prefs: [dom.caches.enabled:true] diff --git a/testing/web-platform/meta/service-workers/cache-storage/worker/cache-storage-match.https.html.ini b/testing/web-platform/meta/service-workers/cache-storage/worker/cache-storage-match.https.html.ini deleted file mode 100644 index 94db1d3279aa..000000000000 --- a/testing/web-platform/meta/service-workers/cache-storage/worker/cache-storage-match.https.html.ini +++ /dev/null @@ -1,15 +0,0 @@ -[cache-storage-match.https.html] - type: testharness - prefs: [dom.caches.enabled:true] - [CacheStorageMatch with no cache name provided] - expected: FAIL - - [CacheStorageMatch from one of many caches] - expected: FAIL - - [CacheStorageMatch from one of many caches by name] - expected: FAIL - - [CacheStorageMatch a string request] - expected: FAIL - diff --git a/testing/web-platform/meta/service-workers/cache-storage/worker/cache-storage.https.html.ini b/testing/web-platform/meta/service-workers/cache-storage/worker/cache-storage.https.html.ini deleted file mode 100644 index 6ed6d9d1af4a..000000000000 --- a/testing/web-platform/meta/service-workers/cache-storage/worker/cache-storage.https.html.ini +++ /dev/null @@ -1,3 +0,0 @@ -[cache-storage.https.html] - type: testharness - prefs: [dom.caches.enabled:true]