browser/devtools/debugger/test/browser_dbg_sources-labels.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/debugger/test/browser_dbg_sources-labels.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,174 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Tests that urls are correctly shortened to unique labels.
     1.9 + */
    1.10 +
    1.11 +const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html";
    1.12 +
    1.13 +function test() {
    1.14 +  let gTab, gDebuggee, gPanel, gDebugger;
    1.15 +  let gSources, gUtils;
    1.16 +
    1.17 +  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    1.18 +    gTab = aTab;
    1.19 +    gDebuggee = aDebuggee;
    1.20 +    gPanel = aPanel;
    1.21 +    gDebugger = gPanel.panelWin;
    1.22 +    gSources = gDebugger.DebuggerView.Sources;
    1.23 +    gUtils = gDebugger.SourceUtils;
    1.24 +
    1.25 +    let ellipsis = gPanel.panelWin.L10N.ellipsis;
    1.26 +    let nananana = new Array(20).join(NaN);
    1.27 +
    1.28 +    // Test trimming url queries.
    1.29 +
    1.30 +    let someUrl = "a/b/c.d?test=1&random=4#reference";
    1.31 +    let shortenedUrl = "a/b/c.d";
    1.32 +    is(gUtils.trimUrlQuery(someUrl), shortenedUrl,
    1.33 +      "Trimming the url query isn't done properly.");
    1.34 +
    1.35 +    // Test trimming long urls with an ellipsis.
    1.36 +
    1.37 +    let largeLabel = new Array(100).join("Beer can in Jamaican sounds like Bacon!");
    1.38 +    let trimmedLargeLabel = gUtils.trimUrlLength(largeLabel, 1234);
    1.39 +    is(trimmedLargeLabel.length, 1235,
    1.40 +      "Trimming large labels isn't done properly.");
    1.41 +    ok(trimmedLargeLabel.endsWith(ellipsis),
    1.42 +      "Trimming large labels should add an ellipsis at the end.");
    1.43 +
    1.44 +    // Test the sources list behaviour with certain urls.
    1.45 +
    1.46 +    let urls = [
    1.47 +      { href: "http://some.address.com/random/", leaf: "subrandom/" },
    1.48 +      { href: "http://some.address.com/random/", leaf: "suprandom/?a=1" },
    1.49 +      { href: "http://some.address.com/random/", leaf: "?a=1" },
    1.50 +      { href: "https://another.address.org/random/subrandom/", leaf: "page.html" },
    1.51 +
    1.52 +      { href: "ftp://interesting.address.org/random/", leaf: "script.js" },
    1.53 +      { href: "ftp://interesting.address.com/random/", leaf: "script.js" },
    1.54 +      { href: "ftp://interesting.address.com/random/", leaf: "x/script.js" },
    1.55 +      { href: "ftp://interesting.address.com/random/", leaf: "x/y/script.js?a=1" },
    1.56 +      { href: "ftp://interesting.address.com/random/x/", leaf: "y/script.js?a=1&b=2" },
    1.57 +      { href: "ftp://interesting.address.com/random/x/y/", leaf: "script.js?a=1&b=2&c=3" },
    1.58 +      { href: "ftp://interesting.address.com/random/", leaf: "x/y/script.js?a=2" },
    1.59 +      { href: "ftp://interesting.address.com/random/x/", leaf: "y/script.js?a=2&b=3" },
    1.60 +      { href: "ftp://interesting.address.com/random/x/y/", leaf: "script.js?a=2&b=3&c=4" },
    1.61 +
    1.62 +      { href: "file://random/", leaf: "script_t1.js&a=1&b=2&c=3" },
    1.63 +      { href: "file://random/", leaf: "script_t2_1.js#id" },
    1.64 +      { href: "file://random/", leaf: "script_t2_2.js?a" },
    1.65 +      { href: "file://random/", leaf: "script_t2_3.js&b" },
    1.66 +      { href: "resource://random/", leaf: "script_t3_1.js#id?a=1&b=2" },
    1.67 +      { href: "resource://random/", leaf: "script_t3_2.js?a=1&b=2#id" },
    1.68 +      { href: "resource://random/", leaf: "script_t3_3.js&a=1&b=2#id" },
    1.69 +
    1.70 +      { href: nananana, leaf: "Batman!" + "{trim me, now and forevermore}" }
    1.71 +    ];
    1.72 +
    1.73 +    is(gSources.itemCount, 1,
    1.74 +      "Should contain the original source label in the sources widget.");
    1.75 +    is(gSources.selectedIndex, 0,
    1.76 +      "The first item in the sources widget should be selected (1).");
    1.77 +    is(gSources.selectedItem.attachment.label, "doc_recursion-stack.html",
    1.78 +      "The first item in the sources widget should be selected (2).");
    1.79 +    is(gSources.selectedValue, TAB_URL,
    1.80 +      "The first item in the sources widget should be selected (3).");
    1.81 +
    1.82 +    gSources.empty();
    1.83 +
    1.84 +    is(gSources.itemCount, 0,
    1.85 +      "Should contain no items in the sources widget after emptying.");
    1.86 +    is(gSources.selectedIndex, -1,
    1.87 +      "No item in the sources widget should be selected (1).");
    1.88 +    is(gSources.selectedItem, null,
    1.89 +      "No item in the sources widget should be selected (2).");
    1.90 +    is(gSources.selectedValue, "",
    1.91 +      "No item in the sources widget should be selected (3).");
    1.92 +
    1.93 +    for (let { href, leaf } of urls) {
    1.94 +      let url = href + leaf;
    1.95 +      let label = gUtils.trimUrlLength(gUtils.getSourceLabel(url));
    1.96 +      let group = gUtils.getSourceGroup(url);
    1.97 +      let dummy = document.createElement("label");
    1.98 +
    1.99 +      gSources.push([dummy, url], {
   1.100 +        attachment: {
   1.101 +          label: label,
   1.102 +          group: group
   1.103 +        }
   1.104 +      });
   1.105 +    }
   1.106 +
   1.107 +    info("Source locations:");
   1.108 +    info(gSources.values.toSource());
   1.109 +
   1.110 +    info("Source attachments:");
   1.111 +    info(gSources.attachments.toSource());
   1.112 +
   1.113 +    for (let { href, leaf, dupe } of urls) {
   1.114 +      let url = href + leaf;
   1.115 +      if (dupe) {
   1.116 +        ok(!gSources.containsValue(url), "Shouldn't contain source: " + url);
   1.117 +      } else {
   1.118 +        ok(gSources.containsValue(url), "Should contain source: " + url);
   1.119 +      }
   1.120 +    }
   1.121 +
   1.122 +    ok(gSources.getItemForAttachment(e => e.label == "random/subrandom/"),
   1.123 +      "Source (0) label is incorrect.");
   1.124 +    ok(gSources.getItemForAttachment(e => e.label == "random/suprandom/?a=1"),
   1.125 +      "Source (1) label is incorrect.");
   1.126 +    ok(gSources.getItemForAttachment(e => e.label == "random/?a=1"),
   1.127 +      "Source (2) label is incorrect.");
   1.128 +    ok(gSources.getItemForAttachment(e => e.label == "page.html"),
   1.129 +      "Source (3) label is incorrect.");
   1.130 +
   1.131 +    ok(gSources.getItemForAttachment(e => e.label == "script.js"),
   1.132 +      "Source (4) label is incorrect.");
   1.133 +    ok(gSources.getItemForAttachment(e => e.label == "random/script.js"),
   1.134 +      "Source (5) label is incorrect.");
   1.135 +    ok(gSources.getItemForAttachment(e => e.label == "random/x/script.js"),
   1.136 +      "Source (6) label is incorrect.");
   1.137 +    ok(gSources.getItemForAttachment(e => e.label == "script.js?a=1"),
   1.138 +      "Source (7) label is incorrect.");
   1.139 +
   1.140 +    ok(gSources.getItemForAttachment(e => e.label == "script_t1.js"),
   1.141 +      "Source (8) label is incorrect.");
   1.142 +    ok(gSources.getItemForAttachment(e => e.label == "script_t2_1.js"),
   1.143 +      "Source (9) label is incorrect.");
   1.144 +    ok(gSources.getItemForAttachment(e => e.label == "script_t2_2.js"),
   1.145 +      "Source (10) label is incorrect.");
   1.146 +    ok(gSources.getItemForAttachment(e => e.label == "script_t2_3.js"),
   1.147 +      "Source (11) label is incorrect.");
   1.148 +    ok(gSources.getItemForAttachment(e => e.label == "script_t3_1.js"),
   1.149 +      "Source (12) label is incorrect.");
   1.150 +    ok(gSources.getItemForAttachment(e => e.label == "script_t3_2.js"),
   1.151 +      "Source (13) label is incorrect.");
   1.152 +    ok(gSources.getItemForAttachment(e => e.label == "script_t3_3.js"),
   1.153 +      "Source (14) label is incorrect.");
   1.154 +
   1.155 +    ok(gSources.getItemForAttachment(e => e.label == nananana + "Batman!" + ellipsis),
   1.156 +      "Source (15) label is incorrect.");
   1.157 +
   1.158 +    is(gSources.itemCount, urls.filter(({ dupe }) => !dupe).length,
   1.159 +      "Didn't get the correct number of sources in the list.");
   1.160 +
   1.161 +    is(gSources.getItemByValue("http://some.address.com/random/subrandom/").attachment.label,
   1.162 +      "random/subrandom/",
   1.163 +      "gSources.getItemByValue isn't functioning properly (0).");
   1.164 +    is(gSources.getItemByValue("http://some.address.com/random/suprandom/?a=1").attachment.label,
   1.165 +      "random/suprandom/?a=1",
   1.166 +      "gSources.getItemByValue isn't functioning properly (1).");
   1.167 +
   1.168 +    is(gSources.getItemForAttachment(e => e.label == "random/subrandom/").value,
   1.169 +      "http://some.address.com/random/subrandom/",
   1.170 +      "gSources.getItemForAttachment isn't functioning properly (0).");
   1.171 +    is(gSources.getItemForAttachment(e => e.label == "random/suprandom/?a=1").value,
   1.172 +      "http://some.address.com/random/suprandom/?a=1",
   1.173 +      "gSources.getItemForAttachment isn't functioning properly (1).");
   1.174 +
   1.175 +    closeDebuggerAndFinish(gPanel);
   1.176 +  });
   1.177 +}

mercurial