summaryrefslogtreecommitdiffstats
path: root/devtools/shared/webconsole/test/unit/test_network_helper.js
blob: 3a43ff4323e72f3ab2aabcec8251419d8865ee5b (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";
var Cu = Components.utils;
const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});

Object.defineProperty(this, "NetworkHelper", {
  get: function () {
    return require("devtools/shared/webconsole/network-helper");
  },
  configurable: true,
  writeable: false,
  enumerable: true
});

function run_test() {
  test_isTextMimeType();
}

function test_isTextMimeType() {
  do_check_eq(NetworkHelper.isTextMimeType("text/plain"), true);
  do_check_eq(NetworkHelper.isTextMimeType("application/javascript"), true);
  do_check_eq(NetworkHelper.isTextMimeType("application/json"), true);
  do_check_eq(NetworkHelper.isTextMimeType("text/css"), true);
  do_check_eq(NetworkHelper.isTextMimeType("text/html"), true);
  do_check_eq(NetworkHelper.isTextMimeType("image/svg+xml"), true);
  do_check_eq(NetworkHelper.isTextMimeType("application/xml"), true);

  // Test custom JSON subtype
  do_check_eq(NetworkHelper.isTextMimeType("application/vnd.tent.posts-feed.v0+json"), true);
  do_check_eq(NetworkHelper.isTextMimeType("application/vnd.tent.posts-feed.v0-json"), true);
  // Test custom XML subtype
  do_check_eq(NetworkHelper.isTextMimeType("application/vnd.tent.posts-feed.v0+xml"), true);
  do_check_eq(NetworkHelper.isTextMimeType("application/vnd.tent.posts-feed.v0-xml"), false);
  // Test case-insensitive
  do_check_eq(NetworkHelper.isTextMimeType("application/vnd.BIG-CORP+json"), true);
  // Test non-text type
  do_check_eq(NetworkHelper.isTextMimeType("image/png"), false);
  // Test invalid types
  do_check_eq(NetworkHelper.isTextMimeType("application/foo-+json"), false);
  do_check_eq(NetworkHelper.isTextMimeType("application/-foo+json"), false);
  do_check_eq(NetworkHelper.isTextMimeType("application/foo--bar+json"), false);

  // Test we do not cause internal errors with unoptimized regex. Bug 961097
  do_check_eq(NetworkHelper.isTextMimeType("application/vnd.google.safebrowsing-chunk"), false);
}