test_clearStoragesForOriginAttributesPattern.js (1477B)
1 /** 2 * Any copyright is dedicated to the Public Domain. 3 * http://creativecommons.org/publicdomain/zero/1.0/ 4 */ 5 6 async function testSteps() { 7 const baseRelativePath = "storage/default"; 8 const userContextForRemoval = 2; 9 10 const origins = [ 11 { 12 userContextId: 1, 13 baseDirName: "https+++example.com", 14 }, 15 16 { 17 userContextId: userContextForRemoval, 18 baseDirName: "https+++example.com", 19 }, 20 21 // TODO: Uncomment this once bug 1638831 is fixed. 22 /* 23 { 24 userContextId: userContextForRemoval, 25 baseDirName: "https+++example.org", 26 }, 27 */ 28 ]; 29 30 function getOriginDirectory(origin) { 31 return getRelativeFile( 32 `${baseRelativePath}/${origin.baseDirName}^userContextId=` + 33 `${origin.userContextId}` 34 ); 35 } 36 37 let request = init(); 38 await requestFinished(request); 39 40 for (const origin of origins) { 41 const directory = getOriginDirectory(origin); 42 directory.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("0755", 8)); 43 } 44 45 request = Services.qms.clearStoragesForOriginAttributesPattern( 46 `{ "userContextId": ${userContextForRemoval} }` 47 ); 48 await requestFinished(request); 49 50 for (const origin of origins) { 51 const directory = getOriginDirectory(origin); 52 if (origin.userContextId === userContextForRemoval) { 53 ok(!directory.exists(), "Origin directory should have been removed"); 54 } else { 55 ok(directory.exists(), "Origin directory shouldn't have been removed"); 56 } 57 } 58 }