basic.https.window.js (4287B)
1 'use strict'; 2 3 test(() => { 4 assert_throws_js(TypeError, () => fetchLater()); 5 }, `fetchLater() cannot be called without request.`); 6 7 test(() => { 8 const result = fetchLater('/'); 9 assert_false(result.activated, `result.activated should be false for '/'`); 10 }, `fetchLater() with same-origin (https) URL does not throw.`); 11 12 test(() => { 13 const url = 'http://localhost'; 14 const result = fetchLater(url); 15 assert_false(result.activated, `result.activated should be false for ${url}`); 16 }, `fetchLater() with http://localhost URL does not throw.`); 17 18 test(() => { 19 const url = 'https://localhost'; 20 const result = fetchLater(url); 21 assert_false(result.activated, `result.activated should be false for ${url}`); 22 }, `fetchLater() with https://localhost URL does not throw.`); 23 24 test(() => { 25 const url = 'http://127.0.0.1'; 26 const result = fetchLater(url); 27 assert_false(result.activated, `result.activated should be false for ${url}`); 28 }, `fetchLater() with http://127.0.0.1 URL does not throw.`); 29 30 test(() => { 31 const url = 'https://127.0.0.1'; 32 const result = fetchLater(url); 33 assert_false(result.activated, `result.activated should be false for ${url}`); 34 }, `fetchLater() with https://127.0.0.1 URL does not throw.`); 35 36 test(() => { 37 const url = 'http://[::1]'; 38 const result = fetchLater(url); 39 assert_false(result.activated, `result.activated should be false for ${url}`); 40 }, `fetchLater() with http://[::1] URL does not throw.`); 41 42 test(() => { 43 const url = 'https://[::1]'; 44 const result = fetchLater(url); 45 assert_false(result.activated, `result.activated should be false for ${url}`); 46 }, `fetchLater() with https://[::1] URL does not throw.`); 47 48 test(() => { 49 const url = 'https://example.com'; 50 const result = fetchLater(url); 51 assert_false(result.activated, `result.activated should be false for ${url}`); 52 }, `fetchLater() with https://example.com URL does not throw.`); 53 54 test(() => { 55 assert_throws_js(TypeError, () => fetchLater('http://example.com')); 56 }, `fetchLater() throws TypeError on non-trustworthy http URL.`); 57 58 test(() => { 59 assert_throws_js(TypeError, () => fetchLater('file://tmp')); 60 }, `fetchLater() throws TypeError on file:// scheme.`); 61 62 test(() => { 63 assert_throws_js(TypeError, () => fetchLater('ftp://example.com')); 64 }, `fetchLater() throws TypeError on ftp:// scheme.`); 65 66 test(() => { 67 assert_throws_js(TypeError, () => fetchLater('ssh://example.com')); 68 }, `fetchLater() throws TypeError on ssh:// scheme.`); 69 70 test(() => { 71 assert_throws_js(TypeError, () => fetchLater('wss://example.com')); 72 }, `fetchLater() throws TypeError on wss:// scheme.`); 73 74 test(() => { 75 assert_throws_js(TypeError, () => fetchLater('about:blank')); 76 }, `fetchLater() throws TypeError on about: scheme.`); 77 78 test(() => { 79 assert_throws_js(TypeError, () => fetchLater(`javascript:alert('');`)); 80 }, `fetchLater() throws TypeError on javascript: scheme.`); 81 82 test(() => { 83 assert_throws_js(TypeError, () => fetchLater('data:text/plain,Hello')); 84 }, `fetchLater() throws TypeError on data: scheme.`); 85 86 test(() => { 87 assert_throws_js( 88 TypeError, () => fetchLater('blob:https://example.com/some-uuid')); 89 }, `fetchLater() throws TypeError on blob: scheme.`); 90 91 test(() => { 92 assert_throws_js( 93 RangeError, 94 () => fetchLater('https://www.google.com', {activateAfter: -1})); 95 }, `fetchLater() throws RangeError on negative activateAfter.`); 96 97 test(() => { 98 const result = fetchLater('/'); 99 assert_false(result.activated); 100 }, `fetchLater()'s return tells the deferred request is not yet sent.`); 101 102 test(() => { 103 const result = fetchLater('/'); 104 assert_throws_js(TypeError, () => result.activated = true); 105 }, `fetchLater() throws TypeError when mutating its returned state.`); 106 107 test(() => { 108 const controller = new AbortController(); 109 // Immediately aborts the controller. 110 controller.abort(); 111 assert_throws_dom( 112 'AbortError', () => fetchLater('/', {signal: controller.signal})); 113 }, `fetchLater() throws AbortError when its initial abort signal is aborted.`); 114 115 test(() => { 116 const controller = new AbortController(); 117 const result = fetchLater('/', {signal: controller.signal}); 118 assert_false(result.activated); 119 controller.abort(); 120 assert_false(result.activated); 121 }, `fetchLater() does not throw error when it is aborted before sending.`);