dom/browser-element/mochitest/browserElement_BrowserWindowNamespace.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/browser-element/mochitest/browserElement_BrowserWindowNamespace.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,53 @@
     1.4 +/* Any copyright is dedicated to the public domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +// Bug 780351 - Test that mozbrowser does /not/ divide the window name namespace.
     1.8 +// Multiple mozbrowsers inside the same app are like multiple browser tabs;
     1.9 +// they share a window name namespace.
    1.10 +
    1.11 +"use strict";
    1.12 +
    1.13 +SimpleTest.waitForExplicitFinish();
    1.14 +browserElementTestHelpers.setEnabledPref(true);
    1.15 +browserElementTestHelpers.addPermission();
    1.16 +
    1.17 +function runTest() {
    1.18 +  var iframe1 = document.createElement('iframe');
    1.19 +  SpecialPowers.wrap(iframe1).mozbrowser = true;
    1.20 +
    1.21 +  // Two mozbrowser frames with the same code both do the same
    1.22 +  // window.open("foo", "bar") call.  We should only get one
    1.23 +  // mozbrowseropenwindow event.
    1.24 +
    1.25 +  iframe1.addEventListener('mozbrowseropenwindow', function(e) {
    1.26 +    ok(true, "Got first mozbrowseropenwindow event.");
    1.27 +    document.body.appendChild(e.detail.frameElement);
    1.28 +
    1.29 +    e.detail.frameElement.addEventListener('mozbrowserlocationchange', function(e) {
    1.30 +      if (e.detail == "http://example.com/#2") {
    1.31 +        ok(true, "Got locationchange to http://example.com/#2");
    1.32 +        SimpleTest.finish();
    1.33 +      }
    1.34 +      else {
    1.35 +        ok(true, "Got locationchange to " + e.detail);
    1.36 +      }
    1.37 +    });
    1.38 +
    1.39 +    SimpleTest.executeSoon(function() {
    1.40 +      var iframe2 = document.createElement('iframe');
    1.41 +      SpecialPowers.wrap(iframe2).mozbrowser = true;
    1.42 +
    1.43 +      iframe2.addEventListener('mozbrowseropenwindow', function(e) {
    1.44 +        ok(false, "Got second mozbrowseropenwindow event.");
    1.45 +      });
    1.46 +
    1.47 +      document.body.appendChild(iframe2);
    1.48 +      iframe2.src = 'file_browserElement_BrowserWindowNamespace.html#2';
    1.49 +    });
    1.50 +  });
    1.51 +
    1.52 +  document.body.appendChild(iframe1);
    1.53 +  iframe1.src = 'file_browserElement_BrowserWindowNamespace.html#1';
    1.54 +}
    1.55 +
    1.56 +addEventListener('testready', runTest);

mercurial