зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1333385 - Fix base64 json in netmonitor. r=jdescottes
This commit is contained in:
Родитель
79576462dc
Коммит
d1aa9f8545
|
@ -64,7 +64,11 @@ const ResponsePanel = createClass({
|
|||
try {
|
||||
json = JSON.parse(response);
|
||||
} catch (err) {
|
||||
error = err;
|
||||
try {
|
||||
json = JSON.parse(atob(response));
|
||||
} catch (err64) {
|
||||
error = err;
|
||||
}
|
||||
}
|
||||
|
||||
if (/\bjson/.test(mimeType) || json) {
|
||||
|
|
|
@ -16,6 +16,7 @@ support-files =
|
|||
html_frame-subdocument.html
|
||||
html_filter-test-page.html
|
||||
html_infinite-get-page.html
|
||||
html_json-b64.html
|
||||
html_json-custom-mime-test-page.html
|
||||
html_json-long-test-page.html
|
||||
html_json-malformed-test-page.html
|
||||
|
@ -107,6 +108,7 @@ skip-if = (os == 'linux' && debug && bits == 32) # Bug 1303439
|
|||
[browser_net_html-preview.js]
|
||||
[browser_net_icon-preview.js]
|
||||
[browser_net_image-tooltip.js]
|
||||
[browser_net_json-b64.js]
|
||||
[browser_net_json-long.js]
|
||||
[browser_net_json-malformed.js]
|
||||
[browser_net_json_custom_mime.js]
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Tests if JSON responses encoded in base64 are handled correctly.
|
||||
*/
|
||||
|
||||
add_task(function* () {
|
||||
let { L10N } = require("devtools/client/netmonitor/l10n");
|
||||
let { tab, monitor } = yield initNetMonitor(JSON_B64_URL);
|
||||
info("Starting test... ");
|
||||
|
||||
let { document, NetMonitorView } = monitor.panelWin;
|
||||
let { RequestsMenu } = NetMonitorView;
|
||||
|
||||
RequestsMenu.lazyUpdate = false;
|
||||
|
||||
let wait = waitForNetworkEvents(monitor, 1);
|
||||
yield ContentTask.spawn(tab.linkedBrowser, {}, function* () {
|
||||
content.wrappedJSObject.performRequests();
|
||||
});
|
||||
yield wait;
|
||||
|
||||
wait = waitForDOM(document, "#panel-3");
|
||||
EventUtils.sendMouseEvent({ type: "mousedown" },
|
||||
document.getElementById("details-pane-toggle"));
|
||||
document.querySelector("#tab-3 a").click();
|
||||
yield wait;
|
||||
|
||||
let tabpanel = document.querySelector("#panel-3");
|
||||
|
||||
is(tabpanel.querySelector(".response-error-header") === null, true,
|
||||
"The response error header doesn't have the intended visibility.");
|
||||
let jsonView = tabpanel.querySelector(".tree-section .treeLabel") || {};
|
||||
is(jsonView.textContent === L10N.getStr("jsonScopeName"), true,
|
||||
"The response json view has the intended visibility.");
|
||||
is(tabpanel.querySelector(".editor-mount iframe") === null, true,
|
||||
"The response editor doesn't have the intended visibility.");
|
||||
is(tabpanel.querySelector(".response-image-box") === null, true,
|
||||
"The response image box doesn't have the intended visibility.");
|
||||
|
||||
is(tabpanel.querySelectorAll(".tree-section").length, 1,
|
||||
"There should be 1 tree sections displayed in this tabpanel.");
|
||||
is(tabpanel.querySelectorAll(".treeRow:not(.tree-section)").length, 1,
|
||||
"There should be 1 json properties displayed in this tabpanel.");
|
||||
is(tabpanel.querySelectorAll(".empty-notice").length, 0,
|
||||
"The empty notice should not be displayed in this tabpanel.");
|
||||
|
||||
let labels = tabpanel
|
||||
.querySelectorAll("tr:not(.tree-section) .treeLabelCell .treeLabel");
|
||||
let values = tabpanel
|
||||
.querySelectorAll("tr:not(.tree-section) .treeValueCell .objectBox");
|
||||
|
||||
is(labels[0].textContent, "greeting",
|
||||
"The first json property name was incorrect.");
|
||||
is(values[0].textContent, "\"This is a base 64 string.\"",
|
||||
"The first json property value was incorrect.");
|
||||
|
||||
yield teardown(monitor);
|
||||
});
|
|
@ -39,6 +39,7 @@ const JSON_LONG_URL = EXAMPLE_URL + "html_json-long-test-page.html";
|
|||
const JSON_MALFORMED_URL = EXAMPLE_URL + "html_json-malformed-test-page.html";
|
||||
const JSON_CUSTOM_MIME_URL = EXAMPLE_URL + "html_json-custom-mime-test-page.html";
|
||||
const JSON_TEXT_MIME_URL = EXAMPLE_URL + "html_json-text-mime-test-page.html";
|
||||
const JSON_B64_URL = EXAMPLE_URL + "html_json-b64.html";
|
||||
const SORTING_URL = EXAMPLE_URL + "html_sorting-test-page.html";
|
||||
const FILTERING_URL = EXAMPLE_URL + "html_filter-test-page.html";
|
||||
const INFINITE_GET_URL = EXAMPLE_URL + "html_infinite-get-page.html";
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
<!-- Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ -->
|
||||
<!doctype html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
|
||||
<meta http-equiv="Pragma" content="no-cache" />
|
||||
<meta http-equiv="Expires" content="0" />
|
||||
<title>Network Monitor test page</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<p>JSON b64 test</p>
|
||||
|
||||
<script type="text/javascript">
|
||||
function get(aAddress, aCallback) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", aAddress, true);
|
||||
|
||||
xhr.onreadystatechange = function() {
|
||||
if (this.readyState == this.DONE) {
|
||||
aCallback();
|
||||
}
|
||||
};
|
||||
xhr.send(null);
|
||||
}
|
||||
|
||||
function performRequests() {
|
||||
get("sjs_content-type-test-server.sjs?fmt=json-b64", function() {
|
||||
// Done.
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -137,6 +137,14 @@ function handleRequest(request, response) {
|
|||
response.finish();
|
||||
break;
|
||||
}
|
||||
case "json-b64": {
|
||||
response.setStatusLine(request.httpVersion, status, "OK");
|
||||
response.setHeader("Content-Type", "text/json; charset=utf-8", false);
|
||||
setCacheHeaders();
|
||||
response.write(btoa("{ \"greeting\": \"This is a base 64 string.\" }"));
|
||||
response.finish();
|
||||
break;
|
||||
}
|
||||
case "json-long": {
|
||||
let str = "{ \"greeting\": \"Hello long string JSON!\" },";
|
||||
response.setStatusLine(request.httpVersion, status, "OK");
|
||||
|
|
Загрузка…
Ссылка в новой задаче