diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /devtools/client/webconsole/net/test/unit | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/client/webconsole/net/test/unit')
4 files changed, 137 insertions, 0 deletions
diff --git a/devtools/client/webconsole/net/test/unit/.eslintrc.js b/devtools/client/webconsole/net/test/unit/.eslintrc.js new file mode 100644 index 000000000..54a9a6361 --- /dev/null +++ b/devtools/client/webconsole/net/test/unit/.eslintrc.js @@ -0,0 +1,6 @@ +"use strict"; + +module.exports = { + // Extend from the common devtools xpcshell eslintrc config. + "extends": "../../../../../.eslintrc.xpcshell.js" +}; diff --git a/devtools/client/webconsole/net/test/unit/test_json-utils.js b/devtools/client/webconsole/net/test/unit/test_json-utils.js new file mode 100644 index 000000000..f8ccdf3aa --- /dev/null +++ b/devtools/client/webconsole/net/test/unit/test_json-utils.js @@ -0,0 +1,45 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set ts=2 et sw=2 tw=80: */ +/* 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", {}); +const { parseJSONString, isJSON } = require("devtools/client/webconsole/net/utils/json"); + +// Test data +const simpleJson = '{"name":"John"}'; +const jsonInFunc = 'someFunc({"name":"John"})'; + +const json1 = "{'a': 1}"; +const json2 = " {'a': 1}"; +const json3 = "\t {'a': 1}"; +const json4 = "\n\n\t {'a': 1}"; +const json5 = "\n\n\t "; + +const textMimeType = "text/plain"; +const jsonMimeType = "text/javascript"; +const unknownMimeType = "text/unknown"; + +/** + * Testing API provided by webconsole/net/utils/json.js + */ +function run_test() { + // parseJSONString + equal(parseJSONString(simpleJson).name, "John"); + equal(parseJSONString(jsonInFunc).name, "John"); + + // isJSON + equal(isJSON(textMimeType, json1), true); + equal(isJSON(textMimeType, json2), true); + equal(isJSON(jsonMimeType, json3), true); + equal(isJSON(jsonMimeType, json4), true); + + equal(isJSON(unknownMimeType, json1), true); + equal(isJSON(textMimeType, json1), true); + + equal(isJSON(unknownMimeType), false); + equal(isJSON(unknownMimeType, json5), false); +} diff --git a/devtools/client/webconsole/net/test/unit/test_net-utils.js b/devtools/client/webconsole/net/test/unit/test_net-utils.js new file mode 100644 index 000000000..512ebcbc7 --- /dev/null +++ b/devtools/client/webconsole/net/test/unit/test_net-utils.js @@ -0,0 +1,77 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set ts=2 et sw=2 tw=80: */ +/* 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", {}); +const { + isImage, + isHTML, + getHeaderValue, + isURLEncodedRequest, + isMultiPartRequest +} = require("devtools/client/webconsole/net/utils/net"); + +// Test data +const imageMimeTypes = ["image/jpeg", "image/jpg", "image/gif", + "image/png", "image/bmp"]; + +const htmlMimeTypes = ["text/html", "text/xml", "application/xml", + "application/rss+xml", "application/atom+xml", "application/xhtml+xml", + "application/mathml+xml", "application/rdf+xml"]; + +const headers = [{name: "headerName", value: "value1"}]; + +const har1 = { + request: { + postData: { + text: "content-type: application/x-www-form-urlencoded" + } + } +}; + +const har2 = { + request: { + headers: [{ + name: "content-type", + value: "application/x-www-form-urlencoded" + }] + } +}; + +const har3 = { + request: { + headers: [{ + name: "content-type", + value: "multipart/form-data" + }] + } +}; + +/** + * Testing API provided by webconsole/net/utils/net.js + */ +function run_test() { + // isImage + imageMimeTypes.forEach(mimeType => { + ok(isImage(mimeType)); + }); + + // isHTML + htmlMimeTypes.forEach(mimeType => { + ok(isHTML(mimeType)); + }); + + // getHeaderValue + equal(getHeaderValue(headers, "headerName"), "value1"); + + // isURLEncodedRequest + ok(isURLEncodedRequest(har1)); + ok(isURLEncodedRequest(har2)); + + // isMultiPartRequest + ok(isMultiPartRequest(har3)); +} diff --git a/devtools/client/webconsole/net/test/unit/xpcshell.ini b/devtools/client/webconsole/net/test/unit/xpcshell.ini new file mode 100644 index 000000000..d988a2ad0 --- /dev/null +++ b/devtools/client/webconsole/net/test/unit/xpcshell.ini @@ -0,0 +1,9 @@ +[DEFAULT] +tags = devtools +head = +tail = +firefox-appdir = browser +skip-if = toolkit == 'android' + +[test_json-utils.js] +[test_net-utils.js] |