dom/browser-element/mochitest/browserElement_Reload.js

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 /* Any copyright is dedicated to the public domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 // Bug 741717 - Test the reload ability of <iframe mozbrowser>.
michael@0 5
michael@0 6 "use strict";
michael@0 7 SimpleTest.waitForExplicitFinish();
michael@0 8 browserElementTestHelpers.setEnabledPref(true);
michael@0 9 browserElementTestHelpers.addPermission();
michael@0 10
michael@0 11 var iframeScript = function() {
michael@0 12 sendAsyncMessage('test:innerHTML', {
michael@0 13 data: XPCNativeWrapper.unwrap(content).document.body.innerHTML
michael@0 14 });
michael@0 15 }
michael@0 16
michael@0 17 var mm;
michael@0 18 var iframe;
michael@0 19 var loadedEvents = 0;
michael@0 20 var countAcc;
michael@0 21
michael@0 22 function runTest() {
michael@0 23 iframe = document.createElement('iframe');
michael@0 24 SpecialPowers.wrap(iframe).mozbrowser = true;
michael@0 25
michael@0 26 iframe.addEventListener('mozbrowserloadend', mozbrowserLoaded);
michael@0 27
michael@0 28 iframe.src = 'file_bug741717.sjs';
michael@0 29 document.body.appendChild(iframe);
michael@0 30 }
michael@0 31
michael@0 32 function iframeBodyRecv(data) {
michael@0 33 data = SpecialPowers.wrap(data);
michael@0 34 var previousCount = countAcc;
michael@0 35 var currentCount = parseInt(data.json.data, 10);
michael@0 36 countAcc = currentCount;
michael@0 37 switch (loadedEvents) {
michael@0 38 case 1:
michael@0 39 iframe.reload();
michael@0 40 break;
michael@0 41 case 2:
michael@0 42 ok(true, 'reload was triggered');
michael@0 43 ok(previousCount === currentCount, 'reload was a soft reload');
michael@0 44 iframe.reload(true);
michael@0 45 break;
michael@0 46 case 3:
michael@0 47 ok(currentCount > previousCount, 'reload was a hard reload');
michael@0 48 SimpleTest.finish();
michael@0 49 }
michael@0 50 }
michael@0 51
michael@0 52 function mozbrowserLoaded() {
michael@0 53 loadedEvents++;
michael@0 54 mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
michael@0 55 mm.addMessageListener('test:innerHTML', iframeBodyRecv);
michael@0 56 mm.loadFrameScript('data:,(' + iframeScript.toString() + ')();', false);
michael@0 57 }
michael@0 58
michael@0 59 addEventListener('testready', runTest);

mercurial