test_storage_remove.js (2415B)
1 /** 2 * Tests removing all address/creditcard records. 3 */ 4 5 "use strict"; 6 7 let FormAutofillStorage; 8 add_setup(async () => { 9 ({ FormAutofillStorage } = ChromeUtils.importESModule( 10 "resource://autofill/FormAutofillStorage.sys.mjs" 11 )); 12 }); 13 14 const TEST_STORE_FILE_NAME = "test-tombstones.json"; 15 16 const TEST_ADDRESS_1 = { 17 "given-name": "Timothy", 18 "additional-name": "John", 19 "family-name": "Berners-Lee", 20 organization: "World Wide Web Consortium", 21 "street-address": "32 Vassar Street\nMIT Room 32-G524", 22 "address-level2": "Cambridge", 23 "address-level1": "MA", 24 "postal-code": "02139", 25 country: "US", 26 tel: "+1 617 253 5702", 27 email: "timbl@w3.org", 28 }; 29 30 const TEST_ADDRESS_2 = { 31 "street-address": "Some Address", 32 country: "US", 33 }; 34 35 const TEST_CREDIT_CARD_1 = { 36 "cc-name": "John Doe", 37 "cc-number": "4111111111111111", 38 "cc-exp-month": 4, 39 "cc-exp-year": 2017, 40 }; 41 42 const TEST_CREDIT_CARD_2 = { 43 "cc-name": "Timothy Berners-Lee", 44 "cc-number": "4929001587121045", 45 "cc-exp-month": 12, 46 "cc-exp-year": 2022, 47 }; 48 49 // Like add_task, but actually adds 2 - one for addresses and one for cards. 50 function add_storage_task(test_function) { 51 add_task(async function () { 52 let path = getTempFile(TEST_STORE_FILE_NAME).path; 53 let profileStorage = new FormAutofillStorage(path); 54 await profileStorage.initialize(); 55 let address_records = [TEST_ADDRESS_1, TEST_ADDRESS_2]; 56 let cc_records = [TEST_CREDIT_CARD_1, TEST_CREDIT_CARD_2]; 57 58 for (let [storage, record] of [ 59 [profileStorage.addresses, address_records], 60 [profileStorage.creditCards, cc_records], 61 ]) { 62 await test_function(storage, record); 63 } 64 }); 65 } 66 67 add_storage_task(async function test_remove_everything(storage, records) { 68 info("check simple tombstone semantics"); 69 70 let guid = await storage.add(records[0]); 71 Assert.equal((await storage.getAll()).length, 1); 72 73 storage.pullSyncChanges(); // force sync metadata, which triggers tombstone behaviour. 74 75 storage.remove(guid); 76 77 await storage.add(records[1]); 78 // getAll() is still 1 as we deleted the first. 79 Assert.equal((await storage.getAll()).length, 1); 80 81 // check we have the tombstone. 82 Assert.equal((await storage.getAll({ includeDeleted: true })).length, 2); 83 84 storage.removeAll(); 85 86 // should have deleted both the existing and deleted records. 87 Assert.equal((await storage.getAll({ includeDeleted: true })).length, 0); 88 });