dom/browser-element/mochitest/browserElement_LoadEvents.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the public domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 // Test that an iframe with the |mozbrowser| attribute emits mozbrowserloadX
     5 // events when this page is in the whitelist.
     7 "use strict";
     8 SimpleTest.waitForExplicitFinish();
     9 browserElementTestHelpers.setEnabledPref(true);
    10 browserElementTestHelpers.addPermission();
    12 function runTest() {
    13   // Load emptypage1 into the iframe, wait for that to finish loading, then
    14   // call runTest2.
    15   //
    16   // This should trigger loadstart, locationchange, and loadend events.
    18   var seenLoadEnd = false;
    19   var seenLoadStart = false;
    20   var seenLocationChange = false;
    22   var iframe = document.createElement('iframe');
    23   SpecialPowers.wrap(iframe).mozbrowser = true;
    24   iframe.id = 'iframe';
    25   iframe.src = 'http://example.com/tests/dom/browser-element/mochitest/file_browserElement_LoadEvents.html';
    27   function loadstart(e) {
    28     ok(e.isTrusted, 'Event should be trusted.');
    29     ok(!seenLoadEnd, 'loadstart before loadend.');
    30     ok(!seenLoadStart, 'Just one loadstart event.');
    31     ok(!seenLocationChange, 'loadstart before locationchange.');
    32     seenLoadStart = true;
    33   }
    35   function locationchange(e) {
    36     ok(e.isTrusted, 'Event should be trusted.');
    37     ok(!seenLocationChange, 'Just one locationchange event.');
    38     seenLocationChange = true;
    39     ok(seenLoadStart, 'Location change after load start.');
    40     ok(!seenLoadEnd, 'Location change before load end.');
    41     ok(e.detail, browserElementTestHelpers.emptyPage1, "event's reported location");
    42   }
    44   function loadend(e) {
    45     ok(e.isTrusted, 'Event should be trusted.');
    46     ok(seenLoadStart, 'loadend after loadstart.');
    47     ok(!seenLoadEnd, 'Just one loadend event.');
    48     ok(seenLocationChange, 'loadend after locationchange.');
    49     is(e.detail.backgroundColor, 'rgb(0, 128, 0)', 'Expected background color reported')
    50     seenLoadEnd = true;
    51   }
    53   iframe.addEventListener('mozbrowserloadstart', loadstart);
    54   iframe.addEventListener('mozbrowserlocationchange', locationchange);
    55   iframe.addEventListener('mozbrowserloadend', loadend);
    57   function waitForAllCallbacks() {
    58     if (!seenLoadStart || !seenLoadEnd) {
    59       SimpleTest.executeSoon(waitForAllCallbacks);
    60       return;
    61     }
    63     iframe.removeEventListener('mozbrowserloadstart', loadstart);
    64     iframe.removeEventListener('mozbrowserlocationchange', locationchange);
    65     iframe.removeEventListener('mozbrowserloadend', loadend);
    66     runTest2();
    67   }
    69   document.body.appendChild(iframe);
    70   waitForAllCallbacks();
    71 }
    73 function runTest2() {
    74   var seenLoadStart = false;
    75   var seenLoadEnd = false;
    76   var seenLocationChange = false;
    78   // Add this event listener to the document; the events should bubble.
    79   document.addEventListener('mozbrowserloadstart', function(e) {
    80     ok(e.isTrusted, 'Event should be trusted.');
    81     ok(!seenLoadStart, 'Just one loadstart event.');
    82     seenLoadStart = true;
    83     ok(!seenLoadEnd, 'Got mozbrowserloadstart before loadend.');
    84     ok(!seenLocationChange, 'Got mozbrowserloadstart before locationchange.');
    85   });
    87   var iframe = document.getElementById('iframe');
    88   iframe.addEventListener('mozbrowserlocationchange', function(e) {
    89     ok(e.isTrusted, 'Event should be trusted.');
    90     ok(!seenLocationChange, 'Just one locationchange event.');
    91     seenLocationChange = true;
    92     ok(seenLoadStart, 'Location change after load start.');
    93     ok(!seenLoadEnd, 'Location change before load end.');
    94     ok(e.detail, browserElementTestHelpers.emptyPage2, "event's reported location");
    95   });
    97   iframe.addEventListener('mozbrowserloadend', function(e) {
    98     ok(e.isTrusted, 'Event should be trusted.');
    99     ok(!seenLoadEnd, 'Just one load end event.');
   100     seenLoadEnd = true;
   101     ok(seenLoadStart, 'Load end after load start.');
   102     ok(seenLocationChange, 'Load end after location change.');
   103     is(e.detail.backgroundColor, 'transparent', 'Expected background color reported')
   104   });
   106   iframe.src = browserElementTestHelpers.emptyPage2;
   108   function waitForAllCallbacks() {
   109     if (!seenLoadStart || !seenLoadEnd || !seenLocationChange) {
   110       SimpleTest.executeSoon(waitForAllCallbacks);
   111       return;
   112     }
   114     SimpleTest.finish();
   115   }
   117   waitForAllCallbacks();
   118 }
   120 addEventListener('testready', runTest);

mercurial