dom/browser-element/mochitest/browserElement_ErrorSecurity.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/browser-element/mochitest/browserElement_ErrorSecurity.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,58 @@
     1.4 +/* Any copyright is dedicated to the public domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +// Bug 764718 - Test that mozbrowsererror works for a security error.
     1.8 +
     1.9 +"use strict";
    1.10 +
    1.11 +SimpleTest.waitForExplicitFinish();
    1.12 +browserElementTestHelpers.setEnabledPref(true);
    1.13 +browserElementTestHelpers.addPermission();
    1.14 +
    1.15 +var iframe = null;
    1.16 +function runTest() {
    1.17 +  iframe = document.createElement('iframe');
    1.18 +  SpecialPowers.wrap(iframe).mozbrowser = true;
    1.19 +  document.body.appendChild(iframe);
    1.20 +
    1.21 +  checkForGenericError();
    1.22 +}
    1.23 +
    1.24 +function checkForGenericError() {
    1.25 +  iframe.addEventListener("mozbrowsererror", function onGenericError(e) {
    1.26 +    iframe.removeEventListener(e.type, onGenericError);
    1.27 +    ok(true, "Got mozbrowsererror event.");
    1.28 +    ok(e.detail.type == "other", "Event's detail has a |type| param with the value '" + e.detail.type + "'.");
    1.29 +
    1.30 +    checkForExpiredCertificateError();
    1.31 +  });
    1.32 +
    1.33 +  iframe.src = "http://this_is_not_a_domain.example.com";
    1.34 +}
    1.35 +
    1.36 +function checkForExpiredCertificateError() {
    1.37 +  iframe.addEventListener("mozbrowsererror", function onCertError(e) {
    1.38 +    iframe.removeEventListener(e.type, onCertError);
    1.39 +    ok(true, "Got mozbrowsererror event.");
    1.40 +    ok(e.detail.type == "certerror", "Event's detail has a |type| param with the value '" + e.detail.type + "'.");
    1.41 +
    1.42 +    checkForNoCertificateError();
    1.43 +  });
    1.44 +
    1.45 +  iframe.src = "https://expired.example.com";
    1.46 +}
    1.47 +
    1.48 +
    1.49 +function checkForNoCertificateError() {
    1.50 +  iframe.addEventListener("mozbrowsererror", function onCertError(e) {
    1.51 +    iframe.removeEventListener(e.type, onCertError);
    1.52 +    ok(true, "Got mozbrowsererror event.");
    1.53 +    ok(e.detail.type == "certerror", "Event's detail has a |type| param with the value '" + e.detail.type + "'.");
    1.54 +
    1.55 +    SimpleTest.finish();
    1.56 +  });
    1.57 +
    1.58 +  iframe.src = "https://nocert.example.com";
    1.59 +}
    1.60 +
    1.61 +addEventListener('testready', runTest);

mercurial