From f5de2fd5d7af1d67b7dea09659f8b037af7ddbab Mon Sep 17 00:00:00 2001 From: Moritz Date: Wed, 4 Sep 2024 09:28:05 +0200 Subject: [PATCH] Add test --- web/lib/src/helpers/extensions.dart | 6 ++++++ web/test/helpers_test.dart | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/web/lib/src/helpers/extensions.dart b/web/lib/src/helpers/extensions.dart index 78612ce5..0efa81d9 100644 --- a/web/lib/src/helpers/extensions.dart +++ b/web/lib/src/helpers/extensions.dart @@ -104,6 +104,12 @@ extension TouchListConvert on TouchList { List toList() => JSImmutableListWrapper(this); } +/// Returns all response headers as a key-value map. +/// +/// Multiple values for the same header key can be combined into one, +/// separated by a comma and a space. +/// +/// See: http://www.w3.org/TR/XMLHttpRequest/#the-getresponseheader()-method extension XMLHttpRequestGlue on XMLHttpRequest { Map get responseHeaders { // from Closure's goog.net.Xhrio.getResponseHeaders. diff --git a/web/test/helpers_test.dart b/web/test/helpers_test.dart index aa419ac3..088d5138 100644 --- a/web/test/helpers_test.dart +++ b/web/test/helpers_test.dart @@ -36,4 +36,22 @@ void main() { // Ensure accessing any arbitrary item in the list does not throw. expect(() => dartList[0], returnsNormally); }); + + test('Headers to map', () async { + final request = XMLHttpRequest(); + request.open('GET', 'www.google.com'); + request.send(); + await request.onLoad.first; + + expect( + request.responseHeaders, + allOf( + containsPair('content-length', '10'), + containsPair('content-type', 'text/plain; charset=utf-8'), + containsPair('x-content-type-options', 'nosniff'), + containsPair('x-frame-options', 'SAMEORIGIN'), + containsPair('x-xss-protection', '1; mode=block'), + ), + ); + }); }