summaryrefslogtreecommitdiffstats
path: root/layout/reftests/bidi
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /layout/reftests/bidi
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'layout/reftests/bidi')
-rw-r--r--layout/reftests/bidi/1067268-1-ref.html25
-rw-r--r--layout/reftests/bidi/1067268-1.html32
-rw-r--r--layout/reftests/bidi/1069941-inline-bidi-border-1-ref.html15
-rw-r--r--layout/reftests/bidi/1069941-inline-bidi-border-1.html15
-rw-r--r--layout/reftests/bidi/1069941-inline-bidi-margin-1-ref.html20
-rw-r--r--layout/reftests/bidi/1069941-inline-bidi-margin-1.html20
-rw-r--r--layout/reftests/bidi/1155359-1-ref.xhtml4
-rw-r--r--layout/reftests/bidi/1155359-1.xhtml4
-rw-r--r--layout/reftests/bidi/1157726-1-ref.html24
-rw-r--r--layout/reftests/bidi/1157726-1.html24
-rw-r--r--layout/reftests/bidi/115921-1-ref.html14
-rw-r--r--layout/reftests/bidi/115921-1.html14
-rw-r--r--layout/reftests/bidi/115921-2-ref.html14
-rw-r--r--layout/reftests/bidi/115921-2.html14
-rw-r--r--layout/reftests/bidi/1161752-1-embed.html34
-rw-r--r--layout/reftests/bidi/1161752-2-embed.html34
-rw-r--r--layout/reftests/bidi/1161752-3-embed.html32
-rw-r--r--layout/reftests/bidi/1161752-4-embed.html34
-rw-r--r--layout/reftests/bidi/1161752-5-embed-ref.html30
-rw-r--r--layout/reftests/bidi/1161752-5-embed.html34
-rw-r--r--layout/reftests/bidi/1161752-ref.html35
-rw-r--r--layout/reftests/bidi/1161752.html73
-rw-r--r--layout/reftests/bidi/1217833-1-ref.html16
-rw-r--r--layout/reftests/bidi/1217833-1.html18
-rw-r--r--layout/reftests/bidi/1217833-2-ref.html21
-rw-r--r--layout/reftests/bidi/1217833-2.html23
-rw-r--r--layout/reftests/bidi/1231175-1-ref.html17
-rw-r--r--layout/reftests/bidi/1231175-1.html17
-rw-r--r--layout/reftests/bidi/1366623-1-ref.html16
-rw-r--r--layout/reftests/bidi/1366623-1.html17
-rw-r--r--layout/reftests/bidi/1426042-1-ref.html61
-rw-r--r--layout/reftests/bidi/1426042-1.html61
-rw-r--r--layout/reftests/bidi/151407-1-ref.html15
-rw-r--r--layout/reftests/bidi/151407-1.html25
-rw-r--r--layout/reftests/bidi/151407-1a.html31
-rw-r--r--layout/reftests/bidi/151407-2-auto-ref.html10
-rw-r--r--layout/reftests/bidi/151407-2-auto.html16
-rw-r--r--layout/reftests/bidi/151407-2-empty-ref.html10
-rw-r--r--layout/reftests/bidi/151407-2-empty.html16
-rw-r--r--layout/reftests/bidi/151407-2-foopy.html16
-rw-r--r--layout/reftests/bidi/151407-2-ltr-ref.html10
-rw-r--r--layout/reftests/bidi/151407-2-ltr.html16
-rw-r--r--layout/reftests/bidi/151407-2-rtl-ref.html10
-rw-r--r--layout/reftests/bidi/151407-2-rtl.html16
-rw-r--r--layout/reftests/bidi/151407-3-auto-ref.html10
-rw-r--r--layout/reftests/bidi/151407-3-auto.html17
-rw-r--r--layout/reftests/bidi/151407-3-empty-ref.html10
-rw-r--r--layout/reftests/bidi/151407-3-foopy.html17
-rw-r--r--layout/reftests/bidi/151407-3-ltr-ref.html10
-rw-r--r--layout/reftests/bidi/151407-3-ltr.html17
-rw-r--r--layout/reftests/bidi/151407-3-rtl-ref.html10
-rw-r--r--layout/reftests/bidi/151407-3-rtl.html17
-rw-r--r--layout/reftests/bidi/1556414-1-ref.html8
-rw-r--r--layout/reftests/bidi/1556414-1.html24
-rw-r--r--layout/reftests/bidi/1567036-1-ref.html14
-rw-r--r--layout/reftests/bidi/1567036-1.html13
-rw-r--r--layout/reftests/bidi/229367-1-ref.html10
-rw-r--r--layout/reftests/bidi/229367-1.html10
-rw-r--r--layout/reftests/bidi/229367-2-ref.html43
-rw-r--r--layout/reftests/bidi/229367-2.html43
-rw-r--r--layout/reftests/bidi/229367-3-ref.html35
-rw-r--r--layout/reftests/bidi/229367-3.html30
-rw-r--r--layout/reftests/bidi/258928-1-ref.html50
-rw-r--r--layout/reftests/bidi/258928-1.html52
-rw-r--r--layout/reftests/bidi/263359-1-ref.html11
-rw-r--r--layout/reftests/bidi/263359-1.html12
-rw-r--r--layout/reftests/bidi/263359-1a.html20
-rw-r--r--layout/reftests/bidi/263359-1b.html20
-rw-r--r--layout/reftests/bidi/263359-2-ref.html47
-rw-r--r--layout/reftests/bidi/263359-2.html46
-rw-r--r--layout/reftests/bidi/263359-3-ref.html35
-rw-r--r--layout/reftests/bidi/263359-3.html36
-rw-r--r--layout/reftests/bidi/263359-4-ref.html16
-rw-r--r--layout/reftests/bidi/263359-4.html24
-rw-r--r--layout/reftests/bidi/267459-1-ref.html24
-rw-r--r--layout/reftests/bidi/267459-1.html30
-rw-r--r--layout/reftests/bidi/267459-2-ref.html24
-rw-r--r--layout/reftests/bidi/267459-2.html24
-rw-r--r--layout/reftests/bidi/299065-1-ref.html13
-rw-r--r--layout/reftests/bidi/299065-1.html13
-rw-r--r--layout/reftests/bidi/305643-1-ref.html17
-rw-r--r--layout/reftests/bidi/305643-1.html17
-rw-r--r--layout/reftests/bidi/332655-1-ref.html11
-rw-r--r--layout/reftests/bidi/332655-1.html16
-rw-r--r--layout/reftests/bidi/332655-2-ref.html11
-rw-r--r--layout/reftests/bidi/332655-2.html16
-rw-r--r--layout/reftests/bidi/381279-1-ref.html23
-rw-r--r--layout/reftests/bidi/381279-1.html23
-rw-r--r--layout/reftests/bidi/386339-ref.html34
-rw-r--r--layout/reftests/bidi/386339.html37
-rw-r--r--layout/reftests/bidi/409375-ref.html14
-rw-r--r--layout/reftests/bidi/409375.html14
-rw-r--r--layout/reftests/bidi/413542-1-ref.html20
-rw-r--r--layout/reftests/bidi/413542-1.html21
-rw-r--r--layout/reftests/bidi/413542-2-ref.html20
-rw-r--r--layout/reftests/bidi/413542-2.html21
-rw-r--r--layout/reftests/bidi/413928-1-ref.html58
-rw-r--r--layout/reftests/bidi/413928-1.html63
-rw-r--r--layout/reftests/bidi/413928-2-ref.html58
-rw-r--r--layout/reftests/bidi/413928-2.html63
-rw-r--r--layout/reftests/bidi/425338-1-ref.html8
-rw-r--r--layout/reftests/bidi/425338-1a.html14
-rw-r--r--layout/reftests/bidi/425338-1b.html16
-rw-r--r--layout/reftests/bidi/489517-1-ref.html11
-rw-r--r--layout/reftests/bidi/489517-1.html20
-rw-r--r--layout/reftests/bidi/489887-1-ref.html15
-rw-r--r--layout/reftests/bidi/489887-1.html15
-rw-r--r--layout/reftests/bidi/492231-1-ref.html7
-rw-r--r--layout/reftests/bidi/492231-1.html7
-rw-r--r--layout/reftests/bidi/496006-1-ref.html10
-rw-r--r--layout/reftests/bidi/496006-1.html21
-rw-r--r--layout/reftests/bidi/503269-1-ref.html16
-rw-r--r--layout/reftests/bidi/503269-1.html16
-rw-r--r--layout/reftests/bidi/503957-1-ref.html20
-rw-r--r--layout/reftests/bidi/503957-1.html24
-rw-r--r--layout/reftests/bidi/525740-1-ref.html11
-rw-r--r--layout/reftests/bidi/525740-1.html11
-rw-r--r--layout/reftests/bidi/536963-1-ref.html13
-rw-r--r--layout/reftests/bidi/536963-1.html20
-rw-r--r--layout/reftests/bidi/562169-1-ref.html31
-rw-r--r--layout/reftests/bidi/562169-1.html32
-rw-r--r--layout/reftests/bidi/562169-1a.html46
-rw-r--r--layout/reftests/bidi/562169-2-ref.html29
-rw-r--r--layout/reftests/bidi/562169-2.html30
-rw-r--r--layout/reftests/bidi/562169-2a.html36
-rw-r--r--layout/reftests/bidi/562169-3-ref.html16
-rw-r--r--layout/reftests/bidi/562169-3.html15
-rw-r--r--layout/reftests/bidi/562169-3a.html26
-rw-r--r--layout/reftests/bidi/562169-4-ref.html16
-rw-r--r--layout/reftests/bidi/562169-4.html29
-rw-r--r--layout/reftests/bidi/588739-1.html12
-rw-r--r--layout/reftests/bidi/588739-2.html12
-rw-r--r--layout/reftests/bidi/588739-3.html12
-rw-r--r--layout/reftests/bidi/588739-ref.html9
-rw-r--r--layout/reftests/bidi/612843-1-ref.html16
-rw-r--r--layout/reftests/bidi/612843-1.html16
-rw-r--r--layout/reftests/bidi/613149-1-ref.html19
-rw-r--r--layout/reftests/bidi/613149-1a.html17
-rw-r--r--layout/reftests/bidi/613149-1b.html20
-rw-r--r--layout/reftests/bidi/613149-2-ref.html9
-rw-r--r--layout/reftests/bidi/613149-2a.html12
-rw-r--r--layout/reftests/bidi/613149-2b.html18
-rw-r--r--layout/reftests/bidi/613157-1-ref.html10
-rw-r--r--layout/reftests/bidi/613157-1.html10
-rw-r--r--layout/reftests/bidi/613157-2-ref.html10
-rw-r--r--layout/reftests/bidi/613157-2.html11
-rw-r--r--layout/reftests/bidi/662288-1-ref.html22
-rw-r--r--layout/reftests/bidi/662288-1.html23
-rw-r--r--layout/reftests/bidi/670226-1-ref.html14
-rw-r--r--layout/reftests/bidi/670226-1.html20
-rw-r--r--layout/reftests/bidi/676245-1-ref.html18
-rw-r--r--layout/reftests/bidi/676245-1.html18
-rw-r--r--layout/reftests/bidi/698291-1-frame.html10
-rw-r--r--layout/reftests/bidi/698291-1-ref.html10
-rw-r--r--layout/reftests/bidi/698291-1.html18
-rw-r--r--layout/reftests/bidi/698706-1-ref.html10
-rw-r--r--layout/reftests/bidi/698706-1.html12
-rw-r--r--layout/reftests/bidi/704837-1-ref.html10
-rw-r--r--layout/reftests/bidi/704837-1.html10
-rw-r--r--layout/reftests/bidi/712600-1-ref.html36
-rw-r--r--layout/reftests/bidi/712600-1.html42
-rw-r--r--layout/reftests/bidi/712600-2-dyn.html45
-rw-r--r--layout/reftests/bidi/712600-2-ref.html33
-rw-r--r--layout/reftests/bidi/712600-2.html32
-rw-r--r--layout/reftests/bidi/712600-3-ref.html51
-rw-r--r--layout/reftests/bidi/712600-3.html63
-rw-r--r--layout/reftests/bidi/718236-1-ref.html9
-rw-r--r--layout/reftests/bidi/718236-1.html22
-rw-r--r--layout/reftests/bidi/718236-2-ref.html9
-rw-r--r--layout/reftests/bidi/718236-2.html22
-rw-r--r--layout/reftests/bidi/718236-3-ref.html9
-rw-r--r--layout/reftests/bidi/718236-3.html22
-rw-r--r--layout/reftests/bidi/726460-1-ref.html9
-rw-r--r--layout/reftests/bidi/726460-1.html23
-rw-r--r--layout/reftests/bidi/729047-1-ref.html10
-rw-r--r--layout/reftests/bidi/729047-1.html10
-rw-r--r--layout/reftests/bidi/730562-1-ref.html12
-rw-r--r--layout/reftests/bidi/730562-1.html24
-rw-r--r--layout/reftests/bidi/746987-1-ref.html10
-rw-r--r--layout/reftests/bidi/746987-1.html15
-rw-r--r--layout/reftests/bidi/746987-2-ref.html24
-rw-r--r--layout/reftests/bidi/746987-2.html27
-rw-r--r--layout/reftests/bidi/746987-3-ref.html25
-rw-r--r--layout/reftests/bidi/746987-3.html31
-rw-r--r--layout/reftests/bidi/746987-4-ref.html24
-rw-r--r--layout/reftests/bidi/746987-4.html33
-rw-r--r--layout/reftests/bidi/779003-1-dynamic.html53
-rw-r--r--layout/reftests/bidi/779003-1-ref.html47
-rw-r--r--layout/reftests/bidi/779003-1.html44
-rw-r--r--layout/reftests/bidi/817406-1-ref.html4
-rw-r--r--layout/reftests/bidi/817406-1.html4
-rw-r--r--layout/reftests/bidi/817406-2-ref.html4
-rw-r--r--layout/reftests/bidi/817406-2.html4
-rw-r--r--layout/reftests/bidi/817406-3.html6
-rw-r--r--layout/reftests/bidi/817406-4.html6
-rw-r--r--layout/reftests/bidi/83958-1-ref.html23
-rw-r--r--layout/reftests/bidi/83958-1a.html24
-rw-r--r--layout/reftests/bidi/83958-1b.html32
-rw-r--r--layout/reftests/bidi/83958-1c.html32
-rw-r--r--layout/reftests/bidi/83958-2-ref.html28
-rw-r--r--layout/reftests/bidi/83958-2a.html29
-rw-r--r--layout/reftests/bidi/83958-2b.html33
-rw-r--r--layout/reftests/bidi/847242-1-ref.html15
-rw-r--r--layout/reftests/bidi/847242-1.html18
-rw-r--r--layout/reftests/bidi/869833-1-ref.xhtml30
-rw-r--r--layout/reftests/bidi/869833-1.xhtml29
-rw-r--r--layout/reftests/bidi/922530-1-ref.html13
-rw-r--r--layout/reftests/bidi/922530-1.html25
-rw-r--r--layout/reftests/bidi/922550-1-ref.html28
-rw-r--r--layout/reftests/bidi/922550-1.html26
-rw-r--r--layout/reftests/bidi/989994-1-ref.html16
-rw-r--r--layout/reftests/bidi/989994-1.html16
-rw-r--r--layout/reftests/bidi/bdi-element-ref.html19
-rw-r--r--layout/reftests/bidi/bdi-element.html19
-rw-r--r--layout/reftests/bidi/bidi-000-ref.html17
-rw-r--r--layout/reftests/bidi/bidi-000.html17
-rw-r--r--layout/reftests/bidi/bidi-001-j.html16
-rw-r--r--layout/reftests/bidi/bidi-001-ref.html15
-rw-r--r--layout/reftests/bidi/bidi-001-v.html16
-rw-r--r--layout/reftests/bidi/bidi-001.html16
-rw-r--r--layout/reftests/bidi/bidi-002-ref.html15
-rw-r--r--layout/reftests/bidi/bidi-002.html16
-rw-r--r--layout/reftests/bidi/bidi-003-ref.html15
-rw-r--r--layout/reftests/bidi/bidi-003.html17
-rw-r--r--layout/reftests/bidi/bidi-004-j.html17
-rw-r--r--layout/reftests/bidi/bidi-004-ref.html16
-rw-r--r--layout/reftests/bidi/bidi-004.html17
-rw-r--r--layout/reftests/bidi/bidi-005-ref.html15
-rw-r--r--layout/reftests/bidi/bidi-005.html16
-rw-r--r--layout/reftests/bidi/bidi-006-j.html49
-rw-r--r--layout/reftests/bidi/bidi-006-ref.html41
-rw-r--r--layout/reftests/bidi/bidi-006.html48
-rw-r--r--layout/reftests/bidi/bidiMirroring-ref.svg8
-rw-r--r--layout/reftests/bidi/bidiMirroring.js407
-rw-r--r--layout/reftests/bidi/bidiMirroring.svg22
-rw-r--r--layout/reftests/bidi/bidiSVG-01-ref.svg3
-rw-r--r--layout/reftests/bidi/bidiSVG-01.svg3
-rw-r--r--layout/reftests/bidi/bidiSVG-02-ref.svg3
-rw-r--r--layout/reftests/bidi/bidiSVG-02.svg3
-rw-r--r--layout/reftests/bidi/bidiSVG-03-ref.svg3
-rw-r--r--layout/reftests/bidi/bidiSVG-03.svg3
-rw-r--r--layout/reftests/bidi/bidiSVG-04-ref.svg3
-rw-r--r--layout/reftests/bidi/bidiSVG-04.svg3
-rw-r--r--layout/reftests/bidi/bidiSVG-05-ref.svg3
-rw-r--r--layout/reftests/bidi/bidiSVG-05.svg3
-rw-r--r--layout/reftests/bidi/brackets-1a-ltr-ref.html15
-rw-r--r--layout/reftests/bidi/brackets-1a-ltr.html16
-rw-r--r--layout/reftests/bidi/brackets-1a-rtl-ref.html15
-rw-r--r--layout/reftests/bidi/brackets-1a-rtl.html16
-rw-r--r--layout/reftests/bidi/brackets-1b-ltr-ref.html15
-rw-r--r--layout/reftests/bidi/brackets-1b-ltr.html16
-rw-r--r--layout/reftests/bidi/brackets-1b-rtl-ref.html15
-rw-r--r--layout/reftests/bidi/brackets-1b-rtl.html16
-rw-r--r--layout/reftests/bidi/brackets-1c-ltr-ref.html15
-rw-r--r--layout/reftests/bidi/brackets-1c-ltr.html16
-rw-r--r--layout/reftests/bidi/brackets-1c-rtl-ref.html15
-rw-r--r--layout/reftests/bidi/brackets-1c-rtl.html16
-rw-r--r--layout/reftests/bidi/brackets-2a-ltr-ref.html15
-rw-r--r--layout/reftests/bidi/brackets-2a-ltr.html16
-rw-r--r--layout/reftests/bidi/brackets-2a-rtl-ref.html15
-rw-r--r--layout/reftests/bidi/brackets-2a-rtl.html16
-rw-r--r--layout/reftests/bidi/brackets-2b-ltr-ref.html15
-rw-r--r--layout/reftests/bidi/brackets-2b-ltr.html16
-rw-r--r--layout/reftests/bidi/brackets-2b-rtl-ref.html15
-rw-r--r--layout/reftests/bidi/brackets-2b-rtl.html16
-rw-r--r--layout/reftests/bidi/brackets-2c-ltr-ref.html15
-rw-r--r--layout/reftests/bidi/brackets-2c-ltr.html16
-rw-r--r--layout/reftests/bidi/brackets-2c-rtl-ref.html15
-rw-r--r--layout/reftests/bidi/brackets-2c-rtl.html16
-rw-r--r--layout/reftests/bidi/brackets-3a-ltr-ref.html15
-rw-r--r--layout/reftests/bidi/brackets-3a-ltr.html16
-rw-r--r--layout/reftests/bidi/brackets-3a-rtl-ref.html15
-rw-r--r--layout/reftests/bidi/brackets-3a-rtl.html16
-rw-r--r--layout/reftests/bidi/brackets-3b-ltr-ref.html16
-rw-r--r--layout/reftests/bidi/brackets-3b-ltr.html16
-rw-r--r--layout/reftests/bidi/brackets-3b-rtl-ref.html16
-rw-r--r--layout/reftests/bidi/brackets-3b-rtl.html16
-rw-r--r--layout/reftests/bidi/clone-intrinsic-size-bidi-ref.html87
-rw-r--r--layout/reftests/bidi/clone-intrinsic-size-bidi.html113
-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.list119
-rw-r--r--layout/reftests/bidi/dirAuto/setDir.js247
-rw-r--r--layout/reftests/bidi/logicalmarquee.html11
-rw-r--r--layout/reftests/bidi/marquee-ref.html11
-rw-r--r--layout/reftests/bidi/mirroring-01-ref.html13
-rw-r--r--layout/reftests/bidi/mirroring-01.html20
-rw-r--r--layout/reftests/bidi/mirroring-02-ref.html11
-rw-r--r--layout/reftests/bidi/mirroring-02.html18
-rw-r--r--layout/reftests/bidi/mirroring-03-ref.html9
-rw-r--r--layout/reftests/bidi/mirroring-03.html9
-rw-r--r--layout/reftests/bidi/mixedChartype-00-j.html17
-rw-r--r--layout/reftests/bidi/mixedChartype-00-ref.html16
-rw-r--r--layout/reftests/bidi/mixedChartype-00.html16
-rw-r--r--layout/reftests/bidi/mixedChartype-01-j.html16
-rw-r--r--layout/reftests/bidi/mixedChartype-01-ref.html16
-rw-r--r--layout/reftests/bidi/mixedChartype-01.html16
-rw-r--r--layout/reftests/bidi/mixedChartype-02-j.html19
-rw-r--r--layout/reftests/bidi/mixedChartype-02-ref.html18
-rw-r--r--layout/reftests/bidi/mixedChartype-02.html18
-rw-r--r--layout/reftests/bidi/mixedChartype-03-j.html17
-rw-r--r--layout/reftests/bidi/mixedChartype-03-ref.html16
-rw-r--r--layout/reftests/bidi/mixedChartype-03.html16
-rw-r--r--layout/reftests/bidi/numeral/arabic-1-ref.html8
-rw-r--r--layout/reftests/bidi/numeral/arabic-1.html8
-rw-r--r--layout/reftests/bidi/numeral/arabic-2-ref.html8
-rw-r--r--layout/reftests/bidi/numeral/arabic-2.html8
-rw-r--r--layout/reftests/bidi/numeral/arabic-3-ref.html8
-rw-r--r--layout/reftests/bidi/numeral/arabic-3.html8
-rw-r--r--layout/reftests/bidi/numeral/arabic-4-ref.html8
-rw-r--r--layout/reftests/bidi/numeral/arabic-4.html8
-rw-r--r--layout/reftests/bidi/numeral/arabic-5-ref.html8
-rw-r--r--layout/reftests/bidi/numeral/arabic-5.html8
-rw-r--r--layout/reftests/bidi/numeral/bug441782-1-ref.html8
-rw-r--r--layout/reftests/bidi/numeral/bug441782-1.html8
-rw-r--r--layout/reftests/bidi/numeral/bug441782-2-ref.html8
-rw-r--r--layout/reftests/bidi/numeral/bug441782-2.html8
-rw-r--r--layout/reftests/bidi/numeral/bug441782-3-ref.html8
-rw-r--r--layout/reftests/bidi/numeral/bug441782-3.html8
-rw-r--r--layout/reftests/bidi/numeral/bug441782-4-ref.html8
-rw-r--r--layout/reftests/bidi/numeral/bug441782-4.html8
-rw-r--r--layout/reftests/bidi/numeral/bug441782-5-ref.html8
-rw-r--r--layout/reftests/bidi/numeral/bug441782-5.html8
-rw-r--r--layout/reftests/bidi/numeral/bug467672-1-ref.html8
-rw-r--r--layout/reftests/bidi/numeral/bug467672-1.html8
-rw-r--r--layout/reftests/bidi/numeral/bug467672-2-ref.html8
-rw-r--r--layout/reftests/bidi/numeral/bug467672-2.html8
-rw-r--r--layout/reftests/bidi/numeral/bug467672-3-ref.html8
-rw-r--r--layout/reftests/bidi/numeral/bug467672-3.html8
-rw-r--r--layout/reftests/bidi/numeral/bug467672-4-ref.html8
-rw-r--r--layout/reftests/bidi/numeral/bug467672-4.html8
-rw-r--r--layout/reftests/bidi/numeral/bug467672-5-ref.html8
-rw-r--r--layout/reftests/bidi/numeral/bug467672-5.html8
-rw-r--r--layout/reftests/bidi/numeral/persian-1-ref.html8
-rw-r--r--layout/reftests/bidi/numeral/persian-1.html8
-rw-r--r--layout/reftests/bidi/numeral/persian-2-ref.html8
-rw-r--r--layout/reftests/bidi/numeral/persian-2.html8
-rw-r--r--layout/reftests/bidi/numeral/persian-3-ref.html8
-rw-r--r--layout/reftests/bidi/numeral/persian-3.html8
-rw-r--r--layout/reftests/bidi/numeral/persian-4-ref.html8
-rw-r--r--layout/reftests/bidi/numeral/persian-4.html8
-rw-r--r--layout/reftests/bidi/numeral/persian-5-ref.html8
-rw-r--r--layout/reftests/bidi/numeral/persian-5.html8
-rw-r--r--layout/reftests/bidi/numeral/reftest.list120
-rw-r--r--layout/reftests/bidi/reftest.list183
-rw-r--r--layout/reftests/bidi/slice-intrinsic-size-bidi-ref.html85
-rw-r--r--layout/reftests/bidi/slice-intrinsic-size-bidi.html108
-rw-r--r--layout/reftests/bidi/unicode-bidi-anonymous-001-ref.html3
-rw-r--r--layout/reftests/bidi/unicode-bidi-anonymous-001.html3
-rw-r--r--layout/reftests/bidi/unicode-bidi-anonymous-002-ref.html5
-rw-r--r--layout/reftests/bidi/unicode-bidi-anonymous-002.html5
-rw-r--r--layout/reftests/bidi/unicode-bidi-isolate-aharon-ref.html69
-rw-r--r--layout/reftests/bidi/unicode-bidi-isolate-aharon.html72
-rw-r--r--layout/reftests/bidi/unicode-bidi-isolate-basic-ref.html22
-rw-r--r--layout/reftests/bidi/unicode-bidi-isolate-basic.html22
-rw-r--r--layout/reftests/bidi/unicode-bidi-isolate-basic.js44
-rw-r--r--layout/reftests/bidi/unicode-bidi-plaintext-ref.html26
-rw-r--r--layout/reftests/bidi/unicode-bidi-plaintext-textarea-1.html17
-rw-r--r--layout/reftests/bidi/unicode-bidi-plaintext-textarea-2.html20
-rw-r--r--layout/reftests/bidi/unicode-bidi-plaintext-textarea-3.html20
-rw-r--r--layout/reftests/bidi/unicode-bidi-plaintext-textarea-4.html20
-rw-r--r--layout/reftests/bidi/unicode-bidi-plaintext-textarea-ref.html19
-rw-r--r--layout/reftests/bidi/unicode-bidi-plaintext.html27
-rw-r--r--layout/reftests/bidi/visualmarquee.html11
-rw-r--r--layout/reftests/bidi/with-first-letter-1-ref.html19
-rw-r--r--layout/reftests/bidi/with-first-letter-1a.html19
-rw-r--r--layout/reftests/bidi/with-first-letter-1b.html19
-rw-r--r--layout/reftests/bidi/with-first-letter-2-ref.html20
-rw-r--r--layout/reftests/bidi/with-first-letter-2a.html19
-rw-r--r--layout/reftests/bidi/with-first-letter-2b.html19
503 files changed, 11193 insertions, 0 deletions
diff --git a/layout/reftests/bidi/1067268-1-ref.html b/layout/reftests/bidi/1067268-1-ref.html
new file mode 100644
index 0000000000..c02883462f
--- /dev/null
+++ b/layout/reftests/bidi/1067268-1-ref.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html dir="rtl">
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <meta charset="utf-8">
+ <title>Testcase for bug 1067268</title>
+ <style type="text/css">
+ .drowning { height: 24px; padding-right: 26px; }
+ </style>
+ </head>
+ <body>
+ <ul>
+ <li>
+ <div>
+ <div class="drowning"><div class="text">חדשות</div></div>
+ </div>
+ </li>
+ <li>
+ <div>
+ <div class="drowning"><div class="text">הודעות</div></div>
+ </div>
+ </li>
+ </ul>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/1067268-1.html b/layout/reftests/bidi/1067268-1.html
new file mode 100644
index 0000000000..463aac64f5
--- /dev/null
+++ b/layout/reftests/bidi/1067268-1.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html dir="rtl">
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <meta charset="utf-8">
+ <style type="text/css">
+ li { clear: both; }
+
+ .text { overflow: hidden; }
+
+ .floating { float: left; width: 21px; height: 24px}
+
+ .drowning { height: 24px; padding-right: 26px; }
+ </style>
+ <title>Testcase for bug 1067268</title>
+ </head>
+ <body>
+ <ul>
+ <li>
+ <div>
+ <div class="floating"></div>
+ <div class="drowning"><div class="text">חדשות</div></div>
+ </div>
+ </li>
+ <li>
+ <div>
+ <div class="drowning"><div class="text">הודעות</div></div>
+ </div>
+ </li>
+ </ul>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/1069941-inline-bidi-border-1-ref.html b/layout/reftests/bidi/1069941-inline-bidi-border-1-ref.html
new file mode 100644
index 0000000000..eeca3ef8cb
--- /dev/null
+++ b/layout/reftests/bidi/1069941-inline-bidi-border-1-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>Test for bug 1069941 -- borders</title>
+</head>
+<body>
+<div dir="ltr">
+ <span dir="ltr" style="color:transparent;background:gray;border-left:10px solid teal;">+٥</span>
+</div>
+<div dir="ltr">
+ <span dir="ltr" style="color:transparent;background:gray;border-right:10px solid teal;">+٥</span>
+</div>
+</body>
+</html>
diff --git a/layout/reftests/bidi/1069941-inline-bidi-border-1.html b/layout/reftests/bidi/1069941-inline-bidi-border-1.html
new file mode 100644
index 0000000000..79b41aaf1b
--- /dev/null
+++ b/layout/reftests/bidi/1069941-inline-bidi-border-1.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<title>Test for bug 1069941 -- borders</title>
+</head>
+<body>
+<div dir="ltr">
+ <span dir="rtl" style="color:transparent;background:gray;border-left:10px solid teal;">+٥</span>
+</div>
+<div dir="ltr">
+ <span dir="rtl" style="color:transparent;background:gray;border-right:10px solid teal;">+٥</span>
+</div>
+</body>
+</html>
diff --git a/layout/reftests/bidi/1069941-inline-bidi-margin-1-ref.html b/layout/reftests/bidi/1069941-inline-bidi-margin-1-ref.html
new file mode 100644
index 0000000000..c981cd73c9
--- /dev/null
+++ b/layout/reftests/bidi/1069941-inline-bidi-margin-1-ref.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Test for bug 1069941 -- margins</title>
+<style type="text/css">
+ .outer {
+ display: inline-block;
+ border: 1px solid lime;
+ }
+ .inner {
+ color:transparent;
+ margin-left: 50px;
+ border: 2px solid teal;
+ }
+</style>
+</head>
+<body>
+<span class="outer"><span class="inner">(12]</span></span>
+</body>
+</html>
diff --git a/layout/reftests/bidi/1069941-inline-bidi-margin-1.html b/layout/reftests/bidi/1069941-inline-bidi-margin-1.html
new file mode 100644
index 0000000000..02d0d325cb
--- /dev/null
+++ b/layout/reftests/bidi/1069941-inline-bidi-margin-1.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Test for bug 1069941 -- margins</title>
+<style type="text/css">
+ .outer {
+ display: inline-block;
+ border: 1px solid lime;
+ }
+ .inner {
+ color:transparent;
+ margin-left: 50px;
+ border: 2px solid teal;
+ }
+</style>
+</head>
+<body>
+<span class="outer"><span class="inner" dir="rtl">[12)</span></span>
+</body>
+</html>
diff --git a/layout/reftests/bidi/1155359-1-ref.xhtml b/layout/reftests/bidi/1155359-1-ref.xhtml
new file mode 100644
index 0000000000..c4820b658b
--- /dev/null
+++ b/layout/reftests/bidi/1155359-1-ref.xhtml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+ <label value="A." style="direction: ltr;"/>
+</window>
diff --git a/layout/reftests/bidi/1155359-1.xhtml b/layout/reftests/bidi/1155359-1.xhtml
new file mode 100644
index 0000000000..9ac4b25c1f
--- /dev/null
+++ b/layout/reftests/bidi/1155359-1.xhtml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+ <label value="A." style="direction: rtl;"/>
+</window>
diff --git a/layout/reftests/bidi/1157726-1-ref.html b/layout/reftests/bidi/1157726-1-ref.html
new file mode 100644
index 0000000000..fd4ff9a74c
--- /dev/null
+++ b/layout/reftests/bidi/1157726-1-ref.html
@@ -0,0 +1,24 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>unicode bidi isolate characters</title>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <meta charset="utf-8">
+</head>
+<body>
+<p>اتع +1-416-848-3114 abc</p>
+
+<p>اتع <bdi>+1-416-848-3114</bdi> abc</p>
+<p>اتع <bdi>+1-416-848-3114a</bdi> abc</p>
+<p>اتع <bdi>+1-416-848-3114ش</bdi> abc</p>
+
+<p>اتع <bdi dir="ltr">+1-416-848-3114</bdi> abc</p>
+<p>اتع <bdi dir="ltr">+1-416-848-3114a</bdi> abc</p>
+<p>اتع <bdi dir="ltr">+1-416-848-3114ش</bdi> abc</p>
+
+<p>اتع <bdi dir="rtl">+1-416-848-3114</bdi> abc</p>
+<p>اتع <bdi dir="rtl">+1-416-848-3114a</bdi> abc</p>
+<p>اتع <bdi dir="rtl">+1-416-848-3114ش</bdi> abc</p>
+
+</body>
+</html>
diff --git a/layout/reftests/bidi/1157726-1.html b/layout/reftests/bidi/1157726-1.html
new file mode 100644
index 0000000000..d8615b43d6
--- /dev/null
+++ b/layout/reftests/bidi/1157726-1.html
@@ -0,0 +1,24 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>unicode bidi isolate characters</title>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <meta charset="utf-8">
+</head>
+<body>
+<p>اتع +1-416-848-3114 abc</p>
+
+<p>اتع &#x2068;+1-416-848-3114&#x2069; abc</p>
+<p>اتع &#x2068;+1-416-848-3114a&#x2069; abc</p>
+<p>اتع &#x2068;+1-416-848-3114ش&#x2069; abc</p>
+
+<p>اتع &#x2066;+1-416-848-3114&#x2069; abc</p>
+<p>اتع &#x2066;+1-416-848-3114a&#x2069; abc</p>
+<p>اتع &#x2066;+1-416-848-3114ش&#x2069; abc</p>
+
+<p>اتع &#x2067;+1-416-848-3114&#x2069; abc</p>
+<p>اتع &#x2067;+1-416-848-3114a&#x2069; abc</p>
+<p>اتع &#x2067;+1-416-848-3114ش&#x2069; abc</p>
+
+</body>
+</html>
diff --git a/layout/reftests/bidi/115921-1-ref.html b/layout/reftests/bidi/115921-1-ref.html
new file mode 100644
index 0000000000..87d40f7dc5
--- /dev/null
+++ b/layout/reftests/bidi/115921-1-ref.html
@@ -0,0 +1,14 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<title>bidi overrides</title>
+</head><body>
+&amp;#x202d; forces ltr<br />
+&amp;#x202e; forces rtl<br />
+&amp;#x202c; restores bidi<br />
+<blockquote>
+this is ltr: hello<br />
+this is rtl: olleh
+</blockquote>
+</body>
+</html>
diff --git a/layout/reftests/bidi/115921-1.html b/layout/reftests/bidi/115921-1.html
new file mode 100644
index 0000000000..f12134f48e
--- /dev/null
+++ b/layout/reftests/bidi/115921-1.html
@@ -0,0 +1,14 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<title>bidi overrides</title>
+</head><body>
+&amp;#x202d; forces ltr<br />
+&amp;#x202e; forces rtl<br />
+&amp;#x202c; restores bidi<br />
+<blockquote>
+this is ltr: &#x202d;hello&#x202c;<br />
+this is rtl: &#x202e;hello&#x202c;
+</blockquote>
+</body>
+</html>
diff --git a/layout/reftests/bidi/115921-2-ref.html b/layout/reftests/bidi/115921-2-ref.html
new file mode 100644
index 0000000000..72685d7062
--- /dev/null
+++ b/layout/reftests/bidi/115921-2-ref.html
@@ -0,0 +1,14 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<title>bidi overrides</title>
+</head><body>
+&lt;bdo dir="LTR"&gt; forces ltr<br />
+&lt;bdo dir="RTL"&gt; forces rtl<br />
+&lt;/bdo&gt; restores bidi<br />
+<blockquote>
+this is ltr: hello<br />
+this is rtl: olleh
+</blockquote>
+</body>
+</html>
diff --git a/layout/reftests/bidi/115921-2.html b/layout/reftests/bidi/115921-2.html
new file mode 100644
index 0000000000..33c41a9f6c
--- /dev/null
+++ b/layout/reftests/bidi/115921-2.html
@@ -0,0 +1,14 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<title>bidi overrides</title>
+</head><body>
+&lt;bdo dir="LTR"&gt; forces ltr<br />
+&lt;bdo dir="RTL"&gt; forces rtl<br />
+&lt;/bdo&gt; restores bidi<br />
+<blockquote>
+this is ltr: <bdo dir="LTR">hello</bdo><br />
+this is rtl: <bdo dir="RTL">hello</bdo>
+</blockquote>
+</body>
+</html>
diff --git a/layout/reftests/bidi/1161752-1-embed.html b/layout/reftests/bidi/1161752-1-embed.html
new file mode 100644
index 0000000000..f8bae49cc4
--- /dev/null
+++ b/layout/reftests/bidi/1161752-1-embed.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title></title>
+
+ <style type="text/css">
+
+ html { direction: ltr; }
+
+ div
+ {
+ background-color: green;
+ border-left: green none 0px;
+ border-right: green none 0px;
+ height: 50px;
+ left: 20%;
+ margin-left: 0px;
+ margin-right: 0px;
+ position: absolute;
+ right: 20%;
+ top: 0px;
+ width: 20%;
+ }
+
+ </style>
+ </head>
+
+ <body>
+
+ <div></div>
+
+ </body>
+</html>
diff --git a/layout/reftests/bidi/1161752-2-embed.html b/layout/reftests/bidi/1161752-2-embed.html
new file mode 100644
index 0000000000..b6a24ce01d
--- /dev/null
+++ b/layout/reftests/bidi/1161752-2-embed.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title></title>
+
+ <style type="text/css">
+
+ html { direction: rtl; }
+
+ div
+ {
+ background-color: green;
+ border-left: green none 0px;
+ border-right: green none 0px;
+ height: 50px;
+ left: 20%;
+ margin-left: 0px;
+ margin-right: 0px;
+ position: absolute;
+ right: 20%;
+ top: 0px;
+ width: 20%;
+ }
+
+ </style>
+ </head>
+
+ <body>
+
+ <div></div>
+
+ </body>
+</html>
diff --git a/layout/reftests/bidi/1161752-3-embed.html b/layout/reftests/bidi/1161752-3-embed.html
new file mode 100644
index 0000000000..d18228fe02
--- /dev/null
+++ b/layout/reftests/bidi/1161752-3-embed.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html dir="ltr">
+ <head>
+ <meta charset="utf-8">
+ <title></title>
+
+ <style type="text/css">
+
+ div
+ {
+ background-color: green;
+ border-left: green none 0px;
+ border-right: green none 0px;
+ height: 50px;
+ left: 20%;
+ margin-left: 0px;
+ margin-right: 0px;
+ position: absolute;
+ right: 20%;
+ top: 0px;
+ width: 20%;
+ }
+
+ </style>
+ </head>
+
+ <body>
+
+ <div></div>
+
+ </body>
+</html>
diff --git a/layout/reftests/bidi/1161752-4-embed.html b/layout/reftests/bidi/1161752-4-embed.html
new file mode 100644
index 0000000000..78e0e27a1f
--- /dev/null
+++ b/layout/reftests/bidi/1161752-4-embed.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title></title>
+
+ <style type="text/css">
+
+ html { direction: ltr; }
+
+ div
+ {
+ background-color: green;
+ border-left: green none 0px;
+ border-right: green none 0px;
+ height: 50px;
+ left: 20%;
+ margin-left: 0px;
+ margin-right: 0px;
+ position: fixed;
+ right: 20%;
+ top: 0px;
+ width: 20%;
+ }
+
+ </style>
+ </head>
+
+ <body>
+
+ <div></div>
+
+ </body>
+</html>
diff --git a/layout/reftests/bidi/1161752-5-embed-ref.html b/layout/reftests/bidi/1161752-5-embed-ref.html
new file mode 100644
index 0000000000..88c4e5f1b4
--- /dev/null
+++ b/layout/reftests/bidi/1161752-5-embed-ref.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html class="reftest-paged">
+ <head>
+ <title>Testcase for bug 1161752</title>
+<style>
+ body,html { margin:0; padding:0; }
+ div
+ {
+ height: 56px;
+ width: 100px;
+ vertical-align: top;
+ margin-bottom: 50px;
+ margin-right: 100px;
+ margin-left: auto;
+ }
+ div div
+ {
+ height: 50px;
+ width: 100px;
+ background-color: green;
+ }
+
+</style>
+ </head>
+ <body>
+
+ <div><div></div></div>
+
+ </body>
+</html>
diff --git a/layout/reftests/bidi/1161752-5-embed.html b/layout/reftests/bidi/1161752-5-embed.html
new file mode 100644
index 0000000000..a72b28e534
--- /dev/null
+++ b/layout/reftests/bidi/1161752-5-embed.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html class="reftest-paged">
+ <head>
+ <meta charset="utf-8">
+ <title></title>
+
+ <style type="text/css">
+
+ html { direction: rtl; }
+
+ div
+ {
+ background-color: green;
+ border-left: green none 0px;
+ border-right: green none 0px;
+ height: 50px;
+ left: 100px;
+ margin-left: 0px;
+ margin-right: 0px;
+ position: fixed;
+ right: 100px;
+ top: 0px;
+ width: 100px;
+ }
+
+ </style>
+ </head>
+
+ <body>
+
+ <div></div>
+
+ </body>
+</html>
diff --git a/layout/reftests/bidi/1161752-ref.html b/layout/reftests/bidi/1161752-ref.html
new file mode 100644
index 0000000000..c6ffce33fb
--- /dev/null
+++ b/layout/reftests/bidi/1161752-ref.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Testcase for bug 1161752</title>
+<style>
+ div
+ {
+ height: 56px;
+ width: 100px;
+ vertical-align: top;
+ margin-bottom: 50px;
+ }
+ div div
+ {
+ height: 50px;
+ width: 100px;
+ background-color: green;
+ margin-left: 300px;
+ }
+
+</style>
+ </head>
+ <body>
+
+ <p>Test passes if there are three filled green rectangles and <strong>no red</strong>.</p>
+
+
+ <div><div></div></div>
+ <div><div></div></div>
+ <div><div></div></div>
+ <div><div></div></div>
+ <div><div></div></div>
+
+ </body>
+</html>
diff --git a/layout/reftests/bidi/1161752.html b/layout/reftests/bidi/1161752.html
new file mode 100644
index 0000000000..e3fa245f56
--- /dev/null
+++ b/layout/reftests/bidi/1161752.html
@@ -0,0 +1,73 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Testcase for bug 1161752</title>
+<style>
+ object.overlapping-green
+ {
+ height: 56px;
+ width: 500px;
+ vertical-align: top;
+ }
+
+ div.red-overlapped-reference
+ {
+ background-color: red;
+ bottom: 56px;
+ height: 50px;
+ left: 300px;
+ position: relative;
+ width: 100px;
+ z-index: -1;
+ }
+</style>
+<script>
+function runTest1() {
+ var root = document.querySelector('#test1').contentDocument.documentElement;
+ root.style.direction='rtl';
+ root.offsetHeight;
+}
+function runTest2() {
+ var root = document.querySelector('#test2').contentDocument.documentElement;
+ root.style.display='none';
+ root.offsetHeight;
+ root.style.display='block';
+ root.offsetHeight;
+}
+function runTest3() {
+ var doc = document.querySelector('#test3').contentDocument;
+ var root = doc.documentElement;
+ doc.removeChild(root);
+ var newRoot = root.cloneNode(true);
+ newRoot.setAttribute('dir','rtl');
+ doc.appendChild(newRoot);
+}
+function runTest4() {
+ var root = document.querySelector('#test4').contentDocument.documentElement;
+ root.style.direction='rtl';
+ root.offsetHeight;
+}
+</script>
+ </head>
+ <body>
+
+ <p>Test passes if there are three filled green rectangles and <strong>no red</strong>.</p>
+
+
+ <div><object id="test1" data="1161752-1-embed.html" type="text/html" class="overlapping-green" onload="runTest1()">This test requires a browser with capability to embed an HTML document thanks to the HTML &lt;object&gt; element.</object></div>
+ <div class="red-overlapped-reference"></div>
+
+ <div><object id="test2" data="1161752-2-embed.html" type="text/html" class="overlapping-green" onload="runTest2()">This test requires a browser with capability to embed an HTML document thanks to the HTML &lt;object&gt; element.</object></div>
+ <div class="red-overlapped-reference"></div>
+
+ <div><object id="test3" data="1161752-3-embed.html" type="text/html" class="overlapping-green" onload="runTest3()">This test requires a browser with capability to embed an HTML document thanks to the HTML &lt;object&gt; element.</object></div>
+ <div class="red-overlapped-reference"></div>
+
+ <div><object id="test4" data="1161752-4-embed.html" type="text/html" class="overlapping-green" onload="runTest4()">This test requires a browser with capability to embed an HTML document thanks to the HTML &lt;object&gt; element.</object></div>
+ <div class="red-overlapped-reference"></div>
+
+ <div><object id="test5" data="1161752-5-embed.html" type="text/html" class="overlapping-green">This test requires a browser with capability to embed an HTML document thanks to the HTML &lt;object&gt; element.</object></div>
+ <div class="red-overlapped-reference"></div>
+
+ </body>
+</html>
diff --git a/layout/reftests/bidi/1217833-1-ref.html b/layout/reftests/bidi/1217833-1-ref.html
new file mode 100644
index 0000000000..9ed72ef3dd
--- /dev/null
+++ b/layout/reftests/bidi/1217833-1-ref.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8" />
+<style>
+html, body { overflow:hidden }
+div{
+ background: yellow;
+ width:150px;
+ height:50px;
+ margin: 0 auto;
+ text-align:right;
+ color: blue;
+}
+</style>
+</head><body><div>test</div></body></html>
diff --git a/layout/reftests/bidi/1217833-1.html b/layout/reftests/bidi/1217833-1.html
new file mode 100644
index 0000000000..2a1eea3259
--- /dev/null
+++ b/layout/reftests/bidi/1217833-1.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html dir="rtl">
+<head>
+<meta charset="utf-8" />
+<style>
+html, body { overflow:hidden }
+div{
+ background: yellow;
+ width:150px;
+ height:50px;
+ margin: 0 auto;
+ text-align:right;
+}
+div:first-line {
+ color: blue;
+}
+</style>
+</head><body><div dir="rtl">test</div></body></html>
diff --git a/layout/reftests/bidi/1217833-2-ref.html b/layout/reftests/bidi/1217833-2-ref.html
new file mode 100644
index 0000000000..e328be5f97
--- /dev/null
+++ b/layout/reftests/bidi/1217833-2-ref.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8" />
+<style>
+html, body { overflow:hidden }
+div{
+ background: yellow;
+ width:150px;
+ height:50px;
+ margin: 0 auto;
+ text-align:right;
+ color: blue;
+ direction: ltr; unicode-bidi: bidi-override;
+}
+span {
+ background: aqua;
+ margin: 0 3px;
+}
+</style>
+</head><body><div dir="rtl">הקי<span>דב</span>te<span>st</span></div></body></html>
diff --git a/layout/reftests/bidi/1217833-2.html b/layout/reftests/bidi/1217833-2.html
new file mode 100644
index 0000000000..699947a2d3
--- /dev/null
+++ b/layout/reftests/bidi/1217833-2.html
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html dir="rtl">
+<head>
+<meta charset="utf-8" />
+<style>
+html, body { overflow:hidden }
+div{
+ background: yellow;
+ width:150px;
+ height:50px;
+ margin: 0 auto;
+ text-align:right;
+}
+div:first-line {
+ color: blue;
+}
+span {
+ background: aqua;
+ margin: 0 3px;
+ box-decoration-break: clone;
+}
+</style>
+</head><body><div dir="rtl">te<span>stבד</span>יקה</div></body></html>
diff --git a/layout/reftests/bidi/1231175-1-ref.html b/layout/reftests/bidi/1231175-1-ref.html
new file mode 100644
index 0000000000..b6238cf6be
--- /dev/null
+++ b/layout/reftests/bidi/1231175-1-ref.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<style>
+div { width: 200px; border: 1px solid blue; }
+span { direction: rtl; color: red; unicode-bidi: bidi-override; }
+</style>
+<body>
+<p>The number in the red text should read "18" in all cases.
+<div>
+<ol dir=rtl>
+<li><span>81 ديسمبر</span></li>
+<li><span>81 ديسمبر</span></li>
+<li><span>81 ديسمبر</span></li>
+<li><span>81 ديسمبر</span></li>
+<li><span>81 ديسمبر</span></li>
+<li><span>81 ديسمبر</span></li>
+<li><span>81 ديسمبر</span></li>
diff --git a/layout/reftests/bidi/1231175-1.html b/layout/reftests/bidi/1231175-1.html
new file mode 100644
index 0000000000..ebe0e26711
--- /dev/null
+++ b/layout/reftests/bidi/1231175-1.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<style>
+div { width: 200px; border: 1px solid blue; }
+span { direction: rtl; color: red; }
+</style>
+<body>
+<p>The number in the red text should read "18" in all cases.
+<div>
+<ol dir=rtl>
+<li><span style="unicode-bidi: normal">18 ديسمبر</span></li>
+<li><span style="unicode-bidi: embed">18 ديسمبر</span></li>
+<li><span style="unicode-bidi: isolate">18 ديسمبر</span></li>
+<li><span style="unicode-bidi: plaintext">18 ديسمبر</span></li>
+<li><span>&#x202B;18 ديسمبر&#x202C;</span></li>
+<li><span>&#x2067;18 ديسمبر&#x2069;</span></li>
+<li><span>&#x2068;18 ديسمبر&#x2069;</span></li>
diff --git a/layout/reftests/bidi/1366623-1-ref.html b/layout/reftests/bidi/1366623-1-ref.html
new file mode 100644
index 0000000000..f8d553a93b
--- /dev/null
+++ b/layout/reftests/bidi/1366623-1-ref.html
@@ -0,0 +1,16 @@
+<html class="reftest-wait">
+<meta charset=utf-8>
+<body>
+<div id="test" contenteditable>Example</div>
+<script>
+var elem = document.getElementById("test");
+var sel = window.getSelection();
+sel.removeAllRanges();
+var range = document.createRange();
+range.setStart(elem.firstChild, 1);
+range.setEnd(elem.firstChild, 1);
+sel.addRange(range);
+sel.removeAllRanges();
+elem.offsetHeight;
+document.documentElement.removeAttribute("class");
+</script>
diff --git a/layout/reftests/bidi/1366623-1.html b/layout/reftests/bidi/1366623-1.html
new file mode 100644
index 0000000000..a70d585181
--- /dev/null
+++ b/layout/reftests/bidi/1366623-1.html
@@ -0,0 +1,17 @@
+<html class="reftest-wait">
+<meta charset=utf-8>
+<body>
+<div id="test" contenteditable>E&#x202e;xample</div>
+<script>
+var elem = document.getElementById("test");
+var sel = window.getSelection();
+sel.removeAllRanges();
+var range = document.createRange();
+range.setStart(elem.firstChild, 1);
+range.setEnd(elem.firstChild, 2);
+sel.addRange(range);
+sel.deleteFromDocument();
+sel.removeAllRanges();
+elem.offsetHeight;
+document.documentElement.removeAttribute("class");
+</script>
diff --git a/layout/reftests/bidi/1426042-1-ref.html b/layout/reftests/bidi/1426042-1-ref.html
new file mode 100644
index 0000000000..e6c20e9277
--- /dev/null
+++ b/layout/reftests/bidi/1426042-1-ref.html
@@ -0,0 +1,61 @@
+<!DOCTYPE html>
+<html dir="rtl" lang="ar">
+<head>
+<meta http-equiv="content-type" content="text/html; charset=UTF-8">
+<meta charset="utf-8">
+<style>
+html[dir="rtl"] {
+ direction: rtl;
+}
+.outer {
+ border: 1px solid blue;
+ margin: 1em;
+ padding: 5px 0;
+ clear: left;
+ float: left;
+}
+.before {
+ margin-left: 20px;
+ border: 5px solid green;
+}
+.after {
+ margin-right: 20px;
+ border: 5px solid red;
+}
+.test1::before {
+ content: "";
+ margin-left: 20px;
+ border: 5px solid green;
+}
+.test1::after {
+ content: "";
+ margin-right: 20px;
+ border: 5px solid red;
+}
+.test2::before {
+ content: "\200b";
+ margin-left: 20px;
+ border: 5px solid green;
+}
+.test2::after {
+ content: "\200b";
+ margin-right: 20px;
+ border: 5px solid red;
+}
+</style>
+</head>
+<body>
+<div dir="ltr">
+The text in all three boxes should be centered, with a green bar to the far right and a red bar to the far left:
+</div>
+<div class="outer">
+ <div><span class="before"></span><span>السلام عليكم</span><span class="after"></span></div>
+</div>
+<div class="outer">
+ <div><span class="before"></span><span>السلام عليكم</span><span class="after"></span></div>
+</div>
+<div class="outer">
+ <div><span class="before"></span><span>السلام عليكم</span><span class="after"></span></div>
+</div>
+</body>
+</html>
diff --git a/layout/reftests/bidi/1426042-1.html b/layout/reftests/bidi/1426042-1.html
new file mode 100644
index 0000000000..724b720d50
--- /dev/null
+++ b/layout/reftests/bidi/1426042-1.html
@@ -0,0 +1,61 @@
+<!DOCTYPE html>
+<html dir="rtl" lang="ar">
+<head>
+<meta http-equiv="content-type" content="text/html; charset=UTF-8">
+<meta charset="utf-8">
+<style>
+html[dir="rtl"] {
+ direction: rtl;
+}
+.outer {
+ border: 1px solid blue;
+ margin: 1em;
+ padding: 5px 0;
+ clear: left;
+ float: left;
+}
+.before {
+ margin-left: 20px;
+ border: 5px solid green;
+}
+.after {
+ margin-right: 20px;
+ border: 5px solid red;
+}
+.test1::before {
+ content: "";
+ margin-left: 20px;
+ border: 5px solid green;
+}
+.test1::after {
+ content: "";
+ margin-right: 20px;
+ border: 5px solid red;
+}
+.test2::before {
+ content: "\200b";
+ margin-left: 20px;
+ border: 5px solid green;
+}
+.test2::after {
+ content: "\200b";
+ margin-right: 20px;
+ border: 5px solid red;
+}
+</style>
+</head>
+<body>
+<div dir="ltr">
+The text in all three boxes should be centered, with a green bar to the far right and a red bar to the far left:
+</div>
+<div class="outer">
+ <div><span class="before"></span><span>السلام عليكم</span><span class="after"></span></div>
+</div>
+<div class="outer">
+ <div class="test1"><span>السلام عليكم</span></div>
+</div>
+<div class="outer">
+ <div class="test2"><span>السلام عليكم</span></div>
+</div>
+</body>
+</html>
diff --git a/layout/reftests/bidi/151407-1-ref.html b/layout/reftests/bidi/151407-1-ref.html
new file mode 100644
index 0000000000..43ef5f3f8d
--- /dev/null
+++ b/layout/reftests/bidi/151407-1-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Test GetDir() for elements</title>
+ </head>
+ <body>
+ <div dir="">dir="", getDir returns ""</div>
+ <div dir="ltr">dir="ltr", getDir returns "ltr"</div>
+ <div dir="rtl">dir="rtl", getDir returns "rtl"</div>
+ <div dir="auto">dir="auto", getDir returns "auto"</div>
+ <div dir="foopy">dir="foopy", getDir returns ""</div>
+ <div>no dir attribute, getDir returns ""</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/151407-1.html b/layout/reftests/bidi/151407-1.html
new file mode 100644
index 0000000000..265c808152
--- /dev/null
+++ b/layout/reftests/bidi/151407-1.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Test GetDir() for elements</title>
+ <script type="text/javascript">
+function fill() {
+ for (var i = 0; ; ++i) {
+ div = document.getElementById("div" + i);
+ if (!div) break;
+ span = document.getElementById("span" + i);
+ span.innerHTML = div.dir;
+ }
+}
+ </script>
+ </head>
+ <body onLoad="fill()">
+ <div id="div0" dir="">dir="", getDir returns "<span id="span0"></span>"</div>
+ <div id="div1" dir="ltr">dir="ltr", getDir returns "<span id="span1"></span>"</div>
+ <div id="div2" dir="rtl">dir="rtl", getDir returns "<span id="span2"></span>"</div>
+ <div id="div3" dir="auto">dir="auto", getDir returns "<span id="span3"></span>"</div>
+ <div id="div4" dir="foopy">dir="foopy", getDir returns "<span id="span4"></span>"</div>
+ <div id="div5">no dir attribute, getDir returns "<span id="span5"></span>"</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/151407-1a.html b/layout/reftests/bidi/151407-1a.html
new file mode 100644
index 0000000000..2406dcf927
--- /dev/null
+++ b/layout/reftests/bidi/151407-1a.html
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Test GetDir() for elements</title>
+ <script type="text/javascript">
+function fill() {
+ div0.dir = "";
+ div1.dir = "ltr";
+ div2.dir = "rtl";
+ div3.dir = "auto";
+ div4.dir = "foopy";
+
+ for (var i = 0; ; ++i) {
+ div = document.getElementById("div" + i);
+ if (!div) break;
+ span = document.getElementById("span" + i);
+ span.innerHTML = div.dir;
+ }
+}
+ </script>
+ </head>
+ <body onLoad="fill()">
+ <div id="div0">dir="", getDir returns "<span id="span0"></span>"</div>
+ <div id="div1">dir="ltr", getDir returns "<span id="span1"></span>"</div>
+ <div id="div2">dir="rtl", getDir returns "<span id="span2"></span>"</div>
+ <div id="div3">dir="auto", getDir returns "<span id="span3"></span>"</div>
+ <div id="div4">dir="foopy", getDir returns "<span id="span4"></span>"</div>
+ <div id="div5">no dir attribute, getDir returns "<span id="span5"></span>"</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/151407-2-auto-ref.html b/layout/reftests/bidi/151407-2-auto-ref.html
new file mode 100644
index 0000000000..bd3b88b99a
--- /dev/null
+++ b/layout/reftests/bidi/151407-2-auto-ref.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html dir="auto">
+ <head>
+ <meta charset="utf-8">
+ <title>Test GetDir() for documents</title>
+ </head>
+ <body>
+ <div>getDir on document returns "auto"</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/151407-2-auto.html b/layout/reftests/bidi/151407-2-auto.html
new file mode 100644
index 0000000000..d1b04fd245
--- /dev/null
+++ b/layout/reftests/bidi/151407-2-auto.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html dir="auto">
+ <head>
+ <meta charset="utf-8">
+ <title>Test GetDir() for documents</title>
+ <script type="text/javascript">
+function fill() {
+ span = document.getElementById("span0");
+ span.innerHTML = document.dir;
+}
+ </script>
+ </head>
+ <body onLoad="fill()">
+ <div>getDir on document returns "<span id="span0"></span>"</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/151407-2-empty-ref.html b/layout/reftests/bidi/151407-2-empty-ref.html
new file mode 100644
index 0000000000..f3d1e3225d
--- /dev/null
+++ b/layout/reftests/bidi/151407-2-empty-ref.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Test GetDir() for documents</title>
+ </head>
+ <body>
+ <div>getDir on document returns ""</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/151407-2-empty.html b/layout/reftests/bidi/151407-2-empty.html
new file mode 100644
index 0000000000..284f9c6b6b
--- /dev/null
+++ b/layout/reftests/bidi/151407-2-empty.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Test GetDir() for documents</title>
+ <script type="text/javascript">
+function fill() {
+ span = document.getElementById("span0");
+ span.innerHTML = document.dir;
+}
+ </script>
+ </head>
+ <body onLoad="fill()">
+ <div>getDir on document returns "<span id="span0"></span>"</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/151407-2-foopy.html b/layout/reftests/bidi/151407-2-foopy.html
new file mode 100644
index 0000000000..71b5eb6b0c
--- /dev/null
+++ b/layout/reftests/bidi/151407-2-foopy.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html dir="foopy">
+ <head>
+ <meta charset="utf-8">
+ <title>Test GetDir() for documents</title>
+ <script type="text/javascript">
+function fill() {
+ span = document.getElementById("span0");
+ span.innerHTML = document.dir;
+}
+ </script>
+ </head>
+ <body onLoad="fill()">
+ <div>getDir on document returns "<span id="span0"></span>"</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/151407-2-ltr-ref.html b/layout/reftests/bidi/151407-2-ltr-ref.html
new file mode 100644
index 0000000000..993afae238
--- /dev/null
+++ b/layout/reftests/bidi/151407-2-ltr-ref.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Test GetDir() for documents</title>
+ </head>
+ <body>
+ <div>getDir on document returns "ltr"</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/151407-2-ltr.html b/layout/reftests/bidi/151407-2-ltr.html
new file mode 100644
index 0000000000..09ebdfed7c
--- /dev/null
+++ b/layout/reftests/bidi/151407-2-ltr.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html dir="ltr">
+ <head>
+ <meta charset="utf-8">
+ <title>Test GetDir() for documents</title>
+ <script type="text/javascript">
+function fill() {
+ span = document.getElementById("span0");
+ span.innerHTML = document.dir;
+}
+ </script>
+ </head>
+ <body onLoad="fill()">
+ <div>getDir on document returns "<span id="span0"></span>"</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/151407-2-rtl-ref.html b/layout/reftests/bidi/151407-2-rtl-ref.html
new file mode 100644
index 0000000000..bec0509f01
--- /dev/null
+++ b/layout/reftests/bidi/151407-2-rtl-ref.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html dir="rtl">
+ <head>
+ <meta charset="utf-8">
+ <title>Test GetDir() for documents</title>
+ </head>
+ <body>
+ <div>getDir on document returns "rtl"</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/151407-2-rtl.html b/layout/reftests/bidi/151407-2-rtl.html
new file mode 100644
index 0000000000..d11378d162
--- /dev/null
+++ b/layout/reftests/bidi/151407-2-rtl.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html dir="rtl">
+ <head>
+ <meta charset="utf-8">
+ <title>Test GetDir() for documents</title>
+ <script type="text/javascript">
+function fill() {
+ span = document.getElementById("span0");
+ span.innerHTML = document.dir;
+}
+ </script>
+ </head>
+ <body onLoad="fill()">
+ <div>getDir on document returns "<span id="span0"></span>"</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/151407-3-auto-ref.html b/layout/reftests/bidi/151407-3-auto-ref.html
new file mode 100644
index 0000000000..3f1241e320
--- /dev/null
+++ b/layout/reftests/bidi/151407-3-auto-ref.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Test SetDir() for documents</title>
+ </head>
+ <body>
+ <div>getDir on document after setDir returns "auto"</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/151407-3-auto.html b/layout/reftests/bidi/151407-3-auto.html
new file mode 100644
index 0000000000..982c5348f7
--- /dev/null
+++ b/layout/reftests/bidi/151407-3-auto.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html dir="rtl">
+ <head>
+ <meta charset="utf-8">
+ <title>Test SetDir() for documents</title>
+ <script type="text/javascript">
+function fill() {
+ document.dir = "auto"
+ span = document.getElementById("span0");
+ span.innerHTML = document.dir;
+}
+ </script>
+ </head>
+ <body onLoad="fill()">
+ <div>getDir on document after setDir returns "<span id="span0"></span>"</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/151407-3-empty-ref.html b/layout/reftests/bidi/151407-3-empty-ref.html
new file mode 100644
index 0000000000..d0feebc956
--- /dev/null
+++ b/layout/reftests/bidi/151407-3-empty-ref.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Test SetDir() for documents</title>
+ </head>
+ <body>
+ <div>getDir on document after setDir returns ""</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/151407-3-foopy.html b/layout/reftests/bidi/151407-3-foopy.html
new file mode 100644
index 0000000000..c77596824b
--- /dev/null
+++ b/layout/reftests/bidi/151407-3-foopy.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html dir="rtl">
+ <head>
+ <meta charset="utf-8">
+ <title>Test SetDir() for documents</title>
+ <script type="text/javascript">
+function fill() {
+ document.dir = "foopy"
+ span = document.getElementById("span0");
+ span.innerHTML = document.dir;
+}
+ </script>
+ </head>
+ <body onLoad="fill()">
+ <div>getDir on document after setDir returns "<span id="span0"></span>"</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/151407-3-ltr-ref.html b/layout/reftests/bidi/151407-3-ltr-ref.html
new file mode 100644
index 0000000000..9cf5539e27
--- /dev/null
+++ b/layout/reftests/bidi/151407-3-ltr-ref.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Test SetDir() for documents</title>
+ </head>
+ <body>
+ <div>getDir on document after setDir returns "ltr"</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/151407-3-ltr.html b/layout/reftests/bidi/151407-3-ltr.html
new file mode 100644
index 0000000000..e043d489e3
--- /dev/null
+++ b/layout/reftests/bidi/151407-3-ltr.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html dir="rtl">
+ <head>
+ <meta charset="utf-8">
+ <title>Test SetDir() for documents</title>
+ <script type="text/javascript">
+function fill() {
+ document.dir = "ltr"
+ span = document.getElementById("span0");
+ span.innerHTML = document.dir;
+}
+ </script>
+ </head>
+ <body onLoad="fill()">
+ <div>getDir on document after setDir returns "<span id="span0"></span>"</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/151407-3-rtl-ref.html b/layout/reftests/bidi/151407-3-rtl-ref.html
new file mode 100644
index 0000000000..884a542176
--- /dev/null
+++ b/layout/reftests/bidi/151407-3-rtl-ref.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html dir="rtl">
+ <head>
+ <meta charset="utf-8">
+ <title>Test SetDir() for documents</title>
+ </head>
+ <body>
+ <div>getDir on document after setDir returns "rtl"</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/151407-3-rtl.html b/layout/reftests/bidi/151407-3-rtl.html
new file mode 100644
index 0000000000..781cd6f795
--- /dev/null
+++ b/layout/reftests/bidi/151407-3-rtl.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html dir="ltr">
+ <head>
+ <meta charset="utf-8">
+ <title>Test SetDir() for documents</title>
+ <script type="text/javascript">
+function fill() {
+ document.dir = "rtl"
+ span = document.getElementById("span0");
+ span.innerHTML = document.dir;
+}
+ </script>
+ </head>
+ <body onLoad="fill()">
+ <div>getDir on document after setDir returns "<span id="span0"></span>"</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/1556414-1-ref.html b/layout/reftests/bidi/1556414-1-ref.html
new file mode 100644
index 0000000000..d42da153c6
--- /dev/null
+++ b/layout/reftests/bidi/1556414-1-ref.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+ <meta charset="utf-8"/>
+</head>
+<body>
+ <span>בדיקה</span>
+</body>
+</html>
diff --git a/layout/reftests/bidi/1556414-1.html b/layout/reftests/bidi/1556414-1.html
new file mode 100644
index 0000000000..474b112388
--- /dev/null
+++ b/layout/reftests/bidi/1556414-1.html
@@ -0,0 +1,24 @@
+<html>
+<head>
+ <meta charset="utf-8"/>
+</head>
+<body>
+ <custom-span text="בדיקה"></custom-span>
+</body>
+<script>
+ class CustomSpan extends HTMLElement {
+ constructor() {
+ super();
+
+ var shadow = this.attachShadow({ mode: 'open' });
+
+ const span = document.createElement('span');
+ span.innerText = this.getAttribute('text');
+
+ shadow.appendChild(span);
+ }
+ }
+
+ window.customElements.define('custom-span', CustomSpan);
+</script>
+</html>
diff --git a/layout/reftests/bidi/1567036-1-ref.html b/layout/reftests/bidi/1567036-1-ref.html
new file mode 100644
index 0000000000..49c52950d4
--- /dev/null
+++ b/layout/reftests/bidi/1567036-1-ref.html
@@ -0,0 +1,14 @@
+<!DOCTYPE HTML>
+<meta charset="UTF-8">
+<title>Reftest Reference</title>
+<style>
+
+p { unicode-bidi: bidi-override }
+.b { border: thin solid blue }
+
+</style>
+
+<p>
+<span class="b" style="border-right: none">ABC</span>&#x5d2;<span class="b" style="border-left: none">&#x5d1;&#x5d0;</span><br>
+ABC
+</p>
diff --git a/layout/reftests/bidi/1567036-1.html b/layout/reftests/bidi/1567036-1.html
new file mode 100644
index 0000000000..9f0825fedd
--- /dev/null
+++ b/layout/reftests/bidi/1567036-1.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML>
+<meta charset="UTF-8">
+<title>Testcase for needing aBpd->mPrevFrame = nullptr after SplitInlineAncestors call</title>
+<style>
+
+.b { border: thin solid blue }
+
+</style>
+
+<p>
+<span class="b"><span>ABC</span><span>&#x5d0;&#x5d1;</span></span>&#x5d2;<br>
+ABC
+</p>
diff --git a/layout/reftests/bidi/229367-1-ref.html b/layout/reftests/bidi/229367-1-ref.html
new file mode 100644
index 0000000000..5e30c4a7ec
--- /dev/null
+++ b/layout/reftests/bidi/229367-1-ref.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>br-as-bidi-paragraph-break</title>
+ <meta charset="UTF-8">
+ </head>
+ <body>
+ <p>&#x05D0; --&gt;&lrm;<br>--&gt; &#x05D1;</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/229367-1.html b/layout/reftests/bidi/229367-1.html
new file mode 100644
index 0000000000..079eb18c6b
--- /dev/null
+++ b/layout/reftests/bidi/229367-1.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>br-as-bidi-paragraph-break</title>
+ <meta charset="UTF-8">
+ </head>
+ <body>
+ <p>&#x05D0; --&gt;<br>--&gt; &#x05D1;</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/229367-2-ref.html b/layout/reftests/bidi/229367-2-ref.html
new file mode 100644
index 0000000000..5d8b606c43
--- /dev/null
+++ b/layout/reftests/bidi/229367-2-ref.html
@@ -0,0 +1,43 @@
+<DOCTYPE html>
+<html DIR=RTL>
+ <head>
+ <meta charset=UTF-8>
+ <title>BIDI Layout Testing</title>
+ </head>
+ <body>
+ <h2>This is a testing for BiDi layout issues.</h2>
+<br>
+
+1 - No tag<br>
+2 - SPAN<br>
+3 - P<br>
+4 - DIV<br>
+
+<br>
+<b>Test1: No space</b><br>
+This is a testing for BiDi layout issues.&rlm;<br>
+<span>This is a testing for BiDi layout issues.&rlm;<br></span>
+<p>This is a testing for BiDi layout issues.&rlm;<br></p>
+<div>This is a testing for BiDi layout issues.&rlm;<br></div>
+<br><br>
+<b>Test2: 3 spaces at the end</b><br>
+This is a testing for BiDi layout issues.&rlm;&nbsp;&nbsp;&nbsp;<br>
+<span>This is a testing for BiDi layout issues.&rlm;&nbsp;&nbsp;&nbsp;<br></span>
+
+<p>This is a testing for BiDi layout issues.&rlm;&nbsp;&nbsp;&nbsp;<br></p>
+<div>This is a testing for BiDi layout issues.&rlm;&nbsp;&nbsp;&nbsp;<br></div>
+<br><br>
+<b>Test3: 3 spaces at the beginning</b><br>
+&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.&rlm;<br>
+<span>&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.&rlm;<br></span>
+<p>&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.&rlm;<br></p>
+<div>&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.&rlm;<br></div>
+<br><br>
+
+<b>Test4: 3 spaces at the end and the beginning</b><br>
+&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.&rlm;&nbsp;&nbsp;&nbsp;<br>
+<span>&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.&rlm;&nbsp;&nbsp;&nbsp;<br></span>
+<p>&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.&rlm;&nbsp;&nbsp;&nbsp;<br></p>
+<div>&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.&rlm;&nbsp;&nbsp;&nbsp;<br></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/229367-2.html b/layout/reftests/bidi/229367-2.html
new file mode 100644
index 0000000000..5c7a2a97c5
--- /dev/null
+++ b/layout/reftests/bidi/229367-2.html
@@ -0,0 +1,43 @@
+<DOCTYPE html>
+<html DIR=RTL>
+ <head>
+ <meta charset=UTF-8>
+ <title>BIDI Layout Testing</title>
+ </head>
+ <body>
+ <h2>This is a testing for BiDi layout issues.</h2>
+<br>
+
+1 - No tag<br>
+2 - SPAN<br>
+3 - P<br>
+4 - DIV<br>
+
+<br>
+<b>Test1: No space</b><br>
+This is a testing for BiDi layout issues.<br>
+<span>This is a testing for BiDi layout issues.<br></span>
+<p>This is a testing for BiDi layout issues.<br></p>
+<div>This is a testing for BiDi layout issues.<br></div>
+<br><br>
+<b>Test2: 3 spaces at the end</b><br>
+This is a testing for BiDi layout issues.&nbsp;&nbsp;&nbsp;<br>
+<span>This is a testing for BiDi layout issues.&nbsp;&nbsp;&nbsp;<br></span>
+
+<p>This is a testing for BiDi layout issues.&nbsp;&nbsp;&nbsp;<br></p>
+<div>This is a testing for BiDi layout issues.&nbsp;&nbsp;&nbsp;<br></div>
+<br><br>
+<b>Test3: 3 spaces at the beginning</b><br>
+&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.<br>
+<span>&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.<br></span>
+<p>&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.<br></p>
+<div>&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.<br></div>
+<br><br>
+
+<b>Test4: 3 spaces at the end and the beginning</b><br>
+&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.&nbsp;&nbsp;&nbsp;<br>
+<span>&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.&nbsp;&nbsp;&nbsp;<br></span>
+<p>&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.&nbsp;&nbsp;&nbsp;<br></p>
+<div>&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.&nbsp;&nbsp;&nbsp;<br></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/229367-3-ref.html b/layout/reftests/bidi/229367-3-ref.html
new file mode 100644
index 0000000000..2f2baf913b
--- /dev/null
+++ b/layout/reftests/bidi/229367-3-ref.html
@@ -0,0 +1,35 @@
+<DOCTYPE html>
+<!-- This tests that embeddings and overrides are preserved after <br> -->
+<html>
+ <head>
+ <meta charset=UTF-8>
+ <title>Bug 229367</title>
+ <style type="text/css">
+ p { margin: 0; text-align: left; }
+ p.er { unicode-bidi: embed; direction: rtl; }
+ p.ol { unicode-bidi: bidi-override; direction: ltr; }
+ p.or { unicode-bidi: bidi-override; direction: rtl; }
+ </style>
+ </head>
+ <body>
+ <p>במה מדליקין,</p>
+ <p>ובמה אין מדליקין?</p>
+ <p class="er">אין מדליקין לא בלכש, </p>
+ <p class="er">ולא בחוסן, </p>
+ <p class="er">ולא בכלך, </p>
+ <p class="er">ולא בפתילת האידן, </p>
+ <p class="ol">ולא בפתילת המדבר, </p>
+ <p class="ol">ולא בירוקה שעל פני המים. </p>
+ <p class="ol">לא בזפת, </p>
+ <p class="or">ולא בשעווה, </p>
+ <p class="or">ולא בשמן קיק, </p>
+ <p class="or">ולא בשמן שריפה, </p>
+ <p class="or">ולא באליה, </p>
+ <p class="ol">ולא בחלב. </p>
+ <p class="ol">נחום המדי אומר, </p>
+ <p class="er">מדליקין בחלב מבושל;</p>
+ <p class="er">וחכמים אומרים, </p>
+ <p>אחד מבושל ואחד שאינו מבושל,</p>
+ <p>אין מדליקין בו.</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/229367-3.html b/layout/reftests/bidi/229367-3.html
new file mode 100644
index 0000000000..1ea70e3b1d
--- /dev/null
+++ b/layout/reftests/bidi/229367-3.html
@@ -0,0 +1,30 @@
+<DOCTYPE html>
+<!-- This tests that embeddings and overrides are preserved after <br> -->
+<html>
+ <head>
+ <meta charset=UTF-8>
+ <title>Bug 229367</title>
+ </head>
+ <body>
+ <div>במה מדליקין,<br>
+ובמה אין מדליקין?<br>
+<span style="unicode-bidi: embed; direction: rtl">אין מדליקין לא בלכש, <br>
+ולא בחוסן, <br>
+ולא בכלך, <br>
+ולא בפתילת האידן, <br>
+<span style="unicode-bidi: bidi-override; direction: ltr">ולא בפתילת המדבר, <br>
+ולא בירוקה שעל פני המים. <br>
+לא בזפת, <br>
+<span style="unicode-bidi: bidi-override; direction: rtl">ולא בשעווה, <br>
+ולא בשמן קיק, <br>
+ולא בשמן שריפה, <br>
+ולא באליה, <br></span>
+ולא בחלב. <br>
+נחום המדי אומר, <br></span>
+מדליקין בחלב מבושל; <br>
+וחכמים אומרים, <br></span>
+אחד מבושל ואחד שאינו מבושל,<br>
+אין מדליקין בו.
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/258928-1-ref.html b/layout/reftests/bidi/258928-1-ref.html
new file mode 100644
index 0000000000..6a3c7d8648
--- /dev/null
+++ b/layout/reftests/bidi/258928-1-ref.html
@@ -0,0 +1,50 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <title>RTL list displayed as inline broken</title>
+ <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
+ <style type="text/css">
+ul {
+ padding: 3px 10px;
+ border-bottom: 3px solid #4949A9;
+ white-space: nowrap;
+ font-size: 13px;
+}
+
+ul li {
+ display: inline;
+ margin: 0;
+ padding: 3px 10px;
+ border-top: 1px solid gray;
+ border-right: 1px solid gray;
+ border-left: 1px solid gray;
+ background-color: #f0f0f0;
+}
+ </style>
+ </head>
+ <body>
+ <h1>Broken RTL list when displayed as inline</h1>
+ <h2>One Item</h2>
+ <ul class="tabs">
+ <li>Tab</li>
+ </ul>
+ <h2>Two Items</h2>
+ <ul class="tabs">
+ <li>Tab</li>
+ <li>Tab</li>
+ </ul>
+ <h2>Many</h2>
+ <ul class="tabs">
+ <li>Tab</li>
+ <li>Tab</li>
+ <li>Tab</li>
+ <li>Tab</li>
+ <li>Tab</li>
+ <li>Tab</li>
+ <li>Tab</li>
+ <li>Tab</li>
+ <li>Tab</li>
+ <li>Tab</li>
+ </ul>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/258928-1.html b/layout/reftests/bidi/258928-1.html
new file mode 100644
index 0000000000..224d0011fe
--- /dev/null
+++ b/layout/reftests/bidi/258928-1.html
@@ -0,0 +1,52 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <title>RTL list displayed as inline broken</title>
+ <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
+ <style type="text/css">
+ul {
+ padding: 3px 10px;
+ border-bottom: 3px solid #4949A9;
+ white-space: nowrap;
+ font-size: 13px;
+ direction: rtl;
+ text-align: left;
+}
+
+ul li {
+ display: inline;
+ margin: 0;
+ padding: 3px 10px;
+ border-top: 1px solid gray;
+ border-right: 1px solid gray;
+ border-left: 1px solid gray;
+ background-color: #f0f0f0;
+}
+ </style>
+ </head>
+ <body>
+ <h1>Broken RTL list when displayed as inline</h1>
+ <h2>One Item</h2>
+ <ul class="tabs">
+ <li>Tab</li>
+ </ul>
+ <h2>Two Items</h2>
+ <ul class="tabs">
+ <li>Tab</li>
+ <li>Tab</li>
+ </ul>
+ <h2>Many</h2>
+ <ul class="tabs">
+ <li>Tab</li>
+ <li>Tab</li>
+ <li>Tab</li>
+ <li>Tab</li>
+ <li>Tab</li>
+ <li>Tab</li>
+ <li>Tab</li>
+ <li>Tab</li>
+ <li>Tab</li>
+ <li>Tab</li>
+ </ul>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/263359-1-ref.html b/layout/reftests/bidi/263359-1-ref.html
new file mode 100644
index 0000000000..203a055e5f
--- /dev/null
+++ b/layout/reftests/bidi/263359-1-ref.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>preformatted-paragraph-break-as-bidi-paragraph-break</title>
+ <meta charset="UTF-8">
+ </head>
+ <body>
+ <pre>&#x05D0; --&gt;&lrm;
+--&gt; &#x05D1;</pre>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/263359-1.html b/layout/reftests/bidi/263359-1.html
new file mode 100644
index 0000000000..71f78338c4
--- /dev/null
+++ b/layout/reftests/bidi/263359-1.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>preformatted-paragraph-break-as-bidi-paragraph-break</title>
+ <meta charset="UTF-8">
+ </head>
+ <body>
+ <pre>&#x05D0; --&gt;
+--&gt; &#x05D1;</pre>
+</body>
+</html>
+
diff --git a/layout/reftests/bidi/263359-1a.html b/layout/reftests/bidi/263359-1a.html
new file mode 100644
index 0000000000..11cc5cd821
--- /dev/null
+++ b/layout/reftests/bidi/263359-1a.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>preformatted-paragraph-break-as-bidi-paragraph-break</title>
+ <meta charset="UTF-8">
+<script type="text/javascript">
+
+function boom()
+{
+ document.getElementById("w").style.whiteSpace="pre";
+}
+
+</script>
+ </head>
+ <body onload="boom();">
+ <pre id="w" style="white-space: normal">&#x05D0; --&gt;
+--&gt; &#x05D1;</pre>
+</body>
+</html>
+
diff --git a/layout/reftests/bidi/263359-1b.html b/layout/reftests/bidi/263359-1b.html
new file mode 100644
index 0000000000..029384af8a
--- /dev/null
+++ b/layout/reftests/bidi/263359-1b.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>preformatted-paragraph-break-as-bidi-paragraph-break</title>
+ <meta charset="UTF-8">
+<script type="text/javascript">
+
+function boom()
+{
+ document.getElementById("w").style.whiteSpace="normal";
+}
+
+</script>
+ </head>
+ <body onload="boom();">
+ <pre id="w">&#x05D0; --&gt;
+--&gt; &#x05D1;</pre>
+</body>
+</html>
+
diff --git a/layout/reftests/bidi/263359-2-ref.html b/layout/reftests/bidi/263359-2-ref.html
new file mode 100644
index 0000000000..bca0323d6e
--- /dev/null
+++ b/layout/reftests/bidi/263359-2-ref.html
@@ -0,0 +1,47 @@
+<DOCTYPE html>
+<html DIR=RTL>
+ <head>
+ <meta charset=UTF-8>
+ <title>BIDI Layout Testing</title>
+ </head>
+ <body>
+ <div style="white-space: pre">
+<b>Test1: No space</b>
+This is a testing for BiDi layout issues. &rlm;
+<span>This is a testing for BiDi layout issues.&rlm;
+</span>
+<p>This is a testing for BiDi layout issues.&rlm;
+</p>
+<div>This is a testing for BiDi layout issues.&rlm;
+</div>
+
+<b>Test2: 3 spaces at the end</b>
+This is a testing for BiDi layout issues.&rlm;&nbsp;&nbsp;&nbsp;
+<span>This is a testing for BiDi layout issues.&rlm;&nbsp;&nbsp;&nbsp;
+</span>
+
+<p>This is a testing for BiDi layout issues.&rlm;&nbsp;&nbsp;&nbsp;
+</p>
+<div>This is a testing for BiDi layout issues.&rlm;&nbsp;&nbsp;&nbsp;
+</div>
+
+<b>Test3: 3 spaces at the beginning</b>
+&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.&rlm;
+<span>&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.&rlm;
+</span>
+<p>&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.&rlm;
+</p>
+<div>&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.&rlm;
+</div>
+
+<b>Test4: 3 spaces at the end and the beginning</b>
+&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.&rlm;&nbsp;&nbsp;&nbsp;
+<span>&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.&rlm;&nbsp;&nbsp;&nbsp;
+</span>
+<p>&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.&rlm;&nbsp;&nbsp;&nbsp;
+</p>
+<div>&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.&rlm;&nbsp;&nbsp;&nbsp;
+</div>
+</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/263359-2.html b/layout/reftests/bidi/263359-2.html
new file mode 100644
index 0000000000..9e6ab5ed47
--- /dev/null
+++ b/layout/reftests/bidi/263359-2.html
@@ -0,0 +1,46 @@
+<DOCTYPE html>
+<html DIR=RTL>
+ <head>
+ <meta charset=UTF-8>
+ <title>BIDI Layout Testing</title>
+ </head>
+ <body>
+ <div style="white-space: pre">
+<b>Test1: No space</b>
+This is a testing for BiDi layout issues.
+<span>This is a testing for BiDi layout issues.
+</span>
+<p>This is a testing for BiDi layout issues.
+</p>
+<div>This is a testing for BiDi layout issues.</div>
+
+<b>Test2: 3 spaces at the end</b>
+This is a testing for BiDi layout issues.&nbsp;&nbsp;&nbsp;
+<span>This is a testing for BiDi layout issues.&nbsp;&nbsp;&nbsp;
+</span>
+
+<p>This is a testing for BiDi layout issues.&nbsp;&nbsp;&nbsp;
+</p>
+<div>This is a testing for BiDi layout issues.&nbsp;&nbsp;&nbsp;
+</div>
+
+<b>Test3: 3 spaces at the beginning</b>
+&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.
+<span>&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.
+</span>
+<p>&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.
+</p>
+<div>&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.
+</div>
+
+<b>Test4: 3 spaces at the end and the beginning</b>
+&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.&nbsp;&nbsp;&nbsp;
+<span>&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.&nbsp;&nbsp;&nbsp;
+</span>
+<p>&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.&nbsp;&nbsp;&nbsp;
+</p>
+<div>&nbsp;&nbsp;&nbsp;This is a testing for BiDi layout issues.&nbsp;&nbsp;&nbsp;
+</div>
+</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/263359-3-ref.html b/layout/reftests/bidi/263359-3-ref.html
new file mode 100644
index 0000000000..92e017b713
--- /dev/null
+++ b/layout/reftests/bidi/263359-3-ref.html
@@ -0,0 +1,35 @@
+<DOCTYPE html>
+<!-- This tests that embeddings and overrides are preserved after <br> -->
+<html>
+ <head>
+ <meta charset=UTF-8>
+ <title>Bug 263359</title>
+ <style type="text/css">
+ p { margin: 0; text-align: left; white-space: pre }
+ p.er { direction: rtl; }
+ p.ol { unicode-bidi: bidi-override; direction: ltr; }
+ p.or { unicode-bidi: bidi-override; direction: rtl; }
+ </style>
+ </head>
+ <body>
+<p>במה מדליקין,</p>
+<p>ובמה אין מדליקין?</p>
+<p class="er">אין מדליקין לא בלכש,</p>
+<p class="er">ולא בחוסן,</p>
+<p class="er">ולא בכלך,</p>
+<p class="er">ולא בפתילת האידן,</p>
+<p class="ol">ולא בפתילת המדבר,</p>
+<p class="ol">ולא בירוקה שעל פני המים.</p>
+<p class="ol">לא בזפת,</p>
+<p class="or">ולא בשעווה,</p>
+<p class="or">ולא בשמן קיק,</p>
+<p class="or">ולא בשמן שריפה,</p>
+<p class="or">ולא באליה,</p>
+<p class="ol">ולא בחלב.</p>
+<p class="ol">נחום המדי אומר,</p>
+<p class="er">מדליקין בחלב מבושל;</p>
+<p class="er">וחכמים אומרים,</p>
+<p>אחד מבושל ואחד שאינו מבושל,</p>
+<p>אין מדליקין בו.</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/263359-3.html b/layout/reftests/bidi/263359-3.html
new file mode 100644
index 0000000000..b225517bdd
--- /dev/null
+++ b/layout/reftests/bidi/263359-3.html
@@ -0,0 +1,36 @@
+<DOCTYPE html>
+<!-- This tests that embeddings and overrides are preserved in <pre> -->
+<html>
+ <head>
+ <meta charset=UTF-8>
+ <title>Bug 263359</title>
+ <style type="text/css">
+ p {
+ white-space: pre;
+ margin: 0;
+ }
+ </style>
+ </head>
+ <body>
+ <p style="">במה מדליקין,
+ובמה אין מדליקין?
+<span dir="rtl">אין מדליקין לא בלכש,
+ולא בחוסן,
+ולא בכלך,
+ולא בפתילת האידן,
+<span style="unicode-bidi: bidi-override; direction: ltr">ולא בפתילת המדבר,
+ולא בירוקה שעל פני המים.
+לא בזפת,
+<span style="unicode-bidi: bidi-override; direction: rtl">ולא בשעווה,
+ולא בשמן קיק,
+ולא בשמן שריפה,
+ולא באליה, </span>
+ולא בחלב.
+נחום המדי אומר, </span>
+מדליקין בחלב מבושל;
+וחכמים אומרים, </span>
+אחד מבושל ואחד שאינו מבושל,
+אין מדליקין בו.
+ </pre>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/263359-4-ref.html b/layout/reftests/bidi/263359-4-ref.html
new file mode 100644
index 0000000000..e155f79d43
--- /dev/null
+++ b/layout/reftests/bidi/263359-4-ref.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>change direction of pre with bidi text</title>
+ <meta charset="UTF-8">
+ </head>
+ <body>
+ <pre dir="rtl"> can_be_executable=TRUE
+ [he]description=סוג לא ידוע
+ description=Unknown type
+ [ar]description=نوع غير معروف
+ [az]description=Namə'lum növ
+</pre>
+</body>
+</html>
+
diff --git a/layout/reftests/bidi/263359-4.html b/layout/reftests/bidi/263359-4.html
new file mode 100644
index 0000000000..d766c862c6
--- /dev/null
+++ b/layout/reftests/bidi/263359-4.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>change direction of pre with bidi text</title>
+ <meta charset="UTF-8">
+<script type="text/javascript">
+
+function boom()
+{
+ document.getElementById("w").style.direction="rtl";
+}
+
+</script>
+ </head>
+ <body onload="boom();">
+ <pre id="w"> can_be_executable=TRUE
+ [he]description=סוג לא ידוע
+ description=Unknown type
+ [ar]description=نوع غير معروف
+ [az]description=Namə'lum növ
+</pre>
+</body>
+</html>
+
diff --git a/layout/reftests/bidi/267459-1-ref.html b/layout/reftests/bidi/267459-1-ref.html
new file mode 100644
index 0000000000..467a4eb445
--- /dev/null
+++ b/layout/reftests/bidi/267459-1-ref.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Test unicode-bidi in form controls</title>
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8">
+ </head>
+ <body>
+ <p dir="rtl">&#x202e;This paragraph should appear backwards&#x202c;</p>
+ <p>
+ <textarea rows="3" cols="80" dir="rtl" style="resize:none">&#x202e;This textarea should appear backwards&#x202c;</textarea><br>
+ <input type="text" size="80" dir="rtl" value="&#x202e;This input should appear backwards&#x202c;"><br>
+ <input type="button" dir="rtl" value="&#x202e;This button should appear backwards&#x202c;"><br>
+ <select dir="rtl" size="6">
+ <option selected>&#x202e;This&#x202c;</option>
+ <optgroup label="&#x202e;select&#x202c;">
+ <option>&#x202e;should&#x202c;</option>
+ <option>&#x202e;appear&#x202c;</option>
+ </optgroup>
+ <optgroup label="&#x202e;backwards&#x202c;">
+ <option>&#x202e;throughout&#x202c;</option>
+ </optgroup>
+ </select><br>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/267459-1.html b/layout/reftests/bidi/267459-1.html
new file mode 100644
index 0000000000..5caf199f0e
--- /dev/null
+++ b/layout/reftests/bidi/267459-1.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Test unicode-bidi in form controls</title>
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8">
+ <style type="text/css">
+ .reversed {
+ direction: rtl;
+ unicode-bidi: bidi-override;
+ }
+ </style>
+ </head>
+ <body>
+ <p class="reversed">This paragraph should appear backwards</p>
+ <p>
+ <textarea class="reversed" rows="3" cols="80" style="resize:none">This textarea should appear backwards</textarea><br>
+ <input class="reversed" type="text" size="80" value="This input should appear backwards"><br>
+ <input class="reversed" type="button" value="This button should appear backwards"><br>
+ <select size="6" class="reversed">
+ <option selected class="reversed">This</option>
+ <optgroup class="reversed" label="select">
+ <option class="reversed">should</option>
+ <option class="reversed">appear</option>
+ </optgroup>
+ <optgroup class="reversed" label="backwards">
+ <option class="reversed">throughout</option>
+ </optgroup>
+ </select><br>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/267459-2-ref.html b/layout/reftests/bidi/267459-2-ref.html
new file mode 100644
index 0000000000..e2a023b530
--- /dev/null
+++ b/layout/reftests/bidi/267459-2-ref.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Test unicode-bidi in form controls</title>
+ <meta http-equiv="Content-type" content="text/html; charset=iso-8859-8-i">
+ </head>
+ <body>
+ <p>&#x202d; &#x202c;</p>
+ <p>
+ <textarea rows="3" cols="80"> </textarea><br>
+ <input type="text" size="80" value=" "><br>
+ <input type="button" value=" "><br>
+ <select size="6">
+ <option selected></option>
+ <optgroup label="">
+ <option></option>
+ <option></option>
+ </optgroup>
+ <optgroup label="">
+ <option></option>
+ </optgroup>
+ </select><br>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/267459-2.html b/layout/reftests/bidi/267459-2.html
new file mode 100644
index 0000000000..9529b32b05
--- /dev/null
+++ b/layout/reftests/bidi/267459-2.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Test unicode-bidi in form controls</title>
+ <meta http-equiv="Content-type" content="text/html; charset=iso-8859-8">
+ </head>
+ <body>
+ <p> </p>
+ <p>
+ <textarea rows="3" cols="80"> </textarea><br>
+ <input type="text" size="80" value=" "><br>
+ <input type="button" value=" "><br>
+ <select size="6">
+ <option selected></option>
+ <optgroup label="">
+ <option></option>
+ <option></option>
+ </optgroup>
+ <optgroup label="">
+ <option></option>
+ </optgroup>
+ </select><br>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/299065-1-ref.html b/layout/reftests/bidi/299065-1-ref.html
new file mode 100644
index 0000000000..e836a04d1d
--- /dev/null
+++ b/layout/reftests/bidi/299065-1-ref.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
+<html lang="en">
+ <head>
+ <title>Testcase, bug 299065</title>
+ <style type="text/css">
+ p { border: thin solid; background: aqua; color: blue; }
+ span { background: yellow; color: olive; }
+ </style>
+ </head>
+ <body>
+ <p>AA<span>AA</span><span>&#x5D0;&#x5D0;</span>&#x5D0;&#x5D0;</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/299065-1.html b/layout/reftests/bidi/299065-1.html
new file mode 100644
index 0000000000..ca55830271
--- /dev/null
+++ b/layout/reftests/bidi/299065-1.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
+<html lang="en">
+ <head>
+ <title>Testcase, bug 299065</title>
+ <style type="text/css">
+ p { border: thin solid; background: aqua; color: blue; }
+ span { background: yellow; color: olive; }
+ </style>
+ </head>
+ <body>
+ <p>AA<span>AA&#x5D0;&#x5D0;</span>&#x5D0;&#x5D0;</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/305643-1-ref.html b/layout/reftests/bidi/305643-1-ref.html
new file mode 100644
index 0000000000..ff8f064149
--- /dev/null
+++ b/layout/reftests/bidi/305643-1-ref.html
@@ -0,0 +1,17 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="iso-8859-8-i">
+ </head>
+ <body>
+ <table>
+ <tbody>
+ <tr>
+ <td dir="rtl" align="right">
+ <span style="unicode-bidi: bidi-override; font-size: 12px;">(: 20:52) : </span>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/305643-1.html b/layout/reftests/bidi/305643-1.html
new file mode 100644
index 0000000000..85562ab34b
--- /dev/null
+++ b/layout/reftests/bidi/305643-1.html
@@ -0,0 +1,17 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="iso-8859-8">
+ </head>
+ <body>
+ <table>
+ <tbody>
+ <tr>
+ <td dir="rtl" align="right">
+ <span style="font-size: 12px;">(: 20:52) : </span>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/332655-1-ref.html b/layout/reftests/bidi/332655-1-ref.html
new file mode 100644
index 0000000000..b4ea71bb10
--- /dev/null
+++ b/layout/reftests/bidi/332655-1-ref.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-type" content="text/html; charset=utf-8">
+<style type="text/css">
+#q { outline: 1px dotted; }
+</style>
+</head>
+
+<body><p><span id="q">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas volutpat. Duis purus lectus, hendrerit vitae, blandit ac, tristique quis, neque. Cras a nisl. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In consectetuer lorem sit amet quam facilisis mollis. Etiam dolor. Donec elementum leo in ligula. Duis lacus diam, sodales vitae, rutrum a, feugiat non, tortor. Maecenas cursus lobortis diam. Mauris in pede eu purus ultricies vehicula. עברית</span></p>
+</body></html>
diff --git a/layout/reftests/bidi/332655-1.html b/layout/reftests/bidi/332655-1.html
new file mode 100644
index 0000000000..324b682bb2
--- /dev/null
+++ b/layout/reftests/bidi/332655-1.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-type" content="text/html; charset=utf-8">
+<script type="text/javascript">
+
+function boom()
+{
+ document.getElementById("q").style.outline="1px dotted";
+}
+
+</script>
+</head>
+
+<body onload="boom();"><p><span id="q">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas volutpat. Duis purus lectus, hendrerit vitae, blandit ac, tristique quis, neque. Cras a nisl. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In consectetuer lorem sit amet quam facilisis mollis. Etiam dolor. Donec elementum leo in ligula. Duis lacus diam, sodales vitae, rutrum a, feugiat non, tortor. Maecenas cursus lobortis diam. Mauris in pede eu purus ultricies vehicula. עברית</span></p>
+</body></html>
diff --git a/layout/reftests/bidi/332655-2-ref.html b/layout/reftests/bidi/332655-2-ref.html
new file mode 100644
index 0000000000..9f7a9b3e6a
--- /dev/null
+++ b/layout/reftests/bidi/332655-2-ref.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-type" content="text/html; charset=utf-8">
+<style type="text/css">
+#q { outline: 1px dotted; }
+</style>
+</head>
+
+<body><p><span id="q">עברית Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas volutpat. Duis purus lectus, hendrerit vitae, blandit ac, tristique quis, neque. Cras a nisl. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In consectetuer lorem sit amet quam facilisis mollis. Etiam dolor. Donec elementum leo in ligula. Duis lacus diam, sodales vitae, rutrum a, feugiat non, tortor. Maecenas cursus lobortis diam. Mauris in pede eu purus ultricies vehicula.</span></p>
+</body></html>
diff --git a/layout/reftests/bidi/332655-2.html b/layout/reftests/bidi/332655-2.html
new file mode 100644
index 0000000000..fcffcd015f
--- /dev/null
+++ b/layout/reftests/bidi/332655-2.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-type" content="text/html; charset=utf-8">
+<script type="text/javascript">
+
+function boom()
+{
+ document.getElementById("q").style.outline="1px dotted";
+}
+
+</script>
+</head>
+
+<body onload="boom();"><p><span id="q">עברית Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas volutpat. Duis purus lectus, hendrerit vitae, blandit ac, tristique quis, neque. Cras a nisl. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In consectetuer lorem sit amet quam facilisis mollis. Etiam dolor. Donec elementum leo in ligula. Duis lacus diam, sodales vitae, rutrum a, feugiat non, tortor. Maecenas cursus lobortis diam. Mauris in pede eu purus ultricies vehicula.</span></p>
+</body></html>
diff --git a/layout/reftests/bidi/381279-1-ref.html b/layout/reftests/bidi/381279-1-ref.html
new file mode 100644
index 0000000000..7a085dffd8
--- /dev/null
+++ b/layout/reftests/bidi/381279-1-ref.html
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+<style>
+div {
+ border: 1px solid black;
+ font-family: monospace;
+ width: 10ch;
+}
+</style>
+</head>
+
+<body>
+<div>
+ <span style="direction: rtl;">
+ <span style="unicode-bidi: bidi-override; color: blue;">abcd abcd abcd</span>
+ foo
+ </span>
+</div>
+</body>
+
+</html>
diff --git a/layout/reftests/bidi/381279-1.html b/layout/reftests/bidi/381279-1.html
new file mode 100644
index 0000000000..89d3f18a3f
--- /dev/null
+++ b/layout/reftests/bidi/381279-1.html
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+<style>
+div {
+ border: 1px solid black;
+ font-family: monospace;
+ width: 10ch;
+}
+</style>
+</head>
+
+<body onload="document.getElementById('r').style.direction = 'rtl';">
+<div>
+ <span id="r">
+ <span style="unicode-bidi: bidi-override; color: blue;">abcd abcd abcd</span>
+ foo
+ </span>
+</div>
+</body>
+
+</html>
diff --git a/layout/reftests/bidi/386339-ref.html b/layout/reftests/bidi/386339-ref.html
new file mode 100644
index 0000000000..b3002d0053
--- /dev/null
+++ b/layout/reftests/bidi/386339-ref.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ </head>
+ <body>
+ <table border="1">
+ <tbody>
+ <tr><th colspan="5">Symmetric characters with mirrored glyphs</th></tr>
+ <tr>
+ <td>U003C</td>
+ <td>LESS-THAN SIGN</td>
+ <td dir="rtl">א &lrm;|&gt;|&lrm; ב</td>
+ <td>a &lrm;|&lt;|&lrm; b</td>
+ <td dir="rtl">ا &lrm;|&gt;|&lrm; ب</td>
+ </tr>
+ <tr>
+ <td>U00AB</td>
+ <td>LEFT-POINTING DOUBLE ANGLE QUOTATION MARK</td>
+ <td dir="rtl">א &lrm;|»|&lrm; ב</td>
+ <td>a &lrm;|«|&lrm; b</td>
+ <td dir="rtl">ا &lrm;|»|&lrm; ب</td>
+ </tr>
+ <tr>
+ <td>U2039</td>
+ <td>SINGLE LEFT-POINTING ANGLE QUOTATION MARK</td>
+ <td dir="rtl">א &lrm;|›|&lrm; ב</td>
+ <td>a &lrm;|‹|&lrm; b</td>
+ <td dir="rtl">ا &lrm;|›|&lrm; ب</td>
+ </tr>
+ </tbody>
+ </table>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/386339.html b/layout/reftests/bidi/386339.html
new file mode 100644
index 0000000000..0746e1ce1f
--- /dev/null
+++ b/layout/reftests/bidi/386339.html
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ </head>
+ <body>
+ <table border="1">
+ <tbody>
+ <tr><th colspan="5">Symmetric characters with mirrored glyphs</th></tr>
+ <!-- NOTE: vertical bars (which do not affect the mirroring)
+ added to work around vertical ClearType clipping at tips
+ of diagonal lines; see bug 559879. -->
+ <tr>
+ <td>U003C</td>
+ <td>LESS-THAN SIGN</td>
+ <td dir="rtl">א |&lt;| ב</td>
+ <td>a |&lt;| b</td>
+ <td dir="rtl">ا |&lt;| ب</td>
+ </tr>
+ <tr>
+ <td>U00AB</td>
+ <td>LEFT-POINTING DOUBLE ANGLE QUOTATION MARK</td>
+ <td dir="rtl">א |«| ב</td>
+ <td>a |«| b</td>
+ <td dir="rtl">ا |«| ب</td>
+ </tr>
+ <tr>
+ <td>U2039</td>
+ <td>SINGLE LEFT-POINTING ANGLE QUOTATION MARK</td>
+ <td dir="rtl">א |‹| ב</td>
+ <td>a |‹| b</td>
+ <td dir="rtl">ا |‹| ب</td>
+ </tr>
+ </tbody>
+ </table>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/409375-ref.html b/layout/reftests/bidi/409375-ref.html
new file mode 100644
index 0000000000..4b05ab2a1b
--- /dev/null
+++ b/layout/reftests/bidi/409375-ref.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ </head>
+ <body>
+ <div dir="rtl">
+ <pre>
+
+English
+
+ </pre>
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/409375.html b/layout/reftests/bidi/409375.html
new file mode 100644
index 0000000000..ca8e998714
--- /dev/null
+++ b/layout/reftests/bidi/409375.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ </head>
+ <body onload="document.getElementById('div').style.direction = 'rtl';">
+ <div id="div">
+ <pre>
+
+English
+
+ </pre>
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/413542-1-ref.html b/layout/reftests/bidi/413542-1-ref.html
new file mode 100644
index 0000000000..63bb8f3c6a
--- /dev/null
+++ b/layout/reftests/bidi/413542-1-ref.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>Percentage padding on inlines ignored in presence of certain characters in source</title>
+ <style type="text/css">
+#test {
+ border: 1px solid #000;
+ width: 500px;
+}
+#test span {
+ border: 1px solid #f00;
+ padding: 0 10%;
+}
+ </style>
+ </head>
+ <body>
+ <div id="test"><span>one</span><span>two</span></div>
+ </body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/413542-1.html b/layout/reftests/bidi/413542-1.html
new file mode 100644
index 0000000000..6638189959
--- /dev/null
+++ b/layout/reftests/bidi/413542-1.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>Percentage padding on inlines ignored in presence of certain characters in source</title>
+ <style type="text/css">
+#test {
+ border: 1px solid #000;
+ width: 500px;
+}
+#test span {
+ border: 1px solid #f00;
+ padding: 0 10%;
+}
+ </style>
+ </head>
+ <body>
+<!-- To enable bidi: א -->
+ <div id="test"><span>one</span><span>two</span></div>
+ </body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/413542-2-ref.html b/layout/reftests/bidi/413542-2-ref.html
new file mode 100644
index 0000000000..606dd74336
--- /dev/null
+++ b/layout/reftests/bidi/413542-2-ref.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>Percentage margin on inlines ignored in presence of certain characters in source</title>
+ <style type="text/css">
+#test {
+ border: 1px solid #000;
+ width: 500px;
+}
+#test span {
+ border: 1px solid #f00;
+ margin: 0 10%;
+}
+ </style>
+ </head>
+ <body>
+ <div id="test"><span>one</span><span>two</span></div>
+ </body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/413542-2.html b/layout/reftests/bidi/413542-2.html
new file mode 100644
index 0000000000..872d889a2e
--- /dev/null
+++ b/layout/reftests/bidi/413542-2.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <title>Percentage margin on inlines ignored in presence of certain characters in source</title>
+ <style type="text/css">
+#test {
+ border: 1px solid #000;
+ width: 500px;
+}
+#test span {
+ border: 1px solid #f00;
+ margin: 0 10%;
+}
+ </style>
+ </head>
+ <body>
+<!-- To enable bidi: א -->
+ <div id="test"><span>one</span><span>two</span></div>
+ </body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/413928-1-ref.html b/layout/reftests/bidi/413928-1-ref.html
new file mode 100644
index 0000000000..e8679fcc84
--- /dev/null
+++ b/layout/reftests/bidi/413928-1-ref.html
@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
+ <title>Bug 413928</title>
+ <style type="text/css">
+.li {
+ line-height: 2em;
+}
+.list-number-he {
+ direction: rtl;
+ unicode-bidi: bidi-override;
+}
+ </style>
+ </head>
+ <body>
+ <div class="li"><span class="list-number">-3.</span></div>
+ <div class="li"><span class="list-number">-2.</span></div>
+ <div class="li"><span class="list-number">-1.</span></div>
+ <div class="li"><span class="list-number">0.</span></div>
+ <div class="li"><span class="list-number-he">.א</span></div>
+ <div class="li"><span class="list-number-he">.ב</span></div>
+ <div class="li"><span class="list-number-he">.ג</span></div>
+ <div class="li"><span class="list-number-he">.ד</span></div>
+ <div class="li"><span class="list-number-he">.ה</span></div>
+ <div class="li"><span class="list-number-he">.יד</span></div>
+ <div class="li"><span class="list-number-he">.טו</span></div>
+ <div class="li"><span class="list-number-he">.טז</span></div>
+ <div class="li"><span class="list-number-he">.יז</span></div>
+ <div class="li"><span class="list-number-he">.צז</span></div>
+ <div class="li"><span class="list-number-he">.צח</span></div>
+ <div class="li"><span class="list-number-he">.צט</span></div>
+ <div class="li"><span class="list-number-he">.ק</span></div>
+ <div class="li"><span class="list-number-he">.קא</span></div>
+ <div class="li"><span class="list-number-he">.תתקמד</span></div>
+ <div class="li"><span class="list-number-he">.תתקמה</span></div>
+ <div class="li"><span class="list-number-he">.תתקמו</span></div>
+ <div class="li"><span class="list-number-he">.תתקצט</span></div>
+ <div class="li"><span class="list-number-he">.א׳</span></div>
+ <div class="li"><span class="list-number-he">.א׳א</span></div>
+ <div class="li"><span class="list-number-he">.א׳תתקצח</span></div>
+ <div class="li"><span class="list-number-he">.א׳תתקצט</span></div>
+ <div class="li"><span class="list-number-he">.ב׳</span></div>
+ <div class="li"><span class="list-number-he">.ב׳א</span></div>
+ <div class="li"><span class="list-number-he">.ב׳ג</span></div>
+ <div class="li"><span class="list-number-he">.ב׳תשמח</span></div>
+ <div class="li"><span class="list-number-he">.ב׳תשנ</span></div>
+ <div class="li"><span class="list-number">1000000.</span></div>
+ <div class="li"><span class="list-number">1500000.</span></div>
+ <div class="li"><span class="list-number">2000000.</span></div>
+ <div class="li"><span class="list-number">9999999.</span></div>
+ <div class="li"><span class="list-number">10000212.</span></div>
+ <div class="li"><span class="list-number">10000425.</span></div>
+ <div class="li"><span class="list-number">10000851.</span></div>
+ <div class="li"><span class="list-number">10001064.</span></div>
+ <div class="li"><span class="list-number">10001277.</span></div>
+ </body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/413928-1.html b/layout/reftests/bidi/413928-1.html
new file mode 100644
index 0000000000..de722d606f
--- /dev/null
+++ b/layout/reftests/bidi/413928-1.html
@@ -0,0 +1,63 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
+ <title>Bug 413928</title>
+ <style type="text/css">
+ ol {
+ list-style-type: hebrew;
+ list-style-position: inside;
+ padding: 0;
+ margin: 0;
+}
+
+ li {
+ line-height: 2em;
+}
+ </style>
+ </head>
+ <body>
+ <ol start="-3">
+ <li></li>
+ <li></li>
+ <li></li>
+ <li></li>
+ <li></li>
+ <li></li>
+ <li></li>
+ <li></li>
+ <li></li>
+ <li value="14"></li>
+ <li></li>
+ <li></li>
+ <li></li>
+ <li value="97"></li>
+ <li></li>
+ <li></li>
+ <li></li>
+ <li></li>
+ <li value="944"></li>
+ <li></li>
+ <li></li>
+ <li value="999"></li>
+ <li></li>
+ <li></li>
+ <li value="1998"></li>
+ <li></li>
+ <li></li>
+ <li></li>
+ <li value="2003"></li>
+ <li value="2748"></li>
+ <li value="2750"></li>
+ <li value="1000000"></li>
+ <li value="1500000"></li>
+ <li value="2000000"></li>
+ <li value="9999999"></li>
+ <li value="10000212"></li>
+ <li value="10000425"></li>
+ <li value="10000851"></li>
+ <li value="10001064"></li>
+ <li value="10001277"></li>
+ </ol>
+ </body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/413928-2-ref.html b/layout/reftests/bidi/413928-2-ref.html
new file mode 100644
index 0000000000..5cd9cd76aa
--- /dev/null
+++ b/layout/reftests/bidi/413928-2-ref.html
@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
+ <title>Bug 413928</title>
+ <style type="text/css">
+.li {
+ line-height: 2em;
+}
+.list-number-he {
+ direction: rtl;
+ unicode-bidi: bidi-override;
+}
+ </style>
+ </head>
+ <body dir="rtl">
+ <div class="li"><span class="list-number">&lrm;-3.</span></div>
+ <div class="li"><span class="list-number">&lrm;-2.</span></div>
+ <div class="li"><span class="list-number">&lrm;-1.</span></div>
+ <div class="li"><span class="list-number">0.</span></div>
+ <div class="li"><span class="list-number-he">א.</span></div>
+ <div class="li"><span class="list-number-he">ב.</span></div>
+ <div class="li"><span class="list-number-he">ג.</span></div>
+ <div class="li"><span class="list-number-he">ד.</span></div>
+ <div class="li"><span class="list-number-he">ה.</span></div>
+ <div class="li"><span class="list-number-he">יד.</span></div>
+ <div class="li"><span class="list-number-he">טו.</span></div>
+ <div class="li"><span class="list-number-he">טז.</span></div>
+ <div class="li"><span class="list-number-he">יז.</span></div>
+ <div class="li"><span class="list-number-he">צז.</span></div>
+ <div class="li"><span class="list-number-he">צח.</span></div>
+ <div class="li"><span class="list-number-he">צט.</span></div>
+ <div class="li"><span class="list-number-he">ק.</span></div>
+ <div class="li"><span class="list-number-he">קא.</span></div>
+ <div class="li"><span class="list-number-he">תתקמד.</span></div>
+ <div class="li"><span class="list-number-he">תתקמה.</span></div>
+ <div class="li"><span class="list-number-he">תתקמו.</span></div>
+ <div class="li"><span class="list-number-he">תתקצט.</span></div>
+ <div class="li"><span class="list-number-he">א׳.</span></div>
+ <div class="li"><span class="list-number-he">א׳א.</span></div>
+ <div class="li"><span class="list-number-he">א׳תתקצח.</span></div>
+ <div class="li"><span class="list-number-he">א׳תתקצט.</span></div>
+ <div class="li"><span class="list-number-he">ב׳.</span></div>
+ <div class="li"><span class="list-number-he">ב׳א.</span></div>
+ <div class="li"><span class="list-number-he">ב׳ג.</span></div>
+ <div class="li"><span class="list-number-he">ב׳תשמח.</span></div>
+ <div class="li"><span class="list-number-he">ב׳תשנ.</span></div>
+ <div class="li"><span class="list-number">1000000.</span></div>
+ <div class="li"><span class="list-number">1500000.</span></div>
+ <div class="li"><span class="list-number">2000000.</span></div>
+ <div class="li"><span class="list-number">9999999.</span></div>
+ <div class="li"><span class="list-number">10000212.</span></div>
+ <div class="li"><span class="list-number">10000425.</span></div>
+ <div class="li"><span class="list-number">10000851.</span></div>
+ <div class="li"><span class="list-number">10001064.</span></div>
+ <div class="li"><span class="list-number">10001277.</span></div>
+ </body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/413928-2.html b/layout/reftests/bidi/413928-2.html
new file mode 100644
index 0000000000..a81e92c44e
--- /dev/null
+++ b/layout/reftests/bidi/413928-2.html
@@ -0,0 +1,63 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
+ <title>Bug 413928</title>
+ <style type="text/css">
+ ol {
+ list-style-type: hebrew;
+ list-style-position: inside;
+ padding: 0;
+ margin: 0;
+}
+
+ li {
+ line-height: 2em;
+}
+ </style>
+ </head>
+ <body dir="rtl">
+ <ol start="-3">
+ <li></li>
+ <li></li>
+ <li></li>
+ <li></li>
+ <li></li>
+ <li></li>
+ <li></li>
+ <li></li>
+ <li></li>
+ <li value="14"></li>
+ <li></li>
+ <li></li>
+ <li></li>
+ <li value="97"></li>
+ <li></li>
+ <li></li>
+ <li></li>
+ <li></li>
+ <li value="944"></li>
+ <li></li>
+ <li></li>
+ <li value="999"></li>
+ <li></li>
+ <li></li>
+ <li value="1998"></li>
+ <li></li>
+ <li></li>
+ <li></li>
+ <li value="2003"></li>
+ <li value="2748"></li>
+ <li value="2750"></li>
+ <li value="1000000"></li>
+ <li value="1500000"></li>
+ <li value="2000000"></li>
+ <li value="9999999"></li>
+ <li value="10000212"></li>
+ <li value="10000425"></li>
+ <li value="10000851"></li>
+ <li value="10001064"></li>
+ <li value="10001277"></li>
+ </ol>
+ </body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/425338-1-ref.html b/layout/reftests/bidi/425338-1-ref.html
new file mode 100644
index 0000000000..0835229622
--- /dev/null
+++ b/layout/reftests/bidi/425338-1-ref.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+<span id="a"><span>a</span>b<span>א</span>c</span>
+</body>
+</html>
diff --git a/layout/reftests/bidi/425338-1a.html b/layout/reftests/bidi/425338-1a.html
new file mode 100644
index 0000000000..70b55cb3c8
--- /dev/null
+++ b/layout/reftests/bidi/425338-1a.html
@@ -0,0 +1,14 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+<script type="text/javascript">
+function c()
+{
+ document.getElementById("a").style.height = "10em";
+}
+</script>
+</head>
+<body onload="c();">
+<span id="a"><span>a</span>b<span>א</span>c</span>
+</body>
+</html>
diff --git a/layout/reftests/bidi/425338-1b.html b/layout/reftests/bidi/425338-1b.html
new file mode 100644
index 0000000000..7d3e063c95
--- /dev/null
+++ b/layout/reftests/bidi/425338-1b.html
@@ -0,0 +1,16 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+<script type="text/javascript">
+function c()
+{
+ document.getElementById("a").style.height = "10em";
+ document.body.offsetHeight;
+ document.getElementById("a").style.height = "";
+}
+</script>
+</head>
+<body onload="c();">
+<span id="a"><span>a</span>b<span>א</span>c</span>
+</body>
+</html>
diff --git a/layout/reftests/bidi/489517-1-ref.html b/layout/reftests/bidi/489517-1-ref.html
new file mode 100644
index 0000000000..c49a11f746
--- /dev/null
+++ b/layout/reftests/bidi/489517-1-ref.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style type="text/css">
+.flipped { direction: rtl; unicode-bidi: bidi-override; }
+</style>
+</head>
+
+<body><div class="flipped">AB</div>
+</body>
+</html>
diff --git a/layout/reftests/bidi/489517-1.html b/layout/reftests/bidi/489517-1.html
new file mode 100644
index 0000000000..95295549be
--- /dev/null
+++ b/layout/reftests/bidi/489517-1.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style type="text/css">
+.flipped { direction: rtl; unicode-bidi: bidi-override; }
+</style>
+
+<script type="text/javascript">
+
+function boom()
+{
+ document.getElementById("outer").className = "flipped";
+}
+
+</script>
+</head>
+
+<body onload="boom();"><div id="outer">AB</div>
+</body>
+</html>
diff --git a/layout/reftests/bidi/489887-1-ref.html b/layout/reftests/bidi/489887-1-ref.html
new file mode 100644
index 0000000000..314d694be4
--- /dev/null
+++ b/layout/reftests/bidi/489887-1-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script type="text/javascript">
+function boom()
+{
+ document.getElementById("w").firstChild.data = "";
+
+}
+</script>
+</head>
+<body onload="boom();">
+<div><span>&#x06cd;</span><span id="w"> </span><span>&#x06cb;</span></div>
+</body>
+</html>
diff --git a/layout/reftests/bidi/489887-1.html b/layout/reftests/bidi/489887-1.html
new file mode 100644
index 0000000000..9bff096729
--- /dev/null
+++ b/layout/reftests/bidi/489887-1.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script type="text/javascript">
+function boom()
+{
+ document.getElementById("w").firstChild.data = "";
+ document.documentElement.appendChild(document.body);
+}
+</script>
+</head>
+<body onload="boom();">
+<div><span>&#x06cd;</span><span id="w"> </span><span>&#x06cb;</span></div>
+</body>
+</html>
diff --git a/layout/reftests/bidi/492231-1-ref.html b/layout/reftests/bidi/492231-1-ref.html
new file mode 100644
index 0000000000..3d276bff11
--- /dev/null
+++ b/layout/reftests/bidi/492231-1-ref.html
@@ -0,0 +1,7 @@
+<!DOCTYPE HTML>
+<html>
+<head><meta charset="iso-8859-8"></head>
+<body style="direction: rtl;">
+<span>+&#x05E9;</span>
+</body>
+</html>
diff --git a/layout/reftests/bidi/492231-1.html b/layout/reftests/bidi/492231-1.html
new file mode 100644
index 0000000000..04ac87374f
--- /dev/null
+++ b/layout/reftests/bidi/492231-1.html
@@ -0,0 +1,7 @@
+<!DOCTYPE HTML>
+<html>
+<head><meta charset="iso-8859-8"></head>
+<body onload="document.body.style.direction = 'rtl';">
+<span>+&#x05E9;</span>
+</body>
+</html>
diff --git a/layout/reftests/bidi/496006-1-ref.html b/layout/reftests/bidi/496006-1-ref.html
new file mode 100644
index 0000000000..704befb66a
--- /dev/null
+++ b/layout/reftests/bidi/496006-1-ref.html
@@ -0,0 +1,10 @@
+<html>
+<head>
+</head>
+<body style="direction: rtl;">
+m
+<span id="a" style="border: 1px solid black"></span>
+<div></div>
+m
+</body>
+</html>
diff --git a/layout/reftests/bidi/496006-1.html b/layout/reftests/bidi/496006-1.html
new file mode 100644
index 0000000000..5629fa4ea5
--- /dev/null
+++ b/layout/reftests/bidi/496006-1.html
@@ -0,0 +1,21 @@
+<html class="reftest-wait">
+<head>
+</head>
+<body style="direction: rtl;">
+m
+<span id="a" style="border: 1px solid black;"></span>
+<div><script>document.body.offsetHeight;</script></div>
+m
+
+<script>
+function doe() {
+var a=document.getElementById('a');
+a.style.outline = '1px solid transparent';
+document.body.offsetHeight;
+a.style.outline = '';
+document.documentElement.removeAttribute('class');
+}
+setTimeout(doe, 500);
+</script>
+</body>
+</html>
diff --git a/layout/reftests/bidi/503269-1-ref.html b/layout/reftests/bidi/503269-1-ref.html
new file mode 100644
index 0000000000..c9401fd854
--- /dev/null
+++ b/layout/reftests/bidi/503269-1-ref.html
@@ -0,0 +1,16 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+ <head>
+ <title>Welcome to Flickr!</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ </head>
+ <body>
+ <div>
+ <ul>
+ <li><span><a href="/photos/foo/" title="مسجد قبة الصخرة by Yaqut"><img src="/foo.jpg" width="75" height="75" alt="مسجد قبة الصخرة by Yaqut"></a></span><div>From <a href="/photos/yaqut/" title="Yaqut">Yaqut</a></div></li>
+ <li><span><a href="/photos/bar/" title="מערכת שליחת ההודעות באתר אורנג עובדת בפיירפוקס - מזל טוב!"><img src="/bar.jpg" width="75" height="75" alt="מערכת שליחת ההודעות באתר אורנג עובדת בפיירפוקס - מזל טוב! by MosheOofnik"></a></span><div>From <a href="/photos/mosheoofnik/" title="MosheOofnik">Moshe Oofnik</a></div></li>
+ <li><span><a href="/photos/baz/" title="Fruit Basket by Elmo"><img src="/baz.jpg" width="75" height="75" alt="Fruit Basket by Elmo"></a></span><div>From <a href="/photos/elmo/" title="Elmo">Elmo</a></div></li>
+ </ul>&rlm;
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/503269-1.html b/layout/reftests/bidi/503269-1.html
new file mode 100644
index 0000000000..c08989e093
--- /dev/null
+++ b/layout/reftests/bidi/503269-1.html
@@ -0,0 +1,16 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+ <head>
+ <title>Welcome to Flickr!</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ </head>
+ <body>
+ <div>
+ <ul>
+ <li><span><a href="/photos/foo/" title="مسجد قبة الصخرة by Yaqut"><img src="/foo.jpg" width="75" height="75" alt="مسجد قبة الصخرة by Yaqut"></a></span><div>From <a href="/photos/yaqut/" title="Yaqut">Yaqut</a></div></li>
+ <li><span><a href="/photos/bar/" title="מערכת שליחת ההודעות באתר אורנג עובדת בפיירפוקס - מזל טוב!"><img src="/bar.jpg" width="75" height="75" alt="מערכת שליחת ההודעות באתר אורנג עובדת בפיירפוקס - מזל טוב! by MosheOofnik"></a></span><div>From <a href="/photos/mosheoofnik/" title="MosheOofnik">Moshe Oofnik</a></div></li>
+ <li><span><a href="/photos/baz/" title="Fruit Basket by Elmo"><img src="/baz.jpg" width="75" height="75" alt="Fruit Basket by Elmo"></a></span><div>From <a href="/photos/elmo/" title="Elmo">Elmo</a></div></li>
+ </ul>
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/503957-1-ref.html b/layout/reftests/bidi/503957-1-ref.html
new file mode 100644
index 0000000000..4f6a43c1a4
--- /dev/null
+++ b/layout/reftests/bidi/503957-1-ref.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html dir="rtl">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>Test Page</title>
+ <style type="text/css">
+ span {
+ margin: 1em;
+ }
+ </style>
+ </head>
+ <body>
+ <p>
+ <span dir="rtl">אתר התוספות של Mozilla</span>
+ <span dir="rtl">one</span>
+ <span dir="rtl">two</span>
+ <span dir="rtl">three</span>
+ </p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/503957-1.html b/layout/reftests/bidi/503957-1.html
new file mode 100644
index 0000000000..f06bea7943
--- /dev/null
+++ b/layout/reftests/bidi/503957-1.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html dir="rtl">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>Test Page</title>
+ <style type="text/css">
+ ol li {
+ display: inline;
+ margin: 1em;
+ }
+ ol {
+ padding-inline-start: 0px;
+ }
+ </style>
+ </head>
+ <body>
+ <ol>
+ <li>אתר התוספות של Mozilla</li>
+ <li>one</li>
+ <li>two</li>
+ <li>three</li>
+ </ol>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/525740-1-ref.html b/layout/reftests/bidi/525740-1-ref.html
new file mode 100644
index 0000000000..0de424fbdf
--- /dev/null
+++ b/layout/reftests/bidi/525740-1-ref.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <style type="text/css">
+ div:first-letter { float: right; color: lime; }
+ </style>
+ </head>
+ <body dir="rtl">
+ <div>ab &#x06CD; c</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/525740-1.html b/layout/reftests/bidi/525740-1.html
new file mode 100644
index 0000000000..45fd1a453f
--- /dev/null
+++ b/layout/reftests/bidi/525740-1.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <style type="text/css">
+ div:first-letter { float: right; color: lime; }
+ </style>
+ </head>
+ <body dir="rtl">
+ <div><span>ab &#x06CD; c</span></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/536963-1-ref.html b/layout/reftests/bidi/536963-1-ref.html
new file mode 100644
index 0000000000..40f7314a70
--- /dev/null
+++ b/layout/reftests/bidi/536963-1-ref.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <title>Dynamic bidi bug</title>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <style type="text/css">
+ p { width: 3ch;}
+ </style>
+ </head>
+ <body>
+ <p dir="rtl">0 123 4</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/536963-1.html b/layout/reftests/bidi/536963-1.html
new file mode 100644
index 0000000000..dd31699232
--- /dev/null
+++ b/layout/reftests/bidi/536963-1.html
@@ -0,0 +1,20 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <title>Dynamic bidi bug</title>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <style type="text/css">
+ p { width: 3ch;}
+ </style>
+ <script type="text/javascript">
+function flip()
+{
+ var flipped= document.getElementById('flipped');
+ flipped.dir = "rtl";
+}
+ </script>
+ </head>
+ <body onload="flip()">
+ <p id="flipped">0 123 4</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/562169-1-ref.html b/layout/reftests/bidi/562169-1-ref.html
new file mode 100644
index 0000000000..8aded4f766
--- /dev/null
+++ b/layout/reftests/bidi/562169-1-ref.html
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>dir() selector</title>
+ <style>
+ .blue { color: blue; direction: ltr; }
+ .lime { color: lime; direction: rtl; }
+ div { text-align: left; }
+ </style>
+ </head>
+ <body>
+ <div class="blue">This element has default direction.</div>
+ <div class="blue">This element is ltr.</div>
+ <div class="lime">This element is rtl.</div>
+ <div class="blue">
+ <div>This element should inherit ltr.</div>
+ <div class="blue">This element is ltr.</div>
+ <div class="lime">This element is rtl.</div>
+ <div class="blue">Every word in this element should inherit ltr.</div>
+ </div>
+ <div class="lime">
+ <div>This element should inherit rtl.</div>
+ <div class="blue">This element is ltr.</div>
+ <div class="lime">This element is rtl.</div>
+ <div class="lime">Every word in this element should inherit rtl.</div>
+ </div>
+ <div class="blue">This element has an invalid dir attribute and
+ should have default direction.</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/562169-1.html b/layout/reftests/bidi/562169-1.html
new file mode 100644
index 0000000000..d6cfe554f8
--- /dev/null
+++ b/layout/reftests/bidi/562169-1.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>dir() selector</title>
+ <style>
+ :dir(ltr) { color: blue }
+ :dir(rtl) { color: lime }
+ :dir(foopy) { color: red }
+ div { text-align: left; }
+ </style>
+ </head>
+ <body>
+ <div>This element has default direction.</div>
+ <div dir="ltr">This element is ltr.</div>
+ <div dir="rtl">This element is rtl.</div>
+ <div dir="ltr">
+ <div>This element should inherit ltr.</div>
+ <div dir="ltr">This element is ltr.</div>
+ <div dir="rtl">This element is rtl.</div>
+ <div><span>Every <span>word <span>in <span>this <span>element <span>should <span>inherit <span>ltr</span></span></span></span></span></span></span></span>.</div>
+ </div>
+ <div dir="rtl">
+ <div>This element should inherit rtl.</div>
+ <div dir="ltr">This element is ltr.</div>
+ <div dir="rtl">This element is rtl.</div>
+ <div><span>Every <span>word <span>in <span>this <span>element <span>should <span>inherit <span>rtl</span></span></span></span></span></span></span></span>.</div>
+ </div>
+ <div dir="foopy">This element has an invalid dir attribute and
+ should have default direction.</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/562169-1a.html b/layout/reftests/bidi/562169-1a.html
new file mode 100644
index 0000000000..f6102951fd
--- /dev/null
+++ b/layout/reftests/bidi/562169-1a.html
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>dir() selector</title>
+ <style>
+ :dir(ltr) { color: blue }
+ :dir(rtl) { color: lime }
+ :dir(foopy) { color: red }
+ div { text-align: left; }
+ </style>
+ <script type="text/javascript">
+function switchDir()
+{
+ divs = document.getElementsByTagName("div");
+ for (var i = 0; i < divs.length; ++i) {
+ theDiv = divs[i];
+ if (theDiv.dir == "ltr") {
+ theDiv.dir = "rtl";
+ } else if (theDiv.dir == "rtl") {
+ theDiv.dir = "ltr";
+ }
+ }
+}
+ </script>
+ </head>
+ <body onload="switchDir()">
+ <div>This element has default direction.</div>
+ <div dir="rtl">This element is ltr.</div>
+ <div dir="ltr">This element is rtl.</div>
+ <div dir="rtl">
+ <div>This element should inherit ltr.</div>
+ <div dir="rtl">This element is ltr.</div>
+ <div dir="ltr">This element is rtl.</div>
+ <div><span>Every <span>word <span>in <span>this <span>element <span>should <span>inherit <span>ltr</span></span></span></span></span></span></span></span>.</div>
+ </div>
+ <div dir="ltr">
+ <div>This element should inherit rtl.</div>
+ <div dir="rtl">This element is ltr.</div>
+ <div dir="ltr">This element is rtl.</div>
+ <div><span>Every <span>word <span>in <span>this <span>element <span>should <span>inherit <span>rtl</span></span></span></span></span></span></span></span>.</div>
+ </div>
+ <div dir="foopy">This element has an invalid dir attribute and
+ should have default direction.</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/562169-2-ref.html b/layout/reftests/bidi/562169-2-ref.html
new file mode 100644
index 0000000000..0acc957b18
--- /dev/null
+++ b/layout/reftests/bidi/562169-2-ref.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>dir() selector</title>
+ <style>
+ .blue { color: blue; direction: ltr; }
+ .lime { color: lime; direction: rtl; }
+ div { text-align: left; }
+ </style>
+ </head>
+ <body>
+ <div class="lime">This element has default direction.</div>
+ <div class="blue">This element is ltr.</div>
+ <div class="lime">This element is rtl.</div>
+ <div class="blue">
+ <div>This element should inherit ltr.</div>
+ <div class="blue">This element is ltr.</div>
+ <div class="lime">This element is rtl.</div>
+ </div>
+ <div class="lime">
+ <div>This element should inherit rtl.</div>
+ <div class="blue">This element is ltr.</div>
+ <div class="lime">This element is rtl.</div>
+ </div>
+ <div class="lime">This element has an invalid dir attribute and
+ should have default direction.</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/562169-2.html b/layout/reftests/bidi/562169-2.html
new file mode 100644
index 0000000000..cea59a3fe0
--- /dev/null
+++ b/layout/reftests/bidi/562169-2.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html dir="rtl">
+ <head>
+ <meta charset="UTF-8">
+ <title>dir() selector</title>
+ <style>
+ :dir(ltr) { color: blue }
+ :dir(rtl) { color: lime }
+ :dir(foopy) { color: red }
+ div { text-align: left; }
+ </style>
+ </head>
+ <body>
+ <div>This element has default direction.</div>
+ <div dir="ltr">This element is ltr.</div>
+ <div dir="rtl">This element is rtl.</div>
+ <div dir="ltr">
+ <div>This element should inherit ltr.</div>
+ <div dir="ltr">This element is ltr.</div>
+ <div dir="rtl">This element is rtl.</div>
+ </div>
+ <div dir="rtl">
+ <div>This element should inherit rtl.</div>
+ <div dir="ltr">This element is ltr.</div>
+ <div dir="rtl">This element is rtl.</div>
+ </div>
+ <div dir="foopy">This element has an invalid dir attribute and
+ should have default direction.</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/562169-2a.html b/layout/reftests/bidi/562169-2a.html
new file mode 100644
index 0000000000..3f8044fd03
--- /dev/null
+++ b/layout/reftests/bidi/562169-2a.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>dir() selector</title>
+ <style>
+ :dir(ltr) { color: blue }
+ :dir(rtl) { color: lime }
+ :dir(foopy) { color: red }
+ div { text-align: left; }
+ </style>
+ <script type="text/javascript">
+function switchDir()
+{
+ document.dir = "rtl";
+}
+ </script>
+ </head>
+ <body onload="switchDir()">
+ <div>This element has default direction.</div>
+ <div dir="ltr">This element is ltr.</div>
+ <div dir="rtl">This element is rtl.</div>
+ <div dir="ltr">
+ <div>This element should inherit ltr.</div>
+ <div dir="ltr">This element is ltr.</div>
+ <div dir="rtl">This element is rtl.</div>
+ </div>
+ <div dir="rtl">
+ <div>This element should inherit rtl.</div>
+ <div dir="ltr">This element is ltr.</div>
+ <div dir="rtl">This element is rtl.</div>
+ </div>
+ <div dir="foopy">This element has an invalid dir attribute and
+ should have default direction.</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/562169-3-ref.html b/layout/reftests/bidi/562169-3-ref.html
new file mode 100644
index 0000000000..ea848f61a1
--- /dev/null
+++ b/layout/reftests/bidi/562169-3-ref.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>dir() selector</title>
+ <style>
+ .ltr { direction: ltr }
+ .rtl { direction: rtl }
+ div { color: lime; text-align: left; }
+ </style>
+ </head>
+ <body>
+ <div class="rtl">This element is rtl.</div>
+ <div>This element has default direction.</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/562169-3.html b/layout/reftests/bidi/562169-3.html
new file mode 100644
index 0000000000..422e608276
--- /dev/null
+++ b/layout/reftests/bidi/562169-3.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>dir() selector</title>
+ <style>
+ :not(:dir(rtl)) + div { color: blue }
+ div { color: lime; text-align: left; }
+ </style>
+ </head>
+ <body>
+ <div dir="rtl">This element is rtl.</div>
+ <div>This element has default direction.</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/562169-3a.html b/layout/reftests/bidi/562169-3a.html
new file mode 100644
index 0000000000..9df28794a5
--- /dev/null
+++ b/layout/reftests/bidi/562169-3a.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>dir() selector</title>
+ <style>
+ :not(:dir(rtl)) + div { color: blue }
+ div { color: lime; text-align: left; }
+ </style>
+ <script type="text/javascript">
+function switchDir()
+{
+ theDiv = document.getElementById("d");
+ if (theDiv.dir == "ltr") {
+ theDiv.dir = "rtl";
+ } else if (theDiv.dir == "rtl") {
+ theDiv.dir = "ltr";
+ }
+}
+ </script>
+ </head>
+ <body onload="switchDir()">
+ <div id="d" dir="ltr">This element is rtl.</div>
+ <div>This element has default direction.</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/562169-4-ref.html b/layout/reftests/bidi/562169-4-ref.html
new file mode 100644
index 0000000000..b5cdada97b
--- /dev/null
+++ b/layout/reftests/bidi/562169-4-ref.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>dir() selector</title>
+ <style>
+ .lime { direction: rtl; color: lime }
+ div { text-align: left; }
+ </style>
+ </head>
+ <body>
+ <div class="lime">This element is rtl. <span>This span should
+ inherit rtl from the parent. <span>This span should inherit rtl
+ from the grandparent.</span></span></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/562169-4.html b/layout/reftests/bidi/562169-4.html
new file mode 100644
index 0000000000..56075adc2b
--- /dev/null
+++ b/layout/reftests/bidi/562169-4.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>dir() selector</title>
+ <style>
+ :dir(ltr) { color: blue }
+ :dir(rtl) { color: lime }
+ div { text-align: left; }
+ </style>
+ <script type="text/javascript">
+function AppendElementWithChild() {
+ var x = document.createElement("span");
+ x.innerHTML = "This span should inherit rtl from the parent. ";
+
+ var y = document.createElement("span");
+ y.innerHTML = "This span should inherit rtl from the grandparent.";
+
+ var z = document.getElementById("z");
+
+ x.appendChild(y);
+ z.appendChild(x);
+}
+ </script>
+ </head>
+ <body onload="AppendElementWithChild()">
+ <div id="z" dir="rtl">This element is rtl. </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/588739-1.html b/layout/reftests/bidi/588739-1.html
new file mode 100644
index 0000000000..842ee5e05a
--- /dev/null
+++ b/layout/reftests/bidi/588739-1.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <style type="text/css">
+ span.page-sep { position:absolute; visibility:hidden; }
+ </style>
+ </head>
+ <body>
+עמוד <span>1<span class="page-sep"></span>2<span class="page-sep"></span>3</span>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/588739-2.html b/layout/reftests/bidi/588739-2.html
new file mode 100644
index 0000000000..65592eb163
--- /dev/null
+++ b/layout/reftests/bidi/588739-2.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <style type="text/css">
+ span.page-sep { visibility:hidden; }
+ </style>
+ </head>
+ <body>
+עמוד <span>1<span class="page-sep"></span>2<span class="page-sep"></span>3</span>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/588739-3.html b/layout/reftests/bidi/588739-3.html
new file mode 100644
index 0000000000..e309774d78
--- /dev/null
+++ b/layout/reftests/bidi/588739-3.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <style type="text/css">
+ span.page-sep { position:absolute; }
+ </style>
+ </head>
+ <body>
+עמוד <span>1<span class="page-sep"></span>2<span class="page-sep"></span>3</span>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/588739-ref.html b/layout/reftests/bidi/588739-ref.html
new file mode 100644
index 0000000000..7cac69a934
--- /dev/null
+++ b/layout/reftests/bidi/588739-ref.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ </head>
+ <body>
+עמוד 321
+ </body>
+</html>
diff --git a/layout/reftests/bidi/612843-1-ref.html b/layout/reftests/bidi/612843-1-ref.html
new file mode 100644
index 0000000000..5dab89080f
--- /dev/null
+++ b/layout/reftests/bidi/612843-1-ref.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<!-- Tests bidi class of U+070F SYRIAC ABBREVIATION MARK -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ </head>
+ <style type="text/css">
+body {
+ font-family: serif;
+ font-size: 24px;
+}
+ </style
+ <body>
+ <p dir="rtl" style="unicode-bidi: bidi-override;">&#x661;&#x662;&#x60c;&#x070f;&#x071f;&#x0725;</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/612843-1.html b/layout/reftests/bidi/612843-1.html
new file mode 100644
index 0000000000..2065322c51
--- /dev/null
+++ b/layout/reftests/bidi/612843-1.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<!-- Tests bidi class of U+070F SYRIAC ABBREVIATION MARK -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ </head>
+ <style type="text/css">
+body {
+ font-family: serif;
+ font-size: 24px;
+}
+ </style
+ <body>
+ <p dir="rtl">&#x662;&#x661;&#x60c;&#x070f;&#x071f;&#x0725;</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/613149-1-ref.html b/layout/reftests/bidi/613149-1-ref.html
new file mode 100644
index 0000000000..906a0951d4
--- /dev/null
+++ b/layout/reftests/bidi/613149-1-ref.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>Bidi isolation - reference</title>
+ <style type="text/css">
+ body { font-family: monospace }
+ p { unicode-bidi: bidi-override; }
+ </style>
+ </head>
+ <body>
+ <p>טאראק 24 בהז הציפ - 3 reviews</p>
+ <p>תובוגת 5 - Joe's לפאלפ Bar :הנושאר הדעסמ</p>
+ <p>תובוגת 5 - Joe's לפאלפ Bar :הנושאר הדעסמ</p>
+ <p>.(position: relative) css-ב שמתשת</p>
+ <p>documents &gt; ילש ןושארה ןמורה &gt; 1 קרפ</p>
+ <p>joe hacker: overdrawn</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/613149-1a.html b/layout/reftests/bidi/613149-1a.html
new file mode 100644
index 0000000000..140d70b93c
--- /dev/null
+++ b/layout/reftests/bidi/613149-1a.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>Bidi isolation - bdi element</title>
+ <!-- Examples from http://www.w3.org/International/docs/html-bidi-requirements/#bidi-isolation -->
+ <style type="text/css">body { font-family: monospace; }</style>
+ </head>
+ <body>
+ <p><bdi>פיצה זהב 24 קאראט</bdi> - 3 reviews</p>
+ <p>מסעדה ראשונה: <bdi dir="ltr">Joe's פלאפל Bar</bdi> - 5 תגובות</p>
+ <p>מסעדה ראשונה: <bdi dir="ltr"><bdo dir="rtl">raB פלאפל s'eoJ</bdo></bdi> - 5 תגובות</p>
+ <p dir="rtl" align="left">תשתמש ב-css (<bdi dir="ltr">position: relative</bdi>).</p>
+ <p>documents &gt; <bdi dir="rtl">הרומן הראשון שלי</bdi> &gt; <bdi dir="rtl">פרק 1</bdi></p>
+ <p><bdi>joe hacker&#x202e;</bdi>: overdrawn</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/613149-1b.html b/layout/reftests/bidi/613149-1b.html
new file mode 100644
index 0000000000..9e8218d0a0
--- /dev/null
+++ b/layout/reftests/bidi/613149-1b.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>Bidi isolation - css</title>
+ <style type="text/css">
+ body { font-family: monospace; }
+ span { unicode-bidi: isolate; }
+ span.override { unicode-bidi: isolate-override; }
+ </style>
+ </head>
+ <body>
+ <p><span>פיצה זהב 24 קאראט</span> - 3 reviews</p>
+ <p>מסעדה ראשונה: <span dir="ltr">Joe's פלאפל Bar</span> - 5 תגובות</p>
+ <p>מסעדה ראשונה: <span class="override" dir="rtl">raB פלאפל s'eoJ</span> - 5 תגובות</p>
+ <p dir="rtl" align="left">תשתמש ב-css (<span dir="ltr">position: relative</span>).</p>
+ <p>documents &gt; <span dir="rtl">הרומן הראשון שלי</span> &gt; <span dir="rtl">פרק 1</span></p>
+ <p><span>joe hacker&#x202e;</span>: overdrawn</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/613149-2-ref.html b/layout/reftests/bidi/613149-2-ref.html
new file mode 100644
index 0000000000..7139f8b569
--- /dev/null
+++ b/layout/reftests/bidi/613149-2-ref.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <title>Google Reader minimized test case</title>
+ </head>
+ <body>
+ <div style="font-size: 18pt; unicode-bidi: bidi-override; text-align: right">אסרג ןוכדע רחאל תלגלגב היעב :Mozilla Firefox • Re</div>
+</body></html>
diff --git a/layout/reftests/bidi/613149-2a.html b/layout/reftests/bidi/613149-2a.html
new file mode 100644
index 0000000000..3fe56e0b73
--- /dev/null
+++ b/layout/reftests/bidi/613149-2a.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <title>Google Reader minimized test case</title>
+ <style type="text/css">
+ span div {display: inline;}
+ </style>
+ </head>
+ <body>
+ <div style="font-size: 18pt" dir="rtl"><span><div>Mozilla Firefox • Re: בעיה בגלגלת לאחר עדכון גרסא</div></span></div>
+</body></html>
diff --git a/layout/reftests/bidi/613149-2b.html b/layout/reftests/bidi/613149-2b.html
new file mode 100644
index 0000000000..074b4326aa
--- /dev/null
+++ b/layout/reftests/bidi/613149-2b.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <title>Google Reader minimized test case</title>
+ <style type="text/css">
+ span div {display: inline;}
+ </style>
+ <script type="text/javascript">
+function boom()
+{
+ document.getElementById("d").style.fontWeight="normal";
+}
+ </script>
+ </head>
+ <body onload="boom()">
+ <div dir="rtl"><span><div id="d" style="font-size: 18pt; font-weight: bold;">Mozilla Firefox • Re: בעיה בגלגלת לאחר עדכון גרסא</div></span></div>
+</body></html>
diff --git a/layout/reftests/bidi/613157-1-ref.html b/layout/reftests/bidi/613157-1-ref.html
new file mode 100644
index 0000000000..38cc7d0629
--- /dev/null
+++ b/layout/reftests/bidi/613157-1-ref.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>block-element-as-bidi-paragraph-break</title>
+ <meta charset="UTF-8">
+ </head>
+ <body>
+ <div>&#x05D0; --&gt;&lrm;<hr>--&gt; &#x05D1;</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/613157-1.html b/layout/reftests/bidi/613157-1.html
new file mode 100644
index 0000000000..63948990c9
--- /dev/null
+++ b/layout/reftests/bidi/613157-1.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>block-element-as-bidi-paragraph-break</title>
+ <meta charset="UTF-8">
+ </head>
+ <body>
+ <div>&#x05D0; --&gt;<hr>--&gt; &#x05D1;</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/613157-2-ref.html b/layout/reftests/bidi/613157-2-ref.html
new file mode 100644
index 0000000000..a41becbea8
--- /dev/null
+++ b/layout/reftests/bidi/613157-2-ref.html
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Inline blocks shouldn't end the paragraph</title>
+ </head>
+ <body>
+ <p>&#x202e;ימים בשבוע 8&lt;-- 4 xoferiF&lt;--אני אוהב</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/613157-2.html b/layout/reftests/bidi/613157-2.html
new file mode 100644
index 0000000000..0d635f6f1f
--- /dev/null
+++ b/layout/reftests/bidi/613157-2.html
@@ -0,0 +1,11 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Inline blocks shouldn't end the paragraph</title>
+ </head>
+ <body>
+ <p><span dir="rtl">אני אוהב</span>--&gt;<span style="display: inline-block">Firefox 4&nbsp;</span>--&gt;8 ימים בשבוע
+ </p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/662288-1-ref.html b/layout/reftests/bidi/662288-1-ref.html
new file mode 100644
index 0000000000..afc16824ca
--- /dev/null
+++ b/layout/reftests/bidi/662288-1-ref.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>pre element with auto-direction</title>
+ </head>
+ <body>
+ <pre><div dir="ltr">The word Automaton is the latinization of the Greek
+αὐτόματον,... automaton, (neuter) “acting of one’s own will”. It is more
+often used to describe non-electronic moving machines, especially those that
+have been made to resemble human or animal actions, such as the jacks on old
+public striking clocks, or the cuckoo and any other animated figures on a
+cuckoo clock.</div><div dir="rtl">העדויות על בובות מכניות ראשונות הן מיוון העתיקה, שם הופעלו פסלים נעים בכוח הקיטור
+שנקראו אוטומטון (ביוונית: αὐτόματος - נע מעצמו). האוטומטונים שימשו הן כצעצועים והן
+לצורכי בימת התיאטרון היווני, כמייצגים אלים, במיוחד בכניסה מפתיעה בסוף המחזה. הביטוי
+דאוס אקס מכינה ("האל מתוך המכונה"), שמשמעותו מצב בסיפור שבו הכותב מכניס לעלילה
+גורם שאינו נובע מהשרשרת הסיבתית העלילתית כדי לפתור בעיות עלילתיות, מגיע מהופעת ה"אל"
+מתוך הפסל המכני שהוריד אותו אל הבמה. למנגנוני תנועה מכניים אוטומטיים מאותה תקופה נמצא
+שריד ארכאולוגי בדמותו של מנגנון אנטיקיתרה, ששימש למכונת חישוב קדומה.</div>
+</pre>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/662288-1.html b/layout/reftests/bidi/662288-1.html
new file mode 100644
index 0000000000..b79f961b87
--- /dev/null
+++ b/layout/reftests/bidi/662288-1.html
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>pre element with auto-direction</title>
+ </head>
+ <body>
+ <pre dir="auto">The word Automaton is the latinization of the Greek
+αὐτόματον,... automaton, (neuter) “acting of one’s own will”. It is more
+often used to describe non-electronic moving machines, especially those that
+have been made to resemble human or animal actions, such as the jacks on old
+public striking clocks, or the cuckoo and any other animated figures on a
+cuckoo clock.
+העדויות על בובות מכניות ראשונות הן מיוון העתיקה, שם הופעלו פסלים נעים בכוח הקיטור
+שנקראו אוטומטון (ביוונית: αὐτόματος - נע מעצמו). האוטומטונים שימשו הן כצעצועים והן
+לצורכי בימת התיאטרון היווני, כמייצגים אלים, במיוחד בכניסה מפתיעה בסוף המחזה. הביטוי
+דאוס אקס מכינה ("האל מתוך המכונה"), שמשמעותו מצב בסיפור שבו הכותב מכניס לעלילה
+גורם שאינו נובע מהשרשרת הסיבתית העלילתית כדי לפתור בעיות עלילתיות, מגיע מהופעת ה"אל"
+מתוך הפסל המכני שהוריד אותו אל הבמה. למנגנוני תנועה מכניים אוטומטיים מאותה תקופה נמצא
+שריד ארכאולוגי בדמותו של מנגנון אנטיקיתרה, ששימש למכונת חישוב קדומה.
+</pre>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/670226-1-ref.html b/layout/reftests/bidi/670226-1-ref.html
new file mode 100644
index 0000000000..ef15ed7495
--- /dev/null
+++ b/layout/reftests/bidi/670226-1-ref.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Bug 670226</title>
+ <style type="text/css">
+ pre:first-letter { float:left; color: lime}
+ pre { font-size: 16pt }
+ </style>
+ </head>
+ <body>
+ <pre dir="rtl">a+b
+c</pre>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/670226-1.html b/layout/reftests/bidi/670226-1.html
new file mode 100644
index 0000000000..bd230a7a93
--- /dev/null
+++ b/layout/reftests/bidi/670226-1.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Bug 670226</title>
+ <style type="text/css">
+ pre:first-letter { float:left; color: lime}
+ </style>
+ <script type="text/javascript">
+function boom()
+{
+ var p = document.getElementById("p");
+ p.style.fontSize="16pt";
+}
+ </script>
+ </head>
+ <body onload="boom()">
+ <pre id="p" dir="rtl">a+b
+c</pre>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/676245-1-ref.html b/layout/reftests/bidi/676245-1-ref.html
new file mode 100644
index 0000000000..4908bb6de3
--- /dev/null
+++ b/layout/reftests/bidi/676245-1-ref.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <title>block-as-inline</title>
+ <style>
+ .inline-block {display: inline-block;}
+ </style>
+ </head>
+ <body>
+ <div>
+ I like:
+ <div class="inline-block">A</div>
+ <div class="inline-block" dir="rtl">&#x05D0;</div>
+ <div class="inline-block" dir="rtl">&#x05D1;</div>
+ (3 things total).
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/676245-1.html b/layout/reftests/bidi/676245-1.html
new file mode 100644
index 0000000000..63470a1d29
--- /dev/null
+++ b/layout/reftests/bidi/676245-1.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <title>block-as-inline</title>
+ <style>
+ .inline {display: inline;}
+ </style>
+ </head>
+ <body>
+ <div>
+ I like:
+ <div class="inline">A</div>
+ <div class="inline" dir="rtl">&#x05D0;</div>
+ <div class="inline" dir="rtl">&#x05D1;</div>
+ (3 things total).
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/698291-1-frame.html b/layout/reftests/bidi/698291-1-frame.html
new file mode 100644
index 0000000000..3b745c77f9
--- /dev/null
+++ b/layout/reftests/bidi/698291-1-frame.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Test for bug 698291</title>
+ </head>
+ <body>
+ <textarea dir="auto" style="width: 100%">בדיקה</textarea>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/698291-1-ref.html b/layout/reftests/bidi/698291-1-ref.html
new file mode 100644
index 0000000000..5526e1c4c3
--- /dev/null
+++ b/layout/reftests/bidi/698291-1-ref.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Test for bug 698291</title>
+ </head>
+ <body>
+ <iframe style="width: 100%" src="698291-1-frame.html"></iframe>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/698291-1.html b/layout/reftests/bidi/698291-1.html
new file mode 100644
index 0000000000..0127e1fa84
--- /dev/null
+++ b/layout/reftests/bidi/698291-1.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html class="reftest-wait">
+ <head>
+ <meta charset="utf-8">
+ <title>Test for bug 698291</title>
+ </head>
+ <body>
+ <iframe style="width: 50%" id="f" src="698291-1-frame.html"></iframe>
+ <script type="text/javascript">
+function expandFrame()
+{
+ document.getElementById("f").style.width="100%";
+ document.documentElement.removeAttribute("class");
+}
+document.addEventListener("MozReftestInvalidate", expandFrame);
+ </script>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/698706-1-ref.html b/layout/reftests/bidi/698706-1-ref.html
new file mode 100644
index 0000000000..a5fb48020e
--- /dev/null
+++ b/layout/reftests/bidi/698706-1-ref.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>Facebook</title>
+ </head>
+ <body dir="rtl">
+ <div style="font-size: 18pt; letter-spacing: 2pt;"><bdi>Winnie the Pooh</bdi> commented on his own קישור on <bdi>Christopher Robin</bdi>'s <bdi>wall</bdi>: "<bdi>Lorem ipsum dolor sit amet</bdi>"</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/698706-1.html b/layout/reftests/bidi/698706-1.html
new file mode 100644
index 0000000000..de7e619bd2
--- /dev/null
+++ b/layout/reftests/bidi/698706-1.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>Facebook</title>
+ </head>
+ <body dir="rtl">
+ <div style="font-size: 18pt; letter-spacing: 2pt;">
+ <div style="display: inline;"><span dir="ltr">Winnie the Pooh</span> commented on his own קישור on <span dir="ltr">Christopher Robin</span>'s <span dir="ltr">wall</span>: "<span dir="ltr">Lorem ipsum dolor sit amet</span>"</div>
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/704837-1-ref.html b/layout/reftests/bidi/704837-1-ref.html
new file mode 100644
index 0000000000..d6c4387333
--- /dev/null
+++ b/layout/reftests/bidi/704837-1-ref.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>Bug 704837</title>
+ </head>
+ <body dir="rtl">
+ <div>אקספלורר 9, פיירפוקס<br> וכרום</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/704837-1.html b/layout/reftests/bidi/704837-1.html
new file mode 100644
index 0000000000..6ba2995106
--- /dev/null
+++ b/layout/reftests/bidi/704837-1.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>Bug 704837</title>
+ </head>
+ <body dir="rtl">
+ <div><div style="display: inline">אקספלורר 9, פיירפוקס<br> וכרום</div></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/712600-1-ref.html b/layout/reftests/bidi/712600-1-ref.html
new file mode 100644
index 0000000000..9a85b379be
--- /dev/null
+++ b/layout/reftests/bidi/712600-1-ref.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html><head>
+<meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <meta charset="utf-8">
+ <title>HTML Test: BDI: neutral to surrounding letters</title>
+ <link rel="reference" href="https://bug712600.bugzilla.mozilla.org/bdi-neutral-to-surrounding-run-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="
+ 'For the purposes of applying the bidirectional algorithm to the paragraph-level
+ container that a bdi element finds itself within, the bdi element must be treated
+ like a U+FFFC OBJECT REPLACEMENT CHARACTER.'
+
+ Thus, regardless of its content and its dir attribute (if any), a BDI will not prevent
+ a strongly RTL (or LTR) character preceding it from forming a single directional run with
+ another strongly RTL (LTR) character following it.">
+ <style>
+ body{
+ font-size:2em;
+ }
+ </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 dir="ltr">‭ג &lt; [b] &lt; א...‬</div>
+ <div dir="ltr">‭ג &lt; [b] &lt; א...‬</div>
+ <div dir="ltr">‭ג &lt; [b] &lt; א...‬</div>
+ <div dir="rtl">‭...a &gt; [ב] &gt; c‬</div>
+ <div dir="rtl">‭...a &gt; [ב] &gt; c‬</div>
+ <div dir="rtl">‭...a &gt; [ב] &gt; c‬</div>
+</body></html>
diff --git a/layout/reftests/bidi/712600-1.html b/layout/reftests/bidi/712600-1.html
new file mode 100644
index 0000000000..b80c334559
--- /dev/null
+++ b/layout/reftests/bidi/712600-1.html
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html><head>
+<meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <meta charset="utf-8">
+ <title>HTML Test: BDI: neutral to surrounding letters</title>
+ <link rel="reference" href="https://bug712600.bugzilla.mozilla.org/bdi-neutral-to-surrounding-run-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="
+ 'For the purposes of applying the bidirectional algorithm to the paragraph-level
+ container that a bdi element finds itself within, the bdi element must be treated
+ like a U+FFFC OBJECT REPLACEMENT CHARACTER.'
+
+ Thus, regardless of its content and its dir attribute (if any), a BDI will not prevent
+ a strongly RTL (or LTR) character preceding it from forming a single directional run with
+ another strongly RTL (LTR) character following it.">
+ <style>
+ body{
+ font-size:2em;
+ }
+ </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. -->
+
+ <!--
+ If the BDI in the following DIV were a SPAN, its b would prevent the &#x05D0; and the &#x05D1;
+ from forming a single RTL run and thus keep the &gt;s between from being mirrored into &lt;s.
+ -->
+ <div dir="ltr">א &gt; <bdi>[b]</bdi> &gt; ג...</div>
+ <div dir="ltr">א &gt; <bdi dir="ltr">[b]</bdi> &gt; ג...</div>
+ <div dir="ltr">א &gt; <bdi dir="rtl">[b]</bdi> &gt; ג...</div>
+ <div dir="rtl">a &gt; <bdi>[ב]</bdi> &gt; c...</div>
+ <div dir="rtl">a &gt; <bdi dir="ltr">[ב]</bdi> &gt; c...</div>
+ <div dir="rtl">a &gt; <bdi dir="rtl">[ב]</bdi> &gt; c...</div>
+
+
+</body></html>
diff --git a/layout/reftests/bidi/712600-2-dyn.html b/layout/reftests/bidi/712600-2-dyn.html
new file mode 100644
index 0000000000..f772241692
--- /dev/null
+++ b/layout/reftests/bidi/712600-2-dyn.html
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<html class="reftest-wait"><head>
+<meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <meta charset="utf-8">
+ <title>HTML Test: BDI: neutral when nested</title>
+ <link rel="reference" href="https://bug712600.bugzilla.mozilla.org/bdi-neutral-nested-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="
+ 'For the purposes of applying the bidirectional algorithm to the paragraph-level
+ container that a bdi element finds itself within, the bdi element must be treated
+ like a U+FFFC OBJECT REPLACEMENT CHARACTER.'">
+ <style>
+ body{
+ font-size:2em;
+ }
+ </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 dir="ltr">א + <bdi>[a + <bdi>[ב + <bdi>[b + 4]</bdi> + 3]</bdi> + 2]</bdi> + 1</div>
+ <div dir="ltr">א + <bdi dir="rtl">[a + <bdi dir="ltr">[ב + <bdi dir="rtl">[b + 4]</bdi> + 3]</bdi> + 2]</bdi> + 1</div>
+ <div dir="ltr">א + <bdi dir="ltr">[<span id='delete1'>z +</span>a + <bdi dir="rtl">[ב + <bdi dir="ltr">[b + 4]</bdi> + 3]</bdi> + 2]</bdi> + 1</div>
+ <div dir="rtl">a + <bdi>[א + <bdi>[b + <bdi>[ב + 3]</bdi> + 2]</bdi> + 1]</bdi> + 0</div>
+ <div dir="rtl">a + <bdi dir="ltr">[א + <bdi dir="rtl">[b + <bdi dir="ltr">[ב + 3]</bdi> + 2]</bdi> + 1]</bdi> + 0</div>
+ <div dir="rtl">a + <bdi dir="rtl">[א + <bdi dir="ltr">[<span
+ id='delete2'>z + </span>b + <bdi dir="rtl">[ב + 3]</bdi> + 2]</bdi> + 1]</bdi> + 0</div>
+
+ <script type="text/javascript">
+ function deleteSpans() {
+ var n = document.getElementById('delete1');
+ var n2 = document.getElementById('delete2');
+ n.remove();
+ n2.remove();
+ document.documentElement.removeAttribute("class");
+ }
+ document.addEventListener("MozReftestInvalidate", deleteSpans);
+ </script>
+
+</body></html>
diff --git a/layout/reftests/bidi/712600-2-ref.html b/layout/reftests/bidi/712600-2-ref.html
new file mode 100644
index 0000000000..3881946557
--- /dev/null
+++ b/layout/reftests/bidi/712600-2-ref.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<html><head>
+<meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <meta charset="utf-8">
+ <title>HTML Test: BDI: neutral when nested</title>
+ <link rel="reference" href="https://bug712600.bugzilla.mozilla.org/bdi-neutral-nested-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="
+ 'For the purposes of applying the bidirectional algorithm to the paragraph-level
+ container that a bdi element finds itself within, the bdi element must be treated
+ like a U+FFFC OBJECT REPLACEMENT CHARACTER.'">
+ <style>
+ body{
+ font-size:2em;
+ }
+ </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 dir="ltr">‭1 + [a + [3 + [b + 4] + ב] + 2] + א‬</div>
+ <div dir="ltr">‭1 + [a + [3 + [b + 4] + ב] + 2] + א‬</div>
+ <div dir="ltr">‭1 + [a + [3 + [b + 4] + ב] + 2] + א‬</div>
+ <div dir="rtl">‭a + [1 + [b + [3 + ב] + 2] + א] + 0‬</div>
+ <div dir="rtl">‭a + [1 + [b + [3 + ב] + 2] + א] + 0‬</div>
+ <div dir="rtl">‭a + [1 + [b + [3 + ב] + 2] + א] + 0‬</div>
+
+</body></html>
diff --git a/layout/reftests/bidi/712600-2.html b/layout/reftests/bidi/712600-2.html
new file mode 100644
index 0000000000..dae4353b3f
--- /dev/null
+++ b/layout/reftests/bidi/712600-2.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html><head>
+<meta http-equiv="content-type" content="text/html; charset=UTF-8">
+ <meta charset="utf-8">
+ <title>HTML Test: BDI: neutral when nested</title>
+ <link rel="reference" href="https://bug712600.bugzilla.mozilla.org/bdi-neutral-nested-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="
+ 'For the purposes of applying the bidirectional algorithm to the paragraph-level
+ container that a bdi element finds itself within, the bdi element must be treated
+ like a U+FFFC OBJECT REPLACEMENT CHARACTER.'">
+ <style>
+ body{
+ font-size:2em;
+ }
+ </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 dir="ltr">א + <bdi>[a + <bdi>[ב + <bdi>[b + 4]</bdi> + 3]</bdi> + 2]</bdi> + 1</div>
+ <div dir="ltr">א + <bdi dir="rtl">[a + <bdi dir="ltr">[ב + <bdi dir="rtl">[b + 4]</bdi> + 3]</bdi> + 2]</bdi> + 1</div>
+ <div dir="ltr">א + <bdi dir="ltr">[a + <bdi dir="rtl">[ב + <bdi dir="ltr">[b + 4]</bdi> + 3]</bdi> + 2]</bdi> + 1</div>
+ <div dir="rtl">a + <bdi>[א + <bdi>[b + <bdi>[ב + 3]</bdi> + 2]</bdi> + 1]</bdi> + 0</div>
+ <div dir="rtl">a + <bdi dir="ltr">[א + <bdi dir="rtl">[b + <bdi dir="ltr">[ב + 3]</bdi> + 2]</bdi> + 1]</bdi> + 0</div>
+ <div dir="rtl">a + <bdi dir="rtl">[א + <bdi dir="ltr">[b + <bdi dir="rtl">[ב + 3]</bdi> + 2]</bdi> + 1]</bdi> + 0</div>
+</body></html>
diff --git a/layout/reftests/bidi/712600-3-ref.html b/layout/reftests/bidi/712600-3-ref.html
new file mode 100644
index 0000000000..123dd3a379
--- /dev/null
+++ b/layout/reftests/bidi/712600-3-ref.html
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>HTML Test: BDI: neutral when wrapped</title>
+ <link rel="reference" href="bdi-neutral-wrapped-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="
+ 'For the purposes of applying the bidirectional algorithm to the paragraph-level
+ container that a bdi element finds itself within, the bdi element must be treated
+ like a U+FFFC OBJECT REPLACEMENT CHARACTER.'
+
+ Obviously, this should hold even if the BDI's content is wrapped over more than one line.
+ A single character (U+FFFC or otherwise) obviously never gets wrapped over more than one
+ line, but we still expect the part of the content preceding the BDI, if any, that is
+ displayed on the same line as some part of the BDI to be ordered the same as it would be
+ if that part of the BDI were replaced with U+FFFC. Similarly, we expect the part of the
+ content following the BDI, if any, that is displayed on the same line as some part of the
+ BDI to be ordered the same as it would be if that part of the BDI were replaced with U+FFFC.
+
+ In the test below, the content surrounding the BDI forms a single directional run (despite
+ the containing element and the BDI both having the opposite direction, because the BDI is
+ treated as a neutral). Thus, on the line containing the first part of the BDI, the BDI's
+ content appears after the content preceding it, and on the line containing the last part of
+ the BDI, the BDI content appears before the content following it, where both 'before' and
+ 'after' are defined relative to the surrounding content's direction. And, of course, the line
+ containing just BDI content should be ordered in the BDI's direction.">
+ <style>
+ body{
+ font-size:2em;
+ }
+ .box {
+ border: medium solid gray;
+ width: 400px;
+ 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;b &lt; &#x05D0;&#x202C;<br/>&#x202D;&gt;&gt;&gt;&#x202C;<br/>&#x202D;&#x05D3; &lt; c...&#x202C;</div>
+ <div dir="rtl">&#x202D;a &gt; &#x05D1;&#x202C;<br/>&#x202D;&lt;&lt;&lt;&#x202C;<br/>&#x202D;...&#x05D2; &gt; d&#x202C;</div>
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/712600-3.html b/layout/reftests/bidi/712600-3.html
new file mode 100644
index 0000000000..68d44b0e3e
--- /dev/null
+++ b/layout/reftests/bidi/712600-3.html
@@ -0,0 +1,63 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>HTML Test: BDI: neutral when wrapped</title>
+ <link rel="reference" href="bdi-neutral-wrapped-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="
+ 'For the purposes of applying the bidirectional algorithm to the paragraph-level
+ container that a bdi element finds itself within, the bdi element must be treated
+ like a U+FFFC OBJECT REPLACEMENT CHARACTER.'
+
+ Obviously, this should hold even if the BDI's content is wrapped over more than one line.
+ A single character (U+FFFC or otherwise) obviously never gets wrapped over more than one
+ line, but we still expect the part of the content preceding the BDI, if any, that is
+ displayed on the same line as some part of the BDI to be ordered the same as it would be
+ if that part of the BDI were replaced with U+FFFC. Similarly, we expect the part of the
+ content following the BDI, if any, that is displayed on the same line as some part of the
+ BDI to be ordered the same as it would be if that part of the BDI were replaced with U+FFFC.
+
+ In the test below, the content surrounding the BDI forms a single directional run (despite
+ the containing element and the BDI both having the opposite direction, because the BDI is
+ treated as a neutral). Thus, on the line containing the first part of the BDI, the BDI's
+ content appears after the content preceding it, and on the line containing the last part of
+ the BDI, the BDI content appears before the content following it, where both 'before' and
+ 'after' are defined relative to the surrounding content's direction. And, of course, the line
+ containing just BDI content should be ordered in the BDI's direction.">
+ <style>
+ body{
+ font-size:2em;
+ }
+ .box {
+ border: medium solid gray;
+ width: 400px;
+ 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">
+ &#x05D0; &gt;
+ <bdi>b
+ &gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+ c</bdi>
+ &gt; &#x05D3;...
+ </div>
+ <div dir="rtl">
+ a &gt;
+ <bdi>&#x05D1;
+ &gt;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+ &#x05D2;</bdi>
+ &gt; d...
+ </div>
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/718236-1-ref.html b/layout/reftests/bidi/718236-1-ref.html
new file mode 100644
index 0000000000..46f88459a9
--- /dev/null
+++ b/layout/reftests/bidi/718236-1-ref.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ </head>
+ <body>
+ <div>&#x062A;<span>&#x0661;</span><span>&#x0663;</span></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/718236-1.html b/layout/reftests/bidi/718236-1.html
new file mode 100644
index 0000000000..6db5650c22
--- /dev/null
+++ b/layout/reftests/bidi/718236-1.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <script>
+
+function boom()
+{
+ // Force frame construction
+ document.documentElement.offsetHeight;
+
+ // A dynamic change
+ var x = document.getElementById("x");
+ x.remove();
+}
+
+ </script>
+ </head>
+ <body onload="boom();">
+ <div>&#x062A;<span>&#x0661;<span id="x"></span>&#x0663;</span></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/718236-2-ref.html b/layout/reftests/bidi/718236-2-ref.html
new file mode 100644
index 0000000000..765430874f
--- /dev/null
+++ b/layout/reftests/bidi/718236-2-ref.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ </head>
+ <body>
+ <div><span>&#x0661;</span><span>&#x0663;</span>&#x062A;</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/718236-2.html b/layout/reftests/bidi/718236-2.html
new file mode 100644
index 0000000000..4c77651b8a
--- /dev/null
+++ b/layout/reftests/bidi/718236-2.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <script>
+
+function boom()
+{
+ // Force frame construction
+ document.documentElement.offsetHeight;
+
+ // A dynamic change
+ var x = document.getElementById("x");
+ x.remove();
+}
+
+ </script>
+ </head>
+ <body onload="boom();">
+ <div><span>&#x0661;<span id="x"></span>&#x0663;</span>&#x062A;</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/718236-3-ref.html b/layout/reftests/bidi/718236-3-ref.html
new file mode 100644
index 0000000000..e25629f29d
--- /dev/null
+++ b/layout/reftests/bidi/718236-3-ref.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ </head>
+ <body>
+ <div><span>&#x0661;</span><span>&#x0663;</span></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/718236-3.html b/layout/reftests/bidi/718236-3.html
new file mode 100644
index 0000000000..aad0de4553
--- /dev/null
+++ b/layout/reftests/bidi/718236-3.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <script>
+
+function boom()
+{
+ // Force frame construction
+ document.documentElement.offsetHeight;
+
+ // A dynamic change
+ var x = document.getElementById("x");
+ x.remove();
+}
+
+ </script>
+ </head>
+ <body onload="boom();">
+ <div><span>&#x0661;<span id="x"></span>&#x0663;</span></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/726460-1-ref.html b/layout/reftests/bidi/726460-1-ref.html
new file mode 100644
index 0000000000..a3430fa71e
--- /dev/null
+++ b/layout/reftests/bidi/726460-1-ref.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ </head>
+ <body>
+ <div><span><span>&#x062A</span>C</span></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/726460-1.html b/layout/reftests/bidi/726460-1.html
new file mode 100644
index 0000000000..4bf756a810
--- /dev/null
+++ b/layout/reftests/bidi/726460-1.html
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <script>
+
+function boom()
+{
+ // Force frame construction
+ document.documentElement.offsetHeight;
+
+ // A dynamic change
+ document.getElementById("x").firstChild.data = "\u062A"
+}
+
+window.addEventListener("load", boom);
+
+ </script>
+ </head>
+ <body>
+ <div><span><span id="x">&#x06CD;B</span>C</span></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/729047-1-ref.html b/layout/reftests/bidi/729047-1-ref.html
new file mode 100644
index 0000000000..e84a1fe966
--- /dev/null
+++ b/layout/reftests/bidi/729047-1-ref.html
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <title>Bug 729047</title>
+ <style>body { line-height: 1.2em; }</style>
+ </head>
+ <body>
+ <div dir=rtl>123,&#x200b;456</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/729047-1.html b/layout/reftests/bidi/729047-1.html
new file mode 100644
index 0000000000..0168476067
--- /dev/null
+++ b/layout/reftests/bidi/729047-1.html
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <title>Bug 729047</title>
+ <style>body { line-height: 1.2em; }</style>
+ </head>
+ <body>
+ <div dir=rtl>123,<wbr>456</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/730562-1-ref.html b/layout/reftests/bidi/730562-1-ref.html
new file mode 100644
index 0000000000..04a7431a49
--- /dev/null
+++ b/layout/reftests/bidi/730562-1-ref.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ </head>
+ <body>
+ <div style="direction: rtl; white-space: pre;"><span style="outline: 1px solid red;" id="x">
+
+
+</span></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/730562-1.html b/layout/reftests/bidi/730562-1.html
new file mode 100644
index 0000000000..b751b5120c
--- /dev/null
+++ b/layout/reftests/bidi/730562-1.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <script>
+
+function boom()
+{
+ // Force frame construction
+ document.documentElement.offsetHeight;
+
+ // A dynamic change
+ var x = document.getElementById("x");
+ x.firstChild.remove();
+ x.appendChild(document.createTextNode("\n\n\n"));
+}
+
+ </script>
+ </head>
+ <body onload="boom();">
+ <div style="direction: rtl; white-space: pre;"><span style="outline: 1px solid red;" id="x">
+ :p</span></div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/746987-1-ref.html b/layout/reftests/bidi/746987-1-ref.html
new file mode 100644
index 0000000000..519be1dcce
--- /dev/null
+++ b/layout/reftests/bidi/746987-1-ref.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>unicode-bidi:plaintext on inline</title>
+ </head>
+ <body>
+ <div>[<span dir="rtl">:-) &#x05d0;</span>&lrm;]: 100</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/746987-1.html b/layout/reftests/bidi/746987-1.html
new file mode 100644
index 0000000000..b576bd8bf8
--- /dev/null
+++ b/layout/reftests/bidi/746987-1.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <style>
+ .plaintext {
+ unicode-bidi: plaintext;
+ }
+ </style>
+ <title>unicode-bidi:plaintext on inline</title>
+ </head>
+ <body>
+ <div>[<span class="plaintext">:-) &#x05d0;</span>]: 100</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/746987-2-ref.html b/layout/reftests/bidi/746987-2-ref.html
new file mode 100644
index 0000000000..e8d74ba6ab
--- /dev/null
+++ b/layout/reftests/bidi/746987-2-ref.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8"/>
+ <style>
+ body {
+ font-size:2em;
+ text-align:left;
+ }
+ .ref {
+ border: medium solid gray;
+ padding: 10px;
+ width: 400px;
+ margin: 20px;
+ }
+ </style>
+ <title>unicode-bidi:plaintext on inline with paragraph breaks</title>
+ </head>
+ <body>
+ <div class="ref">
+ a-><br/>&#x05D0;->&rlm;<br/>a-><br/>&#x05D0;->&rlm;
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/746987-2.html b/layout/reftests/bidi/746987-2.html
new file mode 100644
index 0000000000..7df556b82c
--- /dev/null
+++ b/layout/reftests/bidi/746987-2.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8"/>
+ <style>
+ body {
+ font-size:2em;
+ text-align:left;
+ }
+ .test {
+ border: medium solid gray;
+ padding: 10px;
+ width: 400px;
+ margin: 20px;
+ }
+ .plaintext {
+ unicode-bidi: plaintext;
+ }
+ </style>
+ <title>unicode-bidi:plaintext on inline with paragraph breaks</title>
+ </head>
+ <body>
+ <div class="test">
+ <span class="plaintext">a-><br/>&#x05D0;-><br/>a-><br/>&#x05D0;-></span>
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/746987-3-ref.html b/layout/reftests/bidi/746987-3-ref.html
new file mode 100644
index 0000000000..b195db0a4b
--- /dev/null
+++ b/layout/reftests/bidi/746987-3-ref.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8"/>
+ <style>
+ body {
+ font-size:2em;
+ text-align:left;
+ }
+ .ref {
+ border: medium solid gray;
+ padding: 10px;
+ width: 400px;
+ margin: 20px;
+ }
+ </style>
+ <title>unicode-bidi:plaintext does not apply to embedded unicode-bidi:isolate</title>
+ </head>
+ <body>
+ <div class="ref">
+ &#x05D0;->=>&lrm;
+ <span dir="rtl">&#x05D1;->=></span>
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/746987-3.html b/layout/reftests/bidi/746987-3.html
new file mode 100644
index 0000000000..2afc59503f
--- /dev/null
+++ b/layout/reftests/bidi/746987-3.html
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8"/>
+ <style>
+ body {
+ font-size:2em;
+ text-align:left;
+ }
+ .test {
+ border: medium solid gray;
+ padding: 10px;
+ width: 400px;
+ margin: 20px;
+ }
+ .plaintext {
+ unicode-bidi: plaintext;
+ }
+ .isolate {
+ unicode-bidi: isolate;
+ }
+ </style>
+ <title>unicode-bidi:plaintext does not apply to embedded unicode-bidi:isolate</title>
+ </head>
+ <body>
+ <div class="test">
+ <span class="plaintext"><span class="isolate">&#x05D0;-></span>=></span>
+ <span class="plaintext"><span>&#x05D1;-></span>=></span>
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/746987-4-ref.html b/layout/reftests/bidi/746987-4-ref.html
new file mode 100644
index 0000000000..86043f6cbf
--- /dev/null
+++ b/layout/reftests/bidi/746987-4-ref.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8"/>
+ <style>
+ body {
+ font-size:2em;
+ text-align:left;
+ }
+ .ref {
+ border: medium solid gray;
+ padding: 10px;
+ width: 400px;
+ margin: 20px;
+ }
+ </style>
+ <title>unicode-bidi:plaintext does not apply to embedded display:block</title>
+ </head>
+ <body>
+ <div class="ref">
+ &#x05D0;->&rlm;<br/>&#x05D0;-><br/>a-><br/>&#x05D0;-><br/>&#x05D0;->&rlm;
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/746987-4.html b/layout/reftests/bidi/746987-4.html
new file mode 100644
index 0000000000..37ae02e46a
--- /dev/null
+++ b/layout/reftests/bidi/746987-4.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8"/>
+ <style>
+ body {
+ font-size:2em;
+ text-align:left;
+ }
+ .test {
+ border: medium solid gray;
+ padding: 10px;
+ width: 400px;
+ margin: 20px;
+ }
+ .plaintext {
+ unicode-bidi: plaintext;
+ }
+ </style>
+ <title>unicode-bidi:plaintext does not apply to embedded display:block</title>
+ </head>
+ <body>
+ <div class="test">
+ <div class="plaintext">
+ &#x05D0;->
+ <div>&#x05D0;-></div>
+ a->
+ <div>&#x05D0;-></div>
+ &#x05D0;->
+ </div>
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/779003-1-dynamic.html b/layout/reftests/bidi/779003-1-dynamic.html
new file mode 100644
index 0000000000..3ede41a27d
--- /dev/null
+++ b/layout/reftests/bidi/779003-1-dynamic.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<html class="reftest-wait">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <style type="text/css">
+#searchPaginationFooter {
+ direction: rtl;
+}
+
+.backLink {
+ display: inline;
+}
+
+.nextLink {
+ display: inline;
+}
+
+.pagination,
+.pagination li {
+ display: inline;
+}
+ </style>
+ </head>
+ <body>
+ <div>
+ <div id="searchPaginationFooter">
+ <p class="backLink"> &lt; <span class="gray">السابق</span></p>
+ <ul class="pagination">
+ <li><span class="select">1</span></li>
+ <li><a href="#page=2">2</a></li>
+ <li><a href="#page=3">3</a></li>
+ <li><a href="#page=4">4</a></li>
+ <li><a href="#page=5">5</a></li>
+ <li><a href="#page=6">6</a></li>
+ <li><a href="#page=7">7</a></li>
+ <li><a href="#page=8">8</a></li>
+ <li id="here"><a href="#page=9">9</a></li>
+ <li>...</li>
+ <li><a href="#page=325">325</a></li>
+ </ul>
+ <p class="nextLink"><a href="#page=2">التالي</a> &gt; </p>
+ </div>
+ </div>
+<script type="text/javascript">
+function removePage() {
+ var here = document.getElementById("here");
+ here.remove();
+ document.documentElement.removeAttribute("class");
+}
+document.addEventListener("MozReftestInvalidate", removePage);
+</script>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/779003-1-ref.html b/layout/reftests/bidi/779003-1-ref.html
new file mode 100644
index 0000000000..dfbc638ffc
--- /dev/null
+++ b/layout/reftests/bidi/779003-1-ref.html
@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <style type="text/css">
+#searchPaginationFooter {
+ direction: rtl;
+}
+
+.backLink {
+ display: inline-block;
+}
+
+.nextLink {
+ display: inline-block;
+}
+
+.pagination,
+.pagination li {
+ display: inline-block;
+ margin: 0;
+}
+
+p { margin: 0; }
+ </style>
+ </head>
+ <body>
+ <div>
+ <div id="searchPaginationFooter">
+ <p class="backLink"> &lt; <span class="gray">السابق</span></p>
+ <ul class="pagination">
+ <li><span class="select">1</span></li>
+ <li><a href="#page=2">2</a></li>
+ <li><a href="#page=3">3</a></li>
+ <li><a href="#page=4">4</a></li>
+ <li><a href="#page=5">5</a></li>
+ <li><a href="#page=6">6</a></li>
+ <li><a href="#page=7">7</a></li>
+ <li><a href="#page=8">8</a></li>
+ <li>...</li>
+ <li><a href="#page=325">325</a></li>
+ </ul>
+ <p class="nextLink"><a href="#page=2">التالي</a> &gt; </p>
+ </div>
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/779003-1.html b/layout/reftests/bidi/779003-1.html
new file mode 100644
index 0000000000..2fffb8eb13
--- /dev/null
+++ b/layout/reftests/bidi/779003-1.html
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <style type="text/css">
+#searchPaginationFooter {
+ direction: rtl;
+}
+
+.backLink {
+ display: inline;
+}
+
+.nextLink {
+ display: inline;
+}
+
+.pagination,
+.pagination li {
+ display: inline;
+}
+ </style>
+ </head>
+ <body>
+ <div>
+ <div id="searchPaginationFooter">
+ <p class="backLink"> &lt; <span class="gray">السابق</span></p>
+ <ul class="pagination">
+ <li><span class="select">1</span></li>
+ <li><a href="#page=2">2</a></li>
+ <li><a href="#page=3">3</a></li>
+ <li><a href="#page=4">4</a></li>
+ <li><a href="#page=5">5</a></li>
+ <li><a href="#page=6">6</a></li>
+ <li><a href="#page=7">7</a></li>
+ <li><a href="#page=8">8</a></li>
+ <li>...</li>
+ <li><a href="#page=325">325</a></li>
+ </ul>
+ <p class="nextLink"><a href="#page=2">التالي</a> &gt; </p>
+ </div>
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/817406-1-ref.html b/layout/reftests/bidi/817406-1-ref.html
new file mode 100644
index 0000000000..1e3e747028
--- /dev/null
+++ b/layout/reftests/bidi/817406-1-ref.html
@@ -0,0 +1,4 @@
+<!DOCTYPE html>
+<html style="width: 50%; margin-left: auto;">
+<div style="background: green; height: 10em;"></div>
+</html>
diff --git a/layout/reftests/bidi/817406-1.html b/layout/reftests/bidi/817406-1.html
new file mode 100644
index 0000000000..d01fa724e5
--- /dev/null
+++ b/layout/reftests/bidi/817406-1.html
@@ -0,0 +1,4 @@
+<!DOCTYPE html>
+<html dir="rtl" style="width: 50%;">
+<div style="background: green; height: 10em;"></div>
+</html>
diff --git a/layout/reftests/bidi/817406-2-ref.html b/layout/reftests/bidi/817406-2-ref.html
new file mode 100644
index 0000000000..fd1f20e0cf
--- /dev/null
+++ b/layout/reftests/bidi/817406-2-ref.html
@@ -0,0 +1,4 @@
+<!DOCTYPE html>
+<html style="width: 50%; right: 0; position: absolute;">
+<div style="background: green; height: 10em;"></div>
+</html>
diff --git a/layout/reftests/bidi/817406-2.html b/layout/reftests/bidi/817406-2.html
new file mode 100644
index 0000000000..ebc3ebb98c
--- /dev/null
+++ b/layout/reftests/bidi/817406-2.html
@@ -0,0 +1,4 @@
+<!DOCTYPE html>
+<html style="width: 50%; direction: rtl; position: absolute;">
+<div style="background: green; height: 10em;"></div>
+</html>
diff --git a/layout/reftests/bidi/817406-3.html b/layout/reftests/bidi/817406-3.html
new file mode 100644
index 0000000000..90313bde4a
--- /dev/null
+++ b/layout/reftests/bidi/817406-3.html
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<html style="width: 50%;">
+<body onload="document.documentElement.dir = 'rtl'">
+<div style="background: green; height: 10em;"></div>
+</body>
+</html>
diff --git a/layout/reftests/bidi/817406-4.html b/layout/reftests/bidi/817406-4.html
new file mode 100644
index 0000000000..3e90274248
--- /dev/null
+++ b/layout/reftests/bidi/817406-4.html
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<html style="width: 50%;">
+<body style="direction: rtl;">
+<div style="background: green; height: 10em;"></div>
+</body>
+</html>
diff --git a/layout/reftests/bidi/83958-1-ref.html b/layout/reftests/bidi/83958-1-ref.html
new file mode 100644
index 0000000000..146b7cd321
--- /dev/null
+++ b/layout/reftests/bidi/83958-1-ref.html
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>Bidirectional Text Test 2</title>
+ <style>
+ body { font-size: 300%; }
+ p { font-family: monospace; margin: 0; }
+ </style>
+ </head>
+ <body>
+ <p>The following lines should all read "ABCDEFGHI":</p>
+ <p>ABCDEFGHI</p>
+ <p>ABCDEFGHI</p>
+ <p>ABCDEFGHI</p>
+ <p>ABCDEFGHI</p>
+ <p>ABCDEFGHI</p>
+ <p>ABCDEFGHI</p>
+ <p>ABCDEFGHI</p>
+ <p>ABCDEFGHI</p>
+ <p>ABCDEFGHI</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/83958-1a.html b/layout/reftests/bidi/83958-1a.html
new file mode 100644
index 0000000000..5362759e0b
--- /dev/null
+++ b/layout/reftests/bidi/83958-1a.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>Bidirectional Text Test 2 - Formatting Characters</title>
+ <style>
+ body { font-size: 300%; }
+ p { font-family: monospace; text-align: left; margin: 0; }
+ </style>
+ </head>
+<!-- Testcases based on https://dbaron.org/css/test/bidi2_charcode by L. David Baron. -->
+ <body>
+ <p>The following lines should all read "ABCDEFGHI":</p>
+ <p>ABCDEFGHI</p>
+ <p dir="rtl">&#x202b;ABCDEFGHI&#x202c;</p>
+ <p dir="rtl">&#x202b;ABC<span>DEF</span>GHI&#x202c;</p>
+ <p dir="rtl">&#x202e;IHGFEDCBA&#x202c;</p>
+ <p dir="rtl">&#x202e;IHG<span>FED</span>CBA&#x202c;</p>
+ <p dir="rtl">&#x202e;IHG&#x202b;DEF&#x202c;CBA&#x202c;</p>
+ <p dir="rtl">&#x202e;IHG&#x202e;FED&#x202c;CBA&#x202c;</p>
+ <p dir="rtl">&#x202e;IHG&#x202e;FED&#x202c;CBA&#x202c;</p>
+ <p dir="rtl">&#x202e;IHG&#x202d;DEF&#x202c;CBA&#x202c;</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/83958-1b.html b/layout/reftests/bidi/83958-1b.html
new file mode 100644
index 0000000000..22d72a49cc
--- /dev/null
+++ b/layout/reftests/bidi/83958-1b.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>Bidirectional Text Test 2 - CSS</title>
+ <style>
+ body { font-size: 300%; }
+ p { font-family: monospace; text-align: left; margin: 0; }
+.rtl { direction: rtl; }
+.ltr { direction: ltr; }
+.rle { direction: rtl; unicode-bidi: embed; }
+.lre { direction: ltr; unicode-bidi: embed; }
+.rlo { direction: rtl; unicode-bidi: bidi-override; }
+.lro { direction: ltr; unicode-bidi: bidi-override; }
+.embed { unicode-bidi: embed; }
+.override { unicode-bidi: bidi-override; }
+ </style>
+ </head>
+<!-- Testcases based on https://dbaron.org/css/test/bidi2 by L. David Baron. -->
+ <body>
+ <p>The following lines should all read "ABCDEFGHI":</p>
+ <p>ABCDEFGHI</p>
+ <p class="rtl">ABCDEFGHI</p>
+ <p class="rtl">ABC<span>DEF</span>GHI</p>
+ <p class="rlo">IHGFEDCBA</p>
+ <p class="rlo">IHG<span>FED</span>CBA</p>
+ <p class="rlo">IHG<span class="embed">DEF</span>CBA</p>
+ <p class="rlo">IHG<span class="override">FED</span>CBA</p>
+ <p class="rlo">IHG<span style="unicode-bidi: inherit">FED</span>CBA</p>
+ <p class="rlo">IHG<span class="lro">DEF</span>CBA</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/83958-1c.html b/layout/reftests/bidi/83958-1c.html
new file mode 100644
index 0000000000..b81362fb44
--- /dev/null
+++ b/layout/reftests/bidi/83958-1c.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>Bidirectional Text Test 2 - HTML</title>
+ <style>
+ body { font-size: 300%; }
+ p { font-family: monospace; text-align: left; margin: 0; }
+.rtl { direction: rtl; }
+.ltr { direction: ltr; }
+.rle { direction: rtl; unicode-bidi: embed; }
+.lre { direction: ltr; unicode-bidi: embed; }
+.rlo { direction: rtl; unicode-bidi: bidi-override;}
+.lro { direction: ltr; unicode-bidi: bidi-override; }
+.embed { unicode-bidi: embed; }
+.override { unicode-bidi: bidi-override; }
+ </style>
+ </head>
+<!-- Testcases based on https://dbaron.org/css/test/bidi2_html by L. David Baron. -->
+ <body>
+ <p>The following lines should all read "ABCDEFGHI":</p>
+ <p>ABCDEFGHI</p>
+ <p class="rtl">ABCDEFGHI</p>
+ <p class="rtl">ABC<span>DEF</span>GHI</p>
+ <p class="rlo">IHGFEDCBA</p>
+ <p class="rlo">IHG<span>FED</span>CBA</p>
+ <p class="rlo">IHG<span dir="rtl">DEF</span>CBA</p>
+ <p class="rlo">IHG<bdo dir="rtl">FED</bdo>CBA</p>
+ <p class="rlo">IHG<span style="unicode-bidi: inherit">FED</span>CBA</p>
+ <p class="rlo">IHG<bdo dir="ltr">DEF</bdo>CBA</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/83958-2-ref.html b/layout/reftests/bidi/83958-2-ref.html
new file mode 100644
index 0000000000..2f775efb15
--- /dev/null
+++ b/layout/reftests/bidi/83958-2-ref.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>Bidirectional Text Test 2</title>
+ <style>
+ p { font-family: monospace; direction: ltr; unicode-bidi: bidi-override;}
+ </style>
+ </head>
+ <body>
+ <p>&#x05D2;&#x05D1;&#x05D0;</p>
+ <p>&#x05D2;&#x05D1;&#x05D0;</p>
+ <p>&#x05D0;&#x05D1;&#x05D2;</p>
+ <p>&#x05D2;&#x05D1;&#x05D0;&nbsp;ABC&nbsp;&#x05D5;&#x05D4;&#x05D3;</p>
+ <p>&#x05D5;&#x05D4;&#x05D3;&nbsp;ABC&nbsp;&#x05D2;&#x05D1;&#x05D0;</p>
+ <p>&#x05D2;&#x05D1;&#x05D0;&nbsp;ABC&nbsp;&#x05D5;&#x05D4;&#x05D3;&nbsp;DEF&nbsp;&#x05D8;&#x05D7;&#x05D6;</p>
+ <p>&#x05D2;&#x05D1;&#x05D0;&nbsp;ABC&nbsp;&#x05D5;&#x05D4;&#x05D3;&nbsp;DEF&nbsp;&#x05D8;&#x05D7;&#x05D6;</p>
+ <p>&#x05D2;&#x05D1;&#x05D0;&nbsp;ABC&nbsp;&#x05D5;&#x05D4;&#x05D3;&nbsp;DEF&nbsp;&#x05D8;&#x05D7;&#x05D6;</p>
+ <p>&#x05D8;&#x05D7;&#x05D6;&nbsp;DEF&nbsp;&#x05D5;&#x05D4;&#x05D3;&nbsp;ABC&nbsp;&#x05D2;&#x05D1;&#x05D0;</p>
+ <p>&#x05D5;&#x05D4;&#x05D3;&nbsp;ABC&nbsp;&#x05D2;&#x05D1;&#x05D0;&nbsp;DEF&nbsp;&#x05D8;&#x05D7;&#x05D6;</p>
+ <p>&#x05D5;&#x05D4;&#x05D3;&nbsp;CBA&nbsp;&#x05D2;&#x05D1;&#x05D0;&nbsp;DEF&nbsp;&#x05D8;&#x05D7;&#x05D6;</p>
+ <p>&#x05D2;&#x05D1;&#x05D0;&nbsp;ABC&nbsp;&#x05D3;&#x05D4;&#x05D5;&nbsp;DEF&nbsp;&#x05D8;&#x05D7;&#x05D6;</p>
+ <p>&#x05D8;&#x05D7;&#x05D6;&nbsp;ABC&nbsp;&#x05D3;&#x05D4;&#x05D5;&nbsp;DEF&nbsp;&#x05D2;&#x05D1;&#x05D0;</p>
+ <p>&#x05D2;&#x05D1;&#x05D0;&nbsp;ABC&nbsp;&#x05D5;&#x05D4;&#x05D3;&nbsp;DEF&nbsp;GHI&nbsp;&#x05D8;&#x05D7;&#x05D6;</p>
+ <p>FED&nbsp;&#x05D5;&#x05D4;&#x05D3;&nbsp;CBA&nbsp;&#x05D2;&#x05D1;&#x05D0;&nbsp;GHI&nbsp;&#x05D8;&#x05D7;&#x05D6;</p>
+ <p>&#x05D2;&#x05D1;&#x05D0;&nbsp;ABC&nbsp;FED&nbsp;&#x05D5;&#x05D4;&#x05D3;&nbspGHI&nbsp;&#x05D8;&#x05D7;&#x05D6;</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/83958-2a.html b/layout/reftests/bidi/83958-2a.html
new file mode 100644
index 0000000000..f9872c73ba
--- /dev/null
+++ b/layout/reftests/bidi/83958-2a.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>Bidirectional Text Test 2 - Formatting Characters</title>
+ <style>
+ p { font-family: monospace; text-align: left; }
+ </style>
+ </head>
+<!-- Testcases based on https://dbaron.org/css/test/bidi2_charcode by L. David Baron. -->
+ <body>
+ <p>&#x05D0;&#x05D1;&#x05D2;</p>
+ <p>&#x202a;&#x05D0;&#x05D1;&#x05D2;&#x202c;</p>
+ <p>&#x202d;&#x05D0;&#x05D1;&#x05D2;&#x202c;</p>
+ <p>&#x05D0;&#x05D1;&#x05D2; ABC &#x05D3;&#x05D4;&#x05D5;</p>
+ <p dir="rtl">&#x05D0;&#x05D1;&#x05D2; ABC &#x05D3;&#x05D4;&#x05D5;</p>
+ <p>&#x05D0;&#x05D1;&#x05D2; ABC &#x05D3;&#x05D4;&#x05D5; DEF &#x05D6;&#x05D7;&#x05D8;</p>
+ <p>&#x05D0;&#x05D1;&#x05D2; <span>ABC &#x05D3;&#x05D4;&#x05D5;</span> DEF &#x05D6;&#x05D7;&#x05D8;</p>
+ <p>&#x05D0;&#x05D1;&#x05D2; &#x202a;ABC &#x05D3;&#x05D4;&#x05D5; DEF&#x202c; &#x05D6;&#x05D7;&#x05D8;</p>
+ <p>&#x05D0;&#x05D1;&#x05D2; &#x202b;ABC &#x05D3;&#x05D4;&#x05D5; DEF&#x202c; &#x05D6;&#x05D7;&#x05D8;</p>
+ <p>&#x05D0;&#x05D1;&#x05D2; &#x202b;ABC &#x05D3;&#x05D4;&#x05D5;&#x202c; DEF &#x05D6;&#x05D7;&#x05D8;</p>
+ <p>&#x05D0;&#x05D1;&#x05D2; &#x202e;ABC &#x05D3;&#x05D4;&#x05D5;&#x202c; DEF &#x05D6;&#x05D7;&#x05D8;</p>
+ <p>&#x05D0;&#x05D1;&#x05D2; &#x202d;ABC &#x05D3;&#x05D4;&#x05D5;&#x202c; DEF &#x05D6;&#x05D7;&#x05D8;</p>
+ <p dir="rtl">&#x05D0;&#x05D1;&#x05D2; &#x202d;ABC &#x05D3;&#x05D4;&#x05D5;&#x202c; DEF &#x05D6;&#x05D7;&#x05D8;</p>
+ <p>&#x05D0;&#x05D1;&#x05D2; ABC &#x05D3;&#x05D4;&#x05D5; DEF GHI &#x05D6;&#x05D7;&#x05D8;</p>
+ <p>&#x05D0;&#x05D1;&#x05D2; &#x202e;ABC &#x05D3;&#x05D4;&#x05D5; DEF&#x202c; GHI &#x05D6;&#x05D7;&#x05D8;</p>
+ <p>&#x05D0;&#x05D1;&#x05D2; ABC &#x202e;&#x05D3;&#x05D4;&#x05D5; DEF&#x202c; GHI &#x05D6;&#x05D7;&#x05D8;</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/83958-2b.html b/layout/reftests/bidi/83958-2b.html
new file mode 100644
index 0000000000..d6c8c2f651
--- /dev/null
+++ b/layout/reftests/bidi/83958-2b.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <title>Bidirectional Text Test 2 - CSS</title>
+ <style>
+p { font-family: monospace; text-align: left; }
+.embed { unicode-bidi: embed; }
+.override { unicode-bidi: bidi-override; }
+.rtl { direction: rtl; }
+.ltr { direction: ltr; }
+ </style>
+ </head>
+<!-- Testcases based on https://dbaron.org/css/test/bidi2 by L. David Baron. -->
+ <body>
+ <p>&#x05D0;&#x05D1;&#x05D2;</p>
+ <p class="embed">&#x05D0;&#x05D1;&#x05D2;</p>
+ <p class="override">&#x05D0;&#x05D1;&#x05D2;</p>
+ <p>&#x05D0;&#x05D1;&#x05D2; ABC &#x05D3;&#x05D4;&#x05D5;</p>
+ <p class="rtl">&#x05D0;&#x05D1;&#x05D2; ABC &#x05D3;&#x05D4;&#x05D5;</p>
+ <p>&#x05D0;&#x05D1;&#x05D2; ABC &#x05D3;&#x05D4;&#x05D5; DEF &#x05D6;&#x05D7;&#x05D8;</p>
+ <p>&#x05D0;&#x05D1;&#x05D2; <span>ABC &#x05D3;&#x05D4;&#x05D5;</span> DEF &#x05D6;&#x05D7;&#x05D8;</p>
+ <p>&#x05D0;&#x05D1;&#x05D2; <span class="ltr embed">ABC &#x05D3;&#x05D4;&#x05D5; DEF</span> &#x05D6;&#x05D7;&#x05D8;</p>
+ <p>&#x05D0;&#x05D1;&#x05D2; <span class="rtl embed">ABC &#x05D3;&#x05D4;&#x05D5; DEF</span> &#x05D6;&#x05D7;&#x05D8;</p>
+ <p>&#x05D0;&#x05D1;&#x05D2; <span class="rtl embed">ABC &#x05D3;&#x05D4;&#x05D5;</span> DEF &#x05D6;&#x05D7;&#x05D8;</p>
+ <p>&#x05D0;&#x05D1;&#x05D2; <span class="rtl override">ABC &#x05D3;&#x05D4;&#x05D5;</span> DEF &#x05D6;&#x05D7;&#x05D8;</p>
+ <p>&#x05D0;&#x05D1;&#x05D2; <span class="ltr override">ABC &#x05D3;&#x05D4;&#x05D5;</span> DEF &#x05D6;&#x05D7;&#x05D8;</p>
+ <p class="rtl">&#x05D0;&#x05D1;&#x05D2; <span class="ltr override">ABC &#x05D3;&#x05D4;&#x05D5;</span> DEF &#x05D6;&#x05D7;&#x05D8;</p>
+ <p>&#x05D0;&#x05D1;&#x05D2; ABC &#x05D3;&#x05D4;&#x05D5; DEF GHI &#x05D6;&#x05D7;&#x05D8;</p>
+ <p>&#x05D0;&#x05D1;&#x05D2; <span class="rtl override">ABC &#x05D3;&#x05D4;&#x05D5; DEF</span> GHI &#x05D6;&#x05D7;&#x05D8;</p>
+ <p>&#x05D0;&#x05D1;&#x05D2; ABC <span class="rtl override">&#x05D3;&#x05D4;&#x05D5; DEF</span> GHI &#x05D6;&#x05D7;&#x05D8;</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/847242-1-ref.html b/layout/reftests/bidi/847242-1-ref.html
new file mode 100644
index 0000000000..8bb910fa08
--- /dev/null
+++ b/layout/reftests/bidi/847242-1-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <style>
+ div {
+ font-family: monospace;
+ font-size: 24px;
+ }
+ </style>
+ </head>
+ <body>
+ <div>PASS&#x2029;</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/847242-1.html b/layout/reftests/bidi/847242-1.html
new file mode 100644
index 0000000000..7672216f74
--- /dev/null
+++ b/layout/reftests/bidi/847242-1.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <style>
+ div {
+ unicode-bidi: bidi-override;
+ direction: rtl;
+ text-align: left;
+ font-family: monospace;
+ font-size: 24px;
+ }
+ </style>
+ </head>
+ <body>
+ <div>&#x2029;SSAP</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/869833-1-ref.xhtml b/layout/reftests/bidi/869833-1-ref.xhtml
new file mode 100644
index 0000000000..01215ea160
--- /dev/null
+++ b/layout/reftests/bidi/869833-1-ref.xhtml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?xml-stylesheet type="text/css" href="data:text/css,
+label.ltr { direction: ltr; }
+label.rtl { direction: rtl; }
+tree { height: 100px; }
+"?>
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+ <tree>
+ <treecols>
+ <treecol flex="1"/>
+ </treecols>
+ <treechildren>
+ <treeitem>
+ <treerow>
+ <treecell label="&#x202a;Hello!&#x202c;"/>
+ </treerow>
+ </treeitem>
+ <treeitem>
+ <treerow>
+ <treecell label="&#x202b;שלום!&#x202c;"/>
+ </treerow>
+ </treeitem>
+ <treeitem>
+ <treerow>
+ <treecell label="&#x202b;123 إفتح يا سمسم !&#x202c;"/>
+ </treerow>
+ </treeitem>
+ </treechildren>
+ </tree>
+</window>
diff --git a/layout/reftests/bidi/869833-1.xhtml b/layout/reftests/bidi/869833-1.xhtml
new file mode 100644
index 0000000000..3f306aed6c
--- /dev/null
+++ b/layout/reftests/bidi/869833-1.xhtml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+ <style xmlns="http://www.w3.org/1999/xhtml"><![CDATA[
+ treechildren::-moz-tree-cell, label { unicode-bidi: plaintext; }
+ tree { height: 100px; }
+ ]]></style>
+ <tree>
+ <treecols>
+ <treecol flex="1"/>
+ </treecols>
+ <treechildren>
+ <treeitem>
+ <treerow>
+ <treecell label="Hello!"/>
+ </treerow>
+ </treeitem>
+ <treeitem>
+ <treerow>
+ <treecell label="שלום!"/>
+ </treerow>
+ </treeitem>
+ <treeitem>
+ <treerow>
+ <treecell label="123 إفتح يا سمسم !"/>
+ </treerow>
+ </treeitem>
+ </treechildren>
+ </tree>
+</window>
diff --git a/layout/reftests/bidi/922530-1-ref.html b/layout/reftests/bidi/922530-1-ref.html
new file mode 100644
index 0000000000..ba297056a2
--- /dev/null
+++ b/layout/reftests/bidi/922530-1-ref.html
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>ALM character</title>
+ <style type="text/css">
+ p { font-size: 2em; }
+ </style>
+ </head>
+ <body>
+ <p>a2+1</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/922530-1.html b/layout/reftests/bidi/922530-1.html
new file mode 100644
index 0000000000..584f6d2852
--- /dev/null
+++ b/layout/reftests/bidi/922530-1.html
@@ -0,0 +1,25 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>ALM character</title>
+ <style type="text/css">
+ p { font-size: 2em; }
+ </style>
+ <!--
+ Test that U+061C functions as an invisible Arabic character.
+
+ In the test text it is followed by two European numbers with a
+ European separator between them. By rules W2, W3 and W6 of the
+ Bidi algorithm (http://unicode.org/reports/tr9/#W2) the
+ European numbers change to Arabic numbers, the ARABIC LETTER
+ MARK changes to R and the separator changes to Other Neutral,
+ and then by rule N1 the Arabic numbers make the separator
+ change to R, so the final visual order is "a2+1&#x061c;", but
+ the &#x061c should not appear
+ -->
+</head>
+ <body>
+ <p>a&#x061c;1+2</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/922550-1-ref.html b/layout/reftests/bidi/922550-1-ref.html
new file mode 100644
index 0000000000..40a51ca718
--- /dev/null
+++ b/layout/reftests/bidi/922550-1-ref.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Bidi with European terminators</title>
+ <style type="text/css">
+ p { unicode-bidi: bidi-override; }
+ </style>
+ </head>
+ <body>
+ <p>In the Bidi Algorithm, a sequence of European terminators
+ adjacent to European numbers changes to all European numbers. A
+ change was made in Unicode 6.3 so that all undefined Unicode
+ codepoints betweem U+20A0 and U+20CF would have the bidi category of
+ European terminator by default</p>
+ <p>$$$$1000000 סרפ!!!</p>
+ <p>&#x20A0;&#x20A0;&#x20A0;&#x20A0;1000000 סרפ!!!</p>
+ <p>&#x20BA;&#x20BA;&#x20BA;&#x20BA;1000000 סרפ!!!</p>
+ <p>&#x20CF;&#x20CF;&#x20CF;&#x20CF;1000000 סרפ!!!</p>
+ <p>&#x20A0;&#x20A1;&#x20A2;&#x20A3;&#x20A4;&#x20A5;&#x20A6;<!--
+ -->&#x20A7;&#x20A8;&#x20A9;&#x20AA;&#x20AB;&#x20AC;&#x20AD;<!--
+ -->&#x20AE;&#x20AF;&#x20B0;&#x20B1;&#x20B2;&#x20B3;&#x20B4;<!--
+ -->&#x20B5;&#x20B6;&#x20B7;&#x20B8;&#x20B9;&#x20BA;&#x20BB;<!--
+ -->&#x20BC;&#x20BD;&#x20BE;&#x20BF;&#x20C0;&#x20C1;&#x20C2;<!--
+ -->&#x20C3;&#x20C4;&#x20C5;&#x20C6;&#x20C7;&#x20C8;&#x20C9;<!--
+ -->&#x20CA;&#x20CB;&#x20CC;&#x20CD;&#x20CE;&#x20CF;1000000 סרפ!!!</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/922550-1.html b/layout/reftests/bidi/922550-1.html
new file mode 100644
index 0000000000..6908430791
--- /dev/null
+++ b/layout/reftests/bidi/922550-1.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Bidi with European terminators</title>
+ </head>
+ <body>
+ <p>In the Bidi Algorithm, a sequence of European terminators
+ adjacent to European numbers changes to all European numbers. A
+ change was made in Unicode 6.3 so that all undefined Unicode
+ codepoints betweem U+20A0 and U+20CF would have the bidi category of
+ European terminator by default</p>
+ <p>פרס $$$$1000000!!!</p>
+ <p>פרס &#x20A0;&#x20A0;&#x20A0;&#x20A0;1000000!!!</p>
+ <p>פרס &#x20BA;&#x20BA;&#x20BA;&#x20BA;1000000!!!</p>
+ <p>פרס &#x20CF;&#x20CF;&#x20CF;&#x20CF;1000000!!!</p>
+ <p>פרס
+ &#x20A0;&#x20A1;&#x20A2;&#x20A3;&#x20A4;&#x20A5;&#x20A6;<!--
+ -->&#x20A7;&#x20A8;&#x20A9;&#x20AA;&#x20AB;&#x20AC;&#x20AD;<!--
+ -->&#x20AE;&#x20AF;&#x20B0;&#x20B1;&#x20B2;&#x20B3;&#x20B4;<!--
+ -->&#x20B5;&#x20B6;&#x20B7;&#x20B8;&#x20B9;&#x20BA;&#x20BB;<!--
+ -->&#x20BC;&#x20BD;&#x20BE;&#x20BF;&#x20C0;&#x20C1;&#x20C2;<!--
+ -->&#x20C3;&#x20C4;&#x20C5;&#x20C6;&#x20C7;&#x20C8;&#x20C9;<!--
+ -->&#x20CA;&#x20CB;&#x20CC;&#x20CD;&#x20CE;&#x20CF;1000000!!!</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/989994-1-ref.html b/layout/reftests/bidi/989994-1-ref.html
new file mode 100644
index 0000000000..9c1ca3ad05
--- /dev/null
+++ b/layout/reftests/bidi/989994-1-ref.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Bug 989994</title>
+ <style>
+div:first-letter { color: red; }
+span { color: blue; height: 100px;}
+ </style>
+ </head>
+ <body>
+ <div style="white-space: pre-line;">A
+foo<span>Z
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/989994-1.html b/layout/reftests/bidi/989994-1.html
new file mode 100644
index 0000000000..279d897dbc
--- /dev/null
+++ b/layout/reftests/bidi/989994-1.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Bug 989994</title>
+ <style>
+div:first-letter { color: red; }
+#s { color: blue; }
+ </style>
+ </head>
+ <body onload="document.getElementById('s').style.height = '100px';">
+ <div style="white-space: pre-line;">A
+foo<span dir="rtl" id="s">Z
+ </div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/bdi-element-ref.html b/layout/reftests/bidi/bdi-element-ref.html
new file mode 100644
index 0000000000..875f9e51c2
--- /dev/null
+++ b/layout/reftests/bidi/bdi-element-ref.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+</head>
+<body>
+<p>
+ From WebKit <a href='https://bugs.webkit.org/show_bug.cgi?id=50913'>bug 50913</a>
+</p>
+<p>
+In this example, usernames are shown along with the number of posts that the user has submitted. If the bdi element were not used, the username of the Arabic user would end up confusing the text (the bidirectional algorithm would put the colon and the number "3" next to the word "User" rather than next to the word "posts").
+</p>
+<ul>
+ <li><bdo dir="ltr">User jcranmer: 12 posts.</bdo>
+ <li><bdo dir="ltr">User hober: 5 posts.</bdo>
+ <li><bdo dir="ltr">User نايإ: 3 posts.</bdo>
+</ul>
+</body>
+</html>
diff --git a/layout/reftests/bidi/bdi-element.html b/layout/reftests/bidi/bdi-element.html
new file mode 100644
index 0000000000..d4ef2cd83b
--- /dev/null
+++ b/layout/reftests/bidi/bdi-element.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+</head>
+<body>
+<p>
+ From WebKit <a href='https://bugs.webkit.org/show_bug.cgi?id=50913'>bug 50913</a>
+</p>
+<p>
+In this example, usernames are shown along with the number of posts that the user has submitted. If the bdi element were not used, the username of the Arabic user would end up confusing the text (the bidirectional algorithm would put the colon and the number "3" next to the word "User" rather than next to the word "posts").
+</p>
+<ul>
+ <li>User <bdi>jcranmer</bdi>: 12 posts.
+ <li>User <bdi>hober</bdi>: 5 posts.
+ <li>User <bdi>إيان</bdi>: 3 posts.
+</ul>
+</body>
+</html>
diff --git a/layout/reftests/bidi/bidi-000-ref.html b/layout/reftests/bidi/bidi-000-ref.html
new file mode 100644
index 0000000000..9f86f8fa61
--- /dev/null
+++ b/layout/reftests/bidi/bidi-000-ref.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<!-- Bidi reftest 000: bidi overrides. If this fails, none of the tests in this
+ directory can be relied upon -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ </head>
+ <style type="text/css">
+body {
+ font-family: serif;
+ font-size: 24px;
+}
+ </style>
+ <body>
+ <p>god yzal eht revo spmuj xof nworb kciuq eht</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/bidi-000.html b/layout/reftests/bidi/bidi-000.html
new file mode 100644
index 0000000000..84d8ec534c
--- /dev/null
+++ b/layout/reftests/bidi/bidi-000.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<!-- Bidi reftest 000: bidi overrides. If this fails, none of the tests in this
+ directory can be relied upon -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ </head>
+ <style type="text/css">
+body {
+ font-family: serif;
+ font-size: 24px;
+}
+ </style>
+ <body>
+ <p><span style="direction: rtl; unicode-bidi: bidi-override">the quick brown fox jumps over the lazy dog</span></p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/bidi-001-j.html b/layout/reftests/bidi/bidi-001-j.html
new file mode 100644
index 0000000000..045232ed63
--- /dev/null
+++ b/layout/reftests/bidi/bidi-001-j.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<!-- Bidi reftest 001-j: rtl text only with justification -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ </head>
+ <style type="text/css">
+body {
+ font-family: serif;
+ font-size: 24px;
+}
+ </style>
+ <body>
+ <p lang="he" style="text-align: justify">המשא אשר חזה חבקוק הנביא</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/bidi-001-ref.html b/layout/reftests/bidi/bidi-001-ref.html
new file mode 100644
index 0000000000..26583434d1
--- /dev/null
+++ b/layout/reftests/bidi/bidi-001-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ <style type="text/css">
+body {
+ font-family: serif;
+ font-size: 24px;
+}
+ </style>
+ </head>
+ <body>
+ <p lang="he" style="unicode-bidi: bidi-override">איבנה קוקבח הזח רשא אשמה</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/bidi-001-v.html b/layout/reftests/bidi/bidi-001-v.html
new file mode 100644
index 0000000000..adc4fbdaee
--- /dev/null
+++ b/layout/reftests/bidi/bidi-001-v.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<!-- Bidi reftest 001-v: rtl text only in visual order -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=iso-8859-8">
+ </head>
+ <style type="text/css">
+body {
+ font-family: serif;
+ font-size: 24px;
+}
+ </style>
+ <body>
+ <p lang="he"> </p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/bidi-001.html b/layout/reftests/bidi/bidi-001.html
new file mode 100644
index 0000000000..1b5bedae17
--- /dev/null
+++ b/layout/reftests/bidi/bidi-001.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<!-- Bidi reftest 001: rtl text only -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ </head>
+ <style type="text/css">
+body {
+ font-family: serif;
+ font-size: 24px;
+}
+ </style
+ <body>
+ <p lang="he">המשא אשר חזה חבקוק הנביא</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/bidi-002-ref.html b/layout/reftests/bidi/bidi-002-ref.html
new file mode 100644
index 0000000000..5fd5e7483e
--- /dev/null
+++ b/layout/reftests/bidi/bidi-002-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ <style type="text/css">
+body {
+ font-family: serif;
+ font-size: 24px;
+}
+ </style>
+ </head>
+ <body>
+ <p lang="he" style="unicode-bidi: bidi-override">v2.0.0.4 תירבעה הסריגה Mozilla Firefox</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/bidi-002.html b/layout/reftests/bidi/bidi-002.html
new file mode 100644
index 0000000000..dcb966823a
--- /dev/null
+++ b/layout/reftests/bidi/bidi-002.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<!-- Bidi reftest 002: mixed rtl and ltr text -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ </head>
+ <style type="text/css">
+body {
+ font-family: serif;
+ font-size: 24px;
+}
+ </style>
+ <body>
+ <p lang="he" style="direction: rtl; text-align: left;">Mozilla Firefox הגירסה העברית v2.0.0.4</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/bidi-003-ref.html b/layout/reftests/bidi/bidi-003-ref.html
new file mode 100644
index 0000000000..65f6e8cfb1
--- /dev/null
+++ b/layout/reftests/bidi/bidi-003-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ <style type="text/css">
+body {
+ font-family: serif;
+ font-size: 24px;
+}
+ </style>
+ </head>
+ <body>
+ <p lang="he" style="unicode-bidi: bidi-override">v2.0.0.4 תירבעה <b>הסריגה </b>Mozilla <b>Firefox</b></p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/bidi-003.html b/layout/reftests/bidi/bidi-003.html
new file mode 100644
index 0000000000..56f491c05c
--- /dev/null
+++ b/layout/reftests/bidi/bidi-003.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<!-- Bidi reftest 003: mixed rtl and ltr text with element boundaries crossing
+ directional run boundaries -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ </head>
+ <style type="text/css">
+body {
+ font-family: serif;
+ font-size: 24px;
+}
+ </style>
+ <body>
+ <p lang="he" style="direction: rtl; text-align: left;">Mozilla <b>Firefox הגירסה</b> העברית v2.0.0.4</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/bidi-004-j.html b/layout/reftests/bidi/bidi-004-j.html
new file mode 100644
index 0000000000..92c2cdccc4
--- /dev/null
+++ b/layout/reftests/bidi/bidi-004-j.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<!-- Bidi reftest 004-j: rtl text with diacritics and justification -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ </head>
+ <style type="text/css">
+body {
+ font-family: Times New Roman, serif;
+ font-size: 24px;
+}
+ </style>
+ <body>
+ <p lang="he" style="direction: rtl; text-align: justify;">
+ &#x05D1;&#x05BC;&#x05D5;&#x05BC;&#x05E9;&#x05C1;</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/bidi-004-ref.html b/layout/reftests/bidi/bidi-004-ref.html
new file mode 100644
index 0000000000..8a2f0bb18c
--- /dev/null
+++ b/layout/reftests/bidi/bidi-004-ref.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ <style type="text/css">
+body {
+ font-family: Times New Roman, serif;
+ font-size: 24px;
+}
+ </style>
+ </head>
+ <body>
+ <p lang="he" style="unicode-bidi: bidi-override; text-align: right">
+ &#xFB2A;&#xFB35;&#xFB31;</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/bidi-004.html b/layout/reftests/bidi/bidi-004.html
new file mode 100644
index 0000000000..0a3f4eb5a1
--- /dev/null
+++ b/layout/reftests/bidi/bidi-004.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<!-- Bidi reftest 004: rtl text with diacritics -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ </head>
+ <style type="text/css">
+body {
+ font-family: Times New Roman, serif;
+ font-size: 24px;
+}
+ </style>
+ <body>
+ <p lang="he" style="direction: rtl;">
+ &#x05D1;&#x05BC;&#x05D5;&#x05BC;&#x05E9;&#x05C1;</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/bidi-005-ref.html b/layout/reftests/bidi/bidi-005-ref.html
new file mode 100644
index 0000000000..b7453d1cdd
--- /dev/null
+++ b/layout/reftests/bidi/bidi-005-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ <style type="text/css">
+body {
+ font-family: serif;
+ font-size: 24px;
+}
+ </style>
+ </head>
+ <body>
+ <p lang="he" style="unicode-bidi: bidi-override">&#x10906;&#x10905;&#x10907;&#x10913;&#x10909;&#x1091F;&#x10910;&#x1090E;&#x10900;&#x10905;&#x10907;&#x10913;&#x10909;</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/bidi-005.html b/layout/reftests/bidi/bidi-005.html
new file mode 100644
index 0000000000..0ec2eafc7a
--- /dev/null
+++ b/layout/reftests/bidi/bidi-005.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<!-- Bidi reftest 005: rtl text in SMP -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ </head>
+ <style type="text/css">
+body {
+ font-family: serif;
+ font-size: 24px;
+}
+ </style>
+ <body>
+ <p lang="he">&#x10909;&#x10913;&#x10907;&#x10905;&#x10900;&#x1090E;&#x10910;&#x1091F;&#x10909;&#x10913;&#x10907;&#x10905;&#x10906;</p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/bidi-006-j.html b/layout/reftests/bidi/bidi-006-j.html
new file mode 100644
index 0000000000..f533d7958d
--- /dev/null
+++ b/layout/reftests/bidi/bidi-006-j.html
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<!-- Bidi reftest 006: rtl text with diacritics. This is hard to reftest
+ because if there is a bug it will typically be exhibited in the reference
+ rendering as well as in the test. The approach adopted here is to
+ position boxes around the edges of the character without a diacritic and
+ make sure that the character with the diacritic displays in the same
+ space, so that if the diacritic is shifted to the right or left it will
+ be cut off in the test rendering and be visible (in the wrong place) in
+ the reference rendering.
+
+ Relevant bugs:
+ 378351 (Windows)
+ 386573 (Mac)
+ 387653 (Linux)
+ 395676 (Windows)
+ -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ </head>
+ <style type="text/css">
+body { background: white; color: black; }
+p {
+ font-family: sans-serif;
+ font-size: 36px;
+ margin: 0;
+ text-align: justify;
+}
+span {
+ display: inline-block;
+ width: 3em;
+ height: 3em;
+ margin-top: -2em;
+ vertical-align: bottom;
+ background: white;
+}
+/* borders should be covered by overhang */
+p#test {
+ border-left: 3em solid red;
+ border-right: 3em solid red;
+ width: max-content;
+ width: intrinsic;
+}
+ </style>
+ <body>
+ <p id="test">&#x5e0;&#x5b8;</p>
+ <p id="overhang"><span></span>&#x5e0;<span></span></p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/bidi-006-ref.html b/layout/reftests/bidi/bidi-006-ref.html
new file mode 100644
index 0000000000..5f4a31e44c
--- /dev/null
+++ b/layout/reftests/bidi/bidi-006-ref.html
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<!-- Bidi reftest 006: rtl text with diacritics. This is hard to reftest
+ because if there is a bug it will typically be exhibited in the reference
+ rendering as well as in the test. The approach adopted here is to
+ position boxes around the edges of the character without a diacritic and
+ make sure that the character with the diacritic displays in the same
+ space, so that if the diacritic is shifted to the right or left it will
+ be cut off in the test rendering and be visible (in the wrong place) in
+ the reference rendering.
+
+ Relevant bugs:
+ 378351 (Windows)
+ 386573 (Mac)
+ 387653 (Linux)
+ 395676 (Windows)
+ -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ </head>
+ <style type="text/css">
+body { background: white; color: black; }
+p {
+ font-family: sans-serif;
+ font-size: 36px;
+ margin: 0;
+}
+span {
+ display: inline-block;
+ width: 3em;
+ height: 3em;
+ margin-top: -2em;
+ vertical-align: bottom;
+}
+p#test { margin: 0 3em; }
+ </style>
+ <body>
+ <p id="test">&#x5e0;&#x5b8;</p>
+ <p id="overhang"><span></span>&#x5e0;<span></span></p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/bidi-006.html b/layout/reftests/bidi/bidi-006.html
new file mode 100644
index 0000000000..cf9c14916f
--- /dev/null
+++ b/layout/reftests/bidi/bidi-006.html
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<!-- Bidi reftest 006: rtl text with diacritics. This is hard to reftest
+ because if there is a bug it will typically be exhibited in the reference
+ rendering as well as in the test. The approach adopted here is to
+ position boxes around the edges of the character without a diacritic and
+ make sure that the character with the diacritic displays in the same
+ space, so that if the diacritic is shifted to the right or left it will
+ be cut off in the test rendering and be visible (in the wrong place) in
+ the reference rendering.
+
+ Relevant bugs:
+ 378351 (Windows)
+ 386573 (Mac)
+ 387653 (Linux)
+ 395676 (Windows)
+ -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ </head>
+ <style type="text/css">
+body { background: white; color: black; }
+p {
+ font-family: sans-serif;
+ font-size: 36px;
+ margin: 0;
+}
+span {
+ display: inline-block;
+ width: 3em;
+ height: 3em;
+ margin-top: -2em;
+ vertical-align: bottom;
+ background: white;
+}
+/* borders should be covered by overhang */
+p#test {
+ border-left: 3em solid red;
+ border-right: 3em solid red;
+ width: max-content;
+ width: intrinsic;
+}
+ </style>
+ <body>
+ <p id="test">&#x5e0;&#x5b8;</p>
+ <p id="overhang"><span></span>&#x5e0;<span></span></p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/bidiMirroring-ref.svg b/layout/reftests/bidi/bidiMirroring-ref.svg
new file mode 100644
index 0000000000..988ff28882
--- /dev/null
+++ b/layout/reftests/bidi/bidiMirroring-ref.svg
@@ -0,0 +1,8 @@
+<svg xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ width="800" height="800" class="reftest-wait" onload="reference()">
+ <style>
+ @font-face { font-family: BitPattern; src: url(../fonts/BitPattern.woff); }
+ </style>
+ <script xlink:href="bidiMirroring.js"/>
+</svg>
diff --git a/layout/reftests/bidi/bidiMirroring.js b/layout/reftests/bidi/bidiMirroring.js
new file mode 100644
index 0000000000..0fd521c5f8
--- /dev/null
+++ b/layout/reftests/bidi/bidiMirroring.js
@@ -0,0 +1,407 @@
+// Pairs of mirrored characters from
+// http://www.unicode.org/Public/6.1.0/ucd/BidiMirroring.txt
+var mirrors = [
+ [0x0028, 0x0029],
+ [0x0029, 0x0028],
+ [0x003C, 0x003E],
+ [0x003E, 0x003C],
+ [0x005B, 0x005D],
+ [0x005D, 0x005B],
+ [0x007B, 0x007D],
+ [0x007D, 0x007B],
+ [0x00AB, 0x00BB],
+ [0x00BB, 0x00AB],
+// These four are disabled as on Mac earlier than 10.7, Tibetan characters will
+// not be used from the BitPattern.woff font due to lack of platform support.
+//
+// [0x0F3A, 0x0F3B],
+// [0x0F3B, 0x0F3A],
+// [0x0F3C, 0x0F3D],
+// [0x0F3D, 0x0F3C],
+ [0x169B, 0x169C],
+ [0x169C, 0x169B],
+ [0x2039, 0x203A],
+ [0x203A, 0x2039],
+ [0x2045, 0x2046],
+ [0x2046, 0x2045],
+ [0x207D, 0x207E],
+ [0x207E, 0x207D],
+ [0x208D, 0x208E],
+ [0x208E, 0x208D],
+ [0x2208, 0x220B],
+ [0x2209, 0x220C],
+ [0x220A, 0x220D],
+ [0x220B, 0x2208],
+ [0x220C, 0x2209],
+ [0x220D, 0x220A],
+ [0x2215, 0x29F5],
+ [0x223C, 0x223D],
+ [0x223D, 0x223C],
+ [0x2243, 0x22CD],
+ [0x2252, 0x2253],
+ [0x2253, 0x2252],
+ [0x2254, 0x2255],
+ [0x2255, 0x2254],
+ [0x2264, 0x2265],
+ [0x2265, 0x2264],
+ [0x2266, 0x2267],
+ [0x2267, 0x2266],
+ [0x2268, 0x2269],
+ [0x2269, 0x2268],
+ [0x226A, 0x226B],
+ [0x226B, 0x226A],
+ [0x226E, 0x226F],
+ [0x226F, 0x226E],
+ [0x2270, 0x2271],
+ [0x2271, 0x2270],
+ [0x2272, 0x2273],
+ [0x2273, 0x2272],
+ [0x2274, 0x2275],
+ [0x2275, 0x2274],
+ [0x2276, 0x2277],
+ [0x2277, 0x2276],
+ [0x2278, 0x2279],
+ [0x2279, 0x2278],
+ [0x227A, 0x227B],
+ [0x227B, 0x227A],
+ [0x227C, 0x227D],
+ [0x227D, 0x227C],
+ [0x227E, 0x227F],
+ [0x227F, 0x227E],
+ [0x2280, 0x2281],
+ [0x2281, 0x2280],
+ [0x2282, 0x2283],
+ [0x2283, 0x2282],
+ [0x2284, 0x2285],
+ [0x2285, 0x2284],
+ [0x2286, 0x2287],
+ [0x2287, 0x2286],
+ [0x2288, 0x2289],
+ [0x2289, 0x2288],
+ [0x228A, 0x228B],
+ [0x228B, 0x228A],
+ [0x228F, 0x2290],
+ [0x2290, 0x228F],
+ [0x2291, 0x2292],
+ [0x2292, 0x2291],
+ [0x2298, 0x29B8],
+ [0x22A2, 0x22A3],
+ [0x22A3, 0x22A2],
+ [0x22A6, 0x2ADE],
+ [0x22A8, 0x2AE4],
+ [0x22A9, 0x2AE3],
+ [0x22AB, 0x2AE5],
+ [0x22B0, 0x22B1],
+ [0x22B1, 0x22B0],
+ [0x22B2, 0x22B3],
+ [0x22B3, 0x22B2],
+ [0x22B4, 0x22B5],
+ [0x22B5, 0x22B4],
+ [0x22B6, 0x22B7],
+ [0x22B7, 0x22B6],
+ [0x22C9, 0x22CA],
+ [0x22CA, 0x22C9],
+ [0x22CB, 0x22CC],
+ [0x22CC, 0x22CB],
+ [0x22CD, 0x2243],
+ [0x22D0, 0x22D1],
+ [0x22D1, 0x22D0],
+ [0x22D6, 0x22D7],
+ [0x22D7, 0x22D6],
+ [0x22D8, 0x22D9],
+ [0x22D9, 0x22D8],
+ [0x22DA, 0x22DB],
+ [0x22DB, 0x22DA],
+ [0x22DC, 0x22DD],
+ [0x22DD, 0x22DC],
+ [0x22DE, 0x22DF],
+ [0x22DF, 0x22DE],
+ [0x22E0, 0x22E1],
+ [0x22E1, 0x22E0],
+ [0x22E2, 0x22E3],
+ [0x22E3, 0x22E2],
+ [0x22E4, 0x22E5],
+ [0x22E5, 0x22E4],
+ [0x22E6, 0x22E7],
+ [0x22E7, 0x22E6],
+ [0x22E8, 0x22E9],
+ [0x22E9, 0x22E8],
+ [0x22EA, 0x22EB],
+ [0x22EB, 0x22EA],
+ [0x22EC, 0x22ED],
+ [0x22ED, 0x22EC],
+ [0x22F0, 0x22F1],
+ [0x22F1, 0x22F0],
+ [0x22F2, 0x22FA],
+ [0x22F3, 0x22FB],
+ [0x22F4, 0x22FC],
+ [0x22F6, 0x22FD],
+ [0x22F7, 0x22FE],
+ [0x22FA, 0x22F2],
+ [0x22FB, 0x22F3],
+ [0x22FC, 0x22F4],
+ [0x22FD, 0x22F6],
+ [0x22FE, 0x22F7],
+ [0x2308, 0x2309],
+ [0x2309, 0x2308],
+ [0x230A, 0x230B],
+ [0x230B, 0x230A],
+ [0x2329, 0x232A],
+ [0x232A, 0x2329],
+ [0x2768, 0x2769],
+ [0x2769, 0x2768],
+ [0x276A, 0x276B],
+ [0x276B, 0x276A],
+ [0x276C, 0x276D],
+ [0x276D, 0x276C],
+ [0x276E, 0x276F],
+ [0x276F, 0x276E],
+ [0x2770, 0x2771],
+ [0x2771, 0x2770],
+ [0x2772, 0x2773],
+ [0x2773, 0x2772],
+ [0x2774, 0x2775],
+ [0x2775, 0x2774],
+ [0x27C3, 0x27C4],
+ [0x27C4, 0x27C3],
+ [0x27C5, 0x27C6],
+ [0x27C6, 0x27C5],
+ [0x27C8, 0x27C9],
+ [0x27C9, 0x27C8],
+ [0x27CB, 0x27CD],
+ [0x27CD, 0x27CB],
+ [0x27D5, 0x27D6],
+ [0x27D6, 0x27D5],
+ [0x27DD, 0x27DE],
+ [0x27DE, 0x27DD],
+ [0x27E2, 0x27E3],
+ [0x27E3, 0x27E2],
+ [0x27E4, 0x27E5],
+ [0x27E5, 0x27E4],
+ [0x27E6, 0x27E7],
+ [0x27E7, 0x27E6],
+ [0x27E8, 0x27E9],
+ [0x27E9, 0x27E8],
+ [0x27EA, 0x27EB],
+ [0x27EB, 0x27EA],
+ [0x27EC, 0x27ED],
+ [0x27ED, 0x27EC],
+ [0x27EE, 0x27EF],
+ [0x27EF, 0x27EE],
+ [0x2983, 0x2984],
+ [0x2984, 0x2983],
+ [0x2985, 0x2986],
+ [0x2986, 0x2985],
+ [0x2987, 0x2988],
+ [0x2988, 0x2987],
+ [0x2989, 0x298A],
+ [0x298A, 0x2989],
+ [0x298B, 0x298C],
+ [0x298C, 0x298B],
+ [0x298D, 0x2990],
+ [0x298E, 0x298F],
+ [0x298F, 0x298E],
+ [0x2990, 0x298D],
+ [0x2991, 0x2992],
+ [0x2992, 0x2991],
+ [0x2993, 0x2994],
+ [0x2994, 0x2993],
+ [0x2995, 0x2996],
+ [0x2996, 0x2995],
+ [0x2997, 0x2998],
+ [0x2998, 0x2997],
+ [0x29B8, 0x2298],
+ [0x29C0, 0x29C1],
+ [0x29C1, 0x29C0],
+ [0x29C4, 0x29C5],
+ [0x29C5, 0x29C4],
+ [0x29CF, 0x29D0],
+ [0x29D0, 0x29CF],
+ [0x29D1, 0x29D2],
+ [0x29D2, 0x29D1],
+ [0x29D4, 0x29D5],
+ [0x29D5, 0x29D4],
+ [0x29D8, 0x29D9],
+ [0x29D9, 0x29D8],
+ [0x29DA, 0x29DB],
+ [0x29DB, 0x29DA],
+ [0x29F5, 0x2215],
+ [0x29F8, 0x29F9],
+ [0x29F9, 0x29F8],
+ [0x29FC, 0x29FD],
+ [0x29FD, 0x29FC],
+ [0x2A2B, 0x2A2C],
+ [0x2A2C, 0x2A2B],
+ [0x2A2D, 0x2A2E],
+ [0x2A2E, 0x2A2D],
+ [0x2A34, 0x2A35],
+ [0x2A35, 0x2A34],
+ [0x2A3C, 0x2A3D],
+ [0x2A3D, 0x2A3C],
+ [0x2A64, 0x2A65],
+ [0x2A65, 0x2A64],
+ [0x2A79, 0x2A7A],
+ [0x2A7A, 0x2A79],
+ [0x2A7D, 0x2A7E],
+ [0x2A7E, 0x2A7D],
+ [0x2A7F, 0x2A80],
+ [0x2A80, 0x2A7F],
+ [0x2A81, 0x2A82],
+ [0x2A82, 0x2A81],
+ [0x2A83, 0x2A84],
+ [0x2A84, 0x2A83],
+ [0x2A8B, 0x2A8C],
+ [0x2A8C, 0x2A8B],
+ [0x2A91, 0x2A92],
+ [0x2A92, 0x2A91],
+ [0x2A93, 0x2A94],
+ [0x2A94, 0x2A93],
+ [0x2A95, 0x2A96],
+ [0x2A96, 0x2A95],
+ [0x2A97, 0x2A98],
+ [0x2A98, 0x2A97],
+ [0x2A99, 0x2A9A],
+ [0x2A9A, 0x2A99],
+ [0x2A9B, 0x2A9C],
+ [0x2A9C, 0x2A9B],
+ [0x2AA1, 0x2AA2],
+ [0x2AA2, 0x2AA1],
+ [0x2AA6, 0x2AA7],
+ [0x2AA7, 0x2AA6],
+ [0x2AA8, 0x2AA9],
+ [0x2AA9, 0x2AA8],
+ [0x2AAA, 0x2AAB],
+ [0x2AAB, 0x2AAA],
+ [0x2AAC, 0x2AAD],
+ [0x2AAD, 0x2AAC],
+ [0x2AAF, 0x2AB0],
+ [0x2AB0, 0x2AAF],
+ [0x2AB3, 0x2AB4],
+ [0x2AB4, 0x2AB3],
+ [0x2ABB, 0x2ABC],
+ [0x2ABC, 0x2ABB],
+ [0x2ABD, 0x2ABE],
+ [0x2ABE, 0x2ABD],
+ [0x2ABF, 0x2AC0],
+ [0x2AC0, 0x2ABF],
+ [0x2AC1, 0x2AC2],
+ [0x2AC2, 0x2AC1],
+ [0x2AC3, 0x2AC4],
+ [0x2AC4, 0x2AC3],
+ [0x2AC5, 0x2AC6],
+ [0x2AC6, 0x2AC5],
+ [0x2ACD, 0x2ACE],
+ [0x2ACE, 0x2ACD],
+ [0x2ACF, 0x2AD0],
+ [0x2AD0, 0x2ACF],
+ [0x2AD1, 0x2AD2],
+ [0x2AD2, 0x2AD1],
+ [0x2AD3, 0x2AD4],
+ [0x2AD4, 0x2AD3],
+ [0x2AD5, 0x2AD6],
+ [0x2AD6, 0x2AD5],
+ [0x2ADE, 0x22A6],
+ [0x2AE3, 0x22A9],
+ [0x2AE4, 0x22A8],
+ [0x2AE5, 0x22AB],
+ [0x2AEC, 0x2AED],
+ [0x2AED, 0x2AEC],
+ [0x2AF7, 0x2AF8],
+ [0x2AF8, 0x2AF7],
+ [0x2AF9, 0x2AFA],
+ [0x2AFA, 0x2AF9],
+ [0x2E02, 0x2E03],
+ [0x2E03, 0x2E02],
+ [0x2E04, 0x2E05],
+ [0x2E05, 0x2E04],
+ [0x2E09, 0x2E0A],
+ [0x2E0A, 0x2E09],
+ [0x2E0C, 0x2E0D],
+ [0x2E0D, 0x2E0C],
+ [0x2E1C, 0x2E1D],
+ [0x2E1D, 0x2E1C],
+ [0x2E20, 0x2E21],
+ [0x2E21, 0x2E20],
+ [0x2E22, 0x2E23],
+ [0x2E23, 0x2E22],
+ [0x2E24, 0x2E25],
+ [0x2E25, 0x2E24],
+ [0x2E26, 0x2E27],
+ [0x2E27, 0x2E26],
+ [0x2E28, 0x2E29],
+ [0x2E29, 0x2E28],
+ [0x3008, 0x3009],
+ [0x3009, 0x3008],
+ [0x300A, 0x300B],
+ [0x300B, 0x300A],
+ [0x300C, 0x300D],
+ [0x300D, 0x300C],
+ [0x300E, 0x300F],
+ [0x300F, 0x300E],
+ [0x3010, 0x3011],
+ [0x3011, 0x3010],
+ [0x3014, 0x3015],
+ [0x3015, 0x3014],
+ [0x3016, 0x3017],
+ [0x3017, 0x3016],
+ [0x3018, 0x3019],
+ [0x3019, 0x3018],
+ [0x301A, 0x301B],
+ [0x301B, 0x301A],
+ [0xFE59, 0xFE5A],
+ [0xFE5A, 0xFE59],
+ [0xFE5B, 0xFE5C],
+ [0xFE5C, 0xFE5B],
+ [0xFE5D, 0xFE5E],
+ [0xFE5E, 0xFE5D],
+ [0xFE64, 0xFE65],
+ [0xFE65, 0xFE64],
+ [0xFF08, 0xFF09],
+ [0xFF09, 0xFF08],
+ [0xFF1C, 0xFF1E],
+ [0xFF1E, 0xFF1C],
+ [0xFF3B, 0xFF3D],
+ [0xFF3D, 0xFF3B],
+ [0xFF5B, 0xFF5D],
+ [0xFF5D, 0xFF5B],
+ [0xFF5F, 0xFF60],
+ [0xFF60, 0xFF5F],
+ [0xFF62, 0xFF63],
+ [0xFF63, 0xFF62]
+];
+
+function show(attributes, text) {
+ var e = document.createElementNS("http://www.w3.org/2000/svg", "text");
+ for (var name in attributes) {
+ e.setAttribute(name, attributes[name]);
+ }
+ e.textContent = text;
+ document.documentElement.appendChild(e);
+}
+
+function showCharacters(isReference) {
+ var row = 0, col = 0;
+ for (var i = 0; i < mirrors.length; i++) {
+ show({ x: col * 50 + 30,
+ y: row * 30 + 30,
+ direction: isReference ? "ltr" : "rtl",
+ "unicode-bidi": "embed",
+ "text-anchor": "middle",
+ "font-family": "BitPattern",
+ "font-size": "40px" },
+ String.fromCharCode(mirrors[i][isReference ? 0 : 1]));
+ if (++col == 16) {
+ col = 0;
+ row++;
+ }
+ }
+ document.documentElement.removeAttribute("class");
+}
+
+function test() {
+ showCharacters(false);
+}
+
+function reference() {
+ showCharacters(true);
+}
diff --git a/layout/reftests/bidi/bidiMirroring.svg b/layout/reftests/bidi/bidiMirroring.svg
new file mode 100644
index 0000000000..93ef3a0041
--- /dev/null
+++ b/layout/reftests/bidi/bidiMirroring.svg
@@ -0,0 +1,22 @@
+<svg xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ width="800" height="800" class="reftest-wait" onload="test()">
+ <!--
+ BitPattern.woff is a font with a glyph for each mirrored character.
+ (The glyph is a bit pattern of the character's code point, hence the
+ font name.) The font was generated by:
+
+ 1. Creating an input file that consisted of a four-hex-digit code
+ point per line, for each glyph to be included in the font.
+ (For this test, that would be the 360-odd mirrored characters.)
+
+ 2. Running ./generate-bitpattern-font.pl on that input file, which
+ generates an SVG Font file.
+
+ 3. Using FontForge to convert that SVG Font file into a WOFF file.
+ -->
+ <style>
+ @font-face { font-family: BitPattern; src: url(../fonts/BitPattern.woff); }
+ </style>
+ <script xlink:href="bidiMirroring.js"/>
+</svg>
diff --git a/layout/reftests/bidi/bidiSVG-01-ref.svg b/layout/reftests/bidi/bidiSVG-01-ref.svg
new file mode 100644
index 0000000000..c84d5374c4
--- /dev/null
+++ b/layout/reftests/bidi/bidiSVG-01-ref.svg
@@ -0,0 +1,3 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200">
+ <text x="100" y="20">Bidi in SVG</text>
+</svg>
diff --git a/layout/reftests/bidi/bidiSVG-01.svg b/layout/reftests/bidi/bidiSVG-01.svg
new file mode 100644
index 0000000000..c7abbf1475
--- /dev/null
+++ b/layout/reftests/bidi/bidiSVG-01.svg
@@ -0,0 +1,3 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200">
+ <text x="100" y="20">&#x202e;GVS ni idiB&#x202c;</text>
+</svg>
diff --git a/layout/reftests/bidi/bidiSVG-02-ref.svg b/layout/reftests/bidi/bidiSVG-02-ref.svg
new file mode 100644
index 0000000000..ea11dc429e
--- /dev/null
+++ b/layout/reftests/bidi/bidiSVG-02-ref.svg
@@ -0,0 +1,3 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="800" height="200">
+ <text x="100" y="20">&#x202d;left-to-right text תירבע םע&#x202c;</text>
+</svg>
diff --git a/layout/reftests/bidi/bidiSVG-02.svg b/layout/reftests/bidi/bidiSVG-02.svg
new file mode 100644
index 0000000000..33372f1ad8
--- /dev/null
+++ b/layout/reftests/bidi/bidiSVG-02.svg
@@ -0,0 +1,3 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="800" height="200">
+ <text x="100" y="20">left-to-right text עם עברית</text>
+</svg>
diff --git a/layout/reftests/bidi/bidiSVG-03-ref.svg b/layout/reftests/bidi/bidiSVG-03-ref.svg
new file mode 100644
index 0000000000..455de81e75
--- /dev/null
+++ b/layout/reftests/bidi/bidiSVG-03-ref.svg
@@ -0,0 +1,3 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="800" height="200">
+ <text x="400" y="20" direction="ltr" unicode-bidi="bidi-override" text-anchor="end">in right-to-left element תירבע םע left-to-right text</text>
+</svg>
diff --git a/layout/reftests/bidi/bidiSVG-03.svg b/layout/reftests/bidi/bidiSVG-03.svg
new file mode 100644
index 0000000000..20b18f8e43
--- /dev/null
+++ b/layout/reftests/bidi/bidiSVG-03.svg
@@ -0,0 +1,3 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="800" height="200">
+ <text x="400" y="20" direction="rtl" unicode-bidi="embed">left-to-right text עם עברית in right-to-left element</text>
+</svg>
diff --git a/layout/reftests/bidi/bidiSVG-04-ref.svg b/layout/reftests/bidi/bidiSVG-04-ref.svg
new file mode 100644
index 0000000000..c2f9038db1
--- /dev/null
+++ b/layout/reftests/bidi/bidiSVG-04-ref.svg
@@ -0,0 +1,3 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="800" height="200">
+ <text x="100" y="20" direction="ltr" unicode-bidi="bidi-override" text-anchor="end">&#x0628;&gt;&#x0627;</text>
+</svg>
diff --git a/layout/reftests/bidi/bidiSVG-04.svg b/layout/reftests/bidi/bidiSVG-04.svg
new file mode 100644
index 0000000000..ff5c65ad85
--- /dev/null
+++ b/layout/reftests/bidi/bidiSVG-04.svg
@@ -0,0 +1,3 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="800" height="200">
+ <text x="100" y="20" direction="rtl" unicode-bidi="embed">&#x0627;&lt;&#x0628;</text>
+</svg>
diff --git a/layout/reftests/bidi/bidiSVG-05-ref.svg b/layout/reftests/bidi/bidiSVG-05-ref.svg
new file mode 100644
index 0000000000..29d5707b4e
--- /dev/null
+++ b/layout/reftests/bidi/bidiSVG-05-ref.svg
@@ -0,0 +1,3 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="800" height="200">
+ <text x="100" y="20" unicode-bidi="bidi-override">&#x1090C;&#x1090B;&#x10914;&#x10905;&#x10913;&#x10909;</text>
+</svg>
diff --git a/layout/reftests/bidi/bidiSVG-05.svg b/layout/reftests/bidi/bidiSVG-05.svg
new file mode 100644
index 0000000000..d8e3157472
--- /dev/null
+++ b/layout/reftests/bidi/bidiSVG-05.svg
@@ -0,0 +1,3 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="800" height="200">
+ <text x="100" y="20">&#x10909;&#x10913;&#x10905;&#x10914;&#x1090B;&#x1090C;</text>
+</svg>
diff --git a/layout/reftests/bidi/brackets-1a-ltr-ref.html b/layout/reftests/bidi/brackets-1a-ltr-ref.html
new file mode 100644
index 0000000000..b8e702bef6
--- /dev/null
+++ b/layout/reftests/bidi/brackets-1a-ltr-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; unicode-bidi: bidi-override; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 1:
+ AB ( CD [ & ef ] ! ) gh
+-->
+<div>&#x5d1;&#x5d0;(&#x5d3;&#x5d2;[&amp;ef]!)gh</div>
diff --git a/layout/reftests/bidi/brackets-1a-ltr.html b/layout/reftests/bidi/brackets-1a-ltr.html
new file mode 100644
index 0000000000..4b134f3517
--- /dev/null
+++ b/layout/reftests/bidi/brackets-1a-ltr.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 1:
+ AB ( CD [ & ef ] ! ) gh
+-->
+<!-- LTR -->
+<div>&#x5d0;&#x5d1;(&#x5d2;&#x5d3;[&amp;ef]!)gh</div>
diff --git a/layout/reftests/bidi/brackets-1a-rtl-ref.html b/layout/reftests/bidi/brackets-1a-rtl-ref.html
new file mode 100644
index 0000000000..f72f17514c
--- /dev/null
+++ b/layout/reftests/bidi/brackets-1a-rtl-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; unicode-bidi: bidi-override; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 1:
+ AB ( CD [ & ef ] ! ) gh
+-->
+<div>gh(![ef&amp;]&#x5d3;&#x5d2;)&#x5d1;&#x5d0;</div>
diff --git a/layout/reftests/bidi/brackets-1a-rtl.html b/layout/reftests/bidi/brackets-1a-rtl.html
new file mode 100644
index 0000000000..3672e7b953
--- /dev/null
+++ b/layout/reftests/bidi/brackets-1a-rtl.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 1:
+ AB ( CD [ & ef ] ! ) gh
+-->
+<!-- RTL -->
+<div dir=rtl>&#x5d0;&#x5d1;(&#x5d2;&#x5d3;[&amp;ef]!)gh</div>
diff --git a/layout/reftests/bidi/brackets-1b-ltr-ref.html b/layout/reftests/bidi/brackets-1b-ltr-ref.html
new file mode 100644
index 0000000000..78dd025099
--- /dev/null
+++ b/layout/reftests/bidi/brackets-1b-ltr-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; unicode-bidi: bidi-override; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 1, AB and gh swapped:
+ gh ( CD [ & ef ] ! ) AB
+-->
+<div>gh(&#x5d3;&#x5d2;[&amp;ef]!)&#x5d1;&#x5d0;</div>
diff --git a/layout/reftests/bidi/brackets-1b-ltr.html b/layout/reftests/bidi/brackets-1b-ltr.html
new file mode 100644
index 0000000000..edc047854c
--- /dev/null
+++ b/layout/reftests/bidi/brackets-1b-ltr.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 1, AB and gh swapped:
+ gh ( CD [ & ef ] ! ) AB
+-->
+<!-- LTR -->
+<div>gh(&#x5d2;&#x5d3;[&amp;ef]!)&#x5d0;&#x5d1;</div>
diff --git a/layout/reftests/bidi/brackets-1b-rtl-ref.html b/layout/reftests/bidi/brackets-1b-rtl-ref.html
new file mode 100644
index 0000000000..e627a9e9d8
--- /dev/null
+++ b/layout/reftests/bidi/brackets-1b-rtl-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; unicode-bidi: bidi-override; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 1, AB and gh swapped:
+ gh ( CD [ & ef ] ! ) AB
+-->
+<div>&#x5d1;&#x5d0;(![ef&amp;]&#x5d3;&#x5d2;)gh</div>
diff --git a/layout/reftests/bidi/brackets-1b-rtl.html b/layout/reftests/bidi/brackets-1b-rtl.html
new file mode 100644
index 0000000000..d7ef85e107
--- /dev/null
+++ b/layout/reftests/bidi/brackets-1b-rtl.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 1, AB and gh swapped:
+ gh ( CD [ & ef ] ! ) AB
+-->
+<!-- RTL -->
+<div dir=rtl>gh(&#x5d2;&#x5d3;[&amp;ef]!)&#x5d0;&#x5d1;</div>
diff --git a/layout/reftests/bidi/brackets-1c-ltr-ref.html b/layout/reftests/bidi/brackets-1c-ltr-ref.html
new file mode 100644
index 0000000000..df397968d0
--- /dev/null
+++ b/layout/reftests/bidi/brackets-1c-ltr-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; unicode-bidi: bidi-override; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 1:
+ AB ( ef [ & CD ] ! ) gh
+-->
+<div>&#x5d1;&#x5d0;(ef[&amp;&#x5d3;&#x5d2;]!)gh</div>
diff --git a/layout/reftests/bidi/brackets-1c-ltr.html b/layout/reftests/bidi/brackets-1c-ltr.html
new file mode 100644
index 0000000000..a13eb5c675
--- /dev/null
+++ b/layout/reftests/bidi/brackets-1c-ltr.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 1, CD and ef swapped:
+ AB ( ef [ & CD ] ! ) gh
+-->
+<!-- LTR -->
+<div>&#x5d0;&#x5d1;(ef[&amp;&#x5d2;&#x5d3;]!)gh</div>
diff --git a/layout/reftests/bidi/brackets-1c-rtl-ref.html b/layout/reftests/bidi/brackets-1c-rtl-ref.html
new file mode 100644
index 0000000000..989f48e070
--- /dev/null
+++ b/layout/reftests/bidi/brackets-1c-rtl-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; unicode-bidi: bidi-override; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 1:
+ AB ( ef [ & CD ] ! ) gh
+-->
+<div>gh(![&#x5d3;&#x5d2;&amp;]ef)&#x5d1;&#x5d0;</div>
diff --git a/layout/reftests/bidi/brackets-1c-rtl.html b/layout/reftests/bidi/brackets-1c-rtl.html
new file mode 100644
index 0000000000..852e26e108
--- /dev/null
+++ b/layout/reftests/bidi/brackets-1c-rtl.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 1, CD and ef swapped:
+ AB ( ef [ & CD ] ! ) gh
+-->
+<!-- RTL -->
+<div dir=rtl>&#x5d0;&#x5d1;(ef[&amp;&#x5d2;&#x5d3;]!)gh</div>
diff --git a/layout/reftests/bidi/brackets-2a-ltr-ref.html b/layout/reftests/bidi/brackets-2a-ltr-ref.html
new file mode 100644
index 0000000000..0e624bddcd
--- /dev/null
+++ b/layout/reftests/bidi/brackets-2a-ltr-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; unicode-bidi: bidi-override; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 2:
+ smith (fabrikam ARABIC) HEBREW
+-->
+<div>smith (fabrikam &#x64A;&#x628;&#x631;&#x639;&#x644;&#x627;) &#x5EA;&#x5D9;&#x5E8;&#x5D1;&#x5E2;</div>
diff --git a/layout/reftests/bidi/brackets-2a-ltr.html b/layout/reftests/bidi/brackets-2a-ltr.html
new file mode 100644
index 0000000000..74feb7f2f3
--- /dev/null
+++ b/layout/reftests/bidi/brackets-2a-ltr.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 2:
+ smith (fabrikam ARABIC) HEBREW
+-->
+<!-- LTR -->
+<div>smith (fabrikam &#x627;&#x644;&#x639;&#x631;&#x628;&#x64A;) &#x5E2;&#x5D1;&#x5E8;&#x5D9;&#x5EA;</div>
diff --git a/layout/reftests/bidi/brackets-2a-rtl-ref.html b/layout/reftests/bidi/brackets-2a-rtl-ref.html
new file mode 100644
index 0000000000..7860238ae8
--- /dev/null
+++ b/layout/reftests/bidi/brackets-2a-rtl-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; unicode-bidi: bidi-override; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 2:
+ smith (fabrikam ARABIC) HEBREW
+-->
+<div>&#x5EA;&#x5D9;&#x5E8;&#x5D1;&#x5E2; (&#x64A;&#x628;&#x631;&#x639;&#x644;&#x627; fabrikam) smith</div>
diff --git a/layout/reftests/bidi/brackets-2a-rtl.html b/layout/reftests/bidi/brackets-2a-rtl.html
new file mode 100644
index 0000000000..02d10e27a5
--- /dev/null
+++ b/layout/reftests/bidi/brackets-2a-rtl.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 2:
+ smith (fabrikam ARABIC) HEBREW
+-->
+<!-- RTL -->
+<div dir=rtl>smith (fabrikam &#x627;&#x644;&#x639;&#x631;&#x628;&#x64A;) &#x5E2;&#x5D1;&#x5E8;&#x5D9;&#x5EA;</div>
diff --git a/layout/reftests/bidi/brackets-2b-ltr-ref.html b/layout/reftests/bidi/brackets-2b-ltr-ref.html
new file mode 100644
index 0000000000..271c8445b9
--- /dev/null
+++ b/layout/reftests/bidi/brackets-2b-ltr-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; unicode-bidi: bidi-override; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 2 with smith and HEBREW exchanged:
+ HEBREW (fabrikam ARABIC) smith
+-->
+<div>&#x5EA;&#x5D9;&#x5E8;&#x5D1;&#x5E2; (fabrikam &#x64A;&#x628;&#x631;&#x639;&#x644;&#x627;) smith</div>
diff --git a/layout/reftests/bidi/brackets-2b-ltr.html b/layout/reftests/bidi/brackets-2b-ltr.html
new file mode 100644
index 0000000000..f6a70f62b6
--- /dev/null
+++ b/layout/reftests/bidi/brackets-2b-ltr.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 2 with smith and HEBREW exchanged:
+ HEBREW (fabrikam ARABIC) smith
+-->
+<!-- LTR -->
+<div>&#x5E2;&#x5D1;&#x5E8;&#x5D9;&#x5EA; (fabrikam &#x627;&#x644;&#x639;&#x631;&#x628;&#x64A;) smith</div>
diff --git a/layout/reftests/bidi/brackets-2b-rtl-ref.html b/layout/reftests/bidi/brackets-2b-rtl-ref.html
new file mode 100644
index 0000000000..4a9dcf1070
--- /dev/null
+++ b/layout/reftests/bidi/brackets-2b-rtl-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; unicode-bidi: bidi-override; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 2 with smith and HEBREW exchanged:
+ HEBREW (fabrikam ARABIC) smith
+-->
+<div>smith (&#x64A;&#x628;&#x631;&#x639;&#x644;&#x627; fabrikam) &#x5EA;&#x5D9;&#x5E8;&#x5D1;&#x5E2;</div>
diff --git a/layout/reftests/bidi/brackets-2b-rtl.html b/layout/reftests/bidi/brackets-2b-rtl.html
new file mode 100644
index 0000000000..f0579c903b
--- /dev/null
+++ b/layout/reftests/bidi/brackets-2b-rtl.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 2 with smith and HEBREW exchanged:
+ HEBREW (fabrikam ARABIC) smith
+-->
+<!-- RTL -->
+<div dir=rtl>&#x5E2;&#x5D1;&#x5E8;&#x5D9;&#x5EA; (fabrikam &#x627;&#x644;&#x639;&#x631;&#x628;&#x64A;) smith</div>
diff --git a/layout/reftests/bidi/brackets-2c-ltr-ref.html b/layout/reftests/bidi/brackets-2c-ltr-ref.html
new file mode 100644
index 0000000000..c27a71e604
--- /dev/null
+++ b/layout/reftests/bidi/brackets-2c-ltr-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; unicode-bidi: bidi-override; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 2 with fabrikam and ARABIC exchanged:
+ smith (ARABIC fabrikam) HEBREW
+-->
+<div>smith (&#x64A;&#x628;&#x631;&#x639;&#x644;&#x627; fabrikam) &#x5EA;&#x5D9;&#x5E8;&#x5D1;&#x5E2;</div>
diff --git a/layout/reftests/bidi/brackets-2c-ltr.html b/layout/reftests/bidi/brackets-2c-ltr.html
new file mode 100644
index 0000000000..481ee51c65
--- /dev/null
+++ b/layout/reftests/bidi/brackets-2c-ltr.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 2 with fabrikam and ARABIC exchanged:
+ smith (ARABIC fabrikam) HEBREW
+-->
+<!-- LTR -->
+<div>smith (&#x627;&#x644;&#x639;&#x631;&#x628;&#x64A; fabrikam) &#x5E2;&#x5D1;&#x5E8;&#x5D9;&#x5EA;</div>
diff --git a/layout/reftests/bidi/brackets-2c-rtl-ref.html b/layout/reftests/bidi/brackets-2c-rtl-ref.html
new file mode 100644
index 0000000000..635a1bd80d
--- /dev/null
+++ b/layout/reftests/bidi/brackets-2c-rtl-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; unicode-bidi: bidi-override; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 2 with fabrikam and ARABIC exchanged:
+ smith (ARABIC fabrikam) HEBREW
+-->
+<div>&#x5EA;&#x5D9;&#x5E8;&#x5D1;&#x5E2; (fabrikam &#x64A;&#x628;&#x631;&#x639;&#x644;&#x627;) smith</div>
diff --git a/layout/reftests/bidi/brackets-2c-rtl.html b/layout/reftests/bidi/brackets-2c-rtl.html
new file mode 100644
index 0000000000..1fa504546e
--- /dev/null
+++ b/layout/reftests/bidi/brackets-2c-rtl.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 2 with fabrikam and ARABIC exchanged:
+ smith (ARABIC fabrikam) HEBREW
+-->
+<!-- RTL -->
+<div dir=rtl>smith (&#x627;&#x644;&#x639;&#x631;&#x628;&#x64A; fabrikam) &#x5E2;&#x5D1;&#x5E8;&#x5D9;&#x5EA;</div>
diff --git a/layout/reftests/bidi/brackets-3a-ltr-ref.html b/layout/reftests/bidi/brackets-3a-ltr-ref.html
new file mode 100644
index 0000000000..7ccd06f0da
--- /dev/null
+++ b/layout/reftests/bidi/brackets-3a-ltr-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; unicode-bidi: bidi-override; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 3:
+ ARABIC book(s)
+-->
+<div>&#x64A;&#x628;&#x631;&#x639;&#x644;&#x627; book(s)</div>
diff --git a/layout/reftests/bidi/brackets-3a-ltr.html b/layout/reftests/bidi/brackets-3a-ltr.html
new file mode 100644
index 0000000000..6245352875
--- /dev/null
+++ b/layout/reftests/bidi/brackets-3a-ltr.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 3:
+ ARABIC book(s)
+-->
+<!-- LTR -->
+<div>&#x627;&#x644;&#x639;&#x631;&#x628;&#x64A; book(s)</div>
diff --git a/layout/reftests/bidi/brackets-3a-rtl-ref.html b/layout/reftests/bidi/brackets-3a-rtl-ref.html
new file mode 100644
index 0000000000..038a72c878
--- /dev/null
+++ b/layout/reftests/bidi/brackets-3a-rtl-ref.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; unicode-bidi: bidi-override; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 3:
+ ARABIC book(s)
+-->
+<div>book(s) &#x64A;&#x628;&#x631;&#x639;&#x644;&#x627;</div>
diff --git a/layout/reftests/bidi/brackets-3a-rtl.html b/layout/reftests/bidi/brackets-3a-rtl.html
new file mode 100644
index 0000000000..9fdea3fd32
--- /dev/null
+++ b/layout/reftests/bidi/brackets-3a-rtl.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 3:
+ ARABIC book(s)
+-->
+<!-- RTL -->
+<div dir=rtl>&#x627;&#x644;&#x639;&#x631;&#x628;&#x64A; book(s)</div>
diff --git a/layout/reftests/bidi/brackets-3b-ltr-ref.html b/layout/reftests/bidi/brackets-3b-ltr-ref.html
new file mode 100644
index 0000000000..01f4134b75
--- /dev/null
+++ b/layout/reftests/bidi/brackets-3b-ltr-ref.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; }
+span { unicode-bidi: isolate; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 3, LTR and RTL exchanged:
+ arabic BOOK(S)
+-->
+<div>arabic (<span dir=rtl>&#x643;&#x64f;&#x62a;&#x64f;&#x628;</span>)<span dir=rtl>&#x643;&#x650;&#x62a;&#x64e;&#x627;&#x628;</span></div>
diff --git a/layout/reftests/bidi/brackets-3b-ltr.html b/layout/reftests/bidi/brackets-3b-ltr.html
new file mode 100644
index 0000000000..004f31a578
--- /dev/null
+++ b/layout/reftests/bidi/brackets-3b-ltr.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 3, LTR and RTL exchanged:
+ arabic BOOK(S)
+-->
+<!-- LTR -->
+<div>arabic &#x643;&#x650;&#x62a;&#x64e;&#x627;&#x628;(&#x643;&#x64f;&#x62a;&#x64f;&#x628;)</div>
diff --git a/layout/reftests/bidi/brackets-3b-rtl-ref.html b/layout/reftests/bidi/brackets-3b-rtl-ref.html
new file mode 100644
index 0000000000..10553a120e
--- /dev/null
+++ b/layout/reftests/bidi/brackets-3b-rtl-ref.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; }
+span { unicode-bidi: isolate; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 3, LTR and RTL exchanged:
+ arabic BOOK(S)
+-->
+<div>(<span dir=rtl>&#x643;&#x64f;&#x62a;&#x64f;&#x628;</span>)<span dir=rtl>&#x643;&#x650;&#x62a;&#x64e;&#x627;&#x628;</span> arabic</div>
diff --git a/layout/reftests/bidi/brackets-3b-rtl.html b/layout/reftests/bidi/brackets-3b-rtl.html
new file mode 100644
index 0000000000..916b8736f6
--- /dev/null
+++ b/layout/reftests/bidi/brackets-3b-rtl.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+
+<style>
+body { font: 32px monospace; }
+div { text-align: center; }
+</style>
+
+<body>
+
+<!--
+ http://unicode.org/reports/tr9/#N0, Example 3, LTR and RTL exchanged:
+ arabic BOOK(S)
+-->
+<!-- RTL -->
+<div dir=rtl>arabic &#x643;&#x650;&#x62a;&#x64e;&#x627;&#x628;(&#x643;&#x64f;&#x62a;&#x64f;&#x628;)</div>
diff --git a/layout/reftests/bidi/clone-intrinsic-size-bidi-ref.html b/layout/reftests/bidi/clone-intrinsic-size-bidi-ref.html
new file mode 100644
index 0000000000..acaad0525e
--- /dev/null
+++ b/layout/reftests/bidi/clone-intrinsic-size-bidi-ref.html
@@ -0,0 +1,87 @@
+<!DOCTYPE html>
+<head>
+ <title>CSS Reference: min/max-content size on box-decoration-break:clone inline box with bidi text</title>
+ <link rel="author" title="Mats Palmgren" href="mailto:mats@mozilla.com">
+<style>
+html,body {
+ color:black; background-color:white; font:10px/1 monospace; padding:0; margin:0;
+}
+
+div {
+ border: 5px solid blue;
+ white-space: pre;
+}
+.max > div {
+ width: -moz-max-content;
+ width: -webkit-max-content;
+ width: max-content;
+}
+.min > div {
+ width: -moz-min-content;
+ width: -webkit-min-content;
+ width: min-content;
+}
+
+span {
+ border: 2px solid gray;
+ padding: 0 10px 0 6px;
+ border-width: 0 8px 0 5px;
+ margin: 0 4px 0 3px;
+ background: yellow;
+ -webkit-box-decoration-break: clone;
+ box-decoration-break: clone;
+}
+
+f { margin-right: 30px; float: left; }
+</style>
+<body>
+<f class="max">
+<div><span>&#x202e;a&#x202d;bc</span><span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span>aa<span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span> <span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc </span><span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span><span> d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span> aa<span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc </span>aa<span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span>aa<span> d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span> aa <span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span>aa <span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span>aa</div>
+</f>
+
+<f class="min">
+<div><span>&#x202e;a&#x202d;bc</span><span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span>aa<span>d&#x202e;e&#x202d;f</span>
+</div>
+<!-- FIXME -->
+<div style="white-space: normal;"><span>&#x202e;a&#x202d;bc</span> <span>d&#x202e;e&#x202d;f</span>
+</div>
+<!-- FIXME -->
+<div style="white-space: normal;"><span>&#x202e;a&#x202d;bc </span><span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>bc</span><span></span><span>a</span><br><span>d&#x202e;e&#x202d;f</span></div>
+<div><span>&#x202e;a&#x202d;bc</span><br>aa<span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span><br>aa<span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span>aa<span></span><br><span>d&#x202e;e&#x202d;f</span>
+</div>
+<!-- FIXME -->
+<div style="white-space: normal;"><span>&#x202e;a&#x202d;bc</span> aa <span>d&#x202e;e&#x202d;f</span>
+</div>
+<!-- FIXME -->
+<div style="white-space: normal;"><span>&#x202e;a&#x202d;bc</span>aa <span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span>aa</div>
+</f>
diff --git a/layout/reftests/bidi/clone-intrinsic-size-bidi.html b/layout/reftests/bidi/clone-intrinsic-size-bidi.html
new file mode 100644
index 0000000000..684f2fe13f
--- /dev/null
+++ b/layout/reftests/bidi/clone-intrinsic-size-bidi.html
@@ -0,0 +1,113 @@
+<!DOCTYPE html>
+<head>
+ <title>CSS Test: min/max-content size on box-decoration-break:clone inline box with bidi text</title>
+ <link rel="author" title="Mats Palmgren" href="mailto:mats@mozilla.com">
+ <link rel="help" href="https://drafts.csswg.org/css-sizing-3/#valdef-width-min-content">
+ <link rel="help" href="https://drafts.csswg.org/css-break-3/#break-decoration">
+ <link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1552357">
+ <link rel="match" href="clone-intrinsic-size-bidi-ref.html">
+<style>
+html,body {
+ color:black; background-color:white; font:10px/1 monospace; padding:0; margin:0;
+}
+
+div {
+ border: 5px solid blue;
+}
+.max > div {
+ width: -moz-max-content;
+ width: -webkit-max-content;
+ width: max-content;
+}
+.min > div {
+ width: -moz-min-content;
+ width: -webkit-min-content;
+ width: min-content;
+}
+
+span {
+ border: 2px solid gray;
+ padding: 0 10px 0 6px;
+ border-width: 0 8px 0 5px;
+ margin: 0 4px 0 3px;
+ background: yellow;
+ -webkit-box-decoration-break: clone;
+ box-decoration-break: clone;
+}
+
+f { margin-right: 30px; float: left; }
+</style>
+<body>
+<f class="max">
+<div>
+ <span>&#x202e;a&#x202d;bc</span><span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span>aa<span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span> <span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc </span><span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span><span> d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span> aa<span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc </span>aa<span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span>aa<span> d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span> aa <span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span>aa <span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span>aa </div>
+</f>
+
+<f class="min">
+<div>
+ <span>&#x202e;a&#x202d;bc</span><span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span>aa<span>d&#x202e;e&#x202d;f</span>
+</div>
+<!-- Bug 1556444 -->
+<div>
+ <span>&#x202e;a&#x202d;bc</span> <span>d&#x202e;e&#x202d;f</span>
+</div>
+<!-- Bug 1556444 -->
+<div>
+ <span>&#x202e;a&#x202d;bc </span><span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span><span> d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span> aa<span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc </span>aa<span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span>aa<span> d&#x202e;e&#x202d;f</span>
+</div>
+<!-- Bug 1556444 -->
+<div>
+ <span>&#x202e;a&#x202d;bc</span> aa <span>d&#x202e;e&#x202d;f</span>
+</div>
+<!-- Bug 1556444 -->
+<div>
+ <span>&#x202e;a&#x202d;bc</span>aa <span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span>aa </div>
+</f>
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 0000000000..50fba8c41d
--- /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 0000000000..4092f27f87
--- /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);
+ </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 0000000000..d6e2ab456c
--- /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 0000000000..a532578770
--- /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 0000000000..3127c3e377
--- /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 0000000000..10685967fe
--- /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 0000000000..4a0cd1e16e
--- /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 0000000000..bc520f83f4
--- /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 0000000000..df08a25bd8
--- /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 0000000000..4cddec7fea
--- /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 0000000000..f7afe90f5d
--- /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 0000000000..b692a43f91
--- /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 0000000000..4e0237ba64
--- /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 0000000000..019083d28c
--- /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 0000000000..fd255638a5
--- /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 0000000000..d4fb584200
--- /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 0000000000..d5935d83f6
--- /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 0000000000..5ae48d8970
--- /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 0000000000..41bf37180e
--- /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 0000000000..0c74b3f3b4
--- /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 0000000000..10a75a4cee
--- /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 0000000000..0ff92cb55d
--- /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 0000000000..a786430499
--- /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 0000000000..c2cbdc2415
--- /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 0000000000..f383652215
--- /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 0000000000..a63f718ce1
--- /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 0000000000..223aa56e6d
--- /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 0000000000..bd3dad92a8
--- /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 0000000000..f9af6b961f
--- /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 0000000000..2d07131d57
--- /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 0000000000..38801d2a47
--- /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 0000000000..7cd5db77c4
--- /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 0000000000..b66f5e3061
--- /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 0000000000..4611189966
--- /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 0000000000..2fb2148f99
--- /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 0000000000..087d5104fc
--- /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 0000000000..361fcd1e72
--- /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 0000000000..01e6f6bcba
--- /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 0000000000..f243dec4fa
--- /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 0000000000..0aaedfe4a1
--- /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 0000000000..60df2980c6
--- /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 0000000000..36d2940e58
--- /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 0000000000..440945bb58
--- /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 0000000000..032c2f4eb1
--- /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 0000000000..9c1da6b0fc
--- /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 0000000000..b7c4c36533
--- /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 0000000000..4ba7a037f6
--- /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 0000000000..4bea44d83b
--- /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 0000000000..2c16829530
--- /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 0000000000..ab08388b82
--- /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 0000000000..477e155a0b
--- /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 0000000000..cf4069567e
--- /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 0000000000..16dc62b5b9
--- /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 0000000000..52c0949c91
--- /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 0000000000..62a74bf334
--- /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 0000000000..60619730a8
--- /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 0000000000..4ea471a8d1
--- /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 0000000000..b2f56c1ac1
--- /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 0000000000..71c42ea3e4
--- /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 0000000000..2c1c525f97
--- /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 0000000000..f0400e0d00
--- /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 0000000000..2cbf52716c
--- /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 0000000000..5bcec0648d
--- /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 0000000000..a0423c2468
--- /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 0000000000..2574c867fa
--- /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 0000000000..1913335b8b
--- /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 0000000000..596f1143af
--- /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 0000000000..f22dd147d1
--- /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 0000000000..f876484e4b
--- /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 0000000000..6da8dff2f3
--- /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 0000000000..b63c0dd0d2
--- /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 0000000000..e1b9d82c1c
--- /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 0000000000..9b80f42d0b
--- /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 0000000000..e89fc79211
--- /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 0000000000..5a8e4f1221
--- /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 0000000000..bbc5f80900
--- /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 0000000000..08b21e09a4
--- /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 0000000000..cffe2556b8
--- /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 0000000000..b54417b6f4
--- /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 0000000000..0baeb9fc6d
--- /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 0000000000..ec1de35425
--- /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 0000000000..2040663c35
--- /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 0000000000..f8c2e99a74
--- /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 0000000000..c295012dba
--- /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 0000000000..13e0e5fc8f
--- /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 0000000000..6dce96a606
--- /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 0000000000..2d9973fa1d
--- /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 0000000000..dd1964e01f
--- /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 0000000000..96d7809358
--- /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 0000000000..c5a9bf42df
--- /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 0000000000..b8ed6cda81
--- /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 0000000000..528ffde04e
--- /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 0000000000..884c8fa852
--- /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 0000000000..5cf486c905
--- /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 0000000000..61c7331bd3
--- /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 0000000000..c4cc154cbe
--- /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 0000000000..18e333978c
--- /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 0000000000..483d79fd51
--- /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 0000000000..b0773e6f6c
--- /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 0000000000..77ce26cb3b
--- /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 0000000000..f8cabec1ee
--- /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 0000000000..20621a5a75
--- /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 0000000000..c9e1b560f7
--- /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 0000000000..a2ddd5292f
--- /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 0000000000..87eb118190
--- /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 0000000000..17ec5b453b
--- /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 0000000000..b4c5ebc091
--- /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 0000000000..1859e89bc6
--- /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 0000000000..06c3d71703
--- /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 0000000000..03239e88b7
--- /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 0000000000..fc353ac22f
--- /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 0000000000..52fcf96b37
--- /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 0000000000..074eeab104
--- /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 0000000000..2bb5ad2de5
--- /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 0000000000..79372c6ed3
--- /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 0000000000..2120170153
--- /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 0000000000..272d5f9fce
--- /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 0000000000..d1d1185d2d
--- /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 0000000000..a6f9fa09a2
--- /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 0000000000..ba2bd8bab5
--- /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 0000000000..5833b2e4ad
--- /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 0000000000..1a031d0438
--- /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 0000000000..53074850d3
--- /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 0000000000..63fc1a7465
--- /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 0000000000..31af1459d2
--- /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 0000000000..5fd61d42e6
--- /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 0000000000..d388d5377f
--- /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 0000000000..45ee5c5713
--- /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 0000000000..0df2fc8de1
--- /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 0000000000..0dee370b6b
--- /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 0000000000..dbfbe2125a
--- /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 0000000000..1b401367c1
--- /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 0000000000..d2c70793c2
--- /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 0000000000..ca0153cc2f
--- /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 0000000000..15b323976e
--- /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.list b/layout/reftests/bidi/dirAuto/reftest.list
new file mode 100644
index 0000000000..14ce0aa670
--- /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
+fuzzy-if(Android,0-1,0-1) == dynamicDirAuto-setRTL-Auto2.html dynamicDirAuto-refRTL-RTL.html # android fuzz: bug 1461573
+== dynamicDirAuto-setRTL-Auto3.html dynamicDirAuto-refRTL-RTL.html
+== dynamicDirAuto-setRTL-Auto4.html dynamicDirAuto-refRTL-RTL.html
+fuzzy-if(Android,0-1,0-1) == dynamicDirAuto-setRTL-Auto5.html dynamicDirAuto-refRTL-RTL.html # android fuzz: bug 1459239
+== 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
+fuzzy-if(Android,0-4,0-2) == dynamicDirAuto-setRTL-LTR4.html dynamicDirAuto-refRTL-LTR.html # android fuzz: bug 1356818
+== dynamicDirAuto-setRTL-LTR5.html dynamicDirAuto-refRTL-LTR.html
+== dynamicDirAuto-setRTL-LTR6.html dynamicDirAuto-refRTL-LTR.html
+== dynamicDirAuto-setRTL-LTR7.html dynamicDirAuto-refRTL-LTR.html
+fuzzy-if(Android,0-4,0-2) == dynamicDirAuto-setRTL-LTR8.html dynamicDirAuto-refRTL-LTR.html # android fuzz: bug 1468922
+== 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
+== dynamicDirAuto-ChangeText-RTL3.html dynamicDirAuto-refRTL-RTL.html
+== dynamicDirAuto-ChangeText-RTL4.html dynamicDirAuto-refRTL-RTL.html
+== dynamicDirAuto-ChangeText-RTL5.html dynamicDirAuto-refRTL-RTL.html
+== 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
+fuzzy-if(Android,0-3,0-2) == dynamicDirAuto-DeleteText-LTR3.html dynamicDirAuto-refLTR-LTR.html # android fuzz: bug 1467675
+== 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 0000000000..829935e564
--- /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.remove();
+ }
+}
diff --git a/layout/reftests/bidi/logicalmarquee.html b/layout/reftests/bidi/logicalmarquee.html
new file mode 100644
index 0000000000..cb13827dec
--- /dev/null
+++ b/layout/reftests/bidi/logicalmarquee.html
@@ -0,0 +1,11 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta http-equiv="Content-type" content="text/html; charset=iso-8859-8-i">
+ <title>Marquee in Logical Hebrew</title>
+ </head>
+
+ <body>
+ <marquee scrollamount="0" behavior="alternate" direction="right">&#x05E2;&#x05D3; &#x05E9;&#x05D9;&#x05E4;&#x05D5;&#x05D7; &#x05D4;&#x05D9;&#x05D5;&#x05DD; &#x05D5;&#x05E0;&#x05E1;&#x05D5; &#x05D4;&#x05E6;&#x05DC;&#x05D9;&#x05DC;&#x05D9;&#x05DD;</marquee>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/marquee-ref.html b/layout/reftests/bidi/marquee-ref.html
new file mode 100644
index 0000000000..d8778dc880
--- /dev/null
+++ b/layout/reftests/bidi/marquee-ref.html
@@ -0,0 +1,11 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <meta http-equiv="Content-type" content="text/html; charset=iso-8859-8-i">
+ <title>Marquee in Logical Hebrew</title>
+ </head>
+
+ <body>
+ <div dir="rtl" align="left">&#x05E2;&#x05D3; &#x05E9;&#x05D9;&#x05E4;&#x05D5;&#x05D7; &#x05D4;&#x05D9;&#x05D5;&#x05DD; &#x05D5;&#x05E0;&#x05E1;&#x05D5; &#x05D4;&#x05E6;&#x05DC;&#x05D9;&#x05DC;&#x05D9;&#x05DD;</div>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/mirroring-01-ref.html b/layout/reftests/bidi/mirroring-01-ref.html
new file mode 100644
index 0000000000..a422e66328
--- /dev/null
+++ b/layout/reftests/bidi/mirroring-01-ref.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+</head>
+<body>
+ <!-- some paired chars that should mirror in RTL text -->
+ <p>c(b)a</p>
+ <p>c[b]a</p>
+ <p>c{b}a</p>
+ <p>c&lt;b&gt;a</p>
+</body>
+</html>
diff --git a/layout/reftests/bidi/mirroring-01.html b/layout/reftests/bidi/mirroring-01.html
new file mode 100644
index 0000000000..0ed363ddff
--- /dev/null
+++ b/layout/reftests/bidi/mirroring-01.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ <style type="text/css">
+ p {
+ unicode-bidi:bidi-override;
+ direction:rtl;
+ text-align:left;
+ }
+ </style>
+</head>
+<body>
+ <!-- some paired chars that should mirror in RTL text -->
+ <p>a(b)c</p>
+ <p>a[b]c</p>
+ <p>a{b}c</p>
+ <p>a&lt;b&gt;c</p>
+</body>
+</html>
diff --git a/layout/reftests/bidi/mirroring-02-ref.html b/layout/reftests/bidi/mirroring-02-ref.html
new file mode 100644
index 0000000000..ae4bef0947
--- /dev/null
+++ b/layout/reftests/bidi/mirroring-02-ref.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+</head>
+<body>
+ <!-- some chars that should NOT mirror... -->
+ <p>c&#x2019;b&#x2018;a</p>
+ <p>c&#x201d;b&#x201c;a</p>
+</body>
+</html>
diff --git a/layout/reftests/bidi/mirroring-02.html b/layout/reftests/bidi/mirroring-02.html
new file mode 100644
index 0000000000..2706b2f298
--- /dev/null
+++ b/layout/reftests/bidi/mirroring-02.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ <style type="text/css">
+ p {
+ unicode-bidi:bidi-override;
+ direction:rtl;
+ text-align:left;
+ }
+ </style>
+</head>
+<body>
+ <!-- some chars that should NOT mirror... -->
+ <p>a&#x2018;b&#x2019;c</p>
+ <p>a&#x201c;b&#x201d;c</p>
+</body>
+</html>
diff --git a/layout/reftests/bidi/mirroring-03-ref.html b/layout/reftests/bidi/mirroring-03-ref.html
new file mode 100644
index 0000000000..24bb1ec736
--- /dev/null
+++ b/layout/reftests/bidi/mirroring-03-ref.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<head>
+<title>Test for mirroring parentheses in Hebrew text</title>
+</head>
+<body>
+<p dir="rtl"><span style="unicode-bidi:bidi-override; direction:ltr;">&#x05d2;(&#x05d1;)&#x05d0;</span></p>
+</body>
+</html>
+
diff --git a/layout/reftests/bidi/mirroring-03.html b/layout/reftests/bidi/mirroring-03.html
new file mode 100644
index 0000000000..8380ddc03b
--- /dev/null
+++ b/layout/reftests/bidi/mirroring-03.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<head>
+<title>Test for mirroring parentheses in Hebrew text</title>
+</head>
+<body>
+<p dir="rtl">&#x05d0;(&#x05d1;)&#x05d2;</p>
+</body>
+</html>
+
diff --git a/layout/reftests/bidi/mixedChartype-00-j.html b/layout/reftests/bidi/mixedChartype-00-j.html
new file mode 100644
index 0000000000..7cf8629b9b
--- /dev/null
+++ b/layout/reftests/bidi/mixedChartype-00-j.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<!-- Mixed chartype reftest 00: English - Hebrew -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ <style type="text/css">
+body {
+ font-family: serif;
+ font-size: 24px;
+ text-align: justify;
+}
+ </style>
+ </head>
+ <body>
+ <p><span style="direction: ltr; unicode-bidi: bidi-override">Hello &#x5DD;&#x5DC;&#x5D5;&#x5E2;</span></p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/mixedChartype-00-ref.html b/layout/reftests/bidi/mixedChartype-00-ref.html
new file mode 100644
index 0000000000..ace2a53b12
--- /dev/null
+++ b/layout/reftests/bidi/mixedChartype-00-ref.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<!-- Mixed chartype reftest 00: English - Hebrew -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ <style type="text/css">
+body {
+ font-family: serif;
+ font-size: 24px;
+}
+ </style>
+ </head>
+ <body>
+ <p>Hello &#x5E2;&#x5D5;&#x5DC;&#x5DD;</span></p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/mixedChartype-00.html b/layout/reftests/bidi/mixedChartype-00.html
new file mode 100644
index 0000000000..a1e2ca4065
--- /dev/null
+++ b/layout/reftests/bidi/mixedChartype-00.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<!-- Mixed chartype reftest 00: English - Hebrew -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ <style type="text/css">
+body {
+ font-family: serif;
+ font-size: 24px;
+}
+ </style>
+ </head>
+ <body>
+ <p><span style="direction: ltr; unicode-bidi: bidi-override">Hello &#x5DD;&#x5DC;&#x5D5;&#x5E2;</span></p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/mixedChartype-01-j.html b/layout/reftests/bidi/mixedChartype-01-j.html
new file mode 100644
index 0000000000..f350d1f437
--- /dev/null
+++ b/layout/reftests/bidi/mixedChartype-01-j.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<!-- Mixed chartype reftest 01: Hebrew - English -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ <style type="text/css">
+body {
+ font-family: monospace;
+ font-size: 24px;
+}
+ </style>
+ </head>
+ <body>
+ <p><span style="direction: rtl; unicode-bidi: bidi-override">&#x5E9;&#x5DC;&#x5D5;&#x5DD; dlroW</span></p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/mixedChartype-01-ref.html b/layout/reftests/bidi/mixedChartype-01-ref.html
new file mode 100644
index 0000000000..0182f551b4
--- /dev/null
+++ b/layout/reftests/bidi/mixedChartype-01-ref.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<!-- Mixed chartype reftest 01: Hebrew - English -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ <style type="text/css">
+body {
+ font-family: monospace;
+ font-size: 24px;
+}
+ </style>
+ </head>
+ <body>
+ <p><span>World &#x5E9;&#x5DC;&#x5D5;&#x5DD;</span></p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/mixedChartype-01.html b/layout/reftests/bidi/mixedChartype-01.html
new file mode 100644
index 0000000000..f350d1f437
--- /dev/null
+++ b/layout/reftests/bidi/mixedChartype-01.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<!-- Mixed chartype reftest 01: Hebrew - English -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ <style type="text/css">
+body {
+ font-family: monospace;
+ font-size: 24px;
+}
+ </style>
+ </head>
+ <body>
+ <p><span style="direction: rtl; unicode-bidi: bidi-override">&#x5E9;&#x5DC;&#x5D5;&#x5DD; dlroW</span></p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/mixedChartype-02-j.html b/layout/reftests/bidi/mixedChartype-02-j.html
new file mode 100644
index 0000000000..d26fca251e
--- /dev/null
+++ b/layout/reftests/bidi/mixedChartype-02-j.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<!-- Mixed chartype reftest 02: English - Arabic -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ <style type="text/css">
+body { /* for Mac OS X with Core Text, we need to ensure an AAT (not OpenType)
+ font is used for the Arabic, as CT doesn't shape LTR-override Arabic
+ correctly (rdar://7231250 */
+ font-family: Geeza Pro, serif;
+ font-size: 24px;
+ text-align: justify;
+}
+ </style>
+ </head>
+ <body>
+ <p><span style="direction: ltr; unicode-bidi: bidi-override">Hello &#x629;&#x64A;&#x646;&#x648;&#x62F</span></p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/mixedChartype-02-ref.html b/layout/reftests/bidi/mixedChartype-02-ref.html
new file mode 100644
index 0000000000..b2edd771fe
--- /dev/null
+++ b/layout/reftests/bidi/mixedChartype-02-ref.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<!-- Mixed chartype reftest 02: English - Arabic -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ <style type="text/css">
+body { /* for Mac OS X with Core Text, we need to ensure an AAT (not OpenType)
+ font is used for the Arabic, as CT doesn't shape LTR-override Arabic
+ correctly (rdar://7231250 */
+ font-family: Geeza Pro, serif;
+ font-size: 24px;
+}
+ </style>
+ </head>
+ <body>
+ <p><span>Hello &#x62F;&#x648;&#x646;&#x64A;&#x629;</span></p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/mixedChartype-02.html b/layout/reftests/bidi/mixedChartype-02.html
new file mode 100644
index 0000000000..1bbb1e6fc5
--- /dev/null
+++ b/layout/reftests/bidi/mixedChartype-02.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<!-- Mixed chartype reftest 02: English - Arabic -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ <style type="text/css">
+body { /* for Mac OS X with Core Text, we need to ensure an AAT (not OpenType)
+ font is used for the Arabic, as CT doesn't shape LTR-override Arabic
+ correctly (rdar://7231250 */
+ font-family: Geeza Pro, serif;
+ font-size: 24px;
+}
+ </style>
+ </head>
+ <body>
+ <p><span style="direction: ltr; unicode-bidi: bidi-override">Hello &#x629;&#x64A;&#x646;&#x648;&#x62F</span></p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/mixedChartype-03-j.html b/layout/reftests/bidi/mixedChartype-03-j.html
new file mode 100644
index 0000000000..2d8c25b7f1
--- /dev/null
+++ b/layout/reftests/bidi/mixedChartype-03-j.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<!-- Mixed chartype reftest 03: Arabic - English -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ <style type="text/css">
+body {
+ font-family: monospace;
+ font-size: 24px;
+ text-align: justify;
+}
+ </style>
+ </head>
+ <body>
+ <p><span style="direction: rtl; unicode-bidi: bidi-override">&#x633;&#x644;&#x645;&#x627;&#x62A; dlroW</span></p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/mixedChartype-03-ref.html b/layout/reftests/bidi/mixedChartype-03-ref.html
new file mode 100644
index 0000000000..16231b753a
--- /dev/null
+++ b/layout/reftests/bidi/mixedChartype-03-ref.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<!-- Mixed chartype reftest 03: Arabic - English -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ <style type="text/css">
+body {
+ font-family: monospace;
+ font-size: 24px;
+}
+ </style>
+ </head>
+ <body>
+ <p><span>World &#x633;&#x644;&#x645;&#x627;&#x62A;</span></p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/mixedChartype-03.html b/layout/reftests/bidi/mixedChartype-03.html
new file mode 100644
index 0000000000..819a37d18a
--- /dev/null
+++ b/layout/reftests/bidi/mixedChartype-03.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<!-- Mixed chartype reftest 03: Arabic - English -->
+<html>
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ <style type="text/css">
+body {
+ font-family: monospace;
+ font-size: 24px;
+}
+ </style>
+ </head>
+ <body>
+ <p><span style="direction: rtl; unicode-bidi: bidi-override">&#x633;&#x644;&#x645;&#x627;&#x62A; dlroW</span></p>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/numeral/arabic-1-ref.html b/layout/reftests/bidi/numeral/arabic-1-ref.html
new file mode 100644
index 0000000000..8bc1ea4991
--- /dev/null
+++ b/layout/reftests/bidi/numeral/arabic-1-ref.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+ <img src="youwontfindme.png" width="100" height="50" alt="٠١٢">
+</body>
+</html>
diff --git a/layout/reftests/bidi/numeral/arabic-1.html b/layout/reftests/bidi/numeral/arabic-1.html
new file mode 100644
index 0000000000..b9f8deb744
--- /dev/null
+++ b/layout/reftests/bidi/numeral/arabic-1.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+ <img src="youwontfindme.png" width="100" height="50" alt="012">
+</body>
+</html>
diff --git a/layout/reftests/bidi/numeral/arabic-2-ref.html b/layout/reftests/bidi/numeral/arabic-2-ref.html
new file mode 100644
index 0000000000..3a17736c19
--- /dev/null
+++ b/layout/reftests/bidi/numeral/arabic-2-ref.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+ <img src="youwontfindme.png" width="100" height="50" alt="متن١٢٣">
+</body>
+</html>
diff --git a/layout/reftests/bidi/numeral/arabic-2.html b/layout/reftests/bidi/numeral/arabic-2.html
new file mode 100644
index 0000000000..7e8f727e64
--- /dev/null
+++ b/layout/reftests/bidi/numeral/arabic-2.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+ <img src="youwontfindme.png" width="100" height="50" alt="متن123">
+</body>
+</html>
diff --git a/layout/reftests/bidi/numeral/arabic-3-ref.html b/layout/reftests/bidi/numeral/arabic-3-ref.html
new file mode 100644
index 0000000000..5b43f2c278
--- /dev/null
+++ b/layout/reftests/bidi/numeral/arabic-3-ref.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+ <img src="youwontfindme.png" width="100" height="50" alt="text٢٣٤">
+</body>
+</html>
diff --git a/layout/reftests/bidi/numeral/arabic-3.html b/layout/reftests/bidi/numeral/arabic-3.html
new file mode 100644
index 0000000000..fd77ee5f20
--- /dev/null
+++ b/layout/reftests/bidi/numeral/arabic-3.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+ <img src="youwontfindme.png" width="100" height="50" alt="text234">
+</body>
+</html>
diff --git a/layout/reftests/bidi/numeral/arabic-4-ref.html b/layout/reftests/bidi/numeral/arabic-4-ref.html
new file mode 100644
index 0000000000..84f7ec8fee
--- /dev/null
+++ b/layout/reftests/bidi/numeral/arabic-4-ref.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+ <img src="youwontfindme.png" width="100" height="50" alt="متن ٣٤٥">
+</body>
+</html>
diff --git a/layout/reftests/bidi/numeral/arabic-4.html b/layout/reftests/bidi/numeral/arabic-4.html
new file mode 100644
index 0000000000..7206833f03
--- /dev/null
+++ b/layout/reftests/bidi/numeral/arabic-4.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+ <img src="youwontfindme.png" width="100" height="50" alt="متن 345">
+</body>
+</html>
diff --git a/layout/reftests/bidi/numeral/arabic-5-ref.html b/layout/reftests/bidi/numeral/arabic-5-ref.html
new file mode 100644
index 0000000000..03b58b7021
--- /dev/null
+++ b/layout/reftests/bidi/numeral/arabic-5-ref.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+ <img src="youwontfindme.png" width="100" height="50" alt="text ٤٥٦">
+</body>
+</html>
diff --git a/layout/reftests/bidi/numeral/arabic-5.html b/layout/reftests/bidi/numeral/arabic-5.html
new file mode 100644
index 0000000000..cb66219436
--- /dev/null
+++ b/layout/reftests/bidi/numeral/arabic-5.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+ <img src="youwontfindme.png" width="100" height="50" alt="text 456">
+</body>
+</html>
diff --git a/layout/reftests/bidi/numeral/bug441782-1-ref.html b/layout/reftests/bidi/numeral/bug441782-1-ref.html
new file mode 100644
index 0000000000..b896333c82
--- /dev/null
+++ b/layout/reftests/bidi/numeral/bug441782-1-ref.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+٠١٢
+</body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/numeral/bug441782-1.html b/layout/reftests/bidi/numeral/bug441782-1.html
new file mode 100644
index 0000000000..db145ddbad
--- /dev/null
+++ b/layout/reftests/bidi/numeral/bug441782-1.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+012
+</body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/numeral/bug441782-2-ref.html b/layout/reftests/bidi/numeral/bug441782-2-ref.html
new file mode 100644
index 0000000000..81ad71e2f6
--- /dev/null
+++ b/layout/reftests/bidi/numeral/bug441782-2-ref.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+متن١٢٣
+</body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/numeral/bug441782-2.html b/layout/reftests/bidi/numeral/bug441782-2.html
new file mode 100644
index 0000000000..9a81969a3e
--- /dev/null
+++ b/layout/reftests/bidi/numeral/bug441782-2.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+متن123
+</body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/numeral/bug441782-3-ref.html b/layout/reftests/bidi/numeral/bug441782-3-ref.html
new file mode 100644
index 0000000000..0bfdbd9a99
--- /dev/null
+++ b/layout/reftests/bidi/numeral/bug441782-3-ref.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+text٢٣٤
+</body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/numeral/bug441782-3.html b/layout/reftests/bidi/numeral/bug441782-3.html
new file mode 100644
index 0000000000..01408d0821
--- /dev/null
+++ b/layout/reftests/bidi/numeral/bug441782-3.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+text234
+</body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/numeral/bug441782-4-ref.html b/layout/reftests/bidi/numeral/bug441782-4-ref.html
new file mode 100644
index 0000000000..5cc53dd117
--- /dev/null
+++ b/layout/reftests/bidi/numeral/bug441782-4-ref.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+متن ٣٤٥
+</body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/numeral/bug441782-4.html b/layout/reftests/bidi/numeral/bug441782-4.html
new file mode 100644
index 0000000000..1437d291d6
--- /dev/null
+++ b/layout/reftests/bidi/numeral/bug441782-4.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+متن 345
+</body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/numeral/bug441782-5-ref.html b/layout/reftests/bidi/numeral/bug441782-5-ref.html
new file mode 100644
index 0000000000..d1855ca8dc
--- /dev/null
+++ b/layout/reftests/bidi/numeral/bug441782-5-ref.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+text ٤٥٦
+</body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/numeral/bug441782-5.html b/layout/reftests/bidi/numeral/bug441782-5.html
new file mode 100644
index 0000000000..2b6b7cea1a
--- /dev/null
+++ b/layout/reftests/bidi/numeral/bug441782-5.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+text 456
+</body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/numeral/bug467672-1-ref.html b/layout/reftests/bidi/numeral/bug467672-1-ref.html
new file mode 100644
index 0000000000..5d7965a349
--- /dev/null
+++ b/layout/reftests/bidi/numeral/bug467672-1-ref.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+۳۴۵
+</body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/numeral/bug467672-1.html b/layout/reftests/bidi/numeral/bug467672-1.html
new file mode 100644
index 0000000000..1e572bd99e
--- /dev/null
+++ b/layout/reftests/bidi/numeral/bug467672-1.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+345
+</body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/numeral/bug467672-2-ref.html b/layout/reftests/bidi/numeral/bug467672-2-ref.html
new file mode 100644
index 0000000000..2a73b8a25e
--- /dev/null
+++ b/layout/reftests/bidi/numeral/bug467672-2-ref.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+متن۳۴۵
+</body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/numeral/bug467672-2.html b/layout/reftests/bidi/numeral/bug467672-2.html
new file mode 100644
index 0000000000..0ffdb981c7
--- /dev/null
+++ b/layout/reftests/bidi/numeral/bug467672-2.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+متن345
+</body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/numeral/bug467672-3-ref.html b/layout/reftests/bidi/numeral/bug467672-3-ref.html
new file mode 100644
index 0000000000..47e534b0ba
--- /dev/null
+++ b/layout/reftests/bidi/numeral/bug467672-3-ref.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+text۳۴۵
+</body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/numeral/bug467672-3.html b/layout/reftests/bidi/numeral/bug467672-3.html
new file mode 100644
index 0000000000..60e2e71dbb
--- /dev/null
+++ b/layout/reftests/bidi/numeral/bug467672-3.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+text345
+</body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/numeral/bug467672-4-ref.html b/layout/reftests/bidi/numeral/bug467672-4-ref.html
new file mode 100644
index 0000000000..3842dd5afe
--- /dev/null
+++ b/layout/reftests/bidi/numeral/bug467672-4-ref.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+متن ۳۴۵
+</body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/numeral/bug467672-4.html b/layout/reftests/bidi/numeral/bug467672-4.html
new file mode 100644
index 0000000000..1437d291d6
--- /dev/null
+++ b/layout/reftests/bidi/numeral/bug467672-4.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+متن 345
+</body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/numeral/bug467672-5-ref.html b/layout/reftests/bidi/numeral/bug467672-5-ref.html
new file mode 100644
index 0000000000..0144f94223
--- /dev/null
+++ b/layout/reftests/bidi/numeral/bug467672-5-ref.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+text ۳۴۵
+</body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/numeral/bug467672-5.html b/layout/reftests/bidi/numeral/bug467672-5.html
new file mode 100644
index 0000000000..9dbad10bca
--- /dev/null
+++ b/layout/reftests/bidi/numeral/bug467672-5.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+text 345
+</body>
+</html> \ No newline at end of file
diff --git a/layout/reftests/bidi/numeral/persian-1-ref.html b/layout/reftests/bidi/numeral/persian-1-ref.html
new file mode 100644
index 0000000000..d12001f568
--- /dev/null
+++ b/layout/reftests/bidi/numeral/persian-1-ref.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+ <img src="youwontfindme.png" width="100" height="50" alt="۳۴۵">
+</body>
+</html>
diff --git a/layout/reftests/bidi/numeral/persian-1.html b/layout/reftests/bidi/numeral/persian-1.html
new file mode 100644
index 0000000000..a8185022c1
--- /dev/null
+++ b/layout/reftests/bidi/numeral/persian-1.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+ <img src="youwontfindme.png" width="100" height="50" alt="345">
+</body>
+</html>
diff --git a/layout/reftests/bidi/numeral/persian-2-ref.html b/layout/reftests/bidi/numeral/persian-2-ref.html
new file mode 100644
index 0000000000..ce738adfae
--- /dev/null
+++ b/layout/reftests/bidi/numeral/persian-2-ref.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+ <img src="youwontfindme.png" width="100" height="50" alt="متن۳۴۵">
+</body>
+</html>
diff --git a/layout/reftests/bidi/numeral/persian-2.html b/layout/reftests/bidi/numeral/persian-2.html
new file mode 100644
index 0000000000..96e53d87cc
--- /dev/null
+++ b/layout/reftests/bidi/numeral/persian-2.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+ <img src="youwontfindme.png" width="100" height="50" alt="متن345">
+</body>
+</html>
diff --git a/layout/reftests/bidi/numeral/persian-3-ref.html b/layout/reftests/bidi/numeral/persian-3-ref.html
new file mode 100644
index 0000000000..87018752d4
--- /dev/null
+++ b/layout/reftests/bidi/numeral/persian-3-ref.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+ <img src="youwontfindme.png" width="100" height="50" alt="text۳۴۵">
+</body>
+</html>
diff --git a/layout/reftests/bidi/numeral/persian-3.html b/layout/reftests/bidi/numeral/persian-3.html
new file mode 100644
index 0000000000..9546ed2427
--- /dev/null
+++ b/layout/reftests/bidi/numeral/persian-3.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+ <img src="youwontfindme.png" width="100" height="50" alt="text345">
+</body>
+</html>
diff --git a/layout/reftests/bidi/numeral/persian-4-ref.html b/layout/reftests/bidi/numeral/persian-4-ref.html
new file mode 100644
index 0000000000..5ef1c2a8e4
--- /dev/null
+++ b/layout/reftests/bidi/numeral/persian-4-ref.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+ <img src="youwontfindme.png" width="100" height="50" alt="متن ۳۴۵">
+</body>
+</html>
diff --git a/layout/reftests/bidi/numeral/persian-4.html b/layout/reftests/bidi/numeral/persian-4.html
new file mode 100644
index 0000000000..7206833f03
--- /dev/null
+++ b/layout/reftests/bidi/numeral/persian-4.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+ <img src="youwontfindme.png" width="100" height="50" alt="متن 345">
+</body>
+</html>
diff --git a/layout/reftests/bidi/numeral/persian-5-ref.html b/layout/reftests/bidi/numeral/persian-5-ref.html
new file mode 100644
index 0000000000..1e368e406f
--- /dev/null
+++ b/layout/reftests/bidi/numeral/persian-5-ref.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+ <img src="youwontfindme.png" width="100" height="50" alt="text ۳۴۵">
+</body>
+</html>
diff --git a/layout/reftests/bidi/numeral/persian-5.html b/layout/reftests/bidi/numeral/persian-5.html
new file mode 100644
index 0000000000..3e29ae7d32
--- /dev/null
+++ b/layout/reftests/bidi/numeral/persian-5.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
+</head>
+<body>
+ <img src="youwontfindme.png" width="100" height="50" alt="text 345">
+</body>
+</html>
diff --git a/layout/reftests/bidi/numeral/reftest.list b/layout/reftests/bidi/numeral/reftest.list
new file mode 100644
index 0000000000..c32d92c866
--- /dev/null
+++ b/layout/reftests/bidi/numeral/reftest.list
@@ -0,0 +1,120 @@
+pref(bidi.numeral,0) != arabic-1.html arabic-1-ref.html
+pref(bidi.numeral,1) == arabic-1.html arabic-1-ref.html
+pref(bidi.numeral,2) == arabic-1.html arabic-1-ref.html
+pref(bidi.numeral,3) == arabic-1.html arabic-1-ref.html
+pref(bidi.numeral,4) == arabic-1.html arabic-1-ref.html
+pref(bidi.numeral,0) != arabic-2.html arabic-2-ref.html
+pref(bidi.numeral,1) == arabic-2.html arabic-2-ref.html
+pref(bidi.numeral,2) == arabic-2.html arabic-2-ref.html
+pref(bidi.numeral,3) == arabic-2.html arabic-2-ref.html
+pref(bidi.numeral,4) == arabic-2.html arabic-2-ref.html
+pref(bidi.numeral,0) != arabic-3.html arabic-3-ref.html
+pref(bidi.numeral,1) == arabic-3.html arabic-3-ref.html
+pref(bidi.numeral,2) == arabic-3.html arabic-3-ref.html
+pref(bidi.numeral,3) == arabic-3.html arabic-3-ref.html
+pref(bidi.numeral,4) == arabic-3.html arabic-3-ref.html
+pref(bidi.numeral,0) != arabic-4.html arabic-4-ref.html
+pref(bidi.numeral,1) == arabic-4.html arabic-4-ref.html
+pref(bidi.numeral,2) == arabic-4.html arabic-4-ref.html
+pref(bidi.numeral,3) == arabic-4.html arabic-4-ref.html
+pref(bidi.numeral,4) == arabic-4.html arabic-4-ref.html
+pref(bidi.numeral,0) != arabic-5.html arabic-5-ref.html
+pref(bidi.numeral,1) == arabic-5.html arabic-5-ref.html
+pref(bidi.numeral,2) == arabic-5.html arabic-5-ref.html
+pref(bidi.numeral,3) == arabic-5.html arabic-5-ref.html
+pref(bidi.numeral,4) == arabic-5.html arabic-5-ref.html
+pref(bidi.numeral,0) != bug441782-1.html bug441782-1-ref.html
+pref(bidi.numeral,1) == bug441782-1.html bug441782-1-ref.html
+pref(bidi.numeral,2) == bug441782-1.html bug441782-1-ref.html
+pref(bidi.numeral,3) == bug441782-1.html bug441782-1-ref.html
+pref(bidi.numeral,4) == bug441782-1.html bug441782-1-ref.html
+pref(bidi.numeral,0) != bug441782-2.html bug441782-2-ref.html
+pref(bidi.numeral,1) == bug441782-2.html bug441782-2-ref.html
+pref(bidi.numeral,2) == bug441782-2.html bug441782-2-ref.html
+pref(bidi.numeral,3) == bug441782-2.html bug441782-2-ref.html
+pref(bidi.numeral,4) == bug441782-2.html bug441782-2-ref.html
+pref(bidi.numeral,0) != bug441782-3.html bug441782-3-ref.html
+fuzzy-if(winWidget&&!d2d&&d3d11,0-13,0-1) pref(bidi.numeral,1) == bug441782-3.html bug441782-3-ref.html
+fuzzy-if(winWidget&&!d2d&&d3d11,0-13,0-1) pref(bidi.numeral,2) == bug441782-3.html bug441782-3-ref.html
+fuzzy-if(winWidget&&!d2d&&d3d11,0-13,0-1) pref(bidi.numeral,3) == bug441782-3.html bug441782-3-ref.html
+pref(bidi.numeral,4) == bug441782-3.html bug441782-3-ref.html
+pref(bidi.numeral,0) != bug441782-4.html bug441782-4-ref.html
+pref(bidi.numeral,1) == bug441782-4.html bug441782-4-ref.html
+pref(bidi.numeral,2) == bug441782-4.html bug441782-4-ref.html
+pref(bidi.numeral,3) == bug441782-4.html bug441782-4-ref.html
+pref(bidi.numeral,4) == bug441782-4.html bug441782-4-ref.html
+pref(bidi.numeral,0) != bug441782-5.html bug441782-5-ref.html
+pref(bidi.numeral,1) == bug441782-5.html bug441782-5-ref.html
+pref(bidi.numeral,2) == bug441782-5.html bug441782-5-ref.html
+pref(bidi.numeral,3) == bug441782-5.html bug441782-5-ref.html
+pref(bidi.numeral,4) == bug441782-5.html bug441782-5-ref.html
+pref(bidi.numeral,0) != bug467672-1.html bug467672-1-ref.html
+pref(bidi.numeral,1) == bug467672-1.html bug467672-1-ref.html
+pref(bidi.numeral,2) == bug467672-1.html bug467672-1-ref.html
+pref(bidi.numeral,3) == bug467672-1.html bug467672-1-ref.html
+pref(bidi.numeral,4) == bug467672-1.html bug467672-1-ref.html
+pref(bidi.numeral,5) == bug467672-1.html bug467672-1-ref.html
+pref(bidi.numeral,6) == bug467672-1.html bug467672-1-ref.html
+pref(bidi.numeral,0) != bug467672-2.html bug467672-2-ref.html
+pref(bidi.numeral,1) == bug467672-2.html bug467672-2-ref.html
+pref(bidi.numeral,2) == bug467672-2.html bug467672-2-ref.html
+pref(bidi.numeral,3) == bug467672-2.html bug467672-2-ref.html
+pref(bidi.numeral,4) == bug467672-2.html bug467672-2-ref.html
+pref(bidi.numeral,5) == bug467672-2.html bug467672-2-ref.html
+pref(bidi.numeral,6) == bug467672-2.html bug467672-2-ref.html
+pref(bidi.numeral,0) != bug467672-3.html bug467672-3-ref.html
+pref(bidi.numeral,1) == bug467672-3.html bug467672-3-ref.html
+pref(bidi.numeral,2) == bug467672-3.html bug467672-3-ref.html
+pref(bidi.numeral,3) == bug467672-3.html bug467672-3-ref.html
+pref(bidi.numeral,4) == bug467672-3.html bug467672-3-ref.html
+pref(bidi.numeral,5) == bug467672-3.html bug467672-3-ref.html
+pref(bidi.numeral,6) == bug467672-3.html bug467672-3-ref.html
+pref(bidi.numeral,0) != bug467672-4.html bug467672-4-ref.html
+pref(bidi.numeral,1) == bug467672-4.html bug467672-4-ref.html
+pref(bidi.numeral,2) == bug467672-4.html bug467672-4-ref.html
+pref(bidi.numeral,3) == bug467672-4.html bug467672-4-ref.html
+pref(bidi.numeral,4) == bug467672-4.html bug467672-4-ref.html
+pref(bidi.numeral,5) == bug467672-4.html bug467672-4-ref.html
+pref(bidi.numeral,6) == bug467672-4.html bug467672-4-ref.html
+pref(bidi.numeral,0) != bug467672-5.html bug467672-5-ref.html
+pref(bidi.numeral,1) == bug467672-5.html bug467672-5-ref.html
+pref(bidi.numeral,2) == bug467672-5.html bug467672-5-ref.html
+pref(bidi.numeral,3) == bug467672-5.html bug467672-5-ref.html
+pref(bidi.numeral,4) == bug467672-5.html bug467672-5-ref.html
+pref(bidi.numeral,5) == bug467672-5.html bug467672-5-ref.html
+pref(bidi.numeral,6) == bug467672-5.html bug467672-5-ref.html
+pref(bidi.numeral,0) != persian-1.html persian-1-ref.html
+pref(bidi.numeral,1) == persian-1.html persian-1-ref.html
+pref(bidi.numeral,2) == persian-1.html persian-1-ref.html
+pref(bidi.numeral,3) == persian-1.html persian-1-ref.html
+pref(bidi.numeral,4) == persian-1.html persian-1-ref.html
+pref(bidi.numeral,5) == persian-1.html persian-1-ref.html
+pref(bidi.numeral,6) == persian-1.html persian-1-ref.html
+pref(bidi.numeral,0) != persian-2.html persian-2-ref.html
+pref(bidi.numeral,1) == persian-2.html persian-2-ref.html
+pref(bidi.numeral,2) == persian-2.html persian-2-ref.html
+pref(bidi.numeral,3) == persian-2.html persian-2-ref.html
+pref(bidi.numeral,4) == persian-2.html persian-2-ref.html
+pref(bidi.numeral,5) == persian-2.html persian-2-ref.html
+pref(bidi.numeral,6) == persian-2.html persian-2-ref.html
+pref(bidi.numeral,0) != persian-3.html persian-3-ref.html
+pref(bidi.numeral,1) == persian-3.html persian-3-ref.html
+pref(bidi.numeral,2) == persian-3.html persian-3-ref.html
+pref(bidi.numeral,3) == persian-3.html persian-3-ref.html
+pref(bidi.numeral,4) == persian-3.html persian-3-ref.html
+pref(bidi.numeral,5) == persian-3.html persian-3-ref.html
+pref(bidi.numeral,6) == persian-3.html persian-3-ref.html
+pref(bidi.numeral,0) != persian-4.html persian-4-ref.html
+pref(bidi.numeral,1) == persian-4.html persian-4-ref.html
+pref(bidi.numeral,2) == persian-4.html persian-4-ref.html
+pref(bidi.numeral,3) == persian-4.html persian-4-ref.html
+pref(bidi.numeral,4) == persian-4.html persian-4-ref.html
+pref(bidi.numeral,5) == persian-4.html persian-4-ref.html
+pref(bidi.numeral,6) == persian-4.html persian-4-ref.html
+pref(bidi.numeral,0) != persian-5.html persian-5-ref.html
+pref(bidi.numeral,1) == persian-5.html persian-5-ref.html
+pref(bidi.numeral,2) == persian-5.html persian-5-ref.html
+pref(bidi.numeral,3) == persian-5.html persian-5-ref.html
+pref(bidi.numeral,4) == persian-5.html persian-5-ref.html
+pref(bidi.numeral,5) == persian-5.html persian-5-ref.html
+pref(bidi.numeral,6) == persian-5.html persian-5-ref.html
diff --git a/layout/reftests/bidi/reftest.list b/layout/reftests/bidi/reftest.list
new file mode 100644
index 0000000000..b4eb3ee375
--- /dev/null
+++ b/layout/reftests/bidi/reftest.list
@@ -0,0 +1,183 @@
+include dirAuto/reftest.list
+include numeral/reftest.list
+fuzzy-if(cocoaWidget,0-1,0-1) == bdi-element.html bdi-element-ref.html # Bug 1392106
+== bidi-000.html bidi-000-ref.html
+== bidi-001.html bidi-001-ref.html # Bug 1392106
+== bidi-001-j.html bidi-001-ref.html # Bug 1392106
+== bidi-001-v.html bidi-001-ref.html # Bug 1392106
+fuzzy-if(Android,0-1,0-1) == bidi-002.html bidi-002-ref.html
+fuzzy-if(Android||winWidget,0-1,0-1) == bidi-003.html bidi-003-ref.html
+fuzzy-if(gtkWidget,0-255,0-17) == bidi-004.html bidi-004-ref.html # inconsistency in the Hebrew font that gets used
+fuzzy-if(gtkWidget,0-255,0-17) == bidi-004-j.html bidi-004-ref.html # inconsistency in the Hebrew font that gets used
+== bidi-005.html bidi-005-ref.html
+random-if(cocoaWidget) == bidi-006.html bidi-006-ref.html # bug 734313
+random-if(cocoaWidget) == bidi-006-j.html bidi-006-ref.html # bug 734313
+fuzzy-if(winWidget,0-1,0-1) == bidiSVG-01.svg bidiSVG-01-ref.svg
+fuzzy-if(Android,0-1,0-1) == bidiSVG-02.svg bidiSVG-02-ref.svg # Bug 1392106
+fuzzy-if(Android,0-253,0-77) == bidiSVG-03.svg bidiSVG-03-ref.svg
+fuzzy(0-1,0-1) fuzzy-if(winWidget,0-1,0-2) == bidiSVG-04.svg bidiSVG-04-ref.svg
+== bidiSVG-05.svg bidiSVG-05-ref.svg
+== bidiMirroring.svg bidiMirroring-ref.svg # Bug 1392106
+fuzzy-if(Android,0-9,0-134) random-if(layersGPUAccelerated) == visualmarquee.html marquee-ref.html
+fuzzy-if(Android,0-9,0-134) random-if(layersGPUAccelerated) == logicalmarquee.html marquee-ref.html
+== visualmarquee.html logicalmarquee.html
+# test for glyph mirroring in right-to-left text
+== mirroring-01.html mirroring-01-ref.html
+# quote marks are not supposed to mirror, but Unicode 5.0 said they should, so some systems do it
+random-if(cocoaWidget) == mirroring-02.html mirroring-02-ref.html
+== mirroring-03.html mirroring-03-ref.html
+== mixedChartype-00.html mixedChartype-00-ref.html
+== mixedChartype-00-j.html mixedChartype-00-ref.html
+== mixedChartype-01.html mixedChartype-01-ref.html
+== mixedChartype-01-j.html mixedChartype-01-ref.html
+fuzzy-if(Android,0-1,0-6) fuzzy-if(cocoaWidget,0-1,0-2) == mixedChartype-02.html mixedChartype-02-ref.html
+fuzzy-if(Android,0-1,0-6) fuzzy-if(cocoaWidget,0-1,0-2) == mixedChartype-02-j.html mixedChartype-02-ref.html
+== mixedChartype-03.html mixedChartype-03-ref.html
+== mixedChartype-03-j.html mixedChartype-03-ref.html
+== unicode-bidi-anonymous-001.html unicode-bidi-anonymous-001-ref.html
+== unicode-bidi-anonymous-002.html unicode-bidi-anonymous-002-ref.html
+== unicode-bidi-isolate-basic.html unicode-bidi-isolate-basic-ref.html
+== unicode-bidi-isolate-aharon.html unicode-bidi-isolate-aharon-ref.html
+fuzzy(0-104,0-32) == unicode-bidi-plaintext.html unicode-bidi-plaintext-ref.html # Bug 1392106
+== unicode-bidi-plaintext-textarea-1.html unicode-bidi-plaintext-textarea-ref.html
+== unicode-bidi-plaintext-textarea-2.html unicode-bidi-plaintext-textarea-ref.html
+== unicode-bidi-plaintext-textarea-3.html unicode-bidi-plaintext-textarea-ref.html
+== unicode-bidi-plaintext-textarea-4.html unicode-bidi-plaintext-textarea-ref.html
+== with-first-letter-1a.html with-first-letter-1-ref.html
+== with-first-letter-1b.html with-first-letter-1-ref.html
+random-if(cocoaWidget) == with-first-letter-2a.html with-first-letter-2-ref.html # bug 734313
+random-if(cocoaWidget) == with-first-letter-2b.html with-first-letter-2-ref.html # bug 734313
+== 83958-1a.html 83958-1-ref.html
+== 83958-1b.html 83958-1-ref.html
+== 83958-1c.html 83958-1-ref.html
+fuzzy-if(Android,0-1,0-3) fuzzy-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)&&!layersGPUAccelerated&&!azureSkia,0-111,0-7) == 83958-2a.html 83958-2-ref.html
+fuzzy-if(Android,0-1,0-3) fuzzy-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)&&!layersGPUAccelerated&&!azureSkia,0-111,0-7) == 83958-2b.html 83958-2-ref.html
+== 115921-1.html 115921-1-ref.html
+== 115921-2.html 115921-2-ref.html
+== 151407-1.html 151407-1-ref.html
+== 151407-1a.html 151407-1-ref.html
+== 151407-2-ltr.html 151407-2-ltr-ref.html
+== 151407-2-rtl.html 151407-2-rtl-ref.html
+== 151407-2-auto.html 151407-2-auto-ref.html
+== 151407-2-empty.html 151407-2-empty-ref.html
+== 151407-2-foopy.html 151407-2-empty-ref.html
+== 151407-3-ltr.html 151407-3-ltr-ref.html
+== 151407-3-rtl.html 151407-3-rtl-ref.html
+== 151407-3-auto.html 151407-3-auto-ref.html
+== 151407-3-foopy.html 151407-3-empty-ref.html
+== 229367-1.html 229367-1-ref.html # Bug 1392106
+== 229367-2.html 229367-2-ref.html # Bug 1392106
+== 229367-3.html 229367-3-ref.html # Bug 1392106
+== 258928-1.html 258928-1-ref.html # Bug 1392106
+== 263359-1.html 263359-1-ref.html # Bug 1392106
+== 263359-1a.html 263359-1-ref.html # Bug 1392106
+!= 263359-1b.html 263359-1-ref.html # Bug 1392106
+== 263359-2.html 263359-2-ref.html # Bug 1392106
+== 263359-3.html 263359-3-ref.html # Bug 1392106
+== 263359-4.html 263359-4-ref.html # Bug 1392106
+random-if(winWidget) fuzzy(0-1,0-1700) == 267459-1.html 267459-1-ref.html # depends on windows version, see bug 590101
+fuzzy(0-1,0-1100) == 267459-2.html 267459-2-ref.html
+== 299065-1.html 299065-1-ref.html
+random-if(winWidget) == 305643-1.html 305643-1-ref.html # depends on windows version, see bug 590101
+== 332655-1.html 332655-1-ref.html
+== 332655-2.html 332655-2-ref.html # Bug 1392106
+== 381279-1.html 381279-1-ref.html
+== 386339.html 386339-ref.html
+== 409375.html 409375-ref.html
+== 413542-1.html 413542-1-ref.html
+== 413542-2.html 413542-2-ref.html
+== 413928-1.html 413928-1-ref.html # Bug 1392106
+fuzzy(0-52,0-14) == 413928-2.html 413928-2-ref.html # Bug 1392106
+== 425338-1a.html 425338-1-ref.html
+== 425338-1b.html 425338-1-ref.html
+== 489517-1.html 489517-1-ref.html
+== 489887-1.html 489887-1-ref.html
+== 492231-1.html 492231-1-ref.html
+== 496006-1.html 496006-1-ref.html
+== 503269-1.html 503269-1-ref.html
+== 503957-1.html 503957-1-ref.html
+== 525740-1.html 525740-1-ref.html
+== 536963-1.html 536963-1-ref.html
+fuzzy(0-137,0-1) == 562169-1.html 562169-1-ref.html
+fuzzy(0-137,0-1) == 562169-1a.html 562169-1-ref.html
+== 562169-2.html 562169-2-ref.html
+== 562169-2a.html 562169-2-ref.html
+== 562169-3.html 562169-3-ref.html
+== 562169-3a.html 562169-3-ref.html
+== 562169-4.html 562169-4-ref.html
+== 588739-1.html 588739-ref.html
+== 588739-2.html 588739-ref.html
+== 588739-3.html 588739-ref.html
+== 612843-1.html 612843-1-ref.html
+fuzzy-if(Android,0-1,0-1) == 613149-1a.html 613149-1-ref.html # Bug 1392106
+fuzzy-if(Android,0-1,0-1) == 613149-1b.html 613149-1-ref.html # Bug 1392106
+== 613149-2a.html 613149-2-ref.html # Bug 1392106
+fuzzy-if(Android,0-24,0-1) == 613149-2b.html 613149-2-ref.html # Bug 1392106
+== 613157-1.html 613157-1-ref.html
+fuzzy-if(winWidget,0-1,0-1) fuzzy-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)&&!layersGPUAccelerated&&!azureSkia,0-255,0-6) == 613157-2.html 613157-2-ref.html
+== 662288-1.html 662288-1-ref.html # Bug 1392106
+== 670226-1.html 670226-1-ref.html
+== 676245-1.html 676245-1-ref.html
+fuzzy(0-1,0-3) == 698291-1.html 698291-1-ref.html
+== 698706-1.html 698706-1-ref.html
+== 704837-1.html 704837-1-ref.html
+== 712600-1.html 712600-1-ref.html # Bug 1392106
+== 712600-2.html 712600-2-ref.html # Bug 1392106
+== 712600-2-dyn.html 712600-2-ref.html # Bug 1392106
+== 712600-3.html 712600-3-ref.html # Bug 1392106
+== 718236-1.html 718236-1-ref.html
+== 718236-2.html 718236-2-ref.html
+== 718236-3.html 718236-3-ref.html
+== 726460-1.html 726460-1-ref.html
+== 729047-1.html 729047-1-ref.html
+== 730562-1.html 730562-1-ref.html
+== 746987-1.html 746987-1-ref.html
+== 746987-2.html 746987-2-ref.html
+== 746987-3.html 746987-3-ref.html
+== 746987-4.html 746987-4-ref.html
+== 779003-1.html 779003-1-ref.html
+== 779003-1-dynamic.html 779003-1-ref.html
+== 817406-1.html 817406-1-ref.html
+== 817406-2.html 817406-2-ref.html
+== 817406-3.html 817406-1-ref.html
+== 817406-4.html 817406-1-ref.html
+== 847242-1.html 847242-1-ref.html
+
+# Skip on Android because this is a <tree> test and we don't have the requisite XUL on Android.
+skip-if(Android) fuzzy(0-92,0-350) fuzzy-if(xulRuntime.widgetToolkit=="gtk",0-1,0-11) == chrome://reftest/content/bidi/869833-1.xhtml chrome://reftest/content/bidi/869833-1-ref.xhtml
+
+== 922530-1.html 922530-1-ref.html
+== 922550-1.html 922550-1-ref.html # Bug 1392106
+== 989994-1.html 989994-1-ref.html
+== 1067268-1.html 1067268-1-ref.html
+== 1069941-inline-bidi-border-1.html 1069941-inline-bidi-border-1-ref.html
+== 1069941-inline-bidi-margin-1.html 1069941-inline-bidi-margin-1-ref.html
+!= chrome://reftest/content/bidi/1155359-1.xhtml chrome://reftest/content/bidi/1155359-1-ref.xhtml
+== 1157726-1.html 1157726-1-ref.html
+== 1161752.html 1161752-ref.html
+== 1161752-5-embed.html 1161752-5-embed-ref.html
+== brackets-1a-ltr.html brackets-1a-ltr-ref.html # Bug 1392106
+== brackets-1a-rtl.html brackets-1a-rtl-ref.html # Bug 1392106
+== brackets-1b-ltr.html brackets-1b-ltr-ref.html # Bug 1392106
+== brackets-1b-rtl.html brackets-1b-rtl-ref.html # Bug 1392106
+== brackets-1c-ltr.html brackets-1c-ltr-ref.html # Bug 1392106
+== brackets-1c-rtl.html brackets-1c-rtl-ref.html # Bug 1392106
+fuzzy-if(cocoaWidget,0-1,0-4) fuzzy-if(Android,0-1,0-6) == brackets-2a-ltr.html brackets-2a-ltr-ref.html # Bug 1392106
+fuzzy-if(cocoaWidget,0-1,0-2) fuzzy-if(Android,0-254,0-557) == brackets-2a-rtl.html brackets-2a-rtl-ref.html # Bug 1392106
+fuzzy-if(cocoaWidget,0-1,0-6) fuzzy-if(Android,0-1,0-8) == brackets-2b-ltr.html brackets-2b-ltr-ref.html # Bug 1392106
+fuzzy-if(cocoaWidget,0-1,0-7) fuzzy-if(Android,0-1,0-6) == brackets-2b-rtl.html brackets-2b-rtl-ref.html # Bug 1392106
+fuzzy-if(cocoaWidget,0-1,0-7) fuzzy-if(Android,0-1,0-6) == brackets-2c-ltr.html brackets-2c-ltr-ref.html # Bug 1392106
+fuzzy-if(cocoaWidget,0-1,0-6) fuzzy-if(Android,0-254,0-231) == brackets-2c-rtl.html brackets-2c-rtl-ref.html # Bug 1392106
+fuzzy-if(cocoaWidget,0-1,0-6) fuzzy-if(Android,0-1,0-8) == brackets-3a-ltr.html brackets-3a-ltr-ref.html # Bug 1392106
+fuzzy-if(cocoaWidget,0-1,0-3) fuzzy-if(Android,0-1,0-6) == brackets-3a-rtl.html brackets-3a-rtl-ref.html # Bug 1392106
+== brackets-3b-ltr.html brackets-3b-ltr-ref.html # Bug 1392106
+== brackets-3b-rtl.html brackets-3b-rtl-ref.html # Bug 1392106
+== 1217833-1.html 1217833-1-ref.html
+== 1217833-2.html 1217833-2-ref.html
+== 1231175-1.html 1231175-1-ref.html
+== 1366623-1.html 1366623-1-ref.html
+== 1426042-1.html 1426042-1-ref.html # Bug 1392106
+== clone-intrinsic-size-bidi.html clone-intrinsic-size-bidi-ref.html
+fuzzy-if(winWidget,70-112,8-8) == slice-intrinsic-size-bidi.html slice-intrinsic-size-bidi-ref.html
+== 1556414-1.html 1556414-1-ref.html
+== 1567036-1.html 1567036-1-ref.html
diff --git a/layout/reftests/bidi/slice-intrinsic-size-bidi-ref.html b/layout/reftests/bidi/slice-intrinsic-size-bidi-ref.html
new file mode 100644
index 0000000000..ceab217846
--- /dev/null
+++ b/layout/reftests/bidi/slice-intrinsic-size-bidi-ref.html
@@ -0,0 +1,85 @@
+<!DOCTYPE html>
+<head>
+ <title>CSS Reference: min/max-content size on box-decoration-break:slice inline box with bidi text</title>
+ <link rel="author" title="Mats Palmgren" href="mailto:mats@mozilla.com">
+<style>
+html,body {
+ color:black; background-color:white; font:10px/1 monospace; padding:0; margin:0;
+}
+
+div {
+ border: 5px solid blue;
+ white-space: pre;
+}
+.max > div {
+ width: -moz-max-content;
+ width: -webkit-max-content;
+ width: max-content;
+}
+.min > div {
+ width: -moz-min-content;
+ width: -webkit-min-content;
+ width: min-content;
+}
+
+span {
+ border: 2px solid gray;
+ padding: 0 10px 0 6px;
+ border-width: 0 8px 0 5px;
+ margin: 0 4px 0 3px;
+ background: yellow;
+}
+
+f { margin-right: 30px; float: left; }
+.l { margin-right:0; border-right-width:0; padding-right:0 }
+.r { margin-left:0; border-left-width:0; padding-left:0 }
+</style>
+<body>
+<f class="max">
+<div><span>&#x202e;a&#x202d;bc</span><span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span>aa<span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span> <span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc </span><span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span><span> d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span> aa<span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc </span>aa<span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span>aa<span> d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span> aa <span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span>aa <span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span>aa</div>
+</f>
+
+<f class="min">
+<div><span>&#x202e;a&#x202d;bc</span><span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span>aa<span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span><br><span>d&#x202e;e&#x202d;f</span>
+</div>
+<!-- FIXME -->
+<div style="white-space:normal;"><span>&#x202e;a&#x202d;bc </span><span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span class="l">bc</span><span>&#x202e;a&#x202d;</span><br><span class="r">d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span><br>aa<span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span><br>aa<span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span class="l">bc</span>aa<span>&#x202e;a&#x202d;</span><br><span class="r">d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span><br>aa<br><span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span>aa<br><span>d&#x202e;e&#x202d;f</span>
+</div>
+<div><span>&#x202e;a&#x202d;bc</span>aa</div>
+</f>
diff --git a/layout/reftests/bidi/slice-intrinsic-size-bidi.html b/layout/reftests/bidi/slice-intrinsic-size-bidi.html
new file mode 100644
index 0000000000..249f7386f7
--- /dev/null
+++ b/layout/reftests/bidi/slice-intrinsic-size-bidi.html
@@ -0,0 +1,108 @@
+<!DOCTYPE html>
+<head>
+ <title>CSS Test: min/max-content size on box-decoration-break:slice inline box with bidi text</title>
+ <link rel="author" title="Mats Palmgren" href="mailto:mats@mozilla.com">
+ <link rel="help" href="https://drafts.csswg.org/css-sizing-3/#valdef-width-min-content">
+ <link rel="help" href="https://drafts.csswg.org/css-break-3/#break-decoration">
+ <link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1552357">
+ <link rel="match" href="slice-intrinsic-size-bidi-ref.html">
+<style>
+html,body {
+ color:black; background-color:white; font:10px/1 monospace; padding:0; margin:0;
+}
+
+div {
+ border: 5px solid blue;
+}
+.max > div {
+ width: -moz-max-content;
+ width: -webkit-max-content;
+ width: max-content;
+}
+.min > div {
+ width: -moz-min-content;
+ width: -webkit-min-content;
+ width: min-content;
+}
+
+span {
+ border: 2px solid gray;
+ padding: 0 10px 0 6px;
+ border-width: 0 8px 0 5px;
+ margin: 0 4px 0 3px;
+ background: yellow;
+}
+
+f { margin-right: 30px; float: left; }
+</style>
+<body>
+<f class="max">
+<div>
+ <span>&#x202e;a&#x202d;bc</span><span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span>aa<span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span> <span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc </span><span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span><span> d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span> aa<span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc </span>aa<span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span>aa<span> d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span> aa <span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span>aa <span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span>aa </div>
+</f>
+
+<f class="min">
+<div>
+ <span>&#x202e;a&#x202d;bc</span><span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span>aa<span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span> <span>d&#x202e;e&#x202d;f</span>
+</div>
+<!-- Bug 1556444 -->
+<div>
+ <span>&#x202e;a&#x202d;bc </span><span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span><span> d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span> aa<span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc </span>aa<span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span>aa<span> d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span> aa <span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span>aa <span>d&#x202e;e&#x202d;f</span>
+</div>
+<div>
+ <span>&#x202e;a&#x202d;bc</span>aa </div>
+</f>
diff --git a/layout/reftests/bidi/unicode-bidi-anonymous-001-ref.html b/layout/reftests/bidi/unicode-bidi-anonymous-001-ref.html
new file mode 100644
index 0000000000..64941d5ca1
--- /dev/null
+++ b/layout/reftests/bidi/unicode-bidi-anonymous-001-ref.html
@@ -0,0 +1,3 @@
+<!DOCTYPE HTML>
+<title>Test for 'unicode-bidi' on table cells</title>
+<table border><tr><td>abc</td></tr></table>
diff --git a/layout/reftests/bidi/unicode-bidi-anonymous-001.html b/layout/reftests/bidi/unicode-bidi-anonymous-001.html
new file mode 100644
index 0000000000..a0e3dcb0a0
--- /dev/null
+++ b/layout/reftests/bidi/unicode-bidi-anonymous-001.html
@@ -0,0 +1,3 @@
+<!DOCTYPE HTML>
+<title>Test for 'unicode-bidi' on table cells</title>
+<table border><tr><td style="unicode-bidi: bidi-override; direction: rtl; text-align: left">cba</td></tr></table>
diff --git a/layout/reftests/bidi/unicode-bidi-anonymous-002-ref.html b/layout/reftests/bidi/unicode-bidi-anonymous-002-ref.html
new file mode 100644
index 0000000000..6da4f8dcfd
--- /dev/null
+++ b/layout/reftests/bidi/unicode-bidi-anonymous-002-ref.html
@@ -0,0 +1,5 @@
+<!DOCTYPE HTML>
+<title>Test for 'unicode-bidi' on table cells</title>
+<fieldset>
+ abc
+</fieldset>
diff --git a/layout/reftests/bidi/unicode-bidi-anonymous-002.html b/layout/reftests/bidi/unicode-bidi-anonymous-002.html
new file mode 100644
index 0000000000..9839b29018
--- /dev/null
+++ b/layout/reftests/bidi/unicode-bidi-anonymous-002.html
@@ -0,0 +1,5 @@
+<!DOCTYPE HTML>
+<title>Test for 'unicode-bidi' on table cells</title>
+<fieldset style="unicode-bidi: bidi-override; direction: rtl; text-align: left">
+ cba
+</fieldset>
diff --git a/layout/reftests/bidi/unicode-bidi-isolate-aharon-ref.html b/layout/reftests/bidi/unicode-bidi-isolate-aharon-ref.html
new file mode 100644
index 0000000000..8bfa5a30e4
--- /dev/null
+++ b/layout/reftests/bidi/unicode-bidi-isolate-aharon-ref.html
@@ -0,0 +1,69 @@
+<!DOCTYPE html>
+<html><head>
+<title>Test cases for unicode-bidi:isolate</title>
+<style>
+</style>
+</head><body>
+opposite-to-base isolate followed by number.
+<div>
+ <div class="reference">
+ <span dir="ltr">&#x05D0;</span> (3 reviews)
+ </div>
+</div>
+<hr>
+opposite-to-base isolate with opposite-to-base text before it with neutrals in between.
+<div>
+ <div class="reference">
+ <span dir="ltr">&#x05D0;</span>: <span dir="ltr">&#x05D1;</span>
+ </div>
+</div>
+<hr>
+opposite-to-base isolate with opposite-to-base text before it and nothing in between.
+<div>
+ <div class="reference">
+ <bdo dir="ltr">&#x05D0;&#x05D1;</bdo>
+ </div>
+</div>
+<hr>
+two opposite-to-base isolates with neutrals in between.
+<div>
+ <div class="reference">
+ <span dir="ltr">&#x05D0;</span> = <span dir="ltr">&#x05D1;</span>
+ </div>
+</div>
+<hr>
+two opposite-to-base isolates with nothing in between.
+<div>
+ <div class="reference">
+ <bdo dir="ltr">&#x05D0;&#x05D1;</bdo>
+ </div>
+</div>
+<hr>
+same-as-base isolate preceded by opposite-to-base text and followed by number
+<div dir="rtl">
+ <div class="reference">
+ see <span dir="ltr">&#x05D0;</span><sup>3</sup>
+ </div>
+</div>
+<hr>
+same-as-base isolate surrounded by opposite-to-base text
+<div dir="rtl">
+ <div class="reference">
+ with <span dir="ltr">&#x05D0;</span>=<span dir="ltr">&#x05D1;</span> everywhere
+ </div>
+</div>
+<hr>
+chimeric isolate surrounded by chimeric text
+<div>
+ <div class="reference">
+ about that <span dir="ltr">&#x05D0;</span> - &#x05D1;
+ </div>
+</div>
+<hr>
+nested chimeric isolates surrounded by chimeric text
+<div>
+ <div class="reference">
+ about that strange <span dir="ltr">&#x05D0;</span> - <span dir="ltr">&#x05D1;</span> - &#x05D2;
+ </div>
+</div>
+</body></html>
diff --git a/layout/reftests/bidi/unicode-bidi-isolate-aharon.html b/layout/reftests/bidi/unicode-bidi-isolate-aharon.html
new file mode 100644
index 0000000000..175150b467
--- /dev/null
+++ b/layout/reftests/bidi/unicode-bidi-isolate-aharon.html
@@ -0,0 +1,72 @@
+<!DOCTYPE html>
+<html><head>
+<title>Test cases for unicode-bidi:isolate</title>
+<style>
+ .isolate {
+ unicode-bidi: isolate;
+ }
+</style>
+</head><body>
+opposite-to-base isolate followed by number.
+<div>
+ <div class="test">
+ <span class="isolate">&#x05D0;</span> (3 reviews)
+ </div>
+</div>
+<hr>
+opposite-to-base isolate with opposite-to-base text before it with neutrals in between.
+<div>
+ <div class="test">
+ &#x05D0;: <span class="isolate">&#x05D1;</span>
+ </div>
+</div>
+<hr>
+opposite-to-base isolate with opposite-to-base text before it and nothing in between.
+<div>
+ <div class="test">
+ &#x05D0;<span class="isolate">&#x05D1;</span>
+ </div>
+</div>
+<hr>
+two opposite-to-base isolates with neutrals in between.
+<div>
+ <div class="test">
+ <span class="isolate">&#x05D0;</span> = <span class="isolate">&#x05D1;</span>
+ </div>
+</div>
+<hr>
+two opposite-to-base isolates with nothing in between.
+<div>
+ <div class="test">
+ <span class="isolate">&#x05D0;</span><span class="isolate">&#x05D1;</span>
+ </div>
+</div>
+<hr>
+same-as-base isolate preceded by opposite-to-base text and followed by number
+<div dir="rtl">
+ <div class="test">
+ see <span class="isolate">&#x05D0;</span><sup>3</sup>
+ </div>
+</div>
+<hr>
+same-as-base isolate surrounded by opposite-to-base text
+<div dir="rtl">
+ <div class="test">
+ with <span class="isolate">&#x05D0;</span>=<span class="isolate">&#x05D1;</span> everywhere
+ </div>
+</div>
+<hr>
+chimeric isolate surrounded by chimeric text
+<div>
+ <div class="test">
+ about <span class="isolate">that &#x05D0;</span> - &#x05D1;
+ </div>
+</div>
+<hr>
+nested chimeric isolates surrounded by chimeric text
+<div>
+ <div class="test">
+ about <span class="isolate">that <span class="isolate">strange &#x05D0;</span> - &#x05D1;</span> - &#x05D2;
+ </div>
+</div>
+</body></html>
diff --git a/layout/reftests/bidi/unicode-bidi-isolate-basic-ref.html b/layout/reftests/bidi/unicode-bidi-isolate-basic-ref.html
new file mode 100644
index 0000000000..f907d00b95
--- /dev/null
+++ b/layout/reftests/bidi/unicode-bidi-isolate-basic-ref.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=UTF-8">
+<script type="text/javascript" src="unicode-bidi-isolate-basic.js"></script>
+<style>
+.resultsDiv {
+ column-width: 3em;
+ -webkit-column-width: 3em;
+ column-gap: 5em;
+ -webkit-column-gap: 5em;
+ text-align: left;
+}
+.enclosed { display: inline-block; }
+</style>
+</head>
+<body onload="buildTable();">
+<div id="resultsContainer" style="position: relative">
+<div id="elem" class="resultsDiv"></div>
+</div>
+</body>
+</html>
diff --git a/layout/reftests/bidi/unicode-bidi-isolate-basic.html b/layout/reftests/bidi/unicode-bidi-isolate-basic.html
new file mode 100644
index 0000000000..01c0b848ca
--- /dev/null
+++ b/layout/reftests/bidi/unicode-bidi-isolate-basic.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="content-type" content="text/html; charset=UTF-8">
+<script type="text/javascript" src="unicode-bidi-isolate-basic.js"></script>
+<style>
+.resultsDiv {
+ column-width: 3em;
+ -webkit-column-width: 3em;
+ column-gap: 5em;
+ -webkit-column-gap: 5em;
+ text-align: left;
+}
+.enclosed { unicode-bidi: isolate; }
+</style>
+</head>
+<body onload="buildTable()">
+<div id="resultsContainer" style="position: relative">
+<div id="elem" class="resultsDiv"></div>
+</div>
+</body>
+</html>
diff --git a/layout/reftests/bidi/unicode-bidi-isolate-basic.js b/layout/reftests/bidi/unicode-bidi-isolate-basic.js
new file mode 100644
index 0000000000..e949e6a445
--- /dev/null
+++ b/layout/reftests/bidi/unicode-bidi-isolate-basic.js
@@ -0,0 +1,44 @@
+function buildTable()
+{
+ var seed = 0;
+
+ var neutrals = ['"', ")", "("];
+ var strongRTLs = ['א', 'ב', 'ג', 'ד', 'ה', 'ו', 'ז'];
+ var strongLTRs = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
+ var neutral = function() { return neutrals[seed++ % neutrals.length]; }
+ var strongRTL = function() { return strongRTLs[seed++ % strongRTLs.length]; }
+ var strongLTR = function() { return strongLTRs[seed++ % strongLTRs.length]; }
+ var charClassExamples = [neutral, strongRTL, strongLTR];
+ var possibleDirs = ['ltr', 'rtl'];
+
+ var elem=document.getElementById("elem");
+ for (outerDirIndex in possibleDirs) {
+ var outerDir = possibleDirs[outerDirIndex];
+ for (beforeSpanIndex in charClassExamples) {
+ var beforeSpan = charClassExamples[beforeSpanIndex];
+ for (spanDirIndex in possibleDirs) {
+ var spanDir = possibleDirs[spanDirIndex];
+ for (inSpanIndex in charClassExamples) {
+ var inSpan = charClassExamples[inSpanIndex];
+ for (afterSpanIndex in charClassExamples) {
+ var afterSpan = charClassExamples[afterSpanIndex];
+ function caseWithStyle() {
+ seed = 0;
+ var outerDiv = document.createElement("div");
+ outerDiv.dir = outerDir;
+ outerDiv.appendChild(document.createTextNode(beforeSpan()));
+ var span = document.createElement("span");
+ span.dir = spanDir;
+ span.setAttribute("class", "enclosed")
+ span.appendChild(document.createTextNode(inSpan()));
+ outerDiv.appendChild(span);
+ outerDiv.appendChild(document.createTextNode(afterSpan()));
+ return outerDiv;
+ }
+ elem.appendChild(caseWithStyle());
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/layout/reftests/bidi/unicode-bidi-plaintext-ref.html b/layout/reftests/bidi/unicode-bidi-plaintext-ref.html
new file mode 100644
index 0000000000..8ded86a57f
--- /dev/null
+++ b/layout/reftests/bidi/unicode-bidi-plaintext-ref.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+</head>
+<body>
+<div>
+!hello.<br>
+<span dir=rtl>
+!שלום.
+</span><br>
+<span dir=ltr>
+hello, לוי!
+</span><br>
+<span dir=rtl>
+שלום, WebKit!</span><br>
+<pre>
+a
+(
+!WebKit ,שלום
+hello, לוי!
+)
+</pre>
+</div>
+</body>
+</html>
diff --git a/layout/reftests/bidi/unicode-bidi-plaintext-textarea-1.html b/layout/reftests/bidi/unicode-bidi-plaintext-textarea-1.html
new file mode 100644
index 0000000000..aec6d38df0
--- /dev/null
+++ b/layout/reftests/bidi/unicode-bidi-plaintext-textarea-1.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html><head>
+<title>unicode-bidi:plaintext</title>
+<style>
+ textarea { text-align: left; resize: none; }
+</style>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+</head><body>
+<div>
+The exclamation mark should be on the left side of the first line
+and on the right side of the second line.
+</div>
+<textarea rows=4 cols=50 dir=auto>
+שלום!
+hello!
+</textarea>
+</body></html>
diff --git a/layout/reftests/bidi/unicode-bidi-plaintext-textarea-2.html b/layout/reftests/bidi/unicode-bidi-plaintext-textarea-2.html
new file mode 100644
index 0000000000..aae0f4ffee
--- /dev/null
+++ b/layout/reftests/bidi/unicode-bidi-plaintext-textarea-2.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html><head>
+<title>unicode-bidi:plaintext</title>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<style>
+ .plaintext {
+ unicode-bidi:plaintext;
+ }
+ textarea { text-align: left; resize: none; }
+</style>
+</head><body>
+<div>
+The exclamation mark should be on the left side of the first line
+and on the right side of the second line.
+</div>
+<textarea rows=4 cols=50 class="plaintext">
+שלום!
+hello!
+</textarea>
+</body></html>
diff --git a/layout/reftests/bidi/unicode-bidi-plaintext-textarea-3.html b/layout/reftests/bidi/unicode-bidi-plaintext-textarea-3.html
new file mode 100644
index 0000000000..89ea8a1059
--- /dev/null
+++ b/layout/reftests/bidi/unicode-bidi-plaintext-textarea-3.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html><head>
+<title>unicode-bidi:plaintext</title>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<style>
+ .plaintext {
+ unicode-bidi:plaintext;
+ }
+ textarea { text-align: left; resize: none; }
+</style>
+</head><body>
+<div>
+The exclamation mark should be on the left side of the first line
+and on the right side of the second line.
+</div>
+<textarea rows=4 cols=50 dir="ltr" class="plaintext">
+שלום!
+hello!
+</textarea>
+</body></html>
diff --git a/layout/reftests/bidi/unicode-bidi-plaintext-textarea-4.html b/layout/reftests/bidi/unicode-bidi-plaintext-textarea-4.html
new file mode 100644
index 0000000000..b9cc612890
--- /dev/null
+++ b/layout/reftests/bidi/unicode-bidi-plaintext-textarea-4.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html><head>
+<title>unicode-bidi:plaintext</title>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<style>
+ .plaintext {
+ unicode-bidi:plaintext;
+ }
+ textarea { text-align: left; resize: none; }
+</style>
+</head><body>
+<div>
+The exclamation mark should be on the left side of the first line
+and on the right side of the second line.
+</div>
+<textarea rows=4 cols=50 dir="rtl" class="plaintext">
+שלום!
+hello!
+</textarea>
+</body></html>
diff --git a/layout/reftests/bidi/unicode-bidi-plaintext-textarea-ref.html b/layout/reftests/bidi/unicode-bidi-plaintext-textarea-ref.html
new file mode 100644
index 0000000000..1e89c81909
--- /dev/null
+++ b/layout/reftests/bidi/unicode-bidi-plaintext-textarea-ref.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>unicode-bidi:plaintext</title>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<style>
+ textarea { resize: none; }
+</style>
+</head>
+<body>
+<div>
+The exclamation mark should be on the left side of the first line
+and on the right side of the second line.
+</div>
+<textarea rows=4 cols=50 dir=ltr>
+&#x202b;שלום!&#x202c;
+&#x202a;hello!&#x202c
+</textarea>
+</body></html>
diff --git a/layout/reftests/bidi/unicode-bidi-plaintext.html b/layout/reftests/bidi/unicode-bidi-plaintext.html
new file mode 100644
index 0000000000..2c8d19781a
--- /dev/null
+++ b/layout/reftests/bidi/unicode-bidi-plaintext.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<style>
+div, pre { text-align: left; }
+</style>
+</head>
+<body>
+<div style="unicode-bidi: plaintext;">
+!hello.
+<br>
+!שלום.
+<br>
+hello, לוי!
+<br>
+שלום, WebKit!
+</div>
+<pre dir="auto">
+a
+(
+שלום, WebKit!
+hello, לוי!
+)
+</pre>
+</body>
+</html>
diff --git a/layout/reftests/bidi/visualmarquee.html b/layout/reftests/bidi/visualmarquee.html
new file mode 100644
index 0000000000..932fd775a1
--- /dev/null
+++ b/layout/reftests/bidi/visualmarquee.html
@@ -0,0 +1,11 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+ <head>
+ <meta http-equiv="Content-type" content="text/html; charset=iso-8859-8">
+ <title>Marquee in Visual Hebrew</title>
+ </head>
+
+ <body>
+ <marquee scrollamount="0" behavior="alternate" direction="right">&#x05DD;&#x05D9;&#x05DC;&#x05D9;&#x05DC;&#x05E6;&#x05D4; &#x05D5;&#x05E1;&#x05E0;&#x05D5; &#x05DD;&#x05D5;&#x05D9;&#x05D4; &#x05D7;&#x05D5;&#x05E4;&#x05D9;&#x05E9; &#x05D3;&#x05E2;</marquee>
+ </body>
+</html>
diff --git a/layout/reftests/bidi/with-first-letter-1-ref.html b/layout/reftests/bidi/with-first-letter-1-ref.html
new file mode 100644
index 0000000000..b476685ce7
--- /dev/null
+++ b/layout/reftests/bidi/with-first-letter-1-ref.html
@@ -0,0 +1,19 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<title>Test for bidi splitting and :first-letter</title>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<meta http-equiv="Content-Style-Type" content="text/css">
+<style type="text/css">
+
+p { unicode-bidi: bidi-override; }
+body { font-size: 300%; }
+
+</style>
+</head>
+<body>
+
+<p><span style="background: aqua">T</span>his has AB<span style="background:yellow">CD</span>תש<span style="background:yellow">בא</span></p>
+
+</body>
+</html>
diff --git a/layout/reftests/bidi/with-first-letter-1a.html b/layout/reftests/bidi/with-first-letter-1a.html
new file mode 100644
index 0000000000..5724bf969e
--- /dev/null
+++ b/layout/reftests/bidi/with-first-letter-1a.html
@@ -0,0 +1,19 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<title>Test for bidi splitting and :first-letter</title>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<meta http-equiv="Content-Style-Type" content="text/css">
+<style type="text/css">
+
+p:first-letter { background: aqua; }
+body { font-size: 300%; }
+
+</style>
+</head>
+<body>
+
+<p>This has AB<span style="background:yellow">CDאב</span>שת</p>
+
+</body>
+</html>
diff --git a/layout/reftests/bidi/with-first-letter-1b.html b/layout/reftests/bidi/with-first-letter-1b.html
new file mode 100644
index 0000000000..4f1266f43f
--- /dev/null
+++ b/layout/reftests/bidi/with-first-letter-1b.html
@@ -0,0 +1,19 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<title>Test for bidi splitting and :first-letter</title>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<meta http-equiv="Content-Style-Type" content="text/css">
+<style type="text/css">
+
+p:first-letter { background: aqua; }
+body { font-size: 300%; }
+
+</style>
+</head>
+<body>
+
+<p><span><span>This has AB<span style="background:yellow">CDאב</span>שת</span></span></p>
+
+</body>
+</html>
diff --git a/layout/reftests/bidi/with-first-letter-2-ref.html b/layout/reftests/bidi/with-first-letter-2-ref.html
new file mode 100644
index 0000000000..4338fc3ccd
--- /dev/null
+++ b/layout/reftests/bidi/with-first-letter-2-ref.html
@@ -0,0 +1,20 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<title>Test for bidi splitting and :first-letter</title>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<meta http-equiv="Content-Style-Type" content="text/css">
+<style type="text/css">
+
+p { unicode-bidi: bidi-override; }
+p:first-letter { float:left; font-size: 2em; }
+body { font-size: 300%; }
+
+</style>
+</head>
+<body>
+
+<p>This has AB<span style="background:yellow">CD</span>תש<span style="background:yellow">בא</span></p>
+
+</body>
+</html>
diff --git a/layout/reftests/bidi/with-first-letter-2a.html b/layout/reftests/bidi/with-first-letter-2a.html
new file mode 100644
index 0000000000..8aa415c6c0
--- /dev/null
+++ b/layout/reftests/bidi/with-first-letter-2a.html
@@ -0,0 +1,19 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<title>Test for bidi splitting and :first-letter</title>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<meta http-equiv="Content-Style-Type" content="text/css">
+<style type="text/css">
+
+p:first-letter { float:left; font-size: 2em; }
+body { font-size: 300%; }
+
+</style>
+</head>
+<body>
+
+<p>This has AB<span style="background:yellow">CDאב</span>שת</p>
+
+</body>
+</html>
diff --git a/layout/reftests/bidi/with-first-letter-2b.html b/layout/reftests/bidi/with-first-letter-2b.html
new file mode 100644
index 0000000000..cb80bd6d5f
--- /dev/null
+++ b/layout/reftests/bidi/with-first-letter-2b.html
@@ -0,0 +1,19 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<title>Test for bidi splitting and :first-letter</title>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<meta http-equiv="Content-Style-Type" content="text/css">
+<style type="text/css">
+
+p:first-letter { float:left; font-size: 2em; }
+body { font-size: 300%; }
+
+</style>
+</head>
+<body>
+
+<p><span><span>This has AB<span style="background:yellow">CDאב</span>שת</span></span></p>
+
+</body>
+</html>