test_ShortestPaths_01.html (3588B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 Test that the ShortestPaths component properly renders a graph of the merged shortest paths. 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Tree component test</title> 9 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> 11 12 <script type="application/javascript" 13 src="chrome://global/content/third_party/d3/d3.js"> 14 </script> 15 <script type="application/javascript" 16 src="chrome://devtools/content/shared/vendor/dagre-d3.js"> 17 </script> 18 </head> 19 <body> 20 <!-- Give the container height so that the whole tree is rendered. --> 21 <div id="container" style="height: 900px;"></div> 22 23 <pre id="test"> 24 <script src="head.js" type="application/javascript"></script> 25 <script type="application/javascript"> 26 "use strict"; 27 window.onload = async function() { 28 try { 29 const container = document.getElementById("container"); 30 31 await renderComponent(ShortestPaths(TEST_SHORTEST_PATHS_PROPS), container); 32 33 let found1 = false; 34 let found2 = false; 35 let found3 = false; 36 37 let found1to2 = false; 38 let found1to3 = false; 39 let found2to3 = false; 40 41 const tspans = [...container.querySelectorAll("tspan")]; 42 for (const el of tspans) { 43 const text = el.textContent.trim(); 44 dumpn("tspan's text = " + text); 45 46 switch (text) { 47 // Nodes 48 49 case "other › SomeType @ 0x1": { 50 ok(!found1, "Should only find node 1 once"); 51 found1 = true; 52 break; 53 } 54 55 case "other › SomeType @ 0x2": { 56 ok(!found2, "Should only find node 2 once"); 57 found2 = true; 58 break; 59 } 60 61 case "other › SomeType @ 0x3": { 62 ok(!found3, "Should only find node 3 once"); 63 found3 = true; 64 break; 65 } 66 67 // Edges 68 69 case "1->2": { 70 ok(!found1to2, "Should only find edge 1->2 once"); 71 found1to2 = true; 72 break; 73 } 74 75 case "1->3": { 76 ok(!found1to3, "Should only find edge 1->3 once"); 77 found1to3 = true; 78 break; 79 } 80 81 case "2->3": { 82 ok(!found2to3, "Should only find edge 2->3 once"); 83 found2to3 = true; 84 break; 85 } 86 87 // Unexpected 88 89 default: { 90 ok(false, `Unexpected tspan: ${text}`); 91 break; 92 } 93 } 94 } 95 96 ok(found1, "Should have rendered node 1"); 97 ok(found2, "Should have rendered node 2"); 98 ok(found3, "Should have rendered node 3"); 99 100 ok(found1to2, "Should have rendered edge 1->2"); 101 ok(found1to3, "Should have rendered edge 1->3"); 102 ok(found2to3, "Should have rendered edge 2->3"); 103 } catch (e) { 104 ok(false, "Got an error: " + DevToolsUtils.safeErrorString(e)); 105 } finally { 106 SimpleTest.finish(); 107 } 108 }; 109 </script> 110 </pre> 111 </body> 112 </html>