aboutlogins_common.js (2539B)
1 "use strict"; 2 3 /* exported asyncElementRendered, importDependencies */ 4 5 /** 6 * A helper to await on while waiting for an asynchronous rendering of a Custom 7 * Element. 8 * 9 * @returns {Promise} 10 */ 11 function asyncElementRendered() { 12 return Promise.resolve(); 13 } 14 15 /** 16 * Import the templates from the real page to avoid duplication in the tests. 17 * 18 * @param {HTMLIFrameElement} templateFrame - Frame to copy the resources from 19 * @param {HTMLElement} destinationEl - Where to append the copied resources 20 */ 21 function importDependencies(templateFrame, destinationEl) { 22 let promises = []; 23 for (let template of templateFrame.contentDocument.querySelectorAll( 24 "template" 25 )) { 26 let imported = document.importNode(template, true); 27 destinationEl.appendChild(imported); 28 // Preload the styles in the actual page, to ensure they're loaded on time. 29 for (let element of imported.content.querySelectorAll( 30 "link[rel='stylesheet']" 31 )) { 32 let clone = element.cloneNode(true); 33 promises.push( 34 new Promise(resolve => { 35 clone.onload = function () { 36 resolve(); 37 clone.remove(); 38 }; 39 }) 40 ); 41 destinationEl.appendChild(clone); 42 } 43 } 44 return Promise.all(promises); 45 } 46 47 Object.defineProperty(document, "l10n", { 48 configurable: true, 49 writable: true, 50 value: { 51 connectRoot() {}, 52 disconnectRoot() {}, 53 translateElements() { 54 return Promise.resolve(); 55 }, 56 getAttributes(element) { 57 return { 58 id: element.getAttribute("data-l10n-id"), 59 args: element.getAttribute("data-l10n-args") 60 ? JSON.parse(element.getAttribute("data-l10n-args")) 61 : {}, 62 }; 63 }, 64 setAttributes(element, id, args) { 65 element.setAttribute("data-l10n-id", id); 66 if (args) { 67 element.setAttribute("data-l10n-args", JSON.stringify(args)); 68 } else { 69 element.removeAttribute("data-l10n-args"); 70 } 71 }, 72 }, 73 }); 74 75 Object.defineProperty(window, "AboutLoginsUtils", { 76 configurable: true, 77 writable: true, 78 value: { 79 getLoginOrigin(uriString) { 80 return uriString; 81 }, 82 setFocus(element) { 83 return element.focus(); 84 }, 85 async promptForPrimaryPassword(resolve, _messageId, _reason) { 86 resolve(true); 87 }, 88 doLoginsMatch(login1, login2) { 89 return ( 90 login1.origin == login2.origin && 91 login1.username == login2.username && 92 login1.password == login2.password 93 ); 94 }, 95 primaryPasswordEnabled: false, 96 }, 97 });