summaryrefslogtreecommitdiffstats
path: root/dom/browser-element/mochitest/browserElement_Reload.js
blob: 9ef6d8e7e56ecadeb9a1c2e177fbc65c4d0cb0cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* Any copyright is dedicated to the public domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

// Bug 741717 - Test the reload ability of <iframe mozbrowser>.

"use strict";
SimpleTest.waitForExplicitFinish();
browserElementTestHelpers.setEnabledPref(true);
browserElementTestHelpers.addPermission();

var iframeScript = function() {
  sendAsyncMessage('test:innerHTML', {
    data: XPCNativeWrapper.unwrap(content).document.body.innerHTML
  });
}

var mm;
var iframe;
var loadedEvents = 0;
var countAcc;

function runTest() {
  iframe = document.createElement('iframe');
  iframe.setAttribute('mozbrowser', 'true');

  iframe.addEventListener('mozbrowserloadend', mozbrowserLoaded);

  iframe.src = 'file_bug741717.sjs';
  document.body.appendChild(iframe);
}

function iframeBodyRecv(data) {
  data = SpecialPowers.wrap(data);
  var previousCount = countAcc;
  var currentCount = parseInt(data.json.data, 10);
  countAcc = currentCount;
  switch (loadedEvents) {
  case 1:
    iframe.reload();
    break;
  case 2:
    ok(true, 'reload was triggered');
    ok(previousCount === currentCount, 'reload was a soft reload');
    iframe.reload(true);
    break;
  case 3:
    ok(currentCount > previousCount, 'reload was a hard reload');
    SimpleTest.finish();
  }
}

function mozbrowserLoaded() {
  loadedEvents++;
  mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
  mm.addMessageListener('test:innerHTML', iframeBodyRecv);
  mm.loadFrameScript('data:,(' + iframeScript.toString() + ')();', false);
}

addEventListener('testready', runTest);