test_app_principal_equality.html 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=777467
  5. -->
  6. <head>
  7. <meta charset="utf-8">
  8. <title>Test app principal's equality</title>
  9. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  10. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  11. </head>
  12. <body>
  13. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=777467">Mozilla Bug 777467</a>
  14. <p id="display"></p>
  15. <script>
  16. /** Test for app principal's equality **/
  17. SimpleTest.waitForExplicitFinish();
  18. var permissions = new Promise(resolve => {
  19. SpecialPowers.pushPermissions(
  20. [{ type: "browser", allow: true, context: document },
  21. { type: "embed-apps", allow: true, context: document }],
  22. resolve);
  23. });
  24. permissions.then(() => {
  25. $('content').innerHTML =
  26. '<iframe src="error404"></iframe>\n' +
  27. '<iframe mozbrowser src="error404"></iframe>\n' +
  28. '<iframe mozapp="http://example.org/manifest.webapp" mozbrowser src="error404"></iframe>';
  29. var iframes = document.getElementsByTagName("iframe");
  30. var promises = []
  31. for (var i = 0; i < promises.length; ++i) {
  32. promises.push(new Promise(resolve => {
  33. iframes[i].addEventListener("load", resolve);
  34. }));
  35. }
  36. return Promise.all(promises);
  37. });
  38. var prefs = new Promise(resolve => {
  39. SpecialPowers.pushPrefEnv(
  40. { set: [[ "dom.mozBrowserFramesEnabled", true ],
  41. [ "dom.ipc.browser_frames.oop_by_default", false ]] },
  42. resolve);
  43. });
  44. </script>
  45. <div id="content" style="display: none;">
  46. </div>
  47. <pre id="test">
  48. <script type="application/javascript">
  49. function canAccessDocument(win) {
  50. var result = true;
  51. try {
  52. win.document;
  53. } catch(e) {
  54. result = false;
  55. }
  56. return result;
  57. }
  58. var loaded = new Promise(resolve => addLoadEvent(resolve));
  59. Promise.all([ permissions, prefs, loaded ]).then(runTest);
  60. function runTest() {
  61. // Test the witness frame (we can access same-origin frame).
  62. is(canAccessDocument(frames[0]), true,
  63. "should be able to access the first frame");
  64. // Test different app/browserElement frames.
  65. for (var i=1; i<frames.length; ++i) {
  66. is(canAccessDocument(frames[i]), false,
  67. "should not be able to access the other frames");
  68. }
  69. SimpleTest.finish();
  70. }
  71. </script>
  72. </pre>
  73. </body>
  74. </html>