summaryrefslogtreecommitdiffstats
path: root/devtools/client/memory/test/chrome/test_ShortestPaths_01.html
blob: e2ad1867a3146d76e4937f4c30a1a4e8e3726e75 (plain)
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
<!DOCTYPE HTML>
<html>
<!--
Test that the ShortestPaths component properly renders a graph of the merged shortest paths.
-->
<head>
    <meta charset="utf-8">
    <title>Tree component test</title>
    <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">

    <script type="application/javascript"
            src="chrome://devtools/content/shared/vendor/d3.js">
    </script>
    <script type="application/javascript"
            src="chrome://devtools/content/shared/vendor/dagre-d3.js">
    </script>
</head>
<body>
    <!-- Give the container height so that the whole tree is rendered. -->
    <div id="container" style="height: 900px;"></div>

    <pre id="test">
        <script src="head.js" type="application/javascript;version=1.8"></script>
        <script type="application/javascript;version=1.8">
         window.onload = Task.async(function* () {
           try {
             const container = document.getElementById("container");

             yield renderComponent(ShortestPaths(TEST_SHORTEST_PATHS_PROPS), container);

             let found1 = false;
             let found2 = false;
             let found3 = false;

             let found1to2 = false;
             let found1to3 = false;
             let found2to3 = false;

             const tspans = [...container.querySelectorAll("tspan")];
             for (let el of tspans) {
               const text = el.textContent.trim();
               dumpn("tspan's text = " + text);

               switch (text) {
                 // Nodes

                 case "other › SomeType @ 0x1": {
                   ok(!found1, "Should only find node 1 once");
                   found1 = true;
                   break;
                 }

                 case "other › SomeType @ 0x2": {
                   ok(!found2, "Should only find node 2 once");
                   found2 = true;
                   break;
                 }

                 case "other › SomeType @ 0x3": {
                   ok(!found3, "Should only find node 3 once");
                   found3 = true;
                   break;
                 }

                 // Edges

                 case "1->2": {
                   ok(!found1to2, "Should only find edge 1->2 once");
                   found1to2 = true;
                   break;
                 }

                 case "1->3": {
                   ok(!found1to3, "Should only find edge 1->3 once");
                   found1to3 = true;
                   break;
                 }

                 case "2->3": {
                   ok(!found2to3, "Should only find edge 2->3 once");
                   found2to3 = true;
                   break;
                 }

                 // Unexpected

                 default: {
                   ok(false, `Unexpected tspan: ${text}`);
                   break;
                 }
               }
             }

             ok(found1, "Should have rendered node 1");
             ok(found2, "Should have rendered node 2");
             ok(found3, "Should have rendered node 3");

             ok(found1to2, "Should have rendered edge 1->2");
             ok(found1to3, "Should have rendered edge 1->3");
             ok(found2to3, "Should have rendered edge 2->3");

           } catch(e) {
             ok(false, "Got an error: " + DevToolsUtils.safeErrorString(e));
           } finally {
             SimpleTest.finish();
           }
         });
        </script>
    </pre>
</body>
</html>