test_validOrigins.js (2846B)
1 /** 2 * Any copyright is dedicated to the Public Domain. 3 * http://creativecommons.org/publicdomain/zero/1.0/ 4 */ 5 6 // Use initOrigin to test the operation of the origin parser on a list of URLs 7 // we should support. If the origin doesn't parse, then initOrigin will throw an 8 // exception (and potentially MOZ_ASSERT under debug builds). Handling of 9 // obsolete or invalid origins is handled in other test files. 10 async function testSteps() { 11 const basePath = "storage/default/"; 12 const longExampleOriginSubstring = "a".repeat( 13 255 - "https://example..com".length 14 ); 15 const origins = [ 16 // General 17 { 18 dirName: "https+++example.com", 19 url: "https://example.com", 20 }, 21 { 22 dirName: "https+++smaug----.github.io", 23 url: "https://smaug----.github.io/", 24 }, 25 // About 26 { 27 dirName: "about+home", 28 url: "about:home", 29 }, 30 { 31 dirName: "about+reader", 32 url: "about:reader", 33 }, 34 // IPv6 35 { 36 dirName: "https+++[++]", 37 url: "https://[::]", 38 }, 39 { 40 dirName: "https+++[ffff+ffff+ffff+ffff+ffff+ffff+ffff+ffff]", 41 url: "https://[ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]", 42 }, 43 { 44 dirName: "http+++[2010+836b+4179++836b+4179]", 45 url: "http://[2010:836B:4179::836B:4179]:80", 46 }, 47 { 48 dirName: "https+++[++ffff+8190+3426]", 49 url: "https://[::FFFF:129.144.52.38]", 50 }, 51 // MAX_PATH on Windows (260); storage/default/https+++example.{a....a}.com 52 // should have already exceeded the MAX_PATH limitation on Windows. 53 // There is a limitation (255) for each component on Windows so that we can 54 // only let the component be 255 chars and expect the wwhole path to be 55 // greater then 260. 56 { 57 dirName: `https+++example.${longExampleOriginSubstring}.com`, 58 url: `https://example.${longExampleOriginSubstring}.com`, 59 }, 60 // EndingWithPeriod 61 { 62 dirName: "https+++example.com.", 63 url: "https://example.com.", 64 }, 65 ]; 66 67 info("Initializing"); 68 69 let request = init(); 70 await requestFinished(request); 71 72 info("Initializing temporary storage"); 73 74 request = initTemporaryStorage(); 75 await requestFinished(request); 76 77 for (let origin of origins) { 78 info(`Testing ${origin.url}`); 79 80 try { 81 request = initTemporaryOrigin( 82 "default", 83 getPrincipal(origin.url), 84 /* createIfNonExistent */ true 85 ); 86 await requestFinished(request); 87 88 ok(true, "Should not have thrown"); 89 } catch (ex) { 90 ok(false, "Should not have thrown"); 91 } 92 93 let dir = getRelativeFile(basePath + origin.dirName); 94 ok(dir.exists(), "Origin was created"); 95 Assert.strictEqual( 96 origin.dirName, 97 dir.leafName, 98 `Origin ${origin.dirName} was created expectedly` 99 ); 100 } 101 102 request = clear(); 103 await requestFinished(request); 104 }