browser/base/content/test/general/browser_identity_UI.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Tests for correct behaviour of getEffectiveHost on identity handler */
     2 function test() {
     3   waitForExplicitFinish();
     5   ok(gIdentityHandler, "gIdentityHandler should exist");
     7   gBrowser.selectedTab = gBrowser.addTab();
     8   gBrowser.selectedBrowser.addEventListener("load", checkResult, true);
    10   nextTest();
    11 }
    13 // Greek IDN for 'example.test'.
    14 var idnDomain = "\u03C0\u03B1\u03C1\u03AC\u03B4\u03B5\u03B9\u03B3\u03BC\u03B1.\u03B4\u03BF\u03BA\u03B9\u03BC\u03AE";
    15 var tests = [
    16   {
    17     name: "normal domain",
    18     location: "http://test1.example.org/",
    19     effectiveHost: "example.org"
    20   },
    21   {
    22     name: "view-source",
    23     location: "view-source:http://example.com/",
    24     effectiveHost: null
    25   },
    26   {
    27     name: "normal HTTPS",
    28     location: "https://example.com/",
    29     effectiveHost: "example.com",
    30     isHTTPS: true
    31   },
    32   {
    33     name: "IDN subdomain",
    34     location: "http://sub1." + idnDomain + "/",
    35     effectiveHost: idnDomain
    36   },
    37   {
    38     name: "subdomain with port",
    39     location: "http://sub1.test1.example.org:8000/",
    40     effectiveHost: "example.org"
    41   },
    42   {
    43     name: "subdomain HTTPS",
    44     location: "https://test1.example.com/",
    46     effectiveHost: "example.com",
    47     isHTTPS: true
    48   },
    49   {
    50     name: "view-source HTTPS",
    51     location: "view-source:https://example.com/",
    52     effectiveHost: null,
    53     isHTTPS: true
    54   },
    55   {
    56     name: "IP address",
    57     location: "http://127.0.0.1:8888/",
    58     effectiveHost: "127.0.0.1"
    59   },
    60 ]
    62 let gCurrentTest, gCurrentTestIndex = -1, gTestDesc;
    63 // Go through the tests in both directions, to add additional coverage for
    64 // transitions between different states.
    65 let gForward = true;
    66 let gCheckETLD = false;
    67 function nextTest() {
    68   if (!gCheckETLD) {
    69     if (gForward)
    70       gCurrentTestIndex++;
    71     else
    72       gCurrentTestIndex--;
    74     if (gCurrentTestIndex == tests.length) {
    75       // Went too far, reverse
    76       gCurrentTestIndex--;
    77       gForward = false;
    78     }
    80     if (gCurrentTestIndex == -1) {
    81       gBrowser.selectedBrowser.removeEventListener("load", checkResult, true);
    82       gBrowser.removeCurrentTab();
    83       finish();
    84       return;
    85     }
    87     gCurrentTest = tests[gCurrentTestIndex];
    88     gTestDesc = "#" + gCurrentTestIndex + " (" + gCurrentTest.name + ")";
    89     if (!gForward)
    90       gTestDesc += " (second time)";
    91     if (gCurrentTest.isHTTPS) {
    92       gCheckETLD = true;
    93     }
    94     content.location = gCurrentTest.location;
    95   } else {
    96     gCheckETLD = false;
    97     gTestDesc = "#" + gCurrentTestIndex + " (" + gCurrentTest.name + " without eTLD in identity icon label)";
    98     if (!gForward)
    99       gTestDesc += " (second time)";
   100     content.location.reload(true);
   101   }
   102 }
   104 function checkResult() {
   105   // Sanity check other values, and the value of gIdentityHandler.getEffectiveHost()
   106   is(gIdentityHandler._lastUri.spec, gCurrentTest.location, "location matches for test " + gTestDesc);
   107   // getEffectiveHost can't be called for all modes
   108   if (gCurrentTest.effectiveHost === null)
   109     is(gIdentityHandler._mode == gIdentityHandler.IDENTITY_MODE_UNKNOWN || gIdentityHandler._mode == gIdentityHandler.IDENTITY_MODE_CHROMEUI, true, "mode matched");
   110   else
   111     is(gIdentityHandler.getEffectiveHost(), gCurrentTest.effectiveHost, "effectiveHost matches for test " + gTestDesc);
   113   executeSoon(nextTest);
   114 }

mercurial