test_URLPattern_invalid.js (3594B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 const { parseURLPattern } = ChromeUtils.importESModule( 6 "chrome://remote/content/shared/webdriver/URLPattern.sys.mjs" 7 ); 8 9 add_task( 10 async function test_parseURLPattern_patternPattern_unescapedCharacters() { 11 const properties = ["protocol", "hostname", "port", "pathname", "search"]; 12 const values = ["*", "(", ")", "{", "}"]; 13 for (const property of properties) { 14 for (const value of values) { 15 Assert.throws( 16 () => parseURLPattern({ type: "pattern", [property]: value }), 17 /InvalidArgumentError/ 18 ); 19 } 20 } 21 } 22 ); 23 24 add_task(async function test_parseURLPattern_patternPattern_protocol() { 25 const values = [ 26 "", 27 "http/", 28 "http\\*", 29 "http\\(", 30 "http\\)", 31 "http\\{", 32 "http\\}", 33 "http#", 34 "http@", 35 "http%", 36 ]; 37 for (const value of values) { 38 Assert.throws( 39 () => parseURLPattern({ type: "pattern", protocol: value }), 40 /InvalidArgumentError/ 41 ); 42 } 43 }); 44 45 add_task( 46 async function test_parseURLPattern_patternPattern_unsupported_protocol() { 47 const values = ["ftp", "abc", "webpack"]; 48 for (const value of values) { 49 Assert.throws( 50 () => parseURLPattern({ type: "pattern", protocol: value }), 51 /UnsupportedOperationError/ 52 ); 53 } 54 } 55 ); 56 57 add_task(async function test_parseURLPattern_patternPattern_hostname() { 58 const values = ["", "abc/com/", "abc?com", "abc#com", "abc:com"]; 59 for (const value of values) { 60 Assert.throws( 61 () => parseURLPattern({ type: "pattern", hostname: value }), 62 /InvalidArgumentError/ 63 ); 64 } 65 }); 66 67 add_task(async function test_parseURLPattern_patternPattern_port() { 68 const values = ["", "abcd", "-1", "80 ", "1.3", ":80", "65536"]; 69 for (const value of values) { 70 Assert.throws( 71 () => parseURLPattern({ type: "pattern", port: value }), 72 /InvalidArgumentError/ 73 ); 74 } 75 }); 76 77 add_task(async function test_parseURLPattern_patternPattern_pathname() { 78 const values = ["path?", "path#"]; 79 for (const value of values) { 80 Assert.throws( 81 () => parseURLPattern({ type: "pattern", pathname: value }), 82 /InvalidArgumentError/ 83 ); 84 } 85 }); 86 87 add_task(async function test_parseURLPattern_patternPattern_search() { 88 const values = ["search#"]; 89 for (const value of values) { 90 Assert.throws( 91 () => parseURLPattern({ type: "pattern", search: value }), 92 /InvalidArgumentError/ 93 ); 94 } 95 }); 96 97 add_task(async function test_parseURLPattern_stringPattern_invalid_url() { 98 const values = ["", "invalid", "http:invalid:url", "[1::", "127.0..1"]; 99 for (const value of values) { 100 Assert.throws( 101 () => parseURLPattern({ type: "string", pattern: value }), 102 /InvalidArgumentError/ 103 ); 104 } 105 }); 106 107 add_task( 108 async function test_parseURLPattern_stringPattern_unescaped_characters() { 109 const values = ["*", "(", ")", "{", "}"]; 110 for (const value of values) { 111 Assert.throws( 112 () => parseURLPattern({ type: "string", pattern: value }), 113 /InvalidArgumentError/ 114 ); 115 } 116 } 117 ); 118 119 add_task( 120 async function test_parseURLPattern_stringPattern_unsupported_protocol() { 121 const values = ["ftp://some/path", "abc:pathplaceholder", "webpack://test"]; 122 for (const value of values) { 123 Assert.throws( 124 () => parseURLPattern({ type: "string", pattern: value }), 125 /UnsupportedOperationError/ 126 ); 127 } 128 } 129 );