dom/browser-element/mochitest/browserElement_SecurityChange.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/browser-element/mochitest/browserElement_SecurityChange.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,49 @@
     1.4 +/* Any copyright is dedicated to the public domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +// Bug 763694 - Test that <iframe mozbrowser> delivers proper
     1.8 +// mozbrowsersecuritychange events.
     1.9 +
    1.10 +"use strict";
    1.11 +SimpleTest.waitForExplicitFinish();
    1.12 +browserElementTestHelpers.setEnabledPref(true);
    1.13 +browserElementTestHelpers.addPermission();
    1.14 +
    1.15 +function runTest() {
    1.16 +  var iframe = document.createElement('iframe');
    1.17 +  SpecialPowers.wrap(iframe).mozbrowser = true;
    1.18 +
    1.19 +  var lastSecurityState;
    1.20 +  iframe.addEventListener('mozbrowsersecuritychange', function(e) {
    1.21 +    lastSecurityState = e.detail;
    1.22 +  });
    1.23 +
    1.24 +  var filepath = 'tests/dom/browser-element/mochitest/file_browserElement_SecurityChange.html';
    1.25 +
    1.26 +  var count = 0;
    1.27 +  iframe.addEventListener('mozbrowserloadend', function(e) {
    1.28 +    count++;
    1.29 +    var nextURL;
    1.30 +    switch (count) {
    1.31 +    case 1:
    1.32 +      is(lastSecurityState.state, 'secure');
    1.33 +      is(lastSecurityState.extendedValidation, false);
    1.34 +      iframe.src = "http://example.com/" + filepath;
    1.35 +      break;
    1.36 +    case 2:
    1.37 +      is(lastSecurityState.state, 'insecure');
    1.38 +      is(lastSecurityState.extendedValidation, false);
    1.39 +      iframe.src = 'https://example.com:443/' + filepath + '?broken';
    1.40 +      break;
    1.41 +    case 3:
    1.42 +      is(lastSecurityState.state, 'broken');
    1.43 +      is(lastSecurityState.extendedValidation, false);
    1.44 +      SimpleTest.finish();
    1.45 +    }
    1.46 +  });
    1.47 +
    1.48 +  iframe.src = "https://example.com/" + filepath;
    1.49 +  document.body.appendChild(iframe);
    1.50 +}
    1.51 +
    1.52 +addEventListener('testready', runTest);

mercurial