test_bug292789.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=292789
  5. -->
  6. <head>
  7. <title>Test for Bug 292789</title>
  8. <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  9. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  10. </head>
  11. <body>
  12. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=292789">Mozilla Bug 292789</a>
  13. <p id="display"></p>
  14. <div id="content" style="display: none">
  15. <script src="chrome://global/content/treeUtils.js"></script>
  16. <script type="application/javascript;version=1.8" src="chrome://mozapps/content/xpinstall/xpinstallConfirm.js"></script>
  17. <script id="resjs" type="application/javascript;version=1.8"></script>
  18. </div>
  19. <pre id="test">
  20. <script class="testbody" type="text/javascript">
  21. /** Test for Bug 292789
  22. **
  23. ** Selectively allow access to whitelisted chrome packages
  24. ** even for ALLOW_CHROME mechanisms (<script>, <img> etc)
  25. **/
  26. SimpleTest.waitForExplicitFinish();
  27. /** <script src=""> test **/
  28. function testScriptSrc(aCallback) {
  29. is(typeof gTreeUtils.sort, "function",
  30. "content can still load <script> from chrome://global");
  31. is(typeof XPInstallConfirm, "undefined",
  32. "content should not be able to load <script> from chrome://mozapps");
  33. /** make sure the last one didn't pass because someone
  34. ** moved the resource
  35. **/
  36. var resjs = document.getElementById("resjs");
  37. resjs.onload = scriptOnload;
  38. resjs.src = "resource://gre/chrome/toolkit/content/mozapps/xpinstall/xpinstallConfirm.js";
  39. document.getElementById("content").appendChild(resjs);
  40. function scriptOnload() {
  41. is(typeof XPInstallConfirm, "object",
  42. "xpinstallConfirm.js has not moved unexpectedly");
  43. // trigger the callback
  44. if (aCallback)
  45. aCallback();
  46. }
  47. }
  48. /** <img src=""> tests **/
  49. var img_global = "chrome://global/skin/icons/Error.png";
  50. var img_mozapps = "chrome://mozapps/skin/plugins/contentPluginClose.png";
  51. var res_mozapps = "resource://gre/chrome/toolkit/skin/classic/mozapps/plugins/contentPluginClose.png";
  52. var imgTests = [[img_global, "success"],
  53. [img_mozapps, "fail"],
  54. [res_mozapps, "success"]];
  55. var curImgTest = 0;
  56. function runImgTest() {
  57. var test = imgTests[curImgTest++];
  58. var callback = curImgTest == imgTests.length ? finishTest : runImgTest;
  59. loadImage(test[0], test[1], callback);
  60. }
  61. function finishTest() {
  62. SimpleTest.finish();
  63. }
  64. function fail(event) {
  65. is("fail", event.target.expected,
  66. "content should not be allowed to load "+event.target.src);
  67. if (event.target.callback)
  68. event.target.callback();
  69. }
  70. function success(event) {
  71. is("success", event.target.expected,
  72. "content should be able to load "+event.target.src);
  73. if (event.target.callback)
  74. event.target.callback();
  75. }
  76. function loadImage(uri, expect, callback) {
  77. var img = document.createElement("img");
  78. img.onerror = fail;
  79. img.onload = success;
  80. img.expected = expect;
  81. img.callback = callback;
  82. img.src = uri;
  83. //document.getElementById("content").appendChild(img);
  84. }
  85. // Start off the script src test, and have it start the img tests when complete.
  86. testScriptSrc(runImgTest);
  87. </script>
  88. </pre>
  89. </body>
  90. </html>