test_uri_encoding_edge_cases.js (1814B)
1 /** 2 * Any copyright is dedicated to the Public Domain. 3 * http://creativecommons.org/publicdomain/zero/1.0/ 4 */ 5 6 /** 7 * This test verifies that group and origin strings for URIs with special 8 * characters are consistent between calling 9 * EnsureQuotaForOringin/EnsureOriginIsInitailized and GetQuotaObject in 10 * PrepareDatastoreOp, so writing to local storage won't cause a crash because 11 * of a null quota object. See bug 1516333. 12 */ 13 14 add_task(async function testSteps() { 15 /** 16 * The edge cases are specified in this array of origins. Each edge case must 17 * contain two properties uri and path (origin directory path relative to the 18 * profile directory). 19 */ 20 const origins = [ 21 { 22 uri: "file:///test'.html", 23 path: "storage/default/file++++test'.html", 24 }, 25 { 26 uri: "file:///test>.html", 27 path: "storage/default/file++++test%3E.html", 28 }, 29 ]; 30 31 info("Setting prefs"); 32 33 Services.prefs.setBoolPref( 34 "dom.storage.enable_unsupported_legacy_implementation", 35 false 36 ); 37 38 for (let origin of origins) { 39 const principal = getPrincipal(origin.uri); 40 41 let originDir = getRelativeFile(origin.path); 42 43 info("Checking the origin directory existence"); 44 45 ok( 46 !originDir.exists(), 47 `The origin directory ${origin.path} should not exists` 48 ); 49 50 info("Getting storage"); 51 52 let storage = getLocalStorage(principal); 53 54 info("Adding item"); 55 56 storage.setItem("foo", "bar"); 57 58 info("Resetting origin"); 59 60 // This forces any pending changes to be flushed to disk (including origin 61 // directory creation). 62 let request = resetClient(principal); 63 await requestFinished(request); 64 65 info("Checking the origin directory existence"); 66 67 ok(originDir.exists(), `The origin directory ${origin.path} should exist`); 68 } 69 });