summaryrefslogtreecommitdiffstats
path: root/layout/reftests/bidi/dirAuto
diff options
context:
space:
mode:
Diffstat (limited to 'layout/reftests/bidi/dirAuto')
-rw-r--r--layout/reftests/bidi/dirAuto/1103348-1-ref.html19
-rw-r--r--layout/reftests/bidi/dirAuto/1103348-1.html36
-rw-r--r--layout/reftests/bidi/dirAuto/1169267-delete-add-1-ref.html17
-rw-r--r--layout/reftests/bidi/dirAuto/1169267-delete-add-1a.html18
-rw-r--r--layout/reftests/bidi/dirAuto/1169267-delete-add-1b.html18
-rw-r--r--layout/reftests/bidi/dirAuto/1169267-delete-add-2-ref.html17
-rw-r--r--layout/reftests/bidi/dirAuto/1169267-delete-add-2a.html18
-rw-r--r--layout/reftests/bidi/dirAuto/1169267-delete-add-2b.html18
-rw-r--r--layout/reftests/bidi/dirAuto/839886-1-ref.html17
-rw-r--r--layout/reftests/bidi/dirAuto/839886-1.html17
-rw-r--r--layout/reftests/bidi/dirAuto/859093-1-ref.html11
-rw-r--r--layout/reftests/bidi/dirAuto/859093-1.html11
-rw-r--r--layout/reftests/bidi/dirAuto/889742-1-ref.html16
-rw-r--r--layout/reftests/bidi/dirAuto/889742-1.html21
-rw-r--r--layout/reftests/bidi/dirAuto/bdi-auto-dir-default-ref.html34
-rw-r--r--layout/reftests/bidi/dirAuto/bdi-auto-dir-default.html40
-rw-r--r--layout/reftests/bidi/dirAuto/dir_auto-contained-dir-L-ref.html61
-rw-r--r--layout/reftests/bidi/dirAuto/dir_auto-contained-dir-R-ref.html58
-rw-r--r--layout/reftests/bidi/dirAuto/dir_auto-set-contained-dir-L.html74
-rw-r--r--layout/reftests/bidi/dirAuto/dir_auto-set-contained-dir-R.html71
-rw-r--r--layout/reftests/bidi/dirAuto/dir_auto-set-contained-invalid-dir-L.html75
-rw-r--r--layout/reftests/bidi/dirAuto/dir_auto-set-contained-invalid-dir-R.html72
-rw-r--r--layout/reftests/bidi/dirAuto/dir_auto-unset-contained-dir-L-ref.html61
-rw-r--r--layout/reftests/bidi/dirAuto/dir_auto-unset-contained-dir-L.html71
-rw-r--r--layout/reftests/bidi/dirAuto/dir_auto-unset-contained-dir-R-ref.html64
-rw-r--r--layout/reftests/bidi/dirAuto/dir_auto-unset-contained-dir-R.html74
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR1.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR10.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR2.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR3.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR4.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR5.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR6.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR7.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR8.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR9.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL1.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL10.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL2.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL3.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL4.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL5.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL6.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL7.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL8.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL9.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-DeleteText-LTR1.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-DeleteText-LTR2.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-DeleteText-LTR3.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-DeleteText-RTL1.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-DeleteText-RTL2.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-DeleteText-RTL3.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-addLTR-Auto.html14
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-addRTL-Auto.html14
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-refLTR-LTR.html17
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-refLTR-RTL.html17
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-refRTL-LTR.html17
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-refRTL-NoDir.html20
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-refRTL-RTL.html17
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-Auto1.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-Auto2.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-Auto3.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-Auto4.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-Auto5.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-Auto6.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir1.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir2.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir3.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir4.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir5.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir6.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir7.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir8.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR1.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR2.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR3.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR4.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR5.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR6.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR7.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR8.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir1.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir2.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir3.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir4.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir5.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir6.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir7.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir8.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL1.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL2.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL3.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL4.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL5.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL6.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL7.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL8.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-Auto1.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-Auto2.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-Auto3.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-Auto4.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-Auto5.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-Auto6.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir1.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir2.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir3.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir4.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir5.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir6.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir7.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir8.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR1.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR2.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR3.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR4.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR5.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR6.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR7.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR8.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir1.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir2.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir3.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir4.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir5.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir6.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir7.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir8.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL1.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL2.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL3.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL4.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL5.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL6.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL7.html18
-rw-r--r--layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL8.html18
-rw-r--r--layout/reftests/bidi/dirAuto/reftest-stylo.list120
-rw-r--r--layout/reftests/bidi/dirAuto/reftest.list119
-rw-r--r--layout/reftests/bidi/dirAuto/setDir.js247
138 files changed, 3447 insertions, 0 deletions
diff --git a/layout/reftests/bidi/dirAuto/1103348-1-ref.html b/layout/reftests/bidi/dirAuto/1103348-1-ref.html
new file mode 100644
index 000000000..50fba8c41
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/1103348-1-ref.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Dynamic changes and dir=auto</title>
+ </head>
+ <body>
+ <div>Test for elements with dir="auto" whose content changes between directional and neutral</div>
+ <div dir="auto">xyz</div>
+ <div dir="auto">ابج</div>
+ <div dir="auto">456</div>
+ <div dir="auto">xyz</div>
+ <div dir="auto">ابج</div>
+ <div dir="auto">456</div>
+ <div dir="auto">xyz</div>
+ <div dir="auto">ابج</div>
+ <div dir="auto">456</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/1103348-1.html b/layout/reftests/bidi/dirAuto/1103348-1.html
new file mode 100644
index 000000000..e60202ca8
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/1103348-1.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html class="reftest-wait">
+ <head>
+ <meta charset="utf-8">
+ <title>Dynamic changes and dir=auto</title>
+ </head>
+ <body>
+ <div>Test for elements with dir="auto" whose content changes between directional and neutral</div>
+ <div dir="auto" id="from_ltr_to_ltr">abc</div>
+ <div dir="auto" id="from_ltr_to_rtl">abc</div>
+ <div dir="auto" id="from_ltr_to_neutral">abc</div>
+ <div dir="auto" id="from_rtl_to_ltr">אבג</div>
+ <div dir="auto" id="from_rtl_to_rtl">אבג</div>
+ <div dir="auto" id="from_rtl_to_neutral">אבג</div>
+ <div dir="auto" id="from_neutral_to_ltr">123</div>
+ <div dir="auto" id="from_neutral_to_rtl">123</div>
+ <div dir="auto" id="from_neutral_to_neutral">123</div>
+ <script type="text/javascript">
+function changeContent()
+{
+ var directionalTexts = {ltr:"xyz", rtl:"ابج", neutral:"456"};
+
+ for (var dirFrom in directionalTexts) {
+ for (var dirTo in directionalTexts) {
+ var element = document.getElementById("from_" + dirFrom +
+ "_to_" + dirTo);
+ element.textContent = directionalTexts[dirTo];
+ }
+ }
+ document.documentElement.removeAttribute("class");
+}
+
+document.addEventListener("MozReftestInvalidate", changeContent, false);
+ </script>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/1169267-delete-add-1-ref.html b/layout/reftests/bidi/dirAuto/1169267-delete-add-1-ref.html
new file mode 100644
index 000000000..d6e2ab456
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/1169267-delete-add-1-ref.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Test bug 1169267</title>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body>
+ <div><input type="text" dir="rtl" value="123אבג"></div>
+ <div><span dir="rtl">123אבג</span></div>
+ <div><textarea dir="rtl">123אבג</textarea></div>
+ <div><button dir="rtl">123אבג</button></div>
+ <div><bdi dir="rtl">123אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/1169267-delete-add-1a.html b/layout/reftests/bidi/dirAuto/1169267-delete-add-1a.html
new file mode 100644
index 000000000..a53257877
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/1169267-delete-add-1a.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Test bug 1169267</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="appendTextFromArray(new Array('123', 'אבג'))">
+ <div><input type="text" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto"></span></div>
+ <div><textarea id="set2" dir="auto"></textarea></div>
+ <div><button id="set3" dir="auto"></button></div>
+ <div><bdi id="set4"></bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/1169267-delete-add-1b.html b/layout/reftests/bidi/dirAuto/1169267-delete-add-1b.html
new file mode 100644
index 000000000..3127c3e37
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/1169267-delete-add-1b.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Test bug 1169267</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="appendDeleteAppendTextFromArray(new Array('123', 'אבג', 'אבג'))">
+ <div><input type="text" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto"></span></div>
+ <div><textarea id="set2" dir="auto"></textarea></div>
+ <div><button id="set3" dir="auto"></button></div>
+ <div><bdi id="set4"></bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/1169267-delete-add-2-ref.html b/layout/reftests/bidi/dirAuto/1169267-delete-add-2-ref.html
new file mode 100644
index 000000000..10685967f
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/1169267-delete-add-2-ref.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Test bug 1169267</title>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body>
+ <div><input type="text" dir="rtl" value="456גדה"></div>
+ <div><span dir="rtl">456גדה</span></div>
+ <div><textarea dir="rtl">456גדה</textarea></div>
+ <div><button dir="rtl">456גדה</button></div>
+ <div><bdi dir="rtl">456גדה</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/1169267-delete-add-2a.html b/layout/reftests/bidi/dirAuto/1169267-delete-add-2a.html
new file mode 100644
index 000000000..4a0cd1e16
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/1169267-delete-add-2a.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Test bug 1169267</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="appendTextFromArray(new Array('456', 'גדה'))">
+ <div><input type="text" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto"></span></div>
+ <div><textarea id="set2" dir="auto"></textarea></div>
+ <div><button id="set3" dir="auto"></button></div>
+ <div><bdi id="set4"></bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/1169267-delete-add-2b.html b/layout/reftests/bidi/dirAuto/1169267-delete-add-2b.html
new file mode 100644
index 000000000..bc520f83f
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/1169267-delete-add-2b.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Test bug 1169267</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="appendDeleteAppendTextFromArray(new Array('456', 'def', 'גדה'))">
+ <div><input type="text" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto"></span></div>
+ <div><textarea id="set2" dir="auto"></textarea></div>
+ <div><button id="set3" dir="auto"></button></div>
+ <div><bdi id="set4"></bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/839886-1-ref.html b/layout/reftests/bidi/dirAuto/839886-1-ref.html
new file mode 100644
index 000000000..df08a25bd
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/839886-1-ref.html
@@ -0,0 +1,17 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>dir="auto" and inputs</title>
+ </head>
+ <body>
+ <p>The next three lines should be left-to-right:</p>
+ <div dir="ltr"><input value="abcdefghi"> is left-to-right.</div>
+ <div dir="ltr"><input value="ابتثجحخدذ"> is right-to-left.</div>
+ <div dir="ltr"><input value="!()*;<=>?"> is neutral.</div>
+ <p dir="rtl">The next three lines should be right-to-left:</p>
+ <div dir="rtl"><input value="abcdefghi"> שמאל-ימין.</div>
+ <div dir="rtl"><input value="ابتثجحخدذ"> ימין-שמאל.</div>
+ <div dir="rtl"><input value="!()*;<=>?"> נייטראלי.</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/839886-1.html b/layout/reftests/bidi/dirAuto/839886-1.html
new file mode 100644
index 000000000..4cddec7fe
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/839886-1.html
@@ -0,0 +1,17 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>dir="auto" and inputs</title>
+ </head>
+ <body>
+ <p>The next three lines should be left-to-right:</p>
+ <div dir="auto"><input value="abcdefghi"> is left-to-right.</div>
+ <div dir="auto"><input value="ابتثجحخدذ"> is right-to-left.</div>
+ <div dir="auto"><input value="!()*;<=>?"> is neutral.</div>
+ <p dir="rtl">The next three lines should be right-to-left:</p>
+ <div dir="auto"><input value="abcdefghi"> שמאל-ימין.</div>
+ <div dir="auto"><input value="ابتثجحخدذ"> ימין-שמאל.</div>
+ <div dir="auto"><input value="!()*;<=>?"> נייטראלי.</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/859093-1-ref.html b/layout/reftests/bidi/dirAuto/859093-1-ref.html
new file mode 100644
index 000000000..f7afe90f5
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/859093-1-ref.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html dir="rtl" lang="he">
+ <head>
+ <meta charset="utf-8" />
+ </head>
+ <body>
+ <ul>
+ <li><span lang="en">correct rendering, parentheses at the end of the line: (<span dir="rtl">משהו בעברית: Something in English</span>)</span></li>
+ </ul>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/859093-1.html b/layout/reftests/bidi/dirAuto/859093-1.html
new file mode 100644
index 000000000..b692a43f9
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/859093-1.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html dir="rtl" lang="he">
+ <head>
+ <meta charset="utf-8" />
+ </head>
+ <body>
+ <ul>
+ <li><span lang="en">correct rendering, parentheses at the end of the line: (<span dir="auto">משהו בעברית: Something in English</span>)</span></li>
+ </ul>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/889742-1-ref.html b/layout/reftests/bidi/dirAuto/889742-1-ref.html
new file mode 100644
index 000000000..4e0237ba6
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/889742-1-ref.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Auto dir and alignment</title>
+ </head>
+ <body>
+ <h1>Auto dir and alignment</h1>
+ <p>Every line below should read "<span style="unicode-bidi: bidi-override"
+>!world םולש</span>" and should be aligned to the right</p>
+ <p dir="rtl">שלום world!</p>
+ <p dir="rtl"><b>שלום</b> world!</p>
+ <p dir="rtl">שלום world!</p>
+ <p dir="rtl"><b>שלום</b> world!</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/889742-1.html b/layout/reftests/bidi/dirAuto/889742-1.html
new file mode 100644
index 000000000..019083d28
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/889742-1.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Auto dir and alignment</title>
+ <style type="text/css">
+ p.plaintext {
+ unicode-bidi: plaintext;
+ }
+ </style>
+ </head>
+ <body>
+ <h1>Auto dir and alignment</h1>
+ <p>Every line below should read "<span style="unicode-bidi: bidi-override"
+>!world םולש</span>" and should be aligned to the right</p>
+ <p class="plaintext">שלום world!</p>
+ <p class="plaintext"><b>שלום</b> world!</p>
+ <p dir="auto">שלום world!</p>
+ <p dir="auto"><b>שלום</b> world!</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/bdi-auto-dir-default-ref.html b/layout/reftests/bidi/dirAuto/bdi-auto-dir-default-ref.html
new file mode 100644
index 000000000..fd255638a
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/bdi-auto-dir-default-ref.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>HTML Test: BDI: paragraph-level container</title>
+ <link rel="reference" href="bdi-auto-dir-default-ref.html">
+ <link rel="author" title="Aharon Lanin" href="mailto:aharon@google.com">
+ <link rel="author" title="HTML5 bidi test WG" href="mailto:html5bidi@googlegroups.com">
+ <link rel="help" href="http://dev.w3.org/html5/spec/Overview.html#the-bdi-element">
+ <meta name="assert" content="
+ 'The dir global attribute defaults to auto on this element (it never inherits from the parent
+ element like with other elements).'">
+ <style>
+ body{
+ font-size:2em;
+ }
+ .box {
+ border: medium solid gray;
+ width: 500px;
+ margin: 20px;
+ }
+ </style>
+ </head>
+ <body>
+ <!-- Key to entities used below:
+ &#x05D0; ... &#x05D5; - The first six Hebrew letters (strongly RTL).
+ &#x202D; - The LRO (left-to-right-override) formatting character.
+ &#x202C; - The PDF (pop directional formatting) formatting character; closes LRO. -->
+ <div class="box">
+ <div dir="ltr">&#x202D;[:)], [+- a &#x05D1;], [d &#x05D2; 1]...&#x202C;</div>
+ <div dir="rtl">&#x202D;...[d &#x05D2; 1] ,[+- a &#x05D1;] ,[:)]&#x202C;</div>
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/bdi-auto-dir-default.html b/layout/reftests/bidi/dirAuto/bdi-auto-dir-default.html
new file mode 100644
index 000000000..d4fb58420
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/bdi-auto-dir-default.html
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>HTML Test: BDI: paragraph-level container</title>
+ <link rel="reference" href="bdi-auto-dir-default-ref.html">
+ <link rel="author" title="Aharon Lanin" href="mailto:aharon@google.com">
+ <link rel="author" title="HTML5 bidi test WG" href="mailto:html5bidi@googlegroups.com">
+ <link rel="help" href="http://dev.w3.org/html5/spec/Overview.html#the-bdi-element">
+ <meta name="assert" content="
+ 'The dir global attribute defaults to auto on this element (it never inherits from the parent
+ element like with other elements).'">
+ <style>
+ body{
+ font-size:2em;
+ }
+ .box {
+ border: medium solid gray;
+ width: 500px;
+ margin: 20px;
+ }
+ </style>
+ </head>
+ <body>
+ <!-- Key to entities used below:
+ &#x05D0; ... &#x05D5; - The first six Hebrew letters (strongly RTL).
+ &#x202D; - The LRO (left-to-right-override) formatting character.
+ &#x202C; - The PDF (pop directional formatting) formatting character; closes LRO. -->
+ <div class="box">
+ <!--
+ In each DIV below:
+ - the first BDI, having no characters with strong direction, should be LTR by default;
+ - the second BDI, having an LTR character first, should be LTR by default;
+ - the thord BDI, having an RTL character first, should be RTL by default.
+ -->
+ <div dir="ltr"><bdi>[:)]</bdi>, <bdi>[+- a &#x05D1;]</bdi>, <bdi>[1 &#x05D2; d]</bdi>...</div>
+ <div dir="rtl"><bdi>[:)]</bdi>, <bdi>[+- a &#x05D1;]</bdi>, <bdi>[1 &#x05D2; d]</bdi>...</div>
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dir_auto-contained-dir-L-ref.html b/layout/reftests/bidi/dirAuto/dir_auto-contained-dir-L-ref.html
new file mode 100644
index 000000000..d5935d83f
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dir_auto-contained-dir-L-ref.html
@@ -0,0 +1,61 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8" />
+ <title>HTML Test: dir=auto, start with dir, then L</title>
+ <link rel="reference" href="dir_auto-contained-dir-L-ref.html" />
+ <link rel="author" title="Matitiahu Allouche" href="mailto:matitiahu.allouche@google.com" />
+ <link rel="author" title="Oren Roth" href="mailto:oren.roth@gmail.com" />
+ <link rel="author" title="HTML5 bidi test WG" href="mailto:html5bidi@googlegroups.com" />
+ <link rel="help" href="http://dev.w3.org/html5/spec/Overview.html#the-dir-attribute" />
+ <meta name="assert" content="
+ When dir='auto', the direction is set according to the first strong character
+ of the text while ignoring contained elements with an explicit dir of their own.
+ In this test, it is the Latin letter A, thus the direction must be
+ resolved as LTR." />
+ <style>
+ input, textarea {
+ font-size:1em;
+ }
+ body {
+ font-size:2em;
+ }
+ .test, .ref {
+ border: medium solid gray;
+ width: 400px;
+ margin: 20px;
+ }
+ .comments {
+ display: none;
+ }
+ </style>
+ </head>
+ <body>
+ <div class="instructions"><p>Test passes if the two boxes below look exactly the same.</p></div>
+ <div class="comments">
+ Key to entities used below:
+ &#x05D0; - The Hebrew letter Alef (strongly RTL).
+ &#x05D1; - The Hebrew letter Bet (strongly RTL).
+ &#x05D2; - The Hebrew letter Gimel (strongly RTL).
+ &#x05D3; - The Hebrew letter Dalet (strongly RTL).
+ &#x05D4; - The Hebrew letter He (strongly RTL).
+ &#x05D5; - The Hebrew letter Vav (strongly RTL).
+ </div>
+ <div class="test">
+ <div dir="ltr">
+ <div dir="ltr"><p dir="rtl">&#x05D3;&#x05D4;&#x05D5;</p>ABC&#x05D0;&#x05D1;&#x05D2;.</div>
+ </div>
+ <div dir="rtl">
+ <div dir="ltr"><p dir="rtl">&#x05D3;&#x05D4;&#x05D5;</p>ABC&#x05D0;&#x05D1;&#x05D2;.</div>
+ </div>
+ </div>
+ <div class="ref">
+ <div dir="ltr">
+ <div dir="ltr"><p dir="rtl">&#x05D3;&#x05D4;&#x05D5;</p>ABC&#x05D0;&#x05D1;&#x05D2;.</div>
+ </div>
+ <div dir="rtl">
+ <div dir="ltr"><p dir="rtl">&#x05D3;&#x05D4;&#x05D5;</p>ABC&#x05D0;&#x05D1;&#x05D2;.</div>
+ </div>
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dir_auto-contained-dir-R-ref.html b/layout/reftests/bidi/dirAuto/dir_auto-contained-dir-R-ref.html
new file mode 100644
index 000000000..5ae48d897
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dir_auto-contained-dir-R-ref.html
@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8" />
+ <title>HTML Test: dir=auto, start with dir, then R</title>
+ <link rel="reference" href="dir_auto-contained-dir-R-ref.html" />
+ <link rel="author" title="Matitiahu Allouche" href="mailto:matitiahu.allouche@google.com" />
+ <link rel="author" title="Oren Roth" href="mailto:oren.roth@gmail.com" />
+ <link rel="author" title="HTML5 bidi test WG" href="mailto:html5bidi@googlegroups.com" />
+ <link rel="help" href="http://dev.w3.org/html5/spec/Overview.html#the-dir-attribute" />
+ <meta name="assert" content="
+ When dir='auto', the direction is set according to the first strong character
+ of the text while ignoring contained elements with an explicit dir of their own.
+ In this test, it is the Hebrew letter Alef, thus the direction must be
+ resolved as RTL." />
+ <style>
+ input, textarea {
+ font-size:1em;
+ }
+ body {
+ font-size:2em;
+ }
+ .test, .ref {
+ border: medium solid gray;
+ width: 400px;
+ margin: 20px;
+ }
+ .comments {
+ display: none;
+ }
+ </style>
+ </head>
+ <body>
+ <div class="instructions"><p>Test passes if the two boxes below look exactly the same.</p></div>
+ <div class="comments">
+ Key to entities used below:
+ &#x05D0; - The Hebrew letter Alef (strongly RTL).
+ &#x05D1; - The Hebrew letter Bet (strongly RTL).
+ &#x05D2; - The Hebrew letter Gimel (strongly RTL).
+ </div>
+ <div class="test">
+ <div dir="ltr">
+ <div dir="rtl"><p dir="ltr">DEF</p>&#x05D0;&#x05D1;&#x05D2;ABC.</div>
+ </div>
+ <div dir="rtl">
+ <div dir="rtl"><p dir="ltr">DEF</p>&#x05D0;&#x05D1;&#x05D2;ABC.</div>
+ </div>
+ </div>
+ <div class="ref">
+ <div dir="ltr">
+ <div dir="rtl"><p dir="ltr">DEF</p>&#x05D0;&#x05D1;&#x05D2;ABC.</div>
+ </div>
+ <div dir="rtl">
+ <div dir="rtl"><p dir="ltr">DEF</p>&#x05D0;&#x05D1;&#x05D2;ABC.</div>
+ </div>
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dir_auto-set-contained-dir-L.html b/layout/reftests/bidi/dirAuto/dir_auto-set-contained-dir-L.html
new file mode 100644
index 000000000..41bf37180
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dir_auto-set-contained-dir-L.html
@@ -0,0 +1,74 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8" />
+ <title>HTML Test: dir=auto, start with dir, then L</title>
+ <link rel="reference" href="dir_auto-contained-dir-L-ref.html" />
+ <link rel="author" title="Matitiahu Allouche" href="mailto:matitiahu.allouche@google.com" />
+ <link rel="author" title="Oren Roth" href="mailto:oren.roth@gmail.com" />
+ <link rel="author" title="Simon Montagu" href="mailto:smontagu@smontagu.org" />
+ <link rel="author" title="HTML5 bidi test WG" href="mailto:html5bidi@googlegroups.com" />
+ <link rel="help" href="http://dev.w3.org/html5/spec/Overview.html#the-dir-attribute" />
+ <meta name="assert" content="
+ When dir='auto', the direction is set according to the first strong character
+ of the text while ignoring contained elements with an explicit dir of their own.
+ In this test, it is the Latin letter A, thus the direction must be
+ resolved as LTR.
+ This is a variation of the original dir_auto-contained-dir-L.html in which
+ the explicit dir is set by script after loading the page" />
+ <style>
+ input, textarea {
+ font-size:1em;
+ }
+ body {
+ font-size:2em;
+ }
+ .test, .ref {
+ border: medium solid gray;
+ width: 400px;
+ margin: 20px;
+ }
+ .comments {
+ display: none;
+ }
+ </style>
+ <script type="text/javascript">
+function setDirs(value)
+{
+ var p1 = document.getElementById("p1");
+ p1.dir = value;
+
+ var p1 = document.getElementById("p2");
+ p2.dir = value;
+}
+ </script>
+ </head>
+ <body onload="setDirs('rtl')">
+ <div class="instructions"><p>Test passes if the two boxes below look exactly the same.</p></div>
+ <div class="comments">
+ Key to entities used below:
+ &#x05D0; - The Hebrew letter Alef (strongly RTL).
+ &#x05D1; - The Hebrew letter Bet (strongly RTL).
+ &#x05D2; - The Hebrew letter Gimel (strongly RTL).
+ &#x05D3; - The Hebrew letter Dalet (strongly RTL).
+ &#x05D4; - The Hebrew letter He (strongly RTL).
+ &#x05D5; - The Hebrew letter Vav (strongly RTL).
+ </div>
+ <div class="test">
+ <div dir="ltr">
+ <div dir="auto"><p id="p1">&#x05D3;&#x05D4;&#x05D5;</p>ABC&#x05D0;&#x05D1;&#x05D2;.</div>
+ </div>
+ <div dir="rtl">
+ <div dir="auto"><p id="p2">&#x05D3;&#x05D4;&#x05D5;</p>ABC&#x05D0;&#x05D1;&#x05D2;.</div>
+ </div>
+ </div>
+ <div class="ref">
+ <div dir="ltr">
+ <div dir="ltr"><p dir="rtl">&#x05D3;&#x05D4;&#x05D5;</p>ABC&#x05D0;&#x05D1;&#x05D2;.</div>
+ </div>
+ <div dir="rtl">
+ <div dir="ltr"><p dir="rtl">&#x05D3;&#x05D4;&#x05D5;</p>ABC&#x05D0;&#x05D1;&#x05D2;.</div>
+ </div>
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dir_auto-set-contained-dir-R.html b/layout/reftests/bidi/dirAuto/dir_auto-set-contained-dir-R.html
new file mode 100644
index 000000000..0c74b3f3b
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dir_auto-set-contained-dir-R.html
@@ -0,0 +1,71 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8" />
+ <title>HTML Test: dir=auto, start with dir, then R</title>
+ <link rel="reference" href="dir_auto-contained-dir-R-ref.html" />
+ <link rel="author" title="Matitiahu Allouche" href="mailto:matitiahu.allouche@google.com" />
+ <link rel="author" title="Oren Roth" href="mailto:oren.roth@gmail.com" />
+ <link rel="author" title="Simon Montagu" href="mailto:smontagu@smontagu.org" />
+ <link rel="author" title="HTML5 bidi test WG" href="mailto:html5bidi@googlegroups.com" />
+ <link rel="help" href="http://dev.w3.org/html5/spec/Overview.html#the-dir-attribute" />
+ <meta name="assert" content="
+ When dir='auto', the direction is set according to the first strong character
+ of the text while ignoring contained elements with an explicit dir of their own.
+ In this test, it is the Hebrew letter Alef, thus the direction must be
+ resolved as RTL.
+ This is a variation of the original dir_auto-contained-dir-R.html in which
+ the explicit dir is set by script after loading the page" />
+ <style>
+ input, textarea {
+ font-size:1em;
+ }
+ body {
+ font-size:2em;
+ }
+ .test, .ref {
+ border: medium solid gray;
+ width: 400px;
+ margin: 20px;
+ }
+ .comments {
+ display: none;
+ }
+ </style>
+ <script type="text/javascript">
+function setDirs(value)
+{
+ var p1 = document.getElementById("p1");
+ p1.dir = value;
+
+ var p1 = document.getElementById("p2");
+ p2.dir = value;
+}
+ </script>
+ </head>
+ <body onload="setDirs('ltr')">
+ <div class="instructions"><p>Test passes if the two boxes below look exactly the same.</p></div>
+ <div class="comments">
+ Key to entities used below:
+ &#x05D0; - The Hebrew letter Alef (strongly RTL).
+ &#x05D1; - The Hebrew letter Bet (strongly RTL).
+ &#x05D2; - The Hebrew letter Gimel (strongly RTL).
+ </div>
+ <div class="test">
+ <div dir="ltr">
+ <div dir="auto"><p id="p1">DEF</p>&#x05D0;&#x05D1;&#x05D2;ABC.</div>
+ </div>
+ <div dir="rtl">
+ <div dir="auto"><p id="p2">DEF</p>&#x05D0;&#x05D1;&#x05D2;ABC.</div>
+ </div>
+ </div>
+ <div class="ref">
+ <div dir="ltr">
+ <div dir="rtl"><p dir="ltr">DEF</p>&#x05D0;&#x05D1;&#x05D2;ABC.</div>
+ </div>
+ <div dir="rtl">
+ <div dir="rtl"><p dir="ltr">DEF</p>&#x05D0;&#x05D1;&#x05D2;ABC.</div>
+ </div>
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dir_auto-set-contained-invalid-dir-L.html b/layout/reftests/bidi/dirAuto/dir_auto-set-contained-invalid-dir-L.html
new file mode 100644
index 000000000..10a75a4ce
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dir_auto-set-contained-invalid-dir-L.html
@@ -0,0 +1,75 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8" />
+ <title>HTML Test: dir=auto, start with dir, then L</title>
+ <link rel="reference" href="dir_auto-contained-dir-L-ref.html" />
+ <link rel="author" title="Matitiahu Allouche" href="mailto:matitiahu.allouche@google.com" />
+ <link rel="author" title="Oren Roth" href="mailto:oren.roth@gmail.com" />
+ <link rel="author" title="Simon Montagu" href="mailto:smontagu@smontagu.org" />
+ <link rel="author" title="HTML5 bidi test WG" href="mailto:html5bidi@googlegroups.com" />
+ <link rel="help" href="http://dev.w3.org/html5/spec/Overview.html#the-dir-attribute" />
+ <meta name="assert" content="
+ When dir='auto', the direction is set according to the first strong character
+ of the text while ignoring contained elements with an explicit dir of their own.
+ In this test, it is the Latin letter A, thus the direction must be
+ resolved as LTR.
+ This is a variation of the original dir_auto-contained-dir-L.html in which
+ an element with an invalid dir attribute has the dir attribute set by
+ script after loading the page" />
+ <style>
+ input, textarea {
+ font-size:1em;
+ }
+ body {
+ font-size:2em;
+ }
+ .test, .ref {
+ border: medium solid gray;
+ width: 400px;
+ margin: 20px;
+ }
+ .comments {
+ display: none;
+ }
+ </style>
+ <script type="text/javascript">
+function setDirs(value)
+{
+ var p1 = document.getElementById("p1");
+ p1.dir = value;
+
+ var p1 = document.getElementById("p2");
+ p2.dir = value;
+}
+ </script>
+ </head>
+ <body onload="setDirs('rtl')">
+ <div class="instructions"><p>Test passes if the two boxes below look exactly the same.</p></div>
+ <div class="comments">
+ Key to entities used below:
+ &#x05D0; - The Hebrew letter Alef (strongly RTL).
+ &#x05D1; - The Hebrew letter Bet (strongly RTL).
+ &#x05D2; - The Hebrew letter Gimel (strongly RTL).
+ &#x05D3; - The Hebrew letter Dalet (strongly RTL).
+ &#x05D4; - The Hebrew letter He (strongly RTL).
+ &#x05D5; - The Hebrew letter Vav (strongly RTL).
+ </div>
+ <div class="test">
+ <div dir="ltr">
+ <div dir="auto"><p id="p1" dir="foopy">&#x05D3;&#x05D4;&#x05D5;</p>ABC&#x05D0;&#x05D1;&#x05D2;.</div>
+ </div>
+ <div dir="rtl">
+ <div dir="auto"><p id="p2" dir="foopy">&#x05D3;&#x05D4;&#x05D5;</p>ABC&#x05D0;&#x05D1;&#x05D2;.</div>
+ </div>
+ </div>
+ <div class="ref">
+ <div dir="ltr">
+ <div dir="ltr"><p dir="rtl">&#x05D3;&#x05D4;&#x05D5;</p>ABC&#x05D0;&#x05D1;&#x05D2;.</div>
+ </div>
+ <div dir="rtl">
+ <div dir="ltr"><p dir="rtl">&#x05D3;&#x05D4;&#x05D5;</p>ABC&#x05D0;&#x05D1;&#x05D2;.</div>
+ </div>
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dir_auto-set-contained-invalid-dir-R.html b/layout/reftests/bidi/dirAuto/dir_auto-set-contained-invalid-dir-R.html
new file mode 100644
index 000000000..0ff92cb55
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dir_auto-set-contained-invalid-dir-R.html
@@ -0,0 +1,72 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8" />
+ <title>HTML Test: dir=auto, start with dir, then R</title>
+ <link rel="reference" href="dir_auto-contained-dir-R-ref.html" />
+ <link rel="author" title="Matitiahu Allouche" href="mailto:matitiahu.allouche@google.com" />
+ <link rel="author" title="Oren Roth" href="mailto:oren.roth@gmail.com" />
+ <link rel="author" title="Simon Montagu" href="mailto:smontagu@smontagu.org" />
+ <link rel="author" title="HTML5 bidi test WG" href="mailto:html5bidi@googlegroups.com" />
+ <link rel="help" href="http://dev.w3.org/html5/spec/Overview.html#the-dir-attribute" />
+ <meta name="assert" content="
+ When dir='auto', the direction is set according to the first strong character
+ of the text while ignoring contained elements with an explicit dir of their own.
+ In this test, it is the Hebrew letter Alef, thus the direction must be
+ resolved as RTL.
+ This is a variation of the original dir_auto-contained-dir-R.html in which
+ an element with an invalid dir attribute has the dir attribute set by
+ script after loading the page" />
+ <style>
+ input, textarea {
+ font-size:1em;
+ }
+ body {
+ font-size:2em;
+ }
+ .test, .ref {
+ border: medium solid gray;
+ width: 400px;
+ margin: 20px;
+ }
+ .comments {
+ display: none;
+ }
+ </style>
+ <script type="text/javascript">
+function setDirs(value)
+{
+ var p1 = document.getElementById("p1");
+ p1.dir = value;
+
+ var p1 = document.getElementById("p2");
+ p2.dir = value;
+}
+ </script>
+ </head>
+ <body onload="setDirs('ltr')">
+ <div class="instructions"><p>Test passes if the two boxes below look exactly the same.</p></div>
+ <div class="comments">
+ Key to entities used below:
+ &#x05D0; - The Hebrew letter Alef (strongly RTL).
+ &#x05D1; - The Hebrew letter Bet (strongly RTL).
+ &#x05D2; - The Hebrew letter Gimel (strongly RTL).
+ </div>
+ <div class="test">
+ <div dir="ltr">
+ <div dir="auto"><p id="p1" dir="foopy">DEF</p>&#x05D0;&#x05D1;&#x05D2;ABC.</div>
+ </div>
+ <div dir="rtl">
+ <div dir="auto"><p id="p2" dir="foopy">DEF</p>&#x05D0;&#x05D1;&#x05D2;ABC.</div>
+ </div>
+ </div>
+ <div class="ref">
+ <div dir="ltr">
+ <div dir="rtl"><p dir="ltr">DEF</p>&#x05D0;&#x05D1;&#x05D2;ABC.</div>
+ </div>
+ <div dir="rtl">
+ <div dir="rtl"><p dir="ltr">DEF</p>&#x05D0;&#x05D1;&#x05D2;ABC.</div>
+ </div>
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dir_auto-unset-contained-dir-L-ref.html b/layout/reftests/bidi/dirAuto/dir_auto-unset-contained-dir-L-ref.html
new file mode 100644
index 000000000..a78643049
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dir_auto-unset-contained-dir-L-ref.html
@@ -0,0 +1,61 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8" />
+ <title>HTML Test: dir=auto, start with dir, then R</title>
+ <link rel="reference" href="dir_auto-contained-dir-R-ref.html" />
+ <link rel="author" title="Matitiahu Allouche" href="mailto:matitiahu.allouche@google.com" />
+ <link rel="author" title="Oren Roth" href="mailto:oren.roth@gmail.com" />
+ <link rel="author" title="Simon Montagu" href="mailto:smontagu@smontagu.org" />
+ <link rel="author" title="HTML5 bidi test WG" href="mailto:html5bidi@googlegroups.com" />
+ <link rel="help" href="http://dev.w3.org/html5/spec/Overview.html#the-dir-attribute" />
+ <meta name="assert" content="
+ When dir='auto', the direction is set according to the first strong character
+ of the text while ignoring contained elements with an explicit dir of their own.
+ In this test, it is the Latin letter D, thus the direction must be
+ resolved as LTR.
+ This is a variation of the original dir_auto-contained-dir-R.html in which
+ the explicit dir is unset by script after loading the page" />
+ <style>
+ input, textarea {
+ font-size:1em;
+ }
+ body {
+ font-size:2em;
+ }
+ .test, .ref {
+ border: medium solid gray;
+ width: 400px;
+ margin: 20px;
+ }
+ .comments {
+ display: none;
+ }
+ </style>
+ </head>
+ <body>
+ <div class="instructions"><p>Test passes if the two boxes below look exactly the same.</p></div>
+ <div class="comments">
+ Key to entities used below:
+ &#x05D0; - The Hebrew letter Alef (strongly RTL).
+ &#x05D1; - The Hebrew letter Bet (strongly RTL).
+ &#x05D2; - The Hebrew letter Gimel (strongly RTL).
+ </div>
+ <div class="test">
+ <div dir="ltr">
+ <div dir="ltr"><p id="p1" dir="ltr">DEF</p>&#x05D0;&#x05D1;&#x05D2;ABC.</div>
+ </div>
+ <div dir="rtl">
+ <div dir="ltr"><p id="p2" dir="ltr">DEF</p>&#x05D0;&#x05D1;&#x05D2;ABC.</div>
+ </div>
+ </div>
+ <div class="ref">
+ <div dir="ltr">
+ <div dir="ltr"><p dir="ltr">DEF</p>&#x05D0;&#x05D1;&#x05D2;ABC.</div>
+ </div>
+ <div dir="rtl">
+ <div dir="ltr"><p dir="ltr">DEF</p>&#x05D0;&#x05D1;&#x05D2;ABC.</div>
+ </div>
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dir_auto-unset-contained-dir-L.html b/layout/reftests/bidi/dirAuto/dir_auto-unset-contained-dir-L.html
new file mode 100644
index 000000000..c2cbdc241
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dir_auto-unset-contained-dir-L.html
@@ -0,0 +1,71 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8" />
+ <title>HTML Test: dir=auto, start with dir, then R</title>
+ <link rel="reference" href="dir_auto-contained-dir-R-ref.html" />
+ <link rel="author" title="Matitiahu Allouche" href="mailto:matitiahu.allouche@google.com" />
+ <link rel="author" title="Oren Roth" href="mailto:oren.roth@gmail.com" />
+ <link rel="author" title="Simon Montagu" href="mailto:smontagu@smontagu.org" />
+ <link rel="author" title="HTML5 bidi test WG" href="mailto:html5bidi@googlegroups.com" />
+ <link rel="help" href="http://dev.w3.org/html5/spec/Overview.html#the-dir-attribute" />
+ <meta name="assert" content="
+ When dir='auto', the direction is set according to the first strong character
+ of the text while ignoring contained elements with an explicit dir of their own.
+ In this test, it is the Latin letter D, thus the direction must be
+ resolved as LTR.
+ This is a variation of the original dir_auto-contained-dir-R.html in which
+ the explicit dir is unset by script after loading the page" />
+ <style>
+ input, textarea {
+ font-size:1em;
+ }
+ body {
+ font-size:2em;
+ }
+ .test, .ref {
+ border: medium solid gray;
+ width: 400px;
+ margin: 20px;
+ }
+ .comments {
+ display: none;
+ }
+ </style>
+ <script type="text/javascript">
+function setDirs(value)
+{
+ var p1 = document.getElementById("p1");
+ p1.dir = value;
+
+ var p1 = document.getElementById("p2");
+ p2.dir = value;
+}
+ </script>
+ </head>
+ <body onload="setDirs('')">
+ <div class="instructions"><p>Test passes if the two boxes below look exactly the same.</p></div>
+ <div class="comments">
+ Key to entities used below:
+ &#x05D0; - The Hebrew letter Alef (strongly RTL).
+ &#x05D1; - The Hebrew letter Bet (strongly RTL).
+ &#x05D2; - The Hebrew letter Gimel (strongly RTL).
+ </div>
+ <div class="test">
+ <div dir="ltr">
+ <div dir="auto"><p id="p1" dir="ltr">DEF</p>&#x05D0;&#x05D1;&#x05D2;ABC.</div>
+ </div>
+ <div dir="rtl">
+ <div dir="auto"><p id="p2" dir="ltr">DEF</p>&#x05D0;&#x05D1;&#x05D2;ABC.</div>
+ </div>
+ </div>
+ <div class="ref">
+ <div dir="ltr">
+ <div dir="ltr"><p dir="ltr">DEF</p>&#x05D0;&#x05D1;&#x05D2;ABC.</div>
+ </div>
+ <div dir="rtl">
+ <div dir="ltr"><p dir="ltr">DEF</p>&#x05D0;&#x05D1;&#x05D2;ABC.</div>
+ </div>
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dir_auto-unset-contained-dir-R-ref.html b/layout/reftests/bidi/dirAuto/dir_auto-unset-contained-dir-R-ref.html
new file mode 100644
index 000000000..f38365221
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dir_auto-unset-contained-dir-R-ref.html
@@ -0,0 +1,64 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8" />
+ <title>HTML Test: dir=auto, start with dir, then L</title>
+ <link rel="reference" href="dir_auto-contained-dir-L-ref.html" />
+ <link rel="author" title="Matitiahu Allouche" href="mailto:matitiahu.allouche@google.com" />
+ <link rel="author" title="Oren Roth" href="mailto:oren.roth@gmail.com" />
+ <link rel="author" title="Simon Montagu" href="mailto:smontagu@smontagu.org" />
+ <link rel="author" title="HTML5 bidi test WG" href="mailto:html5bidi@googlegroups.com" />
+ <link rel="help" href="http://dev.w3.org/html5/spec/Overview.html#the-dir-attribute" />
+ <meta name="assert" content="
+ When dir='auto', the direction is set according to the first strong character
+ of the text while ignoring contained elements with an explicit dir of their own.
+ In this test, it is the Hebrew letter Dalet, thus the direction must be
+ resolved as RTL.
+ This is a variation of the original dir_auto-contained-dir-L.html in which
+ the explicit dir is unset by script after loading the page" />
+ <style>
+ input, textarea {
+ font-size:1em;
+ }
+ body {
+ font-size:2em;
+ }
+ .test, .ref {
+ border: medium solid gray;
+ width: 400px;
+ margin: 20px;
+ }
+ .comments {
+ display: none;
+ }
+ </style>
+ </head>
+ <body>
+ <div class="instructions"><p>Test passes if the two boxes below look exactly the same.</p></div>
+ <div class="comments">
+ Key to entities used below:
+ &#x05D0; - The Hebrew letter Alef (strongly RTL).
+ &#x05D1; - The Hebrew letter Bet (strongly RTL).
+ &#x05D2; - The Hebrew letter Gimel (strongly RTL).
+ &#x05D3; - The Hebrew letter Dalet (strongly RTL).
+ &#x05D4; - The Hebrew letter He (strongly RTL).
+ &#x05D5; - The Hebrew letter Vav (strongly RTL).
+ </div>
+ <div class="test">
+ <div dir="ltr">
+ <div dir="rtl"><p id="p1" dir="rtl">&#x05D3;&#x05D4;&#x05D5;</p>ABC&#x05D0;&#x05D1;&#x05D2;.</div>
+ </div>
+ <div dir="rtl">
+ <div dir="rtl"><p id="p2" dir="rtl">&#x05D3;&#x05D4;&#x05D5;</p>ABC&#x05D0;&#x05D1;&#x05D2;.</div>
+ </div>
+ </div>
+ <div class="ref">
+ <div dir="ltr">
+ <div dir="rtl"><p dir="rtl">&#x05D3;&#x05D4;&#x05D5;</p>ABC&#x05D0;&#x05D1;&#x05D2;.</div>
+ </div>
+ <div dir="rtl">
+ <div dir="rtl"><p dir="rtl">&#x05D3;&#x05D4;&#x05D5;</p>ABC&#x05D0;&#x05D1;&#x05D2;.</div>
+ </div>
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dir_auto-unset-contained-dir-R.html b/layout/reftests/bidi/dirAuto/dir_auto-unset-contained-dir-R.html
new file mode 100644
index 000000000..a63f718ce
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dir_auto-unset-contained-dir-R.html
@@ -0,0 +1,74 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8" />
+ <title>HTML Test: dir=auto, start with dir, then L</title>
+ <link rel="reference" href="dir_auto-contained-dir-L-ref.html" />
+ <link rel="author" title="Matitiahu Allouche" href="mailto:matitiahu.allouche@google.com" />
+ <link rel="author" title="Oren Roth" href="mailto:oren.roth@gmail.com" />
+ <link rel="author" title="Simon Montagu" href="mailto:smontagu@smontagu.org" />
+ <link rel="author" title="HTML5 bidi test WG" href="mailto:html5bidi@googlegroups.com" />
+ <link rel="help" href="http://dev.w3.org/html5/spec/Overview.html#the-dir-attribute" />
+ <meta name="assert" content="
+ When dir='auto', the direction is set according to the first strong character
+ of the text while ignoring contained elements with an explicit dir of their own.
+ In this test, it is the Hebrew letter Dalet, thus the direction must be
+ resolved as RTL.
+ This is a variation of the original dir_auto-contained-dir-L.html in which
+ the explicit dir is unset by script after loading the page" />
+ <style>
+ input, textarea {
+ font-size:1em;
+ }
+ body {
+ font-size:2em;
+ }
+ .test, .ref {
+ border: medium solid gray;
+ width: 400px;
+ margin: 20px;
+ }
+ .comments {
+ display: none;
+ }
+ </style>
+ <script type="text/javascript">
+function setDirs(value)
+{
+ var p1 = document.getElementById("p1");
+ p1.dir = value;
+
+ var p1 = document.getElementById("p2");
+ p2.dir = value;
+}
+ </script>
+ </head>
+ <body onload="setDirs('')">
+ <div class="instructions"><p>Test passes if the two boxes below look exactly the same.</p></div>
+ <div class="comments">
+ Key to entities used below:
+ &#x05D0; - The Hebrew letter Alef (strongly RTL).
+ &#x05D1; - The Hebrew letter Bet (strongly RTL).
+ &#x05D2; - The Hebrew letter Gimel (strongly RTL).
+ &#x05D3; - The Hebrew letter Dalet (strongly RTL).
+ &#x05D4; - The Hebrew letter He (strongly RTL).
+ &#x05D5; - The Hebrew letter Vav (strongly RTL).
+ </div>
+ <div class="test">
+ <div dir="ltr">
+ <div dir="auto"><p id="p1" dir="rtl">&#x05D3;&#x05D4;&#x05D5;</p>ABC&#x05D0;&#x05D1;&#x05D2;.</div>
+ </div>
+ <div dir="rtl">
+ <div dir="auto"><p id="p2" dir="rtl">&#x05D3;&#x05D4;&#x05D5;</p>ABC&#x05D0;&#x05D1;&#x05D2;.</div>
+ </div>
+ </div>
+ <div class="ref">
+ <div dir="ltr">
+ <div dir="rtl"><p dir="rtl">&#x05D3;&#x05D4;&#x05D5;</p>ABC&#x05D0;&#x05D1;&#x05D2;.</div>
+ </div>
+ <div dir="rtl">
+ <div dir="rtl"><p dir="rtl">&#x05D3;&#x05D4;&#x05D5;</p>ABC&#x05D0;&#x05D1;&#x05D2;.</div>
+ </div>
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR1.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR1.html
new file mode 100644
index 000000000..223aa56e6
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR1.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllTextValuesTo('ABC אבג')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">אבג ABC</span></div>
+ <div><textarea id="set2" dir="auto">אבג ABC</textarea></div>
+ <div><button id="set3" dir="auto">אבג ABC</button></div>
+ <div><bdi id="set4">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR10.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR10.html
new file mode 100644
index 000000000..bd3dad92a
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR10.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllTextDefaultValuesTo('ABC אבג')">
+ <div><input type="text" value="..." id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">...</span></div>
+ <div><textarea id="set2" dir="auto">...</textarea></div>
+ <div><button id="set3" dir="auto">...</button></div>
+ <div><bdi id="set4">...</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR2.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR2.html
new file mode 100644
index 000000000..f9af6b961
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR2.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllTextValuesTo('ABC אבג')">
+ <div><input type="text" value="..." id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">...</span></div>
+ <div><textarea id="set2" dir="auto">...</textarea></div>
+ <div><button id="set3" dir="auto">...</button></div>
+ <div><bdi id="set4">...</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR3.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR3.html
new file mode 100644
index 000000000..2d07131d5
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR3.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="appendTextFromArray(new Array('ABC', ' ', 'אבג'))">
+ <div><input type="text" value="&#x00ad;" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">&#x00ad;</span></div>
+ <div><textarea id="set2" dir="auto">&#x00ad;</textarea></div>
+ <div><button id="set3" dir="auto">&#x00ad;</button></div>
+ <div><bdi id="set4">&#x00ad;</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR4.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR4.html
new file mode 100644
index 000000000..38801d2a4
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR4.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="prependTextFromArray(new Array('אבג', ' ', 'ABC'))">
+ <div><input type="text" value="&#x00ad;" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">&#x00ad;</span></div>
+ <div><textarea id="set2" dir="auto">&#x00ad;</textarea></div>
+ <div><button id="set3" dir="auto">&#x00ad;</button></div>
+ <div><bdi id="set4">&#x00ad;</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR5.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR5.html
new file mode 100644
index 000000000..7cd5db77c
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR5.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="appendSpansFromArray(new Array('ABC', ' ', 'אבג'))">
+ <div><input type="text" value="&#x00ad;" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">&#x00ad;</span></div>
+ <div><textarea id="set2" dir="auto">&#x00ad;</textarea></div>
+ <div><button id="set3" dir="auto">&#x00ad;</button></div>
+ <div><bdi id="set4">&#x00ad;</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR6.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR6.html
new file mode 100644
index 000000000..b66f5e306
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR6.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="prependSpansFromArray(new Array('אבג', ' ', 'ABC'))">
+ <div><input type="text" value="&#x00ad;" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">&#x00ad;</span></div>
+ <div><textarea id="set2" dir="auto">&#x00ad;</textarea></div>
+ <div><button id="set3" dir="auto">&#x00ad;</button></div>
+ <div><bdi id="set4">&#x00ad;</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR7.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR7.html
new file mode 100644
index 000000000..461118996
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR7.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllTextChildrenTo('ABC אבג')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">אבג ABC</span></div>
+ <div><textarea id="set2" dir="auto">אבג ABC</textarea></div>
+ <div><button id="set3" dir="auto">אבג ABC</button></div>
+ <div><bdi id="set4">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR8.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR8.html
new file mode 100644
index 000000000..2fb2148f9
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR8.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllTextChildrenTo('ABC אבג')">
+ <div><input type="text" value="..." id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">...</span></div>
+ <div><textarea id="set2" dir="auto">...</textarea></div>
+ <div><button id="set3" dir="auto">...</button></div>
+ <div><bdi id="set4">...</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR9.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR9.html
new file mode 100644
index 000000000..087d5104f
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-LTR9.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllTextDefaultValuesTo('ABC אבג')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">אבג ABC</span></div>
+ <div><textarea id="set2" dir="auto">אבג ABC</textarea></div>
+ <div><button id="set3" dir="auto">אבג ABC</button></div>
+ <div><bdi id="set4">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL1.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL1.html
new file mode 100644
index 000000000..361fcd1e7
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL1.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllTextValuesTo('אבג ABC')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">ABC אבג</span></div>
+ <div><textarea id="set2" dir="auto">ABC אבג</textarea></div>
+ <div><button id="set3" dir="auto">ABC אבג</button></div>
+ <div><bdi id="set4">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL10.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL10.html
new file mode 100644
index 000000000..01e6f6bcb
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL10.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllTextDefaultValuesTo('אבג ABC')">
+ <div><input type="text" value="..." id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">...</span></div>
+ <div><textarea id="set2" dir="auto">...</textarea></div>
+ <div><button id="set3" dir="auto">...</button></div>
+ <div><bdi id="set4">...</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL2.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL2.html
new file mode 100644
index 000000000..f243dec4f
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL2.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllTextValuesTo('אבג ABC')">
+ <div><input type="text" value="..." id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">...</span></div>
+ <div><textarea id="set2" dir="auto">...</textarea></div>
+ <div><button id="set3" dir="auto">...</button></div>
+ <div><bdi id="set4">...</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL3.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL3.html
new file mode 100644
index 000000000..0aaedfe4a
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL3.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="appendTextFromArray(new Array('אבג', ' ', 'ABC'))">
+ <div><input type="text" value="&#x00ad;" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">&#x00ad;</span></div>
+ <div><textarea id="set2" dir="auto">&#x00ad;</textarea></div>
+ <div><button id="set3" dir="auto">&#x00ad;</button></div>
+ <div><bdi id="set4">&#x00ad;</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL4.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL4.html
new file mode 100644
index 000000000..60df2980c
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL4.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="prependTextFromArray(new Array('ABC', ' ', 'אבג'))">
+ <div><input type="text" value="&#x00ad;" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">&#x00ad;</span></div>
+ <div><textarea id="set2" dir="auto">&#x00ad;</textarea></div>
+ <div><button id="set3" dir="auto">&#x00ad;</button></div>
+ <div><bdi id="set4">&#x00ad;</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL5.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL5.html
new file mode 100644
index 000000000..36d2940e5
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL5.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="appendSpansFromArray(new Array('אבג', ' ', 'ABC'))">
+ <div><input type="text" value="&#x00ad;" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">&#x00ad;</span></div>
+ <div><textarea id="set2" dir="auto">&#x00ad;</textarea></div>
+ <div><button id="set3" dir="auto">&#x00ad;</button></div>
+ <div><bdi id="set4">&#x00ad;</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL6.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL6.html
new file mode 100644
index 000000000..440945bb5
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL6.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="prependSpansFromArray(new Array('ABC', ' ', 'אבג'))">
+ <div><input type="text" value="&#x00ad;" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">&#x00ad;</span></div>
+ <div><textarea id="set2" dir="auto">&#x00ad;</textarea></div>
+ <div><button id="set3" dir="auto">&#x00ad;</button></div>
+ <div><bdi id="set4">&#x00ad;</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL7.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL7.html
new file mode 100644
index 000000000..032c2f4eb
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL7.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllTextChildrenTo('אבג ABC')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">ABC אבג</span></div>
+ <div><textarea id="set2" dir="auto">ABC אבג</textarea></div>
+ <div><button id="set3" dir="auto">ABC אבג</button></div>
+ <div><bdi id="set4">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL8.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL8.html
new file mode 100644
index 000000000..9c1da6b0f
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL8.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllTextChildrenTo('אבג ABC')">
+ <div><input type="text" value="..." id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">...</span></div>
+ <div><textarea id="set2" dir="auto">...</textarea></div>
+ <div><button id="set3" dir="auto">...</button></div>
+ <div><bdi id="set4">...</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL9.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL9.html
new file mode 100644
index 000000000..b7c4c3653
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-ChangeText-RTL9.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllTextDefaultValuesTo('אבג ABC')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">ABC אבג</span></div>
+ <div><textarea id="set2" dir="auto">ABC אבג</textarea></div>
+ <div><button id="set3" dir="auto">ABC אבג</button></div>
+ <div><bdi id="set4">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-DeleteText-LTR1.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-DeleteText-LTR1.html
new file mode 100644
index 000000000..4ba7a037f
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-DeleteText-LTR1.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="removeElements()">
+ <div><input type="text" value="ABC אבג" dir="auto"></div>
+ <div><span dir="auto"><span id="set0">DEF </span>ABC אבג</span></div>
+ <div><textarea dir="auto">ABC אבג</textarea></div>
+ <div><button dir="auto"><span id="set1">DEF </span>ABC אבג</button></div>
+ <div><bdi><span id="set2">DEF </span>ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-DeleteText-LTR2.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-DeleteText-LTR2.html
new file mode 100644
index 000000000..4bea44d83
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-DeleteText-LTR2.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="removeElements()">
+ <div><input type="text" value="ABC אבג" dir="auto"></div>
+ <div><span dir="auto"><span id="set0">גדה </span>ABC אבג</span></div>
+ <div><textarea dir="auto">ABC אבג</textarea></div>
+ <div><button dir="auto"><span id="set1">גדה </span>ABC אבג</button></div>
+ <div><bdi><span id="set2">גדה </span>ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-DeleteText-LTR3.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-DeleteText-LTR3.html
new file mode 100644
index 000000000..2c1682953
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-DeleteText-LTR3.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="removeElements()">
+ <div><input type="text" value="ABC אבג" dir="auto"></div>
+ <div><span dir="auto"><span id="set0">... </span>ABC אבג</span></div>
+ <div><textarea dir="auto">ABC אבג</textarea></div>
+ <div><button dir="auto"><span id="set1">... </span>ABC אבג</button></div>
+ <div><bdi><span id="set2">... </span>ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-DeleteText-RTL1.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-DeleteText-RTL1.html
new file mode 100644
index 000000000..ab08388b8
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-DeleteText-RTL1.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="removeElements()">
+ <div><input type="text" value="אבג ABC" dir="auto"></div>
+ <div><span dir="auto"><span id="set0">DEF </span>אבג ABC</span></div>
+ <div><textarea dir="auto">אבג ABC</textarea></div>
+ <div><button dir="auto"><span id="set1">DEF </span>אבג ABC</button></div>
+ <div><bdi><span id="set2">DEF </span>אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-DeleteText-RTL2.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-DeleteText-RTL2.html
new file mode 100644
index 000000000..477e155a0
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-DeleteText-RTL2.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="removeElements()">
+ <div><input type="text" value="אבג ABC" dir="auto"></div>
+ <div><span dir="auto"><span id="set0">גדה </span>אבג ABC</span></div>
+ <div><textarea dir="auto">אבג ABC</textarea></div>
+ <div><button dir="auto"><span id="set1">גדה </span>אבג ABC</button></div>
+ <div><bdi><span id="set2">גדה </span>אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-DeleteText-RTL3.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-DeleteText-RTL3.html
new file mode 100644
index 000000000..cf4069567
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-DeleteText-RTL3.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="removeElements()">
+ <div><input type="text" value="אבג ABC" dir="auto"></div>
+ <div><span dir="auto"><span id="set0">... </span>אבג ABC</span></div>
+ <div><textarea dir="auto">אבג ABC</textarea></div>
+ <div><button dir="auto"><span id="set1">... </span>אבג ABC</button></div>
+ <div><bdi><span id="set2">... </span>אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-addLTR-Auto.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-addLTR-Auto.html
new file mode 100644
index 000000000..16dc62b5b
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-addLTR-Auto.html
@@ -0,0 +1,14 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="addLTRAutoElements()">
+ <div id="container"></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-addRTL-Auto.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-addRTL-Auto.html
new file mode 100644
index 000000000..52c0949c9
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-addRTL-Auto.html
@@ -0,0 +1,14 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="addRTLAutoElements()">
+ <div id="container"></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-refLTR-LTR.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-refLTR-LTR.html
new file mode 100644
index 000000000..62a74bf33
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-refLTR-LTR.html
@@ -0,0 +1,17 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body>
+ <div><input type="text" value="ABC אבג" dir="ltr"></div>
+ <div><span dir="ltr">ABC אבג</span></div>
+ <div><textarea dir="ltr">ABC אבג</textarea></div>
+ <div><button dir="ltr">ABC אבג</button></div>
+ <div><span dir="ltr">ABC אבג</span></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-refLTR-RTL.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-refLTR-RTL.html
new file mode 100644
index 000000000..60619730a
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-refLTR-RTL.html
@@ -0,0 +1,17 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body>
+ <div><input type="text" value="ABC אבג" dir="rtl"></div>
+ <div><span dir="rtl">ABC אבג</span></div>
+ <div><textarea dir="rtl">ABC אבג</textarea></div>
+ <div><button dir="rtl">ABC אבג</button></div>
+ <div><span dir="rtl">ABC אבג</span></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-refRTL-LTR.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-refRTL-LTR.html
new file mode 100644
index 000000000..4ea471a8d
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-refRTL-LTR.html
@@ -0,0 +1,17 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body>
+ <div><input type="text" value="אבג ABC" dir="ltr"></div>
+ <div><span dir="ltr">אבג ABC</span></div>
+ <div><textarea dir="ltr">אבג ABC</textarea></div>
+ <div><button dir="ltr">אבג ABC</button></div>
+ <div><span dir="ltr">אבג ABC</span></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-refRTL-NoDir.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-refRTL-NoDir.html
new file mode 100644
index 000000000..b2f56c1ac
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-refRTL-NoDir.html
@@ -0,0 +1,20 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body>
+ <div><input type="text" value="אבג ABC" dir="ltr"></div>
+ <div><span dir="ltr">אבג ABC</span></div>
+ <div><textarea dir="ltr">אבג ABC</textarea></div>
+ <div><button dir="ltr">אבג ABC</button></div>
+ <!-- the last line is span dir="rtl" because it's the reference
+ for a bdi that begins with rtl characters, so with an empty or
+ invalid value for the dir attribute it will be resolved as rtl -->
+ <div><span dir="rtl">אבג ABC</span></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-refRTL-RTL.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-refRTL-RTL.html
new file mode 100644
index 000000000..71c42ea3e
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-refRTL-RTL.html
@@ -0,0 +1,17 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body>
+ <div><input type="text" value="אבג ABC" dir="rtl"></div>
+ <div><span dir="rtl">אבג ABC</span></div>
+ <div><textarea dir="rtl">אבג ABC</textarea></div>
+ <div><button dir="rtl">אבג ABC</button></div>
+ <div><span dir="rtl">אבג ABC</span></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-Auto1.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-Auto1.html
new file mode 100644
index 000000000..2c1c525f9
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-Auto1.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('auto')">
+ <div><input type="text" value="ABC אבג" id="set0"></div>
+ <div><span id="set1">ABC אבג</span></div>
+ <div><textarea id="set2">ABC אבג</textarea></div>
+ <div><button id="set3">ABC אבג</button></div>
+ <div><bdi id="set4">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-Auto2.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-Auto2.html
new file mode 100644
index 000000000..f0400e0d0
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-Auto2.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('auto')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="rtl"></div>
+ <div><span id="set1" dir="rtl">ABC אבג</span></div>
+ <div><textarea id="set2" dir="rtl">ABC אבג</textarea></div>
+ <div><button id="set3" dir="rtl">ABC אבג</button></div>
+ <div><bdi id="set4" dir="rtl">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-Auto3.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-Auto3.html
new file mode 100644
index 000000000..2cbf52716
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-Auto3.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('auto')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="foopy"></div>
+ <div><span id="set1" dir="foopy">ABC אבג</span></div>
+ <div><textarea id="set2" dir="foopy">ABC אבג</textarea></div>
+ <div><button id="set3" dir="foopy">ABC אבג</button></div>
+ <div><bdi id="set4" dir="foopy">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-Auto4.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-Auto4.html
new file mode 100644
index 000000000..5bcec0648
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-Auto4.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('auto')">
+ <div><input type="text" value="ABC אבג" id="set0"></div>
+ <div><span id="set1">ABC אבג</span></div>
+ <div><textarea id="set2">ABC אבג</textarea></div>
+ <div><button id="set3">ABC אבג</button></div>
+ <div><bdi id="set4">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-Auto5.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-Auto5.html
new file mode 100644
index 000000000..a0423c246
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-Auto5.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('auto')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="rtl"></div>
+ <div><span id="set1" dir="rtl">ABC אבג</span></div>
+ <div><textarea id="set2" dir="rtl">ABC אבג</textarea></div>
+ <div><button id="set3" dir="rtl">ABC אבג</button></div>
+ <div><bdi id="set4" dir="rtl">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-Auto6.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-Auto6.html
new file mode 100644
index 000000000..2574c867f
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-Auto6.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('auto')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="foopy"></div>
+ <div><span id="set1" dir="foopy">ABC אבג</span></div>
+ <div><textarea id="set2" dir="foopy">ABC אבג</textarea></div>
+ <div><button id="set3" dir="foopy">ABC אבג</button></div>
+ <div><bdi id="set4" dir="foopy">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir1.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir1.html
new file mode 100644
index 000000000..1913335b8
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir1.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('foopy')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="rtl"></div>
+ <div><span id="set1" dir="rtl">ABC אבג</span></div>
+ <div><textarea id="set2" dir="rtl">ABC אבג</textarea></div>
+ <div><button id="set3" dir="rtl">ABC אבג</button></div>
+ <div><bdi id="set4" dir="rtl">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir2.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir2.html
new file mode 100644
index 000000000..596f1143a
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir2.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('foopy')">
+ <div><input type="text" value="ABC אבג" id="set0"></div>
+ <div><span id="set1">ABC אבג</span></div>
+ <div><textarea id="set2">ABC אבג</textarea></div>
+ <div><button id="set3">ABC אבג</button></div>
+ <div><bdi id="set4">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir3.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir3.html
new file mode 100644
index 000000000..f22dd147d
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir3.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('foopy')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">ABC אבג</span></div>
+ <div><textarea id="set2" dir="auto">ABC אבג</textarea></div>
+ <div><button id="set3" dir="auto">ABC אבג</button></div>
+ <div><bdi id="set4" dir="auto">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir4.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir4.html
new file mode 100644
index 000000000..f876484e4
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir4.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="foopy"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('foopy')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="foopy"></div>
+ <div><span id="set1" dir="foopy">ABC אבג</span></div>
+ <div><textarea id="set2" dir="foopy">ABC אבג</textarea></div>
+ <div><button id="set3" dir="foopy">ABC אבג</button></div>
+ <div><bdi id="set4" dir="foopy">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir5.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir5.html
new file mode 100644
index 000000000..6da8dff2f
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir5.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('foopy')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="rtl"></div>
+ <div><span id="set1" dir="rtl">ABC אבג</span></div>
+ <div><textarea id="set2" dir="rtl">ABC אבג</textarea></div>
+ <div><button id="set3" dir="rtl">ABC אבג</button></div>
+ <div><bdi id="set4" dir="rtl">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir6.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir6.html
new file mode 100644
index 000000000..b63c0dd0d
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir6.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('foopy')">
+ <div><input type="text" value="ABC אבג" id="set0"></div>
+ <div><span id="set1">ABC אבג</span></div>
+ <div><textarea id="set2">ABC אבג</textarea></div>
+ <div><button id="set3">ABC אבג</button></div>
+ <div><bdi id="set4">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir7.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir7.html
new file mode 100644
index 000000000..e1b9d82c1
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir7.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('foopy')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">ABC אבג</span></div>
+ <div><textarea id="set2" dir="auto">ABC אבג</textarea></div>
+ <div><button id="set3" dir="auto">ABC אבג</button></div>
+ <div><bdi id="set4" dir="auto">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir8.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir8.html
new file mode 100644
index 000000000..9b80f42d0
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-InvalidDir8.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="foopy"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('foopy')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="foopy"></div>
+ <div><span id="set1" dir="foopy">ABC אבג</span></div>
+ <div><textarea id="set2" dir="foopy">ABC אבג</textarea></div>
+ <div><button id="set3" dir="foopy">ABC אבג</button></div>
+ <div><bdi id="set4" dir="foopy">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR1.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR1.html
new file mode 100644
index 000000000..e89fc7921
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR1.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('ltr')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="rtl"></div>
+ <div><span id="set1" dir="rtl">ABC אבג</span></div>
+ <div><textarea id="set2" dir="rtl">ABC אבג</textarea></div>
+ <div><button id="set3" dir="rtl">ABC אבג</button></div>
+ <div><bdi id="set4" dir="rtl">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR2.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR2.html
new file mode 100644
index 000000000..5a8e4f122
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR2.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('ltr')">
+ <div><input type="text" value="ABC אבג" id="set0"></div>
+ <div><span id="set1">ABC אבג</span></div>
+ <div><textarea id="set2">ABC אבג</textarea></div>
+ <div><button id="set3">ABC אבג</button></div>
+ <div><bdi id="set4">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR3.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR3.html
new file mode 100644
index 000000000..bbc5f8090
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR3.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('ltr')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">ABC אבג</span></div>
+ <div><textarea id="set2" dir="auto">ABC אבג</textarea></div>
+ <div><button id="set3" dir="auto">ABC אבג</button></div>
+ <div><bdi id="set4" dir="auto">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR4.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR4.html
new file mode 100644
index 000000000..08b21e09a
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR4.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="foopy"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('ltr')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="foopy"></div>
+ <div><span id="set1" dir="foopy">ABC אבג</span></div>
+ <div><textarea id="set2" dir="foopy">ABC אבג</textarea></div>
+ <div><button id="set3" dir="foopy">ABC אבג</button></div>
+ <div><bdi id="set4" dir="foopy">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR5.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR5.html
new file mode 100644
index 000000000..cffe2556b
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR5.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('ltr')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="rtl"></div>
+ <div><span id="set1" dir="rtl">ABC אבג</span></div>
+ <div><textarea id="set2" dir="rtl">ABC אבג</textarea></div>
+ <div><button id="set3" dir="rtl">ABC אבג</button></div>
+ <div><bdi id="set4" dir="rtl">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR6.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR6.html
new file mode 100644
index 000000000..b54417b6f
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR6.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('ltr')">
+ <div><input type="text" value="ABC אבג" id="set0"></div>
+ <div><span id="set1">ABC אבג</span></div>
+ <div><textarea id="set2">ABC אבג</textarea></div>
+ <div><button id="set3">ABC אבג</button></div>
+ <div><bdi id="set4">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR7.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR7.html
new file mode 100644
index 000000000..0baeb9fc6
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR7.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('ltr')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">ABC אבג</span></div>
+ <div><textarea id="set2" dir="auto">ABC אבג</textarea></div>
+ <div><button id="set3" dir="auto">ABC אבג</button></div>
+ <div><bdi id="set4" dir="auto">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR8.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR8.html
new file mode 100644
index 000000000..ec1de3542
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-LTR8.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="foopy"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('ltr')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="foopy"></div>
+ <div><span id="set1" dir="foopy">ABC אבג</span></div>
+ <div><textarea id="set2" dir="foopy">ABC אבג</textarea></div>
+ <div><button id="set3" dir="foopy">ABC אבג</button></div>
+ <div><bdi id="set4" dir="foopy">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir1.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir1.html
new file mode 100644
index 000000000..2040663c3
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir1.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="rtl"></div>
+ <div><span id="set1" dir="rtl">ABC אבג</span></div>
+ <div><textarea id="set2" dir="rtl">ABC אבג</textarea></div>
+ <div><button id="set3" dir="rtl">ABC אבג</button></div>
+ <div><bdi id="set4" dir="rtl">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir2.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir2.html
new file mode 100644
index 000000000..f8c2e99a7
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir2.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('')">
+ <div><input type="text" value="ABC אבג" id="set0"></div>
+ <div><span id="set1">ABC אבג</span></div>
+ <div><textarea id="set2">ABC אבג</textarea></div>
+ <div><button id="set3">ABC אבג</button></div>
+ <div><bdi id="set4">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir3.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir3.html
new file mode 100644
index 000000000..c295012db
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir3.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">ABC אבג</span></div>
+ <div><textarea id="set2" dir="auto">ABC אבג</textarea></div>
+ <div><button id="set3" dir="auto">ABC אבג</button></div>
+ <div><bdi id="set4" dir="auto">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir4.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir4.html
new file mode 100644
index 000000000..13e0e5fc8
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir4.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="foopy"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="foopy"></div>
+ <div><span id="set1" dir="foopy">ABC אבג</span></div>
+ <div><textarea id="set2" dir="foopy">ABC אבג</textarea></div>
+ <div><button id="set3" dir="foopy">ABC אבג</button></div>
+ <div><bdi id="set4" dir="foopy">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir5.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir5.html
new file mode 100644
index 000000000..6dce96a60
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir5.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="removeAllDirAttribute()">
+ <div><input type="text" value="ABC אבג" id="set0" dir="rtl"></div>
+ <div><span id="set1" dir="rtl">ABC אבג</span></div>
+ <div><textarea id="set2" dir="rtl">ABC אבג</textarea></div>
+ <div><button id="set3" dir="rtl">ABC אבג</button></div>
+ <div><bdi id="set4" dir="rtl">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir6.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir6.html
new file mode 100644
index 000000000..2d9973fa1
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir6.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="removeAllDirAttribute()">
+ <div><input type="text" value="ABC אבג" id="set0"></div>
+ <div><span id="set1">ABC אבג</span></div>
+ <div><textarea id="set2">ABC אבג</textarea></div>
+ <div><button id="set3">ABC אבג</button></div>
+ <div><bdi id="set4">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir7.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir7.html
new file mode 100644
index 000000000..dd1964e01
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir7.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="removeAllDirAttribute()">
+ <div><input type="text" value="ABC אבג" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">ABC אבג</span></div>
+ <div><textarea id="set2" dir="auto">ABC אבג</textarea></div>
+ <div><button id="set3" dir="auto">ABC אבג</button></div>
+ <div><bdi id="set4" dir="auto">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir8.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir8.html
new file mode 100644
index 000000000..96d780935
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-NoDir8.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="foopy"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="removeAllDirAttribute()">
+ <div><input type="text" value="ABC אבג" id="set0" dir="foopy"></div>
+ <div><span id="set1" dir="foopy">ABC אבג</span></div>
+ <div><textarea id="set2" dir="foopy">ABC אבג</textarea></div>
+ <div><button id="set3" dir="foopy">ABC אבג</button></div>
+ <div><bdi id="set4" dir="foopy">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL1.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL1.html
new file mode 100644
index 000000000..c5a9bf42d
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL1.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('rtl')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="ltr"></div>
+ <div><span id="set1" dir="ltr">ABC אבג</span></div>
+ <div><textarea id="set2" dir="ltr">ABC אבג</textarea></div>
+ <div><button id="set3" dir="ltr">ABC אבג</button></div>
+ <div><bdi id="set4" dir="ltr">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL2.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL2.html
new file mode 100644
index 000000000..b8ed6cda8
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL2.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('rtl')">
+ <div><input type="text" value="ABC אבג" id="set0"></div>
+ <div><span id="set1">ABC אבג</span></div>
+ <div><textarea id="set2">ABC אבג</textarea></div>
+ <div><button id="set3">ABC אבג</button></div>
+ <div><span id="set4">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL3.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL3.html
new file mode 100644
index 000000000..528ffde04
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL3.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('rtl')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">ABC אבג</span></div>
+ <div><textarea id="set2" dir="auto">ABC אבג</textarea></div>
+ <div><button id="set3" dir="auto">ABC אבג</button></div>
+ <div><span id="set4" dir="auto">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL4.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL4.html
new file mode 100644
index 000000000..884c8fa85
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL4.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="foopy"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('rtl')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="foopy"></div>
+ <div><span id="set1" dir="foopy">ABC אבג</span></div>
+ <div><textarea id="set2" dir="foopy">ABC אבג</textarea></div>
+ <div><button id="set3" dir="foopy">ABC אבג</button></div>
+ <div><span id="set4" dir="foopy">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL5.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL5.html
new file mode 100644
index 000000000..5cf486c90
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL5.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('rtl')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="ltr"></div>
+ <div><span id="set1" dir="ltr">ABC אבג</span></div>
+ <div><textarea id="set2" dir="ltr">ABC אבג</textarea></div>
+ <div><button id="set3" dir="ltr">ABC אבג</button></div>
+ <div><bdi id="set4" dir="ltr">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL6.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL6.html
new file mode 100644
index 000000000..61c7331bd
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL6.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('rtl')">
+ <div><input type="text" value="ABC אבג" id="set0"></div>
+ <div><span id="set1">ABC אבג</span></div>
+ <div><textarea id="set2">ABC אבג</textarea></div>
+ <div><button id="set3">ABC אבג</button></div>
+ <div><span id="set4">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL7.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL7.html
new file mode 100644
index 000000000..c4cc154cb
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL7.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('rtl')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">ABC אבג</span></div>
+ <div><textarea id="set2" dir="auto">ABC אבג</textarea></div>
+ <div><button id="set3" dir="auto">ABC אבג</button></div>
+ <div><span id="set4" dir="auto">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL8.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL8.html
new file mode 100644
index 000000000..18e333978
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setLTR-RTL8.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="foopy"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('rtl')">
+ <div><input type="text" value="ABC אבג" id="set0" dir="foopy"></div>
+ <div><span id="set1" dir="foopy">ABC אבג</span></div>
+ <div><textarea id="set2" dir="foopy">ABC אבג</textarea></div>
+ <div><button id="set3" dir="foopy">ABC אבג</button></div>
+ <div><span id="set4" dir="foopy">ABC אבג</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-Auto1.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-Auto1.html
new file mode 100644
index 000000000..483d79fd5
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-Auto1.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('auto')">
+ <div><input type="text" value="אבג ABC" id="set0"></div>
+ <div><span id="set1">אבג ABC</span></div>
+ <div><textarea id="set2">אבג ABC</textarea></div>
+ <div><button id="set3">אבג ABC</button></div>
+ <div><bdi id="set4">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-Auto2.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-Auto2.html
new file mode 100644
index 000000000..b0773e6f6
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-Auto2.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('auto')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="rtl"></div>
+ <div><span id="set1" dir="rtl">אבג ABC</span></div>
+ <div><textarea id="set2" dir="rtl">אבג ABC</textarea></div>
+ <div><button id="set3" dir="rtl">אבג ABC</button></div>
+ <div><bdi id="set4" dir="rtl">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-Auto3.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-Auto3.html
new file mode 100644
index 000000000..77ce26cb3
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-Auto3.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('auto')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="foopy"></div>
+ <div><span id="set1" dir="foopy">אבג ABC</span></div>
+ <div><textarea id="set2" dir="foopy">אבג ABC</textarea></div>
+ <div><button id="set3" dir="foopy">אבג ABC</button></div>
+ <div><bdi id="set4" dir="foopy">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-Auto4.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-Auto4.html
new file mode 100644
index 000000000..f8cabec1e
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-Auto4.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('auto')">
+ <div><input type="text" value="אבג ABC" id="set0"></div>
+ <div><span id="set1">אבג ABC</span></div>
+ <div><textarea id="set2">אבג ABC</textarea></div>
+ <div><button id="set3">אבג ABC</button></div>
+ <div><bdi id="set4">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-Auto5.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-Auto5.html
new file mode 100644
index 000000000..20621a5a7
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-Auto5.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('auto')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="rtl"></div>
+ <div><span id="set1" dir="rtl">אבג ABC</span></div>
+ <div><textarea id="set2" dir="rtl">אבג ABC</textarea></div>
+ <div><button id="set3" dir="rtl">אבג ABC</button></div>
+ <div><bdi id="set4" dir="rtl">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-Auto6.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-Auto6.html
new file mode 100644
index 000000000..c9e1b560f
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-Auto6.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('auto')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="foopy"></div>
+ <div><span id="set1" dir="foopy">אבג ABC</span></div>
+ <div><textarea id="set2" dir="foopy">אבג ABC</textarea></div>
+ <div><button id="set3" dir="foopy">אבג ABC</button></div>
+ <div><bdi id="set4" dir="foopy">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir1.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir1.html
new file mode 100644
index 000000000..a2ddd5292
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir1.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('foopy')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="rtl"></div>
+ <div><span id="set1" dir="rtl">אבג ABC</span></div>
+ <div><textarea id="set2" dir="rtl">אבג ABC</textarea></div>
+ <div><button id="set3" dir="rtl">אבג ABC</button></div>
+ <div><bdi id="set4" dir="rtl">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir2.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir2.html
new file mode 100644
index 000000000..87eb11819
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir2.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('foopy')">
+ <div><input type="text" value="אבג ABC" id="set0"></div>
+ <div><span id="set1">אבג ABC</span></div>
+ <div><textarea id="set2">אבג ABC</textarea></div>
+ <div><button id="set3">אבג ABC</button></div>
+ <div><bdi id="set4">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir3.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir3.html
new file mode 100644
index 000000000..17ec5b453
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir3.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('foopy')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">אבג ABC</span></div>
+ <div><textarea id="set2" dir="auto">אבג ABC</textarea></div>
+ <div><button id="set3" dir="auto">אבג ABC</button></div>
+ <div><bdi id="set4" dir="auto">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir4.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir4.html
new file mode 100644
index 000000000..b4c5ebc09
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir4.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="foopy"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('foopy')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="foopy"></div>
+ <div><span id="set1" dir="foopy">אבג ABC</span></div>
+ <div><textarea id="set2" dir="foopy">אבג ABC</textarea></div>
+ <div><button id="set3" dir="foopy">אבג ABC</button></div>
+ <div><bdi id="set4" dir="foopy">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir5.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir5.html
new file mode 100644
index 000000000..1859e89bc
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir5.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('foopy')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="rtl"></div>
+ <div><span id="set1" dir="rtl">אבג ABC</span></div>
+ <div><textarea id="set2" dir="rtl">אבג ABC</textarea></div>
+ <div><button id="set3" dir="rtl">אבג ABC</button></div>
+ <div><bdi id="set4" dir="rtl">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir6.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir6.html
new file mode 100644
index 000000000..06c3d7170
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir6.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('foopy')">
+ <div><input type="text" value="אבג ABC" id="set0"></div>
+ <div><span id="set1">אבג ABC</span></div>
+ <div><textarea id="set2">אבג ABC</textarea></div>
+ <div><button id="set3">אבג ABC</button></div>
+ <div><bdi id="set4">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir7.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir7.html
new file mode 100644
index 000000000..03239e88b
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir7.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('foopy')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">אבג ABC</span></div>
+ <div><textarea id="set2" dir="auto">אבג ABC</textarea></div>
+ <div><button id="set3" dir="auto">אבג ABC</button></div>
+ <div><bdi id="set4" dir="auto">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir8.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir8.html
new file mode 100644
index 000000000..fc353ac22
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-InvalidDir8.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="foopy"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('foopy')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="foopy"></div>
+ <div><span id="set1" dir="foopy">אבג ABC</span></div>
+ <div><textarea id="set2" dir="foopy">אבג ABC</textarea></div>
+ <div><button id="set3" dir="foopy">אבג ABC</button></div>
+ <div><bdi id="set4" dir="foopy">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR1.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR1.html
new file mode 100644
index 000000000..52fcf96b3
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR1.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('ltr')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="rtl"></div>
+ <div><span id="set1" dir="rtl">אבג ABC</span></div>
+ <div><textarea id="set2" dir="rtl">אבג ABC</textarea></div>
+ <div><button id="set3" dir="rtl">אבג ABC</button></div>
+ <div><bdi id="set4" dir="rtl">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR2.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR2.html
new file mode 100644
index 000000000..074eeab10
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR2.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('ltr')">
+ <div><input type="text" value="אבג ABC" id="set0"></div>
+ <div><span id="set1">אבג ABC</span></div>
+ <div><textarea id="set2">אבג ABC</textarea></div>
+ <div><button id="set3">אבג ABC</button></div>
+ <div><bdi id="set4">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR3.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR3.html
new file mode 100644
index 000000000..2bb5ad2de
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR3.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('ltr')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">אבג ABC</span></div>
+ <div><textarea id="set2" dir="auto">אבג ABC</textarea></div>
+ <div><button id="set3" dir="auto">אבג ABC</button></div>
+ <div><bdi id="set4" dir="auto">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR4.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR4.html
new file mode 100644
index 000000000..79372c6ed
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR4.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="foopy"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('ltr')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="foopy"></div>
+ <div><span id="set1" dir="foopy">אבג ABC</span></div>
+ <div><textarea id="set2" dir="foopy">אבג ABC</textarea></div>
+ <div><button id="set3" dir="foopy">אבג ABC</button></div>
+ <div><bdi id="set4" dir="foopy">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR5.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR5.html
new file mode 100644
index 000000000..212017015
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR5.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('ltr')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="rtl"></div>
+ <div><span id="set1" dir="rtl">אבג ABC</span></div>
+ <div><textarea id="set2" dir="rtl">אבג ABC</textarea></div>
+ <div><button id="set3" dir="rtl">אבג ABC</button></div>
+ <div><bdi id="set4" dir="rtl">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR6.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR6.html
new file mode 100644
index 000000000..272d5f9fc
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR6.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('ltr')">
+ <div><input type="text" value="אבג ABC" id="set0"></div>
+ <div><span id="set1">אבג ABC</span></div>
+ <div><textarea id="set2">אבג ABC</textarea></div>
+ <div><button id="set3">אבג ABC</button></div>
+ <div><bdi id="set4">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR7.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR7.html
new file mode 100644
index 000000000..d1d1185d2
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR7.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('ltr')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">אבג ABC</span></div>
+ <div><textarea id="set2" dir="auto">אבג ABC</textarea></div>
+ <div><button id="set3" dir="auto">אבג ABC</button></div>
+ <div><bdi id="set4" dir="auto">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR8.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR8.html
new file mode 100644
index 000000000..a6f9fa09a
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-LTR8.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="foopy"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('ltr')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="foopy"></div>
+ <div><span id="set1" dir="foopy">אבג ABC</span></div>
+ <div><textarea id="set2" dir="foopy">אבג ABC</textarea></div>
+ <div><button id="set3" dir="foopy">אבג ABC</button></div>
+ <div><bdi id="set4" dir="foopy">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir1.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir1.html
new file mode 100644
index 000000000..ba2bd8bab
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir1.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="rtl"></div>
+ <div><span id="set1" dir="rtl">אבג ABC</span></div>
+ <div><textarea id="set2" dir="rtl">אבג ABC</textarea></div>
+ <div><button id="set3" dir="rtl">אבג ABC</button></div>
+ <div><bdi id="set4" dir="rtl">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir2.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir2.html
new file mode 100644
index 000000000..5833b2e4a
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir2.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('')">
+ <div><input type="text" value="אבג ABC" id="set0"></div>
+ <div><span id="set1">אבג ABC</span></div>
+ <div><textarea id="set2">אבג ABC</textarea></div>
+ <div><button id="set3">אבג ABC</button></div>
+ <div><bdi id="set4">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir3.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir3.html
new file mode 100644
index 000000000..1a031d043
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir3.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">אבג ABC</span></div>
+ <div><textarea id="set2" dir="auto">אבג ABC</textarea></div>
+ <div><button id="set3" dir="auto">אבג ABC</button></div>
+ <div><bdi id="set4" dir="auto">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir4.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir4.html
new file mode 100644
index 000000000..53074850d
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir4.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="foopy"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="foopy"></div>
+ <div><span id="set1" dir="foopy">אבג ABC</span></div>
+ <div><textarea id="set2" dir="foopy">אבג ABC</textarea></div>
+ <div><button id="set3" dir="foopy">אבג ABC</button></div>
+ <div><bdi id="set4" dir="foopy">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir5.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir5.html
new file mode 100644
index 000000000..63fc1a746
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir5.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="removeAllDirAttribute()">
+ <div><input type="text" value="אבג ABC" id="set0" dir="rtl"></div>
+ <div><span id="set1" dir="rtl">אבג ABC</span></div>
+ <div><textarea id="set2" dir="rtl">אבג ABC</textarea></div>
+ <div><button id="set3" dir="rtl">אבג ABC</button></div>
+ <div><bdi id="set4" dir="rtl">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir6.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir6.html
new file mode 100644
index 000000000..31af1459d
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir6.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="removeAllDirAttribute()">
+ <div><input type="text" value="אבג ABC" id="set0"></div>
+ <div><span id="set1">אבג ABC</span></div>
+ <div><textarea id="set2">אבג ABC</textarea></div>
+ <div><button id="set3">אבג ABC</button></div>
+ <div><bdi id="set4">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir7.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir7.html
new file mode 100644
index 000000000..5fd61d42e
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir7.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="removeAllDirAttribute()">
+ <div><input type="text" value="אבג ABC" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">אבג ABC</span></div>
+ <div><textarea id="set2" dir="auto">אבג ABC</textarea></div>
+ <div><button id="set3" dir="auto">אבג ABC</button></div>
+ <div><bdi id="set4" dir="auto">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir8.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir8.html
new file mode 100644
index 000000000..d388d5377
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-NoDir8.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="foopy"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="removeAllDirAttribute()">
+ <div><input type="text" value="אבג ABC" id="set0" dir="foopy"></div>
+ <div><span id="set1" dir="foopy">אבג ABC</span></div>
+ <div><textarea id="set2" dir="foopy">אבג ABC</textarea></div>
+ <div><button id="set3" dir="foopy">אבג ABC</button></div>
+ <div><bdi id="set4" dir="foopy">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL1.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL1.html
new file mode 100644
index 000000000..45ee5c571
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL1.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('rtl')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="ltr"></div>
+ <div><span id="set1" dir="ltr">אבג ABC</span></div>
+ <div><textarea id="set2" dir="ltr">אבג ABC</textarea></div>
+ <div><button id="set3" dir="ltr">אבג ABC</button></div>
+ <div><bdi id="set4" dir="ltr">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL2.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL2.html
new file mode 100644
index 000000000..0df2fc8de
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL2.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('rtl')">
+ <div><input type="text" value="אבג ABC" id="set0"></div>
+ <div><span id="set1">אבג ABC</span></div>
+ <div><textarea id="set2">אבג ABC</textarea></div>
+ <div><button id="set3">אבג ABC</button></div>
+ <div><bdi id="set4">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL3.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL3.html
new file mode 100644
index 000000000..0dee370b6
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL3.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('rtl')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">אבג ABC</span></div>
+ <div><textarea id="set2" dir="auto">אבג ABC</textarea></div>
+ <div><button id="set3" dir="auto">אבג ABC</button></div>
+ <div><bdi id="set4" dir="auto">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL4.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL4.html
new file mode 100644
index 000000000..dbfbe2125
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL4.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="foopy"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDir('rtl')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="foopy"></div>
+ <div><span id="set1" dir="foopy">אבג ABC</span></div>
+ <div><textarea id="set2" dir="foopy">אבג ABC</textarea></div>
+ <div><button id="set3" dir="foopy">אבג ABC</button></div>
+ <div><bdi id="set4" dir="foopy">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL5.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL5.html
new file mode 100644
index 000000000..1b401367c
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL5.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('rtl')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="ltr"></div>
+ <div><span id="set1" dir="ltr">אבג ABC</span></div>
+ <div><textarea id="set2" dir="ltr">אבג ABC</textarea></div>
+ <div><button id="set3" dir="ltr">אבג ABC</button></div>
+ <div><bdi id="set4" dir="ltr">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL6.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL6.html
new file mode 100644
index 000000000..d2c70793c
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL6.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('rtl')">
+ <div><input type="text" value="אבג ABC" id="set0"></div>
+ <div><span id="set1">אבג ABC</span></div>
+ <div><textarea id="set2">אבג ABC</textarea></div>
+ <div><button id="set3">אבג ABC</button></div>
+ <div><bdi id="set4">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL7.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL7.html
new file mode 100644
index 000000000..ca0153cc2
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL7.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="auto"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('rtl')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="auto"></div>
+ <div><span id="set1" dir="auto">אבג ABC</span></div>
+ <div><textarea id="set2" dir="auto">אבג ABC</textarea></div>
+ <div><button id="set3" dir="auto">אבג ABC</button></div>
+ <div><bdi id="set4" dir="auto">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL8.html b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL8.html
new file mode 100644
index 000000000..15b323976
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/dynamicDirAuto-setRTL-RTL8.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Set and unset dir="foopy"</title>
+ <script type="text/javascript" src="setDir.js"></script>
+ <style>
+ textarea { resize: none; }
+ </style>
+ </head>
+ <body onload="setAllDirAttribute('rtl')">
+ <div><input type="text" value="אבג ABC" id="set0" dir="foopy"></div>
+ <div><span id="set1" dir="foopy">אבג ABC</span></div>
+ <div><textarea id="set2" dir="foopy">אבג ABC</textarea></div>
+ <div><button id="set3" dir="foopy">אבג ABC</button></div>
+ <div><bdi id="set4" dir="foopy">אבג ABC</bdi></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/dirAuto/reftest-stylo.list b/layout/reftests/bidi/dirAuto/reftest-stylo.list
new file mode 100644
index 000000000..991841fee
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/reftest-stylo.list
@@ -0,0 +1,120 @@
+# DO NOT EDIT! This is a auto-generated temporary list for Stylo testing
+== bdi-auto-dir-default.html bdi-auto-dir-default.html
+== dir_auto-set-contained-dir-L.html dir_auto-set-contained-dir-L.html
+== dir_auto-set-contained-dir-R.html dir_auto-set-contained-dir-R.html
+== dir_auto-set-contained-invalid-dir-L.html dir_auto-set-contained-invalid-dir-L.html
+== dir_auto-set-contained-invalid-dir-R.html dir_auto-set-contained-invalid-dir-R.html
+== dir_auto-unset-contained-dir-L.html dir_auto-unset-contained-dir-L.html
+== dir_auto-unset-contained-dir-R.html dir_auto-unset-contained-dir-R.html
+== dynamicDirAuto-setLTR-Auto1.html dynamicDirAuto-setLTR-Auto1.html
+== dynamicDirAuto-setLTR-Auto2.html dynamicDirAuto-setLTR-Auto2.html
+== dynamicDirAuto-setLTR-Auto3.html dynamicDirAuto-setLTR-Auto3.html
+== dynamicDirAuto-setLTR-Auto4.html dynamicDirAuto-setLTR-Auto4.html
+== dynamicDirAuto-setLTR-Auto5.html dynamicDirAuto-setLTR-Auto5.html
+== dynamicDirAuto-setLTR-Auto6.html dynamicDirAuto-setLTR-Auto6.html
+== dynamicDirAuto-setLTR-LTR1.html dynamicDirAuto-setLTR-LTR1.html
+== dynamicDirAuto-setLTR-LTR2.html dynamicDirAuto-setLTR-LTR2.html
+== dynamicDirAuto-setLTR-LTR3.html dynamicDirAuto-setLTR-LTR3.html
+== dynamicDirAuto-setLTR-LTR4.html dynamicDirAuto-setLTR-LTR4.html
+== dynamicDirAuto-setLTR-LTR5.html dynamicDirAuto-setLTR-LTR5.html
+== dynamicDirAuto-setLTR-LTR6.html dynamicDirAuto-setLTR-LTR6.html
+== dynamicDirAuto-setLTR-LTR7.html dynamicDirAuto-setLTR-LTR7.html
+== dynamicDirAuto-setLTR-LTR8.html dynamicDirAuto-setLTR-LTR8.html
+== dynamicDirAuto-setLTR-RTL1.html dynamicDirAuto-setLTR-RTL1.html
+== dynamicDirAuto-setLTR-RTL2.html dynamicDirAuto-setLTR-RTL2.html
+== dynamicDirAuto-setLTR-RTL3.html dynamicDirAuto-setLTR-RTL3.html
+== dynamicDirAuto-setLTR-RTL4.html dynamicDirAuto-setLTR-RTL4.html
+== dynamicDirAuto-setLTR-RTL5.html dynamicDirAuto-setLTR-RTL5.html
+== dynamicDirAuto-setLTR-RTL6.html dynamicDirAuto-setLTR-RTL6.html
+== dynamicDirAuto-setLTR-RTL7.html dynamicDirAuto-setLTR-RTL7.html
+== dynamicDirAuto-setLTR-RTL8.html dynamicDirAuto-setLTR-RTL8.html
+== dynamicDirAuto-setLTR-NoDir1.html dynamicDirAuto-setLTR-NoDir1.html
+== dynamicDirAuto-setLTR-NoDir2.html dynamicDirAuto-setLTR-NoDir2.html
+== dynamicDirAuto-setLTR-NoDir3.html dynamicDirAuto-setLTR-NoDir3.html
+== dynamicDirAuto-setLTR-NoDir4.html dynamicDirAuto-setLTR-NoDir4.html
+== dynamicDirAuto-setLTR-NoDir5.html dynamicDirAuto-setLTR-NoDir5.html
+== dynamicDirAuto-setLTR-NoDir6.html dynamicDirAuto-setLTR-NoDir6.html
+== dynamicDirAuto-setLTR-NoDir7.html dynamicDirAuto-setLTR-NoDir7.html
+== dynamicDirAuto-setLTR-NoDir8.html dynamicDirAuto-setLTR-NoDir8.html
+== dynamicDirAuto-setLTR-InvalidDir1.html dynamicDirAuto-setLTR-InvalidDir1.html
+== dynamicDirAuto-setLTR-InvalidDir2.html dynamicDirAuto-setLTR-InvalidDir2.html
+== dynamicDirAuto-setLTR-InvalidDir3.html dynamicDirAuto-setLTR-InvalidDir3.html
+== dynamicDirAuto-setLTR-InvalidDir4.html dynamicDirAuto-setLTR-InvalidDir4.html
+== dynamicDirAuto-setLTR-InvalidDir5.html dynamicDirAuto-setLTR-InvalidDir5.html
+== dynamicDirAuto-setLTR-InvalidDir6.html dynamicDirAuto-setLTR-InvalidDir6.html
+== dynamicDirAuto-setLTR-InvalidDir7.html dynamicDirAuto-setLTR-InvalidDir7.html
+== dynamicDirAuto-setLTR-InvalidDir7.html dynamicDirAuto-setLTR-InvalidDir7.html
+== dynamicDirAuto-setRTL-Auto1.html dynamicDirAuto-setRTL-Auto1.html
+== dynamicDirAuto-setRTL-Auto2.html dynamicDirAuto-setRTL-Auto2.html
+== dynamicDirAuto-setRTL-Auto3.html dynamicDirAuto-setRTL-Auto3.html
+== dynamicDirAuto-setRTL-Auto4.html dynamicDirAuto-setRTL-Auto4.html
+== dynamicDirAuto-setRTL-Auto5.html dynamicDirAuto-setRTL-Auto5.html
+== dynamicDirAuto-setRTL-Auto6.html dynamicDirAuto-setRTL-Auto6.html
+== dynamicDirAuto-setRTL-LTR1.html dynamicDirAuto-setRTL-LTR1.html
+== dynamicDirAuto-setRTL-LTR2.html dynamicDirAuto-setRTL-LTR2.html
+== dynamicDirAuto-setRTL-LTR3.html dynamicDirAuto-setRTL-LTR3.html
+== dynamicDirAuto-setRTL-LTR4.html dynamicDirAuto-setRTL-LTR4.html
+== dynamicDirAuto-setRTL-LTR5.html dynamicDirAuto-setRTL-LTR5.html
+== dynamicDirAuto-setRTL-LTR6.html dynamicDirAuto-setRTL-LTR6.html
+== dynamicDirAuto-setRTL-LTR7.html dynamicDirAuto-setRTL-LTR7.html
+== dynamicDirAuto-setRTL-LTR8.html dynamicDirAuto-setRTL-LTR8.html
+== dynamicDirAuto-setRTL-RTL1.html dynamicDirAuto-setRTL-RTL1.html
+== dynamicDirAuto-setRTL-RTL2.html dynamicDirAuto-setRTL-RTL2.html
+== dynamicDirAuto-setRTL-RTL3.html dynamicDirAuto-setRTL-RTL3.html
+== dynamicDirAuto-setRTL-RTL4.html dynamicDirAuto-setRTL-RTL4.html
+== dynamicDirAuto-setRTL-RTL5.html dynamicDirAuto-setRTL-RTL5.html
+== dynamicDirAuto-setRTL-RTL6.html dynamicDirAuto-setRTL-RTL6.html
+== dynamicDirAuto-setRTL-RTL7.html dynamicDirAuto-setRTL-RTL7.html
+== dynamicDirAuto-setRTL-RTL8.html dynamicDirAuto-setRTL-RTL8.html
+== dynamicDirAuto-setRTL-NoDir1.html dynamicDirAuto-setRTL-NoDir1.html
+== dynamicDirAuto-setRTL-NoDir2.html dynamicDirAuto-setRTL-NoDir2.html
+== dynamicDirAuto-setRTL-NoDir3.html dynamicDirAuto-setRTL-NoDir3.html
+== dynamicDirAuto-setRTL-NoDir4.html dynamicDirAuto-setRTL-NoDir4.html
+== dynamicDirAuto-setRTL-NoDir5.html dynamicDirAuto-setRTL-NoDir5.html
+== dynamicDirAuto-setRTL-NoDir6.html dynamicDirAuto-setRTL-NoDir6.html
+== dynamicDirAuto-setRTL-NoDir7.html dynamicDirAuto-setRTL-NoDir7.html
+== dynamicDirAuto-setRTL-NoDir8.html dynamicDirAuto-setRTL-NoDir8.html
+== dynamicDirAuto-setRTL-InvalidDir1.html dynamicDirAuto-setRTL-InvalidDir1.html
+== dynamicDirAuto-setRTL-InvalidDir2.html dynamicDirAuto-setRTL-InvalidDir2.html
+== dynamicDirAuto-setRTL-InvalidDir3.html dynamicDirAuto-setRTL-InvalidDir3.html
+== dynamicDirAuto-setRTL-InvalidDir4.html dynamicDirAuto-setRTL-InvalidDir4.html
+== dynamicDirAuto-setRTL-InvalidDir5.html dynamicDirAuto-setRTL-InvalidDir5.html
+== dynamicDirAuto-setRTL-InvalidDir6.html dynamicDirAuto-setRTL-InvalidDir6.html
+== dynamicDirAuto-setRTL-InvalidDir7.html dynamicDirAuto-setRTL-InvalidDir7.html
+== dynamicDirAuto-setRTL-InvalidDir8.html dynamicDirAuto-setRTL-InvalidDir8.html
+== dynamicDirAuto-addLTR-Auto.html dynamicDirAuto-addLTR-Auto.html
+== dynamicDirAuto-addRTL-Auto.html dynamicDirAuto-addRTL-Auto.html
+== dynamicDirAuto-ChangeText-LTR1.html dynamicDirAuto-ChangeText-LTR1.html
+== dynamicDirAuto-ChangeText-LTR2.html dynamicDirAuto-ChangeText-LTR2.html
+== dynamicDirAuto-ChangeText-LTR3.html dynamicDirAuto-ChangeText-LTR3.html
+== dynamicDirAuto-ChangeText-LTR4.html dynamicDirAuto-ChangeText-LTR4.html
+== dynamicDirAuto-ChangeText-LTR5.html dynamicDirAuto-ChangeText-LTR5.html
+== dynamicDirAuto-ChangeText-LTR6.html dynamicDirAuto-ChangeText-LTR6.html
+== dynamicDirAuto-ChangeText-LTR7.html dynamicDirAuto-ChangeText-LTR7.html
+== dynamicDirAuto-ChangeText-LTR8.html dynamicDirAuto-ChangeText-LTR8.html
+== dynamicDirAuto-ChangeText-LTR9.html dynamicDirAuto-ChangeText-LTR9.html
+== dynamicDirAuto-ChangeText-LTR10.html dynamicDirAuto-ChangeText-LTR10.html
+== dynamicDirAuto-ChangeText-RTL1.html dynamicDirAuto-ChangeText-RTL1.html
+== dynamicDirAuto-ChangeText-RTL2.html dynamicDirAuto-ChangeText-RTL2.html
+fuzzy-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)&&!layersGPUAccelerated&&!azureSkia,30,1) == dynamicDirAuto-ChangeText-RTL3.html dynamicDirAuto-ChangeText-RTL3.html
+fuzzy-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)&&!layersGPUAccelerated&&!azureSkia,30,1) == dynamicDirAuto-ChangeText-RTL4.html dynamicDirAuto-ChangeText-RTL4.html
+fuzzy-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)&&!layersGPUAccelerated&&!azureSkia,30,1) == dynamicDirAuto-ChangeText-RTL5.html dynamicDirAuto-ChangeText-RTL5.html
+fuzzy-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)&&!layersGPUAccelerated&&!azureSkia,30,1) == dynamicDirAuto-ChangeText-RTL6.html dynamicDirAuto-ChangeText-RTL6.html
+== dynamicDirAuto-ChangeText-RTL7.html dynamicDirAuto-ChangeText-RTL7.html
+== dynamicDirAuto-ChangeText-RTL8.html dynamicDirAuto-ChangeText-RTL8.html
+== dynamicDirAuto-ChangeText-RTL9.html dynamicDirAuto-ChangeText-RTL9.html
+== dynamicDirAuto-ChangeText-RTL10.html dynamicDirAuto-ChangeText-RTL10.html
+== dynamicDirAuto-DeleteText-LTR1.html dynamicDirAuto-DeleteText-LTR1.html
+== dynamicDirAuto-DeleteText-LTR2.html dynamicDirAuto-DeleteText-LTR2.html
+== dynamicDirAuto-DeleteText-LTR3.html dynamicDirAuto-DeleteText-LTR3.html
+== dynamicDirAuto-DeleteText-RTL1.html dynamicDirAuto-DeleteText-RTL1.html
+== dynamicDirAuto-DeleteText-RTL2.html dynamicDirAuto-DeleteText-RTL2.html
+== dynamicDirAuto-DeleteText-RTL3.html dynamicDirAuto-DeleteText-RTL3.html
+== 839886-1.html 839886-1.html
+== 859093-1.html 859093-1.html
+== 889742-1.html 889742-1.html
+== 1103348-1.html 1103348-1.html
+== 1169267-delete-add-1a.html 1169267-delete-add-1a.html
+== 1169267-delete-add-1b.html 1169267-delete-add-1b.html
+== 1169267-delete-add-2a.html 1169267-delete-add-2a.html
+== 1169267-delete-add-2b.html 1169267-delete-add-2b.html
diff --git a/layout/reftests/bidi/dirAuto/reftest.list b/layout/reftests/bidi/dirAuto/reftest.list
new file mode 100644
index 000000000..456935442
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/reftest.list
@@ -0,0 +1,119 @@
+== bdi-auto-dir-default.html bdi-auto-dir-default-ref.html
+== dir_auto-set-contained-dir-L.html dir_auto-contained-dir-L-ref.html
+== dir_auto-set-contained-dir-R.html dir_auto-contained-dir-R-ref.html
+== dir_auto-set-contained-invalid-dir-L.html dir_auto-contained-dir-L-ref.html
+== dir_auto-set-contained-invalid-dir-R.html dir_auto-contained-dir-R-ref.html
+== dir_auto-unset-contained-dir-L.html dir_auto-unset-contained-dir-L-ref.html
+== dir_auto-unset-contained-dir-R.html dir_auto-unset-contained-dir-R-ref.html
+== dynamicDirAuto-setLTR-Auto1.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-Auto2.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-Auto3.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-Auto4.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-Auto5.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-Auto6.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-LTR1.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-LTR2.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-LTR3.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-LTR4.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-LTR5.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-LTR6.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-LTR7.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-LTR8.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-RTL1.html dynamicDirAuto-refLTR-RTL.html
+== dynamicDirAuto-setLTR-RTL2.html dynamicDirAuto-refLTR-RTL.html
+== dynamicDirAuto-setLTR-RTL3.html dynamicDirAuto-refLTR-RTL.html
+== dynamicDirAuto-setLTR-RTL4.html dynamicDirAuto-refLTR-RTL.html
+== dynamicDirAuto-setLTR-RTL5.html dynamicDirAuto-refLTR-RTL.html
+== dynamicDirAuto-setLTR-RTL6.html dynamicDirAuto-refLTR-RTL.html
+== dynamicDirAuto-setLTR-RTL7.html dynamicDirAuto-refLTR-RTL.html
+== dynamicDirAuto-setLTR-RTL8.html dynamicDirAuto-refLTR-RTL.html
+== dynamicDirAuto-setLTR-NoDir1.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-NoDir2.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-NoDir3.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-NoDir4.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-NoDir5.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-NoDir6.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-NoDir7.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-NoDir8.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-InvalidDir1.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-InvalidDir2.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-InvalidDir3.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-InvalidDir4.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-InvalidDir5.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-InvalidDir6.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-InvalidDir7.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setLTR-InvalidDir7.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-setRTL-Auto1.html dynamicDirAuto-refRTL-RTL.html
+== dynamicDirAuto-setRTL-Auto2.html dynamicDirAuto-refRTL-RTL.html
+== dynamicDirAuto-setRTL-Auto3.html dynamicDirAuto-refRTL-RTL.html
+== dynamicDirAuto-setRTL-Auto4.html dynamicDirAuto-refRTL-RTL.html
+== dynamicDirAuto-setRTL-Auto5.html dynamicDirAuto-refRTL-RTL.html
+== dynamicDirAuto-setRTL-Auto6.html dynamicDirAuto-refRTL-RTL.html
+== dynamicDirAuto-setRTL-LTR1.html dynamicDirAuto-refRTL-LTR.html
+== dynamicDirAuto-setRTL-LTR2.html dynamicDirAuto-refRTL-LTR.html
+== dynamicDirAuto-setRTL-LTR3.html dynamicDirAuto-refRTL-LTR.html
+== dynamicDirAuto-setRTL-LTR4.html dynamicDirAuto-refRTL-LTR.html
+== dynamicDirAuto-setRTL-LTR5.html dynamicDirAuto-refRTL-LTR.html
+== dynamicDirAuto-setRTL-LTR6.html dynamicDirAuto-refRTL-LTR.html
+== dynamicDirAuto-setRTL-LTR7.html dynamicDirAuto-refRTL-LTR.html
+== dynamicDirAuto-setRTL-LTR8.html dynamicDirAuto-refRTL-LTR.html
+== dynamicDirAuto-setRTL-RTL1.html dynamicDirAuto-refRTL-RTL.html
+== dynamicDirAuto-setRTL-RTL2.html dynamicDirAuto-refRTL-RTL.html
+== dynamicDirAuto-setRTL-RTL3.html dynamicDirAuto-refRTL-RTL.html
+== dynamicDirAuto-setRTL-RTL4.html dynamicDirAuto-refRTL-RTL.html
+== dynamicDirAuto-setRTL-RTL5.html dynamicDirAuto-refRTL-RTL.html
+== dynamicDirAuto-setRTL-RTL6.html dynamicDirAuto-refRTL-RTL.html
+== dynamicDirAuto-setRTL-RTL7.html dynamicDirAuto-refRTL-RTL.html
+== dynamicDirAuto-setRTL-RTL8.html dynamicDirAuto-refRTL-RTL.html
+== dynamicDirAuto-setRTL-NoDir1.html dynamicDirAuto-refRTL-NoDir.html
+== dynamicDirAuto-setRTL-NoDir2.html dynamicDirAuto-refRTL-NoDir.html
+== dynamicDirAuto-setRTL-NoDir3.html dynamicDirAuto-refRTL-NoDir.html
+== dynamicDirAuto-setRTL-NoDir4.html dynamicDirAuto-refRTL-NoDir.html
+== dynamicDirAuto-setRTL-NoDir5.html dynamicDirAuto-refRTL-NoDir.html
+== dynamicDirAuto-setRTL-NoDir6.html dynamicDirAuto-refRTL-NoDir.html
+== dynamicDirAuto-setRTL-NoDir7.html dynamicDirAuto-refRTL-NoDir.html
+== dynamicDirAuto-setRTL-NoDir8.html dynamicDirAuto-refRTL-NoDir.html
+== dynamicDirAuto-setRTL-InvalidDir1.html dynamicDirAuto-refRTL-NoDir.html
+== dynamicDirAuto-setRTL-InvalidDir2.html dynamicDirAuto-refRTL-NoDir.html
+== dynamicDirAuto-setRTL-InvalidDir3.html dynamicDirAuto-refRTL-NoDir.html
+== dynamicDirAuto-setRTL-InvalidDir4.html dynamicDirAuto-refRTL-NoDir.html
+== dynamicDirAuto-setRTL-InvalidDir5.html dynamicDirAuto-refRTL-NoDir.html
+== dynamicDirAuto-setRTL-InvalidDir6.html dynamicDirAuto-refRTL-NoDir.html
+== dynamicDirAuto-setRTL-InvalidDir7.html dynamicDirAuto-refRTL-NoDir.html
+== dynamicDirAuto-setRTL-InvalidDir8.html dynamicDirAuto-refRTL-NoDir.html
+== dynamicDirAuto-addLTR-Auto.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-addRTL-Auto.html dynamicDirAuto-refRTL-RTL.html
+== dynamicDirAuto-ChangeText-LTR1.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-ChangeText-LTR2.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-ChangeText-LTR3.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-ChangeText-LTR4.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-ChangeText-LTR5.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-ChangeText-LTR6.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-ChangeText-LTR7.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-ChangeText-LTR8.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-ChangeText-LTR9.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-ChangeText-LTR10.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-ChangeText-RTL1.html dynamicDirAuto-refRTL-RTL.html
+== dynamicDirAuto-ChangeText-RTL2.html dynamicDirAuto-refRTL-RTL.html
+fuzzy-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)&&!layersGPUAccelerated&&!azureSkia,30,1) == dynamicDirAuto-ChangeText-RTL3.html dynamicDirAuto-refRTL-RTL.html
+fuzzy-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)&&!layersGPUAccelerated&&!azureSkia,30,1) == dynamicDirAuto-ChangeText-RTL4.html dynamicDirAuto-refRTL-RTL.html
+fuzzy-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)&&!layersGPUAccelerated&&!azureSkia,30,1) == dynamicDirAuto-ChangeText-RTL5.html dynamicDirAuto-refRTL-RTL.html
+fuzzy-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)&&!layersGPUAccelerated&&!azureSkia,30,1) == dynamicDirAuto-ChangeText-RTL6.html dynamicDirAuto-refRTL-RTL.html
+== dynamicDirAuto-ChangeText-RTL7.html dynamicDirAuto-refRTL-RTL.html
+== dynamicDirAuto-ChangeText-RTL8.html dynamicDirAuto-refRTL-RTL.html
+== dynamicDirAuto-ChangeText-RTL9.html dynamicDirAuto-refRTL-RTL.html
+== dynamicDirAuto-ChangeText-RTL10.html dynamicDirAuto-refRTL-RTL.html
+== dynamicDirAuto-DeleteText-LTR1.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-DeleteText-LTR2.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-DeleteText-LTR3.html dynamicDirAuto-refLTR-LTR.html
+== dynamicDirAuto-DeleteText-RTL1.html dynamicDirAuto-refRTL-RTL.html
+== dynamicDirAuto-DeleteText-RTL2.html dynamicDirAuto-refRTL-RTL.html
+== dynamicDirAuto-DeleteText-RTL3.html dynamicDirAuto-refRTL-RTL.html
+== 839886-1.html 839886-1-ref.html
+== 859093-1.html 859093-1-ref.html
+== 889742-1.html 889742-1-ref.html
+== 1103348-1.html 1103348-1-ref.html
+== 1169267-delete-add-1a.html 1169267-delete-add-1-ref.html
+== 1169267-delete-add-1b.html 1169267-delete-add-1-ref.html
+== 1169267-delete-add-2a.html 1169267-delete-add-2-ref.html
+== 1169267-delete-add-2b.html 1169267-delete-add-2-ref.html
diff --git a/layout/reftests/bidi/dirAuto/setDir.js b/layout/reftests/bidi/dirAuto/setDir.js
new file mode 100644
index 000000000..0d8c2afb3
--- /dev/null
+++ b/layout/reftests/bidi/dirAuto/setDir.js
@@ -0,0 +1,247 @@
+function setAllDir(value)
+{
+ for (var i = 0; ; ++i) {
+ try {
+ theElement = document.getElementById("set" + i);
+ theElement.dir = value;
+ } catch(e) {
+ break;
+ }
+ }
+}
+
+function setAllDirAttribute(value)
+{
+ for (var i = 0; ; ++i) {
+ try {
+ theElement = document.getElementById("set" + i);
+ theElement.setAttribute("dir", value);
+ } catch(e) {
+ break;
+ }
+ }
+}
+
+function removeAllDirAttribute()
+{
+ for (var i = 0; ; ++i) {
+ try {
+ theElement = document.getElementById("set" + i);
+ theElement.removeAttribute("dir");
+ } catch(e) {
+ break;
+ }
+ }
+}
+
+function addOneElement(innerHTML)
+{
+ var container = document.getElementById("container");
+ var elem = document.createElement("div");
+ elem.innerHTML = innerHTML;
+ container.appendChild(elem);
+}
+
+function addLTRAutoElements()
+{
+ addOneElement('<input type="text" value="ABC אבג" id="set0" dir="auto">');
+ addOneElement('<span id="set1" dir="auto">ABC אבג</span>');
+ addOneElement('<textarea id="set2" dir="auto">ABC אבג</textarea>');
+ addOneElement('<button id="set3" dir="auto">ABC אבג</button>');
+ addOneElement('<bdi id="set4">ABC אבג</bdi>');
+}
+
+function addRTLAutoElements()
+{
+ addOneElement('<input type="text" value="אבג ABC" id="set0" dir="auto">');
+ addOneElement('<span id="set1" dir="auto">אבג ABC</span>');
+ addOneElement('<textarea id="set2" dir="auto">אבג ABC</textarea>');
+ addOneElement('<button id="set3" dir="auto">אבג ABC</button>');
+ addOneElement('<bdi id="set4">אבג ABC</bdi>');
+}
+
+function setAllTextValuesTo(newText)
+{
+ for (var i = 0; ; ++i) {
+ theElement = document.getElementById("set" + i);
+ if (!theElement) {
+ break;
+ }
+ if (theElement.tagName == "INPUT" ||
+ theElement.tagName == "TEXTAREA") {
+ theElement.value = newText;
+ } else {
+ theElement.firstChild.textContent = newText;
+ }
+ }
+}
+
+function setAllTextDefaultValuesTo(newText)
+{
+ for (var i = 0; ; ++i) {
+ theElement = document.getElementById("set" + i);
+ if (!theElement) {
+ break;
+ }
+ if (theElement.tagName == "INPUT" ||
+ theElement.tagName == "TEXTAREA") {
+ theElement.defaultValue = newText;
+ } else {
+ theElement.firstChild.textContent = newText;
+ }
+ }
+}
+
+function setAllTextChildrenTo(newText)
+{
+ for (var i = 0; ; ++i) {
+ theElement = document.getElementById("set" + i);
+ if (!theElement) {
+ break;
+ }
+ if (theElement.tagName == "INPUT") {
+ theElement.value = newText;
+ } else {
+ theElement.firstChild.textContent = newText;
+ }
+ }
+}
+
+function appendTextFromArray(textArray)
+{
+ for (var i = 0; ; ++i) {
+ theElement = document.getElementById("set" + i);
+ if (!theElement) {
+ break;
+ }
+ for (var j = 0; j < textArray.length; ++j) {
+ if (theElement.tagName == "INPUT") {
+ theElement.value += textArray[j];
+ } else {
+ var textNode = document.createTextNode(textArray[j]);
+ theElement.appendChild(textNode);
+ }
+ }
+ }
+}
+
+// Add the members of the array to the text content of the elements in
+// the document, not including the last member. Then delete the last but
+// one and add the last one
+// Useful for testing scenarios like bug 1169267
+function appendDeleteAppendTextFromArray(textArray)
+{
+ if (textArray.length < 2) {
+ return;
+ }
+
+ for (var i = 0; ; ++i) {
+ theElement = document.getElementById("set" + i);
+ if (!theElement) {
+ break;
+ }
+ var isInput = (theElement.tagName == "INPUT");
+ if (!isInput) {
+ var textNode = document.createTextNode("");
+ theElement.appendChild(textNode);
+ }
+
+ for (var j = 0; j < textArray.length - 1; ++j) {
+ if (isInput) {
+ theElement.value += textArray[j];
+ } else {
+ textNode.appendData(textArray[j]);
+ }
+ }
+
+ // delete the last element added
+ var deleteElt = textArray[textArray.length - 2];
+ if (isInput) {
+ theElement.value = theElement.value.slice(0, -deleteElt.length);
+ } else {
+ textNode.deleteData(textNode.length - deleteElt.length,
+ deleteElt.length);
+ }
+
+ // add the next element
+ var addElt = textArray[textArray.length - 1];
+ if (isInput) {
+ theElement.value += addElt;
+ } else {
+ textNode.appendData(addElt);
+ }
+ }
+}
+
+function appendSpansFromArray(textArray)
+{
+ for (var i = 0; ; ++i) {
+ theElement = document.getElementById("set" + i);
+ if (!theElement) {
+ break;
+ }
+ for (var j = 0; j < textArray.length; ++j) {
+ // fake the result for elements that can't have markup content
+ if (theElement.tagName == "INPUT") {
+ theElement.value += textArray[j];
+ } else if (theElement.tagName == "TEXTAREA") {
+ theElement.innerHTML += textArray[j];
+ } else {
+ var span = document.createElement("span");
+ span.innerHTML = textArray[j];
+ theElement.appendChild(span);
+ }
+ }
+ }
+}
+
+function prependTextFromArray(textArray)
+{
+ for (var i = 0; ; ++i) {
+ theElement = document.getElementById("set" + i);
+ if (!theElement) {
+ break;
+ }
+ for (var j = 0; j < textArray.length; ++j) {
+ if (theElement.tagName == "INPUT") {
+ theElement.value = textArray[j] + theElement.value;
+ } else {
+ var textNode = document.createTextNode(textArray[j]);
+ theElement.insertBefore(textNode, theElement.firstChild);
+ }
+ }
+ }
+}
+
+function prependSpansFromArray(textArray)
+{
+ for (var i = 0; ; ++i) {
+ theElement = document.getElementById("set" + i);
+ if (!theElement) {
+ break;
+ }
+ for (var j = 0; j < textArray.length; ++j) {
+ // fake the result for elements that can't have markup content
+ if (theElement.tagName == "INPUT") {
+ theElement.value = textArray[j] + theElement.value;
+ } else if (theElement.tagName == "TEXTAREA") {
+ theElement.innerHTML = textArray[j] + theElement.innerHTML;
+ } else {
+ var span = document.createElement("span");
+ span.innerHTML = textArray[j];
+ theElement.insertBefore(span, theElement.firstChild);
+ }
+ }
+ }
+}
+
+function removeElements()
+{
+ for (var i = 0; ; ++i) {
+ theElement = document.getElementById("set" + i);
+ if (!theElement) {
+ break;
+ }
+ theElement.parentNode.removeChild(theElement);
+ }
+}