file_crossOriginObjects_documentDomain.html 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script>
  5. function loadFrames() {
  6. window.A = document.getElementById('A').contentWindow;
  7. window.B = document.getElementById('B').contentWindow;
  8. window.C = document.getElementById('C').contentWindow;
  9. window.D = document.getElementById('D').contentWindow;
  10. var path = location.pathname.substring(0, location.pathname.lastIndexOf('/')) + '/file_crossOriginObjects.html';
  11. A.location = 'file_crossOriginObjects.html';
  12. B.location = frameURI = 'http://test2.mochi.test:' + location.port + path;
  13. C.location = frameURI = 'http://test1.mochi.test:' + location.port + path;
  14. D.location = frameURI = 'http://test1.mochi.test:' + location.port + path;
  15. var loadCount = 0;
  16. function frameLoaded() {
  17. if (++loadCount == 4)
  18. go();
  19. }
  20. Array.forEach(document.getElementsByTagName('iframe'), function(ifr) { ifr.onload = frameLoaded; });
  21. }
  22. var results = [];
  23. function assert(cond, msg) {
  24. results.push({pass: !!cond, message: msg});
  25. }
  26. function go() {
  27. window.onmessage = function() {
  28. assert(B.checkWindowReferences(), "B's Window references are still self-consistent after document.domain");
  29. for (var i = 0; i < window.length; ++i) {
  30. assert(window[i] === B.windowReferences[i],
  31. "Window reference " + i + " consistent between globals after document.domain");
  32. assert(window[i].location === B.locationReferences[i],
  33. "Location reference " + i + " consistent between globals after document.domain");
  34. }
  35. opener.postMessage(results, '*');
  36. };
  37. A.document.domain = A.document.domain;
  38. document.domain = document.domain;
  39. B.postMessage('', '*');
  40. }
  41. </script>
  42. </head>
  43. <body onload="loadFrames()">
  44. <iframe id="A"></iframe>
  45. <iframe id="B"></iframe>
  46. <iframe id="C"></iframe>
  47. <iframe id="D"></iframe>
  48. </body>
  49. </html>