browser/devtools/debugger/test/browser_dbg_sources-labels.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.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 /**
michael@0 5 * Tests that urls are correctly shortened to unique labels.
michael@0 6 */
michael@0 7
michael@0 8 const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html";
michael@0 9
michael@0 10 function test() {
michael@0 11 let gTab, gDebuggee, gPanel, gDebugger;
michael@0 12 let gSources, gUtils;
michael@0 13
michael@0 14 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
michael@0 15 gTab = aTab;
michael@0 16 gDebuggee = aDebuggee;
michael@0 17 gPanel = aPanel;
michael@0 18 gDebugger = gPanel.panelWin;
michael@0 19 gSources = gDebugger.DebuggerView.Sources;
michael@0 20 gUtils = gDebugger.SourceUtils;
michael@0 21
michael@0 22 let ellipsis = gPanel.panelWin.L10N.ellipsis;
michael@0 23 let nananana = new Array(20).join(NaN);
michael@0 24
michael@0 25 // Test trimming url queries.
michael@0 26
michael@0 27 let someUrl = "a/b/c.d?test=1&random=4#reference";
michael@0 28 let shortenedUrl = "a/b/c.d";
michael@0 29 is(gUtils.trimUrlQuery(someUrl), shortenedUrl,
michael@0 30 "Trimming the url query isn't done properly.");
michael@0 31
michael@0 32 // Test trimming long urls with an ellipsis.
michael@0 33
michael@0 34 let largeLabel = new Array(100).join("Beer can in Jamaican sounds like Bacon!");
michael@0 35 let trimmedLargeLabel = gUtils.trimUrlLength(largeLabel, 1234);
michael@0 36 is(trimmedLargeLabel.length, 1235,
michael@0 37 "Trimming large labels isn't done properly.");
michael@0 38 ok(trimmedLargeLabel.endsWith(ellipsis),
michael@0 39 "Trimming large labels should add an ellipsis at the end.");
michael@0 40
michael@0 41 // Test the sources list behaviour with certain urls.
michael@0 42
michael@0 43 let urls = [
michael@0 44 { href: "http://some.address.com/random/", leaf: "subrandom/" },
michael@0 45 { href: "http://some.address.com/random/", leaf: "suprandom/?a=1" },
michael@0 46 { href: "http://some.address.com/random/", leaf: "?a=1" },
michael@0 47 { href: "https://another.address.org/random/subrandom/", leaf: "page.html" },
michael@0 48
michael@0 49 { href: "ftp://interesting.address.org/random/", leaf: "script.js" },
michael@0 50 { href: "ftp://interesting.address.com/random/", leaf: "script.js" },
michael@0 51 { href: "ftp://interesting.address.com/random/", leaf: "x/script.js" },
michael@0 52 { href: "ftp://interesting.address.com/random/", leaf: "x/y/script.js?a=1" },
michael@0 53 { href: "ftp://interesting.address.com/random/x/", leaf: "y/script.js?a=1&b=2" },
michael@0 54 { href: "ftp://interesting.address.com/random/x/y/", leaf: "script.js?a=1&b=2&c=3" },
michael@0 55 { href: "ftp://interesting.address.com/random/", leaf: "x/y/script.js?a=2" },
michael@0 56 { href: "ftp://interesting.address.com/random/x/", leaf: "y/script.js?a=2&b=3" },
michael@0 57 { href: "ftp://interesting.address.com/random/x/y/", leaf: "script.js?a=2&b=3&c=4" },
michael@0 58
michael@0 59 { href: "file://random/", leaf: "script_t1.js&a=1&b=2&c=3" },
michael@0 60 { href: "file://random/", leaf: "script_t2_1.js#id" },
michael@0 61 { href: "file://random/", leaf: "script_t2_2.js?a" },
michael@0 62 { href: "file://random/", leaf: "script_t2_3.js&b" },
michael@0 63 { href: "resource://random/", leaf: "script_t3_1.js#id?a=1&b=2" },
michael@0 64 { href: "resource://random/", leaf: "script_t3_2.js?a=1&b=2#id" },
michael@0 65 { href: "resource://random/", leaf: "script_t3_3.js&a=1&b=2#id" },
michael@0 66
michael@0 67 { href: nananana, leaf: "Batman!" + "{trim me, now and forevermore}" }
michael@0 68 ];
michael@0 69
michael@0 70 is(gSources.itemCount, 1,
michael@0 71 "Should contain the original source label in the sources widget.");
michael@0 72 is(gSources.selectedIndex, 0,
michael@0 73 "The first item in the sources widget should be selected (1).");
michael@0 74 is(gSources.selectedItem.attachment.label, "doc_recursion-stack.html",
michael@0 75 "The first item in the sources widget should be selected (2).");
michael@0 76 is(gSources.selectedValue, TAB_URL,
michael@0 77 "The first item in the sources widget should be selected (3).");
michael@0 78
michael@0 79 gSources.empty();
michael@0 80
michael@0 81 is(gSources.itemCount, 0,
michael@0 82 "Should contain no items in the sources widget after emptying.");
michael@0 83 is(gSources.selectedIndex, -1,
michael@0 84 "No item in the sources widget should be selected (1).");
michael@0 85 is(gSources.selectedItem, null,
michael@0 86 "No item in the sources widget should be selected (2).");
michael@0 87 is(gSources.selectedValue, "",
michael@0 88 "No item in the sources widget should be selected (3).");
michael@0 89
michael@0 90 for (let { href, leaf } of urls) {
michael@0 91 let url = href + leaf;
michael@0 92 let label = gUtils.trimUrlLength(gUtils.getSourceLabel(url));
michael@0 93 let group = gUtils.getSourceGroup(url);
michael@0 94 let dummy = document.createElement("label");
michael@0 95
michael@0 96 gSources.push([dummy, url], {
michael@0 97 attachment: {
michael@0 98 label: label,
michael@0 99 group: group
michael@0 100 }
michael@0 101 });
michael@0 102 }
michael@0 103
michael@0 104 info("Source locations:");
michael@0 105 info(gSources.values.toSource());
michael@0 106
michael@0 107 info("Source attachments:");
michael@0 108 info(gSources.attachments.toSource());
michael@0 109
michael@0 110 for (let { href, leaf, dupe } of urls) {
michael@0 111 let url = href + leaf;
michael@0 112 if (dupe) {
michael@0 113 ok(!gSources.containsValue(url), "Shouldn't contain source: " + url);
michael@0 114 } else {
michael@0 115 ok(gSources.containsValue(url), "Should contain source: " + url);
michael@0 116 }
michael@0 117 }
michael@0 118
michael@0 119 ok(gSources.getItemForAttachment(e => e.label == "random/subrandom/"),
michael@0 120 "Source (0) label is incorrect.");
michael@0 121 ok(gSources.getItemForAttachment(e => e.label == "random/suprandom/?a=1"),
michael@0 122 "Source (1) label is incorrect.");
michael@0 123 ok(gSources.getItemForAttachment(e => e.label == "random/?a=1"),
michael@0 124 "Source (2) label is incorrect.");
michael@0 125 ok(gSources.getItemForAttachment(e => e.label == "page.html"),
michael@0 126 "Source (3) label is incorrect.");
michael@0 127
michael@0 128 ok(gSources.getItemForAttachment(e => e.label == "script.js"),
michael@0 129 "Source (4) label is incorrect.");
michael@0 130 ok(gSources.getItemForAttachment(e => e.label == "random/script.js"),
michael@0 131 "Source (5) label is incorrect.");
michael@0 132 ok(gSources.getItemForAttachment(e => e.label == "random/x/script.js"),
michael@0 133 "Source (6) label is incorrect.");
michael@0 134 ok(gSources.getItemForAttachment(e => e.label == "script.js?a=1"),
michael@0 135 "Source (7) label is incorrect.");
michael@0 136
michael@0 137 ok(gSources.getItemForAttachment(e => e.label == "script_t1.js"),
michael@0 138 "Source (8) label is incorrect.");
michael@0 139 ok(gSources.getItemForAttachment(e => e.label == "script_t2_1.js"),
michael@0 140 "Source (9) label is incorrect.");
michael@0 141 ok(gSources.getItemForAttachment(e => e.label == "script_t2_2.js"),
michael@0 142 "Source (10) label is incorrect.");
michael@0 143 ok(gSources.getItemForAttachment(e => e.label == "script_t2_3.js"),
michael@0 144 "Source (11) label is incorrect.");
michael@0 145 ok(gSources.getItemForAttachment(e => e.label == "script_t3_1.js"),
michael@0 146 "Source (12) label is incorrect.");
michael@0 147 ok(gSources.getItemForAttachment(e => e.label == "script_t3_2.js"),
michael@0 148 "Source (13) label is incorrect.");
michael@0 149 ok(gSources.getItemForAttachment(e => e.label == "script_t3_3.js"),
michael@0 150 "Source (14) label is incorrect.");
michael@0 151
michael@0 152 ok(gSources.getItemForAttachment(e => e.label == nananana + "Batman!" + ellipsis),
michael@0 153 "Source (15) label is incorrect.");
michael@0 154
michael@0 155 is(gSources.itemCount, urls.filter(({ dupe }) => !dupe).length,
michael@0 156 "Didn't get the correct number of sources in the list.");
michael@0 157
michael@0 158 is(gSources.getItemByValue("http://some.address.com/random/subrandom/").attachment.label,
michael@0 159 "random/subrandom/",
michael@0 160 "gSources.getItemByValue isn't functioning properly (0).");
michael@0 161 is(gSources.getItemByValue("http://some.address.com/random/suprandom/?a=1").attachment.label,
michael@0 162 "random/suprandom/?a=1",
michael@0 163 "gSources.getItemByValue isn't functioning properly (1).");
michael@0 164
michael@0 165 is(gSources.getItemForAttachment(e => e.label == "random/subrandom/").value,
michael@0 166 "http://some.address.com/random/subrandom/",
michael@0 167 "gSources.getItemForAttachment isn't functioning properly (0).");
michael@0 168 is(gSources.getItemForAttachment(e => e.label == "random/suprandom/?a=1").value,
michael@0 169 "http://some.address.com/random/suprandom/?a=1",
michael@0 170 "gSources.getItemForAttachment isn't functioning properly (1).");
michael@0 171
michael@0 172 closeDebuggerAndFinish(gPanel);
michael@0 173 });
michael@0 174 }

mercurial