From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- dom/base/test/unit/test_generate_xpath.js | 85 +++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 dom/base/test/unit/test_generate_xpath.js (limited to 'dom/base/test/unit/test_generate_xpath.js') diff --git a/dom/base/test/unit/test_generate_xpath.js b/dom/base/test/unit/test_generate_xpath.js new file mode 100644 index 0000000000..e8c7043690 --- /dev/null +++ b/dom/base/test/unit/test_generate_xpath.js @@ -0,0 +1,85 @@ +function run_test() { + test_generate_xpath(); +} + +// TEST CODE + +function test_generate_xpath() { + let docString = ` + + + + + + + + + + `; + let doc = getParser().parseFromString(docString, "text/html"); + + // Test generate xpath for body. + info("Test generate xpath for body node"); + let body = doc.getElementsByTagName("body")[0]; + let bodyXPath = body.generateXPath(); + let bodyExpXPath = "/xhtml:html/xhtml:body"; + equal(bodyExpXPath, bodyXPath, " xpath generated for body"); + + // Test generate xpath for input with id. + info("Test generate xpath for input with id"); + let inputWithId = doc.getElementById("input1"); + let inputWithIdXPath = inputWithId.generateXPath(); + let inputWithIdExpXPath = "//xhtml:input[@id='input1']"; + equal( + inputWithIdExpXPath, + inputWithIdXPath, + " xpath generated for input with id" + ); + + // Test generate xpath for input with id has single quote. + info("Test generate xpath for input with id has single quote"); + let inputWithIdSingleQuote = doc.getElementsByTagName("input")[1]; + let inputWithIdXPathSingleQuote = inputWithIdSingleQuote.generateXPath(); + let inputWithIdExpXPathSingleQuote = '//xhtml:input[@id="input2\'"]'; + equal( + inputWithIdExpXPathSingleQuote, + inputWithIdXPathSingleQuote, + " xpath generated for input with id" + ); + + // Test generate xpath for input with id has double quote. + info("Test generate xpath for input with id has double quote"); + let inputWithIdDoubleQuote = doc.getElementsByTagName("input")[2]; + let inputWithIdXPathDoubleQuote = inputWithIdDoubleQuote.generateXPath(); + let inputWithIdExpXPathDoubleQuote = "//xhtml:input[@id='\"input3\"']"; + equal( + inputWithIdExpXPathDoubleQuote, + inputWithIdXPathDoubleQuote, + " xpath generated for input with id" + ); + + // Test generate xpath for input with id has both single and double quote. + info("Test generate xpath for input with id has single and double quote"); + let inputWithIdSingleDoubleQuote = doc.getElementsByTagName("input")[3]; + inputWithIdSingleDoubleQuote.setAttribute("id", "\"input'4"); + let inputWithIdXPathSingleDoubleQuote = + inputWithIdSingleDoubleQuote.generateXPath(); + let inputWithIdExpXPathSingleDoubleQuote = + "//xhtml:input[@id=concat('\"input',\"'\",'4')]"; + equal( + inputWithIdExpXPathSingleDoubleQuote, + inputWithIdXPathSingleDoubleQuote, + " xpath generated for input with id" + ); + + // Test generate xpath for input without id. + info("Test generate xpath for input without id"); + let inputNoId = doc.getElementsByTagName("input")[4]; + let inputNoIdXPath = inputNoId.generateXPath(); + let inputNoIdExpXPath = "/xhtml:html/xhtml:body/xhtml:label[5]/xhtml:input"; + equal( + inputNoIdExpXPath, + inputNoIdXPath, + " xpath generated for input without id" + ); +} -- cgit v1.2.3