diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /browser/extensions/formautofill/test/unit/test_extractLabelStrings.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/extensions/formautofill/test/unit/test_extractLabelStrings.js')
-rw-r--r-- | browser/extensions/formautofill/test/unit/test_extractLabelStrings.js | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/browser/extensions/formautofill/test/unit/test_extractLabelStrings.js b/browser/extensions/formautofill/test/unit/test_extractLabelStrings.js new file mode 100644 index 0000000000..4c03c263f8 --- /dev/null +++ b/browser/extensions/formautofill/test/unit/test_extractLabelStrings.js @@ -0,0 +1,77 @@ +"use strict"; + +var { LabelUtils } = ChromeUtils.importESModule( + "resource://gre/modules/shared/LabelUtils.sys.mjs" +); + +const TESTCASES = [ + { + description: "A label element contains one input element.", + document: `<label id="typeA"> label type A + <!-- This comment should not be extracted. --> + <input type="text"> + <script>FOO</script> + <noscript>FOO</noscript> + <option>FOO</option> + <style>FOO</style> + </label>`, + inputId: "typeA", + expectedStrings: ["label type A"], + }, + { + description: "A label element with inner div contains one input element.", + document: `<label id="typeB"> label type B + <!-- This comment should not be extracted. --> + <script>FOO</script> + <noscript>FOO</noscript> + <option>FOO</option> + <style>FOO</style> + <div> inner div + <input type="text"> + </div> + </label>`, + inputId: "typeB", + expectedStrings: ["label type B", "inner div"], + }, + { + description: + "A label element with inner prefix/postfix strings contains span elements.", + document: `<label id="typeC"> label type C + <!-- This comment should not be extracted. --> + <script>FOO</script> + <noscript>FOO</noscript> + <option>FOO</option> + <style>FOO</style> + <div> inner div prefix + <span>test C-1 </span> + <span> test C-2</span> + inner div postfix + </div> + </label>`, + inputId: "typeC", + expectedStrings: [ + "label type C", + "inner div prefix", + "test C-1", + "test C-2", + "inner div postfix", + ], + }, +]; + +TESTCASES.forEach(testcase => { + add_task(async function () { + info("Starting testcase: " + testcase.description); + LabelUtils._labelStrings = new WeakMap(); + + let doc = MockDocument.createTestDocument( + "http://localhost:8080/test/", + testcase.document + ); + + let element = doc.getElementById(testcase.inputId); + let strings = LabelUtils.extractLabelStrings(element); + + Assert.deepEqual(strings, testcase.expectedStrings); + }); +}); |