dom/browser-element/mochitest/browserElement_DataURI.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/browser-element/mochitest/browserElement_DataURI.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,68 @@
     1.4 +/* Any copyright is dedicated to the public domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +// Test that data: URIs work with mozbrowserlocationchange events.
     1.8 +
     1.9 +"use strict";
    1.10 +SimpleTest.waitForExplicitFinish();
    1.11 +browserElementTestHelpers.setEnabledPref(true);
    1.12 +browserElementTestHelpers.addPermission();
    1.13 +
    1.14 +function runTest() {
    1.15 +  var iframe1 = document.createElement('iframe');
    1.16 +  SpecialPowers.wrap(iframe1).mozbrowser = true;
    1.17 +  iframe1.id = 'iframe1';
    1.18 +  iframe1.addEventListener('mozbrowserloadend', function if1_loadend() {
    1.19 +    iframe1.removeEventListener('mozbrowserloadend', if1_loadend);
    1.20 +    ok(true, 'Got first loadend event.');
    1.21 +    SimpleTest.executeSoon(runTest2);
    1.22 +  });
    1.23 +  iframe1.src = browserElementTestHelpers.emptyPage1;
    1.24 +  document.body.appendChild(iframe1);
    1.25 +
    1.26 +  var iframe2 = document.createElement('iframe');
    1.27 +  iframe2.id = 'iframe2';
    1.28 +  document.body.appendChild(iframe2);
    1.29 +}
    1.30 +
    1.31 +function runTest2() {
    1.32 +  var iframe1 = document.getElementById('iframe1');
    1.33 +  var iframe2 = document.getElementById('iframe2');
    1.34 +
    1.35 +  var sawLoadEnd = false;
    1.36 +  var sawLocationChange = false;
    1.37 +
    1.38 +  iframe1.addEventListener('mozbrowserlocationchange', function(e) {
    1.39 +    ok(e.isTrusted, 'Event should be trusted.');
    1.40 +    ok(!sawLocationChange, 'Just one locationchange event.');
    1.41 +    ok(!sawLoadEnd, 'locationchange before load.');
    1.42 +    is(e.detail, 'data:text/html,1', "event's reported location");
    1.43 +    sawLocationChange = true;
    1.44 +  });
    1.45 +
    1.46 +  iframe1.addEventListener('mozbrowserloadend', function() {
    1.47 +    ok(sawLocationChange, 'Loadend after locationchange.');
    1.48 +    ok(!sawLoadEnd, 'Just one loadend event.');
    1.49 +    sawLoadEnd = true;
    1.50 +  });
    1.51 +
    1.52 +  function iframe2Load() {
    1.53 +    if (!sawLoadEnd || !sawLocationChange) {
    1.54 +      // Spin if iframe1 hasn't loaded yet.
    1.55 +      SimpleTest.executeSoon(iframe2Load);
    1.56 +      return;
    1.57 +    }
    1.58 +    ok(true, 'Got iframe2 load.');
    1.59 +    SimpleTest.finish();
    1.60 +  }
    1.61 +  iframe2.addEventListener('load', iframe2Load);
    1.62 +
    1.63 +
    1.64 +  iframe1.src = 'data:text/html,1';
    1.65 +
    1.66 +  // Load something into iframe2 to check that it doesn't trigger a
    1.67 +  // locationchange for our iframe1 listener.
    1.68 +  iframe2.src = browserElementTestHelpers.emptyPage2;
    1.69 +}
    1.70 +
    1.71 +addEventListener('testready', runTest);

mercurial