michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Tests that urls are correctly shortened to unique labels. michael@0: */ michael@0: michael@0: const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html"; michael@0: michael@0: function test() { michael@0: let gTab, gDebuggee, gPanel, gDebugger; michael@0: let gSources, gUtils; michael@0: michael@0: initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { michael@0: gTab = aTab; michael@0: gDebuggee = aDebuggee; michael@0: gPanel = aPanel; michael@0: gDebugger = gPanel.panelWin; michael@0: gSources = gDebugger.DebuggerView.Sources; michael@0: gUtils = gDebugger.SourceUtils; michael@0: michael@0: let ellipsis = gPanel.panelWin.L10N.ellipsis; michael@0: let nananana = new Array(20).join(NaN); michael@0: michael@0: // Test trimming url queries. michael@0: michael@0: let someUrl = "a/b/c.d?test=1&random=4#reference"; michael@0: let shortenedUrl = "a/b/c.d"; michael@0: is(gUtils.trimUrlQuery(someUrl), shortenedUrl, michael@0: "Trimming the url query isn't done properly."); michael@0: michael@0: // Test trimming long urls with an ellipsis. michael@0: michael@0: let largeLabel = new Array(100).join("Beer can in Jamaican sounds like Bacon!"); michael@0: let trimmedLargeLabel = gUtils.trimUrlLength(largeLabel, 1234); michael@0: is(trimmedLargeLabel.length, 1235, michael@0: "Trimming large labels isn't done properly."); michael@0: ok(trimmedLargeLabel.endsWith(ellipsis), michael@0: "Trimming large labels should add an ellipsis at the end."); michael@0: michael@0: // Test the sources list behaviour with certain urls. michael@0: michael@0: let urls = [ michael@0: { href: "http://some.address.com/random/", leaf: "subrandom/" }, michael@0: { href: "http://some.address.com/random/", leaf: "suprandom/?a=1" }, michael@0: { href: "http://some.address.com/random/", leaf: "?a=1" }, michael@0: { href: "https://another.address.org/random/subrandom/", leaf: "page.html" }, michael@0: michael@0: { href: "ftp://interesting.address.org/random/", leaf: "script.js" }, michael@0: { href: "ftp://interesting.address.com/random/", leaf: "script.js" }, michael@0: { href: "ftp://interesting.address.com/random/", leaf: "x/script.js" }, michael@0: { href: "ftp://interesting.address.com/random/", leaf: "x/y/script.js?a=1" }, michael@0: { href: "ftp://interesting.address.com/random/x/", leaf: "y/script.js?a=1&b=2" }, michael@0: { href: "ftp://interesting.address.com/random/x/y/", leaf: "script.js?a=1&b=2&c=3" }, michael@0: { href: "ftp://interesting.address.com/random/", leaf: "x/y/script.js?a=2" }, michael@0: { href: "ftp://interesting.address.com/random/x/", leaf: "y/script.js?a=2&b=3" }, michael@0: { href: "ftp://interesting.address.com/random/x/y/", leaf: "script.js?a=2&b=3&c=4" }, michael@0: michael@0: { href: "file://random/", leaf: "script_t1.js&a=1&b=2&c=3" }, michael@0: { href: "file://random/", leaf: "script_t2_1.js#id" }, michael@0: { href: "file://random/", leaf: "script_t2_2.js?a" }, michael@0: { href: "file://random/", leaf: "script_t2_3.js&b" }, michael@0: { href: "resource://random/", leaf: "script_t3_1.js#id?a=1&b=2" }, michael@0: { href: "resource://random/", leaf: "script_t3_2.js?a=1&b=2#id" }, michael@0: { href: "resource://random/", leaf: "script_t3_3.js&a=1&b=2#id" }, michael@0: michael@0: { href: nananana, leaf: "Batman!" + "{trim me, now and forevermore}" } michael@0: ]; michael@0: michael@0: is(gSources.itemCount, 1, michael@0: "Should contain the original source label in the sources widget."); michael@0: is(gSources.selectedIndex, 0, michael@0: "The first item in the sources widget should be selected (1)."); michael@0: is(gSources.selectedItem.attachment.label, "doc_recursion-stack.html", michael@0: "The first item in the sources widget should be selected (2)."); michael@0: is(gSources.selectedValue, TAB_URL, michael@0: "The first item in the sources widget should be selected (3)."); michael@0: michael@0: gSources.empty(); michael@0: michael@0: is(gSources.itemCount, 0, michael@0: "Should contain no items in the sources widget after emptying."); michael@0: is(gSources.selectedIndex, -1, michael@0: "No item in the sources widget should be selected (1)."); michael@0: is(gSources.selectedItem, null, michael@0: "No item in the sources widget should be selected (2)."); michael@0: is(gSources.selectedValue, "", michael@0: "No item in the sources widget should be selected (3)."); michael@0: michael@0: for (let { href, leaf } of urls) { michael@0: let url = href + leaf; michael@0: let label = gUtils.trimUrlLength(gUtils.getSourceLabel(url)); michael@0: let group = gUtils.getSourceGroup(url); michael@0: let dummy = document.createElement("label"); michael@0: michael@0: gSources.push([dummy, url], { michael@0: attachment: { michael@0: label: label, michael@0: group: group michael@0: } michael@0: }); michael@0: } michael@0: michael@0: info("Source locations:"); michael@0: info(gSources.values.toSource()); michael@0: michael@0: info("Source attachments:"); michael@0: info(gSources.attachments.toSource()); michael@0: michael@0: for (let { href, leaf, dupe } of urls) { michael@0: let url = href + leaf; michael@0: if (dupe) { michael@0: ok(!gSources.containsValue(url), "Shouldn't contain source: " + url); michael@0: } else { michael@0: ok(gSources.containsValue(url), "Should contain source: " + url); michael@0: } michael@0: } michael@0: michael@0: ok(gSources.getItemForAttachment(e => e.label == "random/subrandom/"), michael@0: "Source (0) label is incorrect."); michael@0: ok(gSources.getItemForAttachment(e => e.label == "random/suprandom/?a=1"), michael@0: "Source (1) label is incorrect."); michael@0: ok(gSources.getItemForAttachment(e => e.label == "random/?a=1"), michael@0: "Source (2) label is incorrect."); michael@0: ok(gSources.getItemForAttachment(e => e.label == "page.html"), michael@0: "Source (3) label is incorrect."); michael@0: michael@0: ok(gSources.getItemForAttachment(e => e.label == "script.js"), michael@0: "Source (4) label is incorrect."); michael@0: ok(gSources.getItemForAttachment(e => e.label == "random/script.js"), michael@0: "Source (5) label is incorrect."); michael@0: ok(gSources.getItemForAttachment(e => e.label == "random/x/script.js"), michael@0: "Source (6) label is incorrect."); michael@0: ok(gSources.getItemForAttachment(e => e.label == "script.js?a=1"), michael@0: "Source (7) label is incorrect."); michael@0: michael@0: ok(gSources.getItemForAttachment(e => e.label == "script_t1.js"), michael@0: "Source (8) label is incorrect."); michael@0: ok(gSources.getItemForAttachment(e => e.label == "script_t2_1.js"), michael@0: "Source (9) label is incorrect."); michael@0: ok(gSources.getItemForAttachment(e => e.label == "script_t2_2.js"), michael@0: "Source (10) label is incorrect."); michael@0: ok(gSources.getItemForAttachment(e => e.label == "script_t2_3.js"), michael@0: "Source (11) label is incorrect."); michael@0: ok(gSources.getItemForAttachment(e => e.label == "script_t3_1.js"), michael@0: "Source (12) label is incorrect."); michael@0: ok(gSources.getItemForAttachment(e => e.label == "script_t3_2.js"), michael@0: "Source (13) label is incorrect."); michael@0: ok(gSources.getItemForAttachment(e => e.label == "script_t3_3.js"), michael@0: "Source (14) label is incorrect."); michael@0: michael@0: ok(gSources.getItemForAttachment(e => e.label == nananana + "Batman!" + ellipsis), michael@0: "Source (15) label is incorrect."); michael@0: michael@0: is(gSources.itemCount, urls.filter(({ dupe }) => !dupe).length, michael@0: "Didn't get the correct number of sources in the list."); michael@0: michael@0: is(gSources.getItemByValue("http://some.address.com/random/subrandom/").attachment.label, michael@0: "random/subrandom/", michael@0: "gSources.getItemByValue isn't functioning properly (0)."); michael@0: is(gSources.getItemByValue("http://some.address.com/random/suprandom/?a=1").attachment.label, michael@0: "random/suprandom/?a=1", michael@0: "gSources.getItemByValue isn't functioning properly (1)."); michael@0: michael@0: is(gSources.getItemForAttachment(e => e.label == "random/subrandom/").value, michael@0: "http://some.address.com/random/subrandom/", michael@0: "gSources.getItemForAttachment isn't functioning properly (0)."); michael@0: is(gSources.getItemForAttachment(e => e.label == "random/suprandom/?a=1").value, michael@0: "http://some.address.com/random/suprandom/?a=1", michael@0: "gSources.getItemForAttachment isn't functioning properly (1)."); michael@0: michael@0: closeDebuggerAndFinish(gPanel); michael@0: }); michael@0: }