summaryrefslogtreecommitdiffstats
path: root/devtools/client/netmonitor/src/har/test/browser_net_har_import_no-mime.js
blob: 91c51602172d8378af9c38827087f9fdc79a08c6 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

/**
 * Tests importing HAR with missing `response.content.mimeType` does not crash the netmonitor.
 */
add_task(async () => {
  const { monitor } = await initNetMonitor(SIMPLE_URL, {
    requestCount: 1,
  });

  info("Starting test... ");

  const { document, actions, store, windowRequire } = monitor.panelWin;
  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");

  const { HarImporter } = windowRequire(
    "devtools/client/netmonitor/src/har/har-importer"
  );

  store.dispatch(Actions.batchEnable(false));

  // Invalid HAR json which should contain `entries[0].response.content.mimeType`
  const invalidHarJSON = {
    log: {
      version: "1.2",
      pages: [
        {
          title: "bla",
        },
      ],
      entries: [
        {
          request: {
            method: "POST",
            url: "https://bla.com",
            httpVersion: "",
            headers: [],
            cookies: [],
            queryString: [],
          },
          response: {
            content: {
              size: 1231,
              text: '{"requests":[{"uri":"https://bla.com"}]}',
            },
            headers: [],
          },
          timings: {},
          cache: {},
        },
      ],
    },
  };

  // Import invalid Har file
  const importer = new HarImporter(actions);
  importer.import(JSON.stringify(invalidHarJSON));

  const waitForResponsePanelOpen = waitUntil(() =>
    document.querySelector("#response-panel")
  );

  // Open the response details panel
  EventUtils.sendMouseEvent(
    { type: "mousedown" },
    document.querySelector(".request-list-item")
  );
  clickOnSidebarTab(document, "response");

  await waitForResponsePanelOpen;
  ok(true, "The response panel opened");

  // Clean up
  return teardown(monitor);
});