| OLD | NEW |
| (Empty) |
| 1 importScripts('worker-test-helpers.js'); | |
| 2 | |
| 3 test(function() { | |
| 4 var expectedMap = { | |
| 5 'Content-Language': 'ja', | |
| 6 'Content-Type': 'text/html; charset=UTF-8', | |
| 7 'X-ServiceWorker-Test': 'response test field' | |
| 8 }; | |
| 9 | |
| 10 var headers = new HeaderMap; | |
| 11 Object.keys(expectedMap).forEach(function(key) { | |
| 12 headers.set(key, expectedMap[key]); | |
| 13 }); | |
| 14 | |
| 15 // 'size' | |
| 16 assert_equals(headers.size, 3, 'headers.size should match'); | |
| 17 | |
| 18 // 'has()', 'get()' | |
| 19 var key = 'Content-Type'; | |
| 20 assert_true(headers.has(key)); | |
| 21 assert_equals(headers.get(key), expectedMap[key]); | |
| 22 | |
| 23 // 'delete()' | |
| 24 var deleteKey = 'Content-Type'; | |
| 25 headers.delete(deleteKey); | |
| 26 assert_equals(headers.size, 2, 'headers.size should have -1 size'); | |
| 27 Object.keys(expectedMap).forEach(function(key) { | |
| 28 if (key == deleteKey) | |
| 29 assert_false(headers.has(key)); | |
| 30 else | |
| 31 assert_true(headers.has(key)); | |
| 32 }); | |
| 33 | |
| 34 // 'set()' | |
| 35 var testCasesForSet = [ | |
| 36 // For a new key/value pair. | |
| 37 { key: 'Cache-Control', | |
| 38 value: 'max-age=3600', | |
| 39 isNewEntry: true }, | |
| 40 | |
| 41 // For an existing key. | |
| 42 { key: 'X-ServiceWorker-Test', | |
| 43 value: 'response test field - updated', | |
| 44 isUpdate: true }, | |
| 45 | |
| 46 // For setting a numeric value, expecting to see DOMString on getting. | |
| 47 { key: 'X-Numeric-Value', | |
| 48 value: 12345, | |
| 49 expectedValue: '12345', | |
| 50 isNewEntry: true }, | |
| 51 | |
| 52 // For case-sensitivity test. (FIXME: if we want HeaderMap to | |
| 53 // work in an case-insensitive way (as we do for headers in XHR) | |
| 54 // update the test and code) | |
| 55 { key: 'content-language', | |
| 56 value: 'fi', | |
| 57 isNewEntry: true } | |
| 58 ]; | |
| 59 | |
| 60 var expectedHeaderSize = headers.size; | |
| 61 testCasesForSet.forEach(function(testCase) { | |
| 62 var key = testCase.key; | |
| 63 var value = testCase.value; | |
| 64 var expectedValue = ('expectedValue' in testCase) ? testCase.expectedVal
ue : testCase.value; | |
| 65 expectedHeaderSize = testCase.isNewEntry ? (expectedHeaderSize + 1) : ex
pectedHeaderSize; | |
| 66 | |
| 67 headers.set(key, value); | |
| 68 assert_true(headers.has(key)); | |
| 69 assert_equals(headers.get(key), expectedValue); | |
| 70 if (testCase.isUpdate) | |
| 71 assert_true(headers.get(key) != expectedMap[key]); | |
| 72 assert_equals(headers.size, expectedHeaderSize); | |
| 73 | |
| 74 // Update expectedMap too for forEach() test below. | |
| 75 expectedMap[key] = expectedValue; | |
| 76 }); | |
| 77 | |
| 78 // 'forEach()' | |
| 79 headers.forEach(function(value, key) { | |
| 80 assert_true(key != deleteKey); | |
| 81 assert_true(key in expectedMap); | |
| 82 assert_equals(headers.get(key), expectedMap[key]); | |
| 83 }); | |
| 84 | |
| 85 // 'forEach()' with thisArg | |
| 86 var that = {}, saw_that; | |
| 87 headers = new HeaderMap; | |
| 88 headers.set('a', 'b'); | |
| 89 headers.forEach(function() { saw_that = this; }, that); | |
| 90 assert_equals(saw_that, that, 'Passed thisArg should match'); | |
| 91 | |
| 92 headers.forEach(function() { 'use strict'; saw_that = this; }, 'abc'); | |
| 93 assert_equals(saw_that, 'abc', 'Passed non-object thisArg should match'); | |
| 94 | |
| 95 headers.forEach(function() { saw_that = this; }, null); | |
| 96 assert_equals(saw_that, self, 'Passed null thisArg should be replaced with g
lobal object'); | |
| 97 | |
| 98 }, 'HeaderMap in ServiceWorkerGlobalScope'); | |
| OLD | NEW |