test_stringLength2.js (2000B)
1 /** 2 * Any copyright is dedicated to the Public Domain. 3 * http://creativecommons.org/publicdomain/zero/1.0/ 4 */ 5 6 /** 7 * This test is mainly to verify that string length is correctly computed for 8 * database values containing NULs. See bug 1541681. 9 */ 10 11 add_task(async function testSteps() { 12 const principal = getPrincipal("http://example.org"); 13 14 const data = {}; 15 data.key = "foobar"; 16 data.secondKey = "foobaz"; 17 data.value = { 18 length: 19253, 19 }; 20 data.usage = data.key.length + data.value.length; 21 22 async function checkUsage(expectedUsage) { 23 info("Checking usage"); 24 25 // This forces any pending changes to be flushed to disk. It also forces 26 // data to be reloaded from disk at next localStorage API call. 27 request = resetClient(principal); 28 await requestFinished(request); 29 30 request = getOriginUsage(principal); 31 await requestFinished(request); 32 33 is(request.result.usage, expectedUsage, "Correct usage"); 34 } 35 36 info("Setting pref"); 37 38 Services.prefs.setBoolPref( 39 "dom.storage.enable_unsupported_legacy_implementation", 40 false 41 ); 42 43 info("Stage 1 - Checking usage after profile installation"); 44 45 info("Clearing"); 46 47 let request = clear(); 48 await requestFinished(request); 49 50 info("Installing package"); 51 52 // The profile contains storage.sqlite and webappsstore.sqlite. 53 installPackage("stringLength2_profile"); 54 55 await checkUsage(0); 56 57 info("Stage 2 - Checking usage after archived data migration"); 58 59 info("Opening database"); 60 61 let storage = getLocalStorage(principal); 62 storage.open(); 63 64 await checkUsage(data.usage); 65 66 info("Stage 3 - Checking usage after copying the value"); 67 68 info("Adding a second copy of the value"); 69 70 let value = storage.getItem(data.key); 71 storage.setItem(data.secondKey, value); 72 73 await checkUsage(2 * data.usage); 74 75 info("Stage 4 - Checking length of the copied value"); 76 77 value = storage.getItem(data.secondKey); 78 Assert.strictEqual(value.length, data.value.length, "Correct string length"); 79 });