1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const { require } = ChromeUtils.importESModule(
"resource://devtools/shared/loader/Loader.sys.mjs"
);
const {
withCommonPathPrefixRemoved,
} = require("resource://devtools/client/performance-new/shared/utils.js");
add_task(function test() {
info(
"withCommonPathPrefixRemoved() removes the common prefix from an array " +
"of paths. This test ensures that the paths are correctly removed."
);
if (Services.appinfo.OS === "WINNT") {
info("Check Windows paths");
deepEqual(withCommonPathPrefixRemoved([]), [], "Windows empty paths");
deepEqual(
withCommonPathPrefixRemoved(["source\\file1.js", "source\\file2.js"]),
["source\\file1.js", "source\\file2.js"],
"Windows relative paths"
);
deepEqual(
withCommonPathPrefixRemoved([
"C:\\Users\\SomeUser\\Desktop\\source\\file1.js",
"D:\\Users\\SomeUser\\Desktop\\source\\file2.js",
]),
[
"C:\\Users\\SomeUser\\Desktop\\source\\file1.js",
"D:\\Users\\SomeUser\\Desktop\\source\\file2.js",
],
"Windows multiple disks"
);
deepEqual(
withCommonPathPrefixRemoved([
"C:\\Users\\SomeUser\\Desktop\\source\\file1.js",
"C:\\Users\\SomeUser\\Desktop\\source\\file2.js",
]),
["file1.js", "file2.js"],
"Windows full path match"
);
deepEqual(
withCommonPathPrefixRemoved([
"C:\\Users\\SomeUser\\Desktop\\source\\file1.js",
"C:\\Users\\SomeUser\\file2.js",
]),
["Desktop\\source\\file1.js", "file2.js"],
"Windows path match at level 3"
);
deepEqual(
withCommonPathPrefixRemoved([
"C:\\Users\\SomeUser\\Desktop\\source\\file1.js",
"C:\\Users\\SomeUser\\file2.js",
"C:\\Users\\file3.js",
]),
["SomeUser\\Desktop\\source\\file1.js", "SomeUser\\file2.js", "file3.js"],
"Windows path match at level 2"
);
deepEqual(
withCommonPathPrefixRemoved(["C:\\dev"]),
["C:\\dev"],
"Windows path match at level 1"
);
} else {
info("Check UNIX paths");
deepEqual(withCommonPathPrefixRemoved([]), [], "UNIX empty paths");
deepEqual(
withCommonPathPrefixRemoved(["source/file1.js", "source/file2.js"]),
["source/file1.js", "source/file2.js"],
"UNIX relative paths"
);
deepEqual(
withCommonPathPrefixRemoved([
"/home/someuser/Desktop/source/file1.js",
"/home/someuser/Desktop/source/file2.js",
]),
["file1.js", "file2.js"],
"UNIX full path match"
);
deepEqual(
withCommonPathPrefixRemoved([
"/home/someuser/Desktop/source/file1.js",
"/home/someuser/file2.js",
]),
["Desktop/source/file1.js", "file2.js"],
"UNIX path match at level 3"
);
deepEqual(
withCommonPathPrefixRemoved([
"/home/someuser/Desktop/source/file1.js",
"/home/someuser/file2.js",
"/home/file3.js",
]),
["someuser/Desktop/source/file1.js", "someuser/file2.js", "file3.js"],
"UNIX path match at level 2"
);
deepEqual(
withCommonPathPrefixRemoved(["/bin"]),
["/bin"],
"UNIX path match at level 1"
);
}
});
|