test_enable_backup_encryption.html (4913B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Tests for the enable-backup-encryption component</title> 6 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 7 <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 8 <script type="application/javascript" src="head.js"></script> 9 <script 10 src="chrome://browser/content/backup/enable-backup-encryption.mjs" 11 type="module" 12 ></script> 13 <link rel="localization" href="browser/backupSettings.ftl"/> 14 <link rel="localization" href="branding/brand.ftl"/> 15 <link rel="stylesheet" href="chrome://mochikit/content/tests/SimpleTest/test.css"/> 16 <script> 17 18 const { BrowserTestUtils } = ChromeUtils.importESModule( 19 "resource://testing-common/BrowserTestUtils.sys.mjs" 20 ); 21 22 /** 23 * Tests that pressing the confirm button for the set-password type dialog will dispatch the expected events. 24 */ 25 add_task(async function test_type_set_password_confirm() { 26 let enableBackupEncryption = document.getElementById("test-enable-backup-encryption"); 27 28 let confirmButton = enableBackupEncryption.confirmButtonEl; 29 ok(confirmButton, "Confirm button should be found"); 30 ok(confirmButton.disabled, "Confirm button should now be disabled since there are passwords expanded options"); 31 32 let passwordInputs = enableBackupEncryption.passwordInputsEl; 33 ok(passwordInputs, "password-validation-inputs should be found"); 34 35 let confirmButtonPromise = BrowserTestUtils.waitForMutationCondition( 36 confirmButton, 37 { attributes: true }, 38 () => !confirmButton.disabled 39 ); 40 41 // Mock validation event passed by inputs 42 let validationPromise = createMockValidityPassEventPromise(enableBackupEncryption, passwordInputs, "ValidPasswordsDetected"); 43 44 await validationPromise; 45 await confirmButtonPromise; 46 47 ok(!confirmButton.disabled, "Confirm button should no longer be disabled"); 48 49 let content = document.getElementById("content"); 50 let encryptionPromise = BrowserTestUtils.waitForEvent(content, "BackupUI:EnableEncryption"); 51 52 confirmButton.click() 53 54 await encryptionPromise; 55 ok(true, "Detected event after selecting the confirm button"); 56 57 enableBackupEncryption.reset(); 58 }) 59 60 /** 61 * Tests that pressing the confirm button for the set-password type dialog will dispatch the expected events. 62 */ 63 add_task(async function test_type_change_password_confirm() { 64 let enableBackupEncryption = document.getElementById("test-enable-backup-encryption"); 65 enableBackupEncryption.type = "change-password"; 66 await enableBackupEncryption.updateComplete; 67 68 let confirmButton = enableBackupEncryption.confirmButtonEl; 69 ok(confirmButton, "Confirm button should be found"); 70 ok(confirmButton.disabled, "Confirm button should now be disabled since there are passwords expanded options"); 71 72 let passwordInputs = enableBackupEncryption.passwordInputsEl; 73 ok(passwordInputs, "password-validation-inputs should be found"); 74 75 let confirmButtonPromise = BrowserTestUtils.waitForMutationCondition( 76 confirmButton, 77 { attributes: true }, 78 () => !confirmButton.disabled 79 ); 80 81 // Mock validation event passed by inputs 82 let validationPromise = createMockValidityPassEventPromise(enableBackupEncryption, passwordInputs, "ValidPasswordsDetected"); 83 84 await validationPromise; 85 await confirmButtonPromise; 86 87 ok(!confirmButton.disabled, "Confirm button should no longer be disabled"); 88 89 let content = document.getElementById("content"); 90 let encryptionPromise = BrowserTestUtils.waitForEvent(content, "BackupUI:EnableEncryption"); 91 92 confirmButton.click() 93 94 await encryptionPromise; 95 ok(true, "Detected event after selecting the confirm button"); 96 97 enableBackupEncryption.reset(); 98 }) 99 100 /** 101 * Tests that pressing the cancel button will dispatch the expected events. 102 */ 103 add_task(async function test_cancel() { 104 let enableBackupEncryption = document.getElementById("test-enable-backup-encryption"); 105 enableBackupEncryption.type = "set-password"; 106 await enableBackupEncryption.updateComplete; 107 108 let cancelButton = enableBackupEncryption.cancelButtonEl; 109 110 ok(cancelButton, "Cancel button should be found"); 111 112 let content = document.getElementById("content"); 113 let promise = BrowserTestUtils.waitForEvent(content, "dialogCancel"); 114 115 cancelButton.click() 116 117 await promise; 118 ok(true, "Detected event after selecting the cancel button"); 119 120 enableBackupEncryption.reset(); 121 }) 122 </script> 123 </head> 124 <body> 125 <p id="display"></p> 126 <div id="content" style="display: none"> 127 <enable-backup-encryption id="test-enable-backup-encryption"></enable-backup-encryption> 128 </div> 129 <pre id="test"></pre> 130 </body> 131 </html>