41 "//input[@name='input']": Date.now().toString(),
42 "//input[@name='spaced 1']": Math.random().toString(),
43 "//input[3]":
"three",
44 "//input[@type='checkbox']":
true,
45 "//input[@name='uncheck']":
false,
46 "//input[@type='radio'][1]":
false,
47 "//input[@type='radio'][2]":
true,
48 "//input[@type='radio'][3]":
false,
50 "//select[@multiple]": [1, 3],
52 "//textarea[2]":
"Some text... " + Math.random(),
53 "//textarea[3]":
"Some more text\n" +
new Date(),
54 "//input[@type='file'][1]": [
"/dev/null"],
55 "//input[@type='file'][2]": [
"/dev/null",
"/dev/stdin"]
58 function getElementByXPath(
aTab, aQuery) {
59 let
doc =
aTab.linkedBrowser.contentDocument;
60 let xptype =
Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE;
61 return doc.evaluate(aQuery, doc,
null, xptype,
null).singleNodeValue;
65 let
node = getElementByXPath(
aTab, aQuery);
66 if (typeof
aValue ==
"string")
68 else if (typeof
aValue ==
"boolean")
70 else if (typeof
aValue ==
"number")
71 node.selectedIndex =
aValue;
72 else if (node instanceof
Ci.nsIDOMHTMLInputElement && node.type ==
"file")
75 Array.forEach(node.options,
function(aOpt,
aIx)
76 (aOpt.selected =
aValue.indexOf(
aIx) > -1));
79 function compareFormValue(
aTab, aQuery,
aValue) {
80 let
node = getElementByXPath(
aTab, aQuery);
83 if (node instanceof
Ci.nsIDOMHTMLInputElement) {
84 if (node.type ==
"file") {
85 let fileNames = node.mozGetFileNameArray();
86 return fileNames.length ==
aValue.length &&
87 Array.every(fileNames,
function(aFile)
aValue.indexOf(aFile) >= 0);
89 return aValue == (node.type ==
"checkbox" || node.type ==
"radio" ?
90 node.checked : node.value);
92 if (node instanceof
Ci.nsIDOMHTMLTextAreaElement)
93 return aValue == node.value;
95 return aValue == node.selectedIndex;
96 return Array.every(node.options,
function(aOpt,
aIx)
97 (
aValue.indexOf(
aIx) > -1) == aOpt.selected);
105 gPrefService.setIntPref(
"browser.sessionstore.privacy_level", 2);
107 let
testURL =
"chrome://mochikit/content/browser/" +
108 "browser/components/sessionstore/test/browser/browser_346337_sample.html";
109 let
tab = tabbrowser.addTab(testURL);
110 tab.linkedBrowser.addEventListener(
"load",
function(aEvent) {
111 for (let xpath in fieldList)
112 setFormValue(tab, xpath, fieldList[xpath]);
114 let
tab2 = tabbrowser.duplicateTab(tab);
115 tab2.linkedBrowser.addEventListener(
"load",
function(aEvent) {
116 for (let xpath in fieldList)
117 ok(compareFormValue(tab2, xpath, fieldList[xpath]),
118 "The value for \"" + xpath +
"\" was correctly restored");
121 tabbrowser.removeTab(tab2);
122 tabbrowser.removeTab(tab);
125 tab.linkedBrowser.addEventListener(
"load",
function(aEvent) {
126 for (let xpath in fieldList)
127 if (fieldList[xpath])
128 ok(!compareFormValue(tab, xpath, fieldList[xpath]),
129 "The value for \"" + xpath +
"\" was correctly discarded");
131 if (
gPrefService.prefHasUserValue(
"browser.sessionstore.privacy_level"))
132 gPrefService.clearUserPref(
"browser.sessionstore.privacy_level");
135 if (tabbrowser.tabContainer.childNodes.length == 1)
137 tabbrowser.removeTab(tab);
function doc() browser.contentDocument
function getBrowser() gBrowser
restoreHistoryPrecursor aIx
_replaceLoadingTitle aTab
function undoCloseTab(aIndex)