summaryrefslogtreecommitdiffstats
path: root/devtools/client/netmonitor/test/browser_net_streaming-response.js
blob: 49a75ec3267b0489f2ccae1ece040974caa80199 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Tests if reponses from streaming content types (MPEG-DASH, HLS) are
 * displayed as XML or plain text
 */

add_task(function* () {
  let { tab, monitor } = yield initNetMonitor(CUSTOM_GET_URL);

  info("Starting test... ");
  let { panelWin } = monitor;
  let { document, Editor, NetMonitorView } = panelWin;
  let { RequestsMenu } = NetMonitorView;

  const REQUESTS = [
    [ "hls-m3u8", /^#EXTM3U/, Editor.modes.text ],
    [ "mpeg-dash", /^<\?xml/, Editor.modes.html ]
  ];

  RequestsMenu.lazyUpdate = false;

  let wait = waitForNetworkEvents(monitor, REQUESTS.length);
  for (let [fmt] of REQUESTS) {
    let url = CONTENT_TYPE_SJS + "?fmt=" + fmt;
    yield ContentTask.spawn(tab.linkedBrowser, { url }, function* (args) {
      content.wrappedJSObject.performRequests(1, args.url);
    });
  }
  yield wait;

  REQUESTS.forEach(([ fmt ], i) => {
    verifyRequestItemTarget(RequestsMenu.getItemAtIndex(i),
      "GET", CONTENT_TYPE_SJS + "?fmt=" + fmt, {
        status: 200,
        statusText: "OK"
      });
  });

  EventUtils.sendMouseEvent({ type: "mousedown" },
    document.getElementById("details-pane-toggle"));
  EventUtils.sendMouseEvent({ type: "mousedown" },
    document.querySelectorAll("#details-pane tab")[3]);

  yield panelWin.once(panelWin.EVENTS.RESPONSE_BODY_DISPLAYED);
  let editor = yield NetMonitorView.editor("#response-content-textarea");

  // the hls-m3u8 part
  testEditorContent(editor, REQUESTS[0]);

  RequestsMenu.selectedIndex = 1;
  yield panelWin.once(panelWin.EVENTS.TAB_UPDATED);
  yield panelWin.once(panelWin.EVENTS.RESPONSE_BODY_DISPLAYED);

  // the mpeg-dash part
  testEditorContent(editor, REQUESTS[1]);

  return teardown(monitor);

  function testEditorContent(e, [ fmt, textRe, mode ]) {
    ok(e.getText().match(textRe),
      "The text shown in the source editor for " + fmt + " is correct.");
    is(e.getMode(), mode,
      "The mode active in the source editor for " + fmt + " is correct.");
  }
});