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

// Bug 795317: Test that the browser element sanitizes its URIs by removing the
// "unexposable" parts before sending them in the locationchange event.

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

var iframe;

function testPassword() {
  function locationchange(e) {
    var uri = e.detail.url;
    is(uri, 'http://mochi.test:8888/tests/dom/browser-element/mochitest/file_empty.html',
       "Username and password shouldn't be exposed in uri.");
    SimpleTest.finish();
  }

  iframe.addEventListener('mozbrowserlocationchange', locationchange);
  iframe.src = "http://iamuser:iampassword@mochi.test:8888/tests/dom/browser-element/mochitest/file_empty.html";
}

function testWyciwyg() {
  var locationChangeCount = 0;

  function locationchange(e) {
    // locationChangeCount:
    //  0 - the first load.
    //  1 - after document.write().
    if (locationChangeCount == 0) {
      locationChangeCount ++;
    } else if (locationChangeCount == 1) {
      var uri = e.detail.url;
      is(uri, 'http://mochi.test:8888/tests/dom/browser-element/mochitest/file_wyciwyg.html', "Scheme in string shouldn't be wyciwyg");
      iframe.removeEventListener('mozbrowserlocationchange', locationchange);
      SimpleTest.executeSoon(testPassword);
    }
  }

  // file_wyciwyg.html calls document.write() to create a wyciwyg channel.
  iframe.src = 'file_wyciwyg.html';
  iframe.addEventListener('mozbrowserlocationchange', locationchange);
}

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

addEventListener('testready', runTest);