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