summaryrefslogtreecommitdiffstats
path: root/dom/browser-element/mochitest/browserElement_Stop.js
blob: 67720c148df9c6d5b945a9827fc7a0d987007a0a (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
/* Any copyright is dedicated to the public domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

// Bug 709759 - Test the stop ability of <iframe mozbrowser>.

// The img that is loaded will never be returned and will block
// the page from loading, the timeout ensures that the page is
// actually blocked from loading, once stop is called the
// image load will be cancaelled and mozbrowserloadend should be called.

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

var iframe;
var stopped = false;
var imgSrc = 'http://test/tests/dom/browser-element/mochitest/file_bug709759.sjs';

function runTest() {
  iframe = document.createElement('iframe');
  iframe.setAttribute('mozbrowser', 'true');
  // FIXME: Bug 1270790
  iframe.setAttribute('remote', 'true');
  iframe.addEventListener('mozbrowserloadend', loadend);
  iframe.src = 'data:text/html,<html>' +
    '<body><img src="' + imgSrc + '" /></body></html>';

  document.body.appendChild(iframe);

  setTimeout(function() {
    stopped = true;
    iframe.stop();
  }, 200);
}

function loadend() {
  ok(stopped, 'Iframes network connections were stopped');

  // Wait 1 second and make sure there isn't a mozbrowsererror after stop();
  iframe.addEventListener('mozbrowsererror', handleError);
  window.setTimeout(function() {
    iframe.removeEventListener('mozbrowsererror', handleError);
    SimpleTest.finish();
  }, 1000);
}

function handleError() {
  ok(false, "mozbrowsererror should not be fired");
}

addEventListener('testready', runTest);