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