File: browser_net_sort-03.js

package info (click to toggle)
iceweasel 31.6.0esr-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 1,368,576 kB
  • sloc: cpp: 3,692,968; ansic: 1,797,194; python: 193,401; java: 180,622; asm: 133,557; xml: 89,288; sh: 71,748; perl: 22,087; makefile: 21,687; objc: 4,014; yacc: 1,995; pascal: 1,292; lex: 950; exp: 449; lisp: 228; awk: 211; php: 113; sed: 43; csh: 31; ada: 16; ruby: 3
file content (191 lines) | stat: -rw-r--r-- 7,646 bytes parent folder | download | duplicates (5)
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Test if sorting columns in the network table works correctly with new requests.
 */

function test() {
  initNetMonitor(SORTING_URL).then(([aTab, aDebuggee, aMonitor]) => {
    info("Starting test... ");

    // It seems that this test may be slow on debug builds. This could be because
    // of the heavy dom manipulation associated with sorting.
    requestLongerTimeout(2);

    let { $, $all, L10N, NetMonitorView } = aMonitor.panelWin;
    let { RequestsMenu } = NetMonitorView;

    RequestsMenu.lazyUpdate = false;

    waitForNetworkEvents(aMonitor, 5).then(() => {
      EventUtils.sendMouseEvent({ type: "mousedown" }, $("#details-pane-toggle"));

      isnot(RequestsMenu.selectedItem, null,
        "There should be a selected item in the requests menu.");
      is(RequestsMenu.selectedIndex, 0,
        "The first item should be selected in the requests menu.");
      is(NetMonitorView.detailsPaneHidden, false,
        "The details pane should not be hidden after toggle button was pressed.");

      testHeaders();
      testContents([0, 2, 4, 3, 1], 0)
        .then(() => {
          info("Testing status sort, ascending.");
          EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button"));
          testHeaders("status", "ascending");
          return testContents([0, 1, 2, 3, 4], 0);
        })
        .then(() => {
          info("Performing more requests.");
          aDebuggee.performRequests();
          return waitForNetworkEvents(aMonitor, 5);
        })
        .then(() => {
          info("Testing status sort again, ascending.");
          testHeaders("status", "ascending");
          return testContents([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0);
        })
        .then(() => {
          info("Testing status sort, descending.");
          EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button"));
          testHeaders("status", "descending");
          return testContents([9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 9);
        })
        .then(() => {
          info("Performing more requests.");
          aDebuggee.performRequests();
          return waitForNetworkEvents(aMonitor, 5);
        })
        .then(() => {
          info("Testing status sort again, descending.");
          testHeaders("status", "descending");
          return testContents([14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 14);
        })
        .then(() => {
          info("Testing status sort yet again, ascending.");
          EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button"));
          testHeaders("status", "ascending");
          return testContents([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], 0);
        })
        .then(() => {
          info("Testing status sort yet again, descending.");
          EventUtils.sendMouseEvent({ type: "click" }, $("#requests-menu-status-button"));
          testHeaders("status", "descending");
          return testContents([14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], 14);
        })
        .then(() => {
          return teardown(aMonitor);
        })
        .then(finish);
    });

    function testHeaders(aSortType, aDirection) {
      let doc = aMonitor.panelWin.document;
      let target = doc.querySelector("#requests-menu-" + aSortType + "-button");
      let headers = doc.querySelectorAll(".requests-menu-header-button");

      for (let header of headers) {
        if (header != target) {
          is(header.hasAttribute("sorted"), false,
            "The " + header.id + " header should not have a 'sorted' attribute.");
          is(header.hasAttribute("tooltiptext"), false,
            "The " + header.id + " header should not have a 'tooltiptext' attribute.");
        } else {
          is(header.getAttribute("sorted"), aDirection,
            "The " + header.id + " header has an incorrect 'sorted' attribute.");
          is(header.getAttribute("tooltiptext"), aDirection == "ascending"
            ? L10N.getStr("networkMenu.sortedAsc")
            : L10N.getStr("networkMenu.sortedDesc"),
            "The " + header.id + " has an incorrect 'tooltiptext' attribute.");
        }
      }
    }

    function testContents(aOrder, aSelection) {
      isnot(RequestsMenu.selectedItem, null,
        "There should still be a selected item after sorting.");
      is(RequestsMenu.selectedIndex, aSelection,
        "The first item should be still selected after sorting.");
      is(NetMonitorView.detailsPaneHidden, false,
        "The details pane should still be visible after sorting.");

      is(RequestsMenu.items.length, aOrder.length,
        "There should be a specific number of items in the requests menu.");
      is(RequestsMenu.visibleItems.length, aOrder.length,
        "There should be a specific number of visbile items in the requests menu.");
      is($all(".side-menu-widget-item").length, aOrder.length,
        "The visible items in the requests menu are, in fact, visible!");

      for (let i = 0; i < aOrder.length; i++) {
        is(RequestsMenu.getItemAtIndex(i), RequestsMenu.items[i],
          "The requests menu items aren't ordered correctly. Misplaced item " + i + ".");
      }

      for (let i = 0, len = aOrder.length / 5; i < len; i++) {
        verifyRequestItemTarget(RequestsMenu.getItemAtIndex(aOrder[i]),
          "GET1", SORTING_SJS + "?index=1", {
            fuzzyUrl: true,
            status: 101,
            statusText: "Meh",
            type: "1",
            fullMimeType: "text/1",
            size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0),
            time: true
          });
      }
      for (let i = 0, len = aOrder.length / 5; i < len; i++) {
        verifyRequestItemTarget(RequestsMenu.getItemAtIndex(aOrder[i + len]),
          "GET2", SORTING_SJS + "?index=2", {
            fuzzyUrl: true,
            status: 200,
            statusText: "Meh",
            type: "2",
            fullMimeType: "text/2",
            size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.01),
            time: true
          });
      }
      for (let i = 0, len = aOrder.length / 5; i < len; i++) {
        verifyRequestItemTarget(RequestsMenu.getItemAtIndex(aOrder[i + len * 2]),
          "GET3", SORTING_SJS + "?index=3", {
            fuzzyUrl: true,
            status: 300,
            statusText: "Meh",
            type: "3",
            fullMimeType: "text/3",
            size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.02),
            time: true
          });
      }
      for (let i = 0, len = aOrder.length / 5; i < len; i++) {
        verifyRequestItemTarget(RequestsMenu.getItemAtIndex(aOrder[i + len * 3]),
          "GET4", SORTING_SJS + "?index=4", {
            fuzzyUrl: true,
            status: 400,
            statusText: "Meh",
            type: "4",
            fullMimeType: "text/4",
            size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.03),
            time: true
          });
      }
      for (let i = 0, len = aOrder.length / 5; i < len; i++) {
        verifyRequestItemTarget(RequestsMenu.getItemAtIndex(aOrder[i + len * 4]),
          "GET5", SORTING_SJS + "?index=5", {
            fuzzyUrl: true,
            status: 500,
            statusText: "Meh",
            type: "5",
            fullMimeType: "text/5",
            size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.04),
            time: true
          });
      }

      return promise.resolve(null);
    }

    aDebuggee.performRequests();
  });
}