/toolkit/content/tests/chrome/test_righttoleft.xul

http://github.com/zpao/v8monkey · Unknown · 126 lines · 103 code · 23 blank · 0 comment · 0 complexity · 1b9404a116b9f4e1bcee80a8d27999bb MD5 · raw file

  1. <?xml version="1.0"?>
  2. <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
  3. <?xml-stylesheet
  4. href="chrome://mochikit/content/tests/SimpleTest/test.css"
  5. type="text/css"?>
  6. <window title="Right to Left UI Test"
  7. onload="runTest()"
  8. xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  9. <script type="application/javascript"
  10. src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  11. <script type="application/javascript"
  12. src="chrome://mochikit/content/chrome-harness.js"></script>
  13. <script type="application/javascript"
  14. src="RegisterUnregisterChrome.js"></script>
  15. <body xmlns="http://www.w3.org/1999/xhtml">
  16. <p id="display"></p>
  17. <div id="content" style="display: none">
  18. </div>
  19. <pre id="test">
  20. </pre>
  21. </body>
  22. <iframe id="subframe" width="100" height="100" onload="frameLoaded();"/>
  23. <script type="application/javascript">
  24. <![CDATA[
  25. SimpleTest.waitForExplicitFinish();
  26. let prefs = Cc["@mozilla.org/preferences-service;1"].
  27. getService(Ci.nsIPrefBranch);
  28. const UI_DIRECTION_PREF = "intl.uidirection.ar";
  29. prefs.setCharPref(UI_DIRECTION_PREF, "rtl");
  30. let rootDir = getRootDirectory(window.location.href);
  31. registerManifestPermanently(rootDir + "rtltest/righttoleft.manifest");
  32. function runTest()
  33. {
  34. var subframe = document.getElementById("subframe");
  35. subframe.setAttribute("src", "chrome://ltrtest/content/dirtest.xul");
  36. }
  37. function frameLoaded()
  38. {
  39. var subframe = document.getElementById("subframe");
  40. var subwin = subframe.contentWindow;
  41. var subdoc = subframe.contentDocument;
  42. var url = String(subwin.location);
  43. if (url.indexOf("chrome://ltrtest") == 0) {
  44. is(subwin.getComputedStyle(subdoc.getElementById("hbox"), "").backgroundColor,
  45. "rgb(255, 255, 0)", "left to right with :-moz-locale-dir(ltr)");
  46. is(subwin.getComputedStyle(subdoc.getElementById("vbox"), "").backgroundColor,
  47. "rgb(255, 255, 255)", "left to right with :-moz-locale-dir(rtl)");
  48. is(subwin.getComputedStyle(subdoc.documentElement, "").direction, "ltr",
  49. "left to right direction");
  50. subdoc.documentElement.setAttribute("localedir", "rtl");
  51. is(subwin.getComputedStyle(subdoc.getElementById("hbox"), "").backgroundColor,
  52. "rgb(255, 255, 255)", "left to right with :-moz-locale-dir(ltr) and localedir='rtl'");
  53. is(subwin.getComputedStyle(subdoc.getElementById("vbox"), "").backgroundColor,
  54. "rgb(0, 128, 0)", "left to right with :-moz-locale-dir(rtl) and localedir='rtl'");
  55. is(subwin.getComputedStyle(subdoc.documentElement, "").direction, "rtl",
  56. "left to right direction with localedir='rtl'");
  57. subdoc.documentElement.removeAttribute("localedir");
  58. is(subwin.getComputedStyle(subdoc.getElementById("hbox"), "").backgroundColor,
  59. "rgb(255, 255, 0)", "left to right with :-moz-locale-dir(ltr) and localedir removed");
  60. is(subwin.getComputedStyle(subdoc.getElementById("vbox"), "").backgroundColor,
  61. "rgb(255, 255, 255)", "left to right with :-moz-locale-dir(rtl) and localedir removed");
  62. is(subwin.getComputedStyle(subdoc.documentElement, "").direction, "ltr",
  63. "left to right direction with localedir removed");
  64. subframe.setAttribute("src", "chrome://rtltest/content/dirtest.xul");
  65. }
  66. else if (url.indexOf("chrome://rtltest") == 0) {
  67. is(subwin.getComputedStyle(subdoc.getElementById("hbox"), "").backgroundColor,
  68. "rgb(255, 255, 255)", "right to left with :-moz-locale-dir(ltr)");
  69. is(subwin.getComputedStyle(subdoc.getElementById("vbox"), "").backgroundColor,
  70. "rgb(0, 128, 0)", "right to left with :-moz-locale-dir(rtl)");
  71. is(subwin.getComputedStyle(subdoc.documentElement, "").direction, "rtl",
  72. "right to left direction");
  73. subdoc.documentElement.setAttribute("localedir", "ltr");
  74. is(subwin.getComputedStyle(subdoc.getElementById("hbox"), "").backgroundColor,
  75. "rgb(255, 255, 0)", "right to left with :-moz-locale-dir(ltr) and localedir='ltr'");
  76. is(subwin.getComputedStyle(subdoc.getElementById("vbox"), "").backgroundColor,
  77. "rgb(255, 255, 255)", "right to left with :-moz-locale-dir(rtl) and localedir='ltr'");
  78. is(subwin.getComputedStyle(subdoc.documentElement, "").direction, "ltr",
  79. "right to left direction with localedir='ltr'");
  80. subdoc.documentElement.removeAttribute("localedir");
  81. prefs.setCharPref(UI_DIRECTION_PREF, "");
  82. is(subwin.getComputedStyle(subdoc.documentElement, "").direction, "ltr",
  83. "left to right direction with no preference set");
  84. prefs.setCharPref(UI_DIRECTION_PREF + "-QA", "rtl");
  85. is(subwin.getComputedStyle(subdoc.documentElement, "").direction, "rtl",
  86. "right to left direction with more specific preference set");
  87. prefs.setCharPref(UI_DIRECTION_PREF, "ltr");
  88. is(subwin.getComputedStyle(subdoc.documentElement, "").direction, "rtl",
  89. "right to left direction with less specific and more specific preference set");
  90. prefs.setCharPref(UI_DIRECTION_PREF, "rtl");
  91. prefs.setCharPref(UI_DIRECTION_PREF + "-QA", "ltr");
  92. is(subwin.getComputedStyle(subdoc.documentElement, "").direction, "ltr",
  93. "left to right direction specific preference overrides");
  94. if (prefs.prefHasUserValue(UI_DIRECTION_PREF + "-QA"))
  95. prefs.clearUserPref(UI_DIRECTION_PREF + "-QA");
  96. if (prefs.prefHasUserValue(UI_DIRECTION_PREF))
  97. prefs.clearUserPref(UI_DIRECTION_PREF);
  98. SimpleTest.finish();
  99. }
  100. }
  101. ]]>
  102. </script>
  103. </window>