Bug 860232 - Function callbacks in jsonp responses should be displayed in the Response tab, r=rcampbell

This commit is contained in:
Victor Porof 2013-04-11 21:11:47 +03:00
parent 9f7c4f4973
commit 9a521bedba
5 changed files with 25 additions and 7 deletions

View File

@ -1048,9 +1048,16 @@ create({ constructor: NetworkDetailsView, proto: MenuContainer.prototype }, {
// Handle json.
if (mimeType.contains("/json")) {
$("#response-content-json-box").hidden = false;
let jsonScope = this._json.addScope("JSON");
let sanitizedText = aString.replace(/^[a-zA-Z0-9_$]+\(|\)$/g, ""); // JSONP
jsonScope.addVar().populate(JSON.parse(sanitizedText), { expanded: true });
let jsonpRegex = /^[a-zA-Z0-9_$]+\(|\)$/g; // JSONP with callback.
let sanitizedJSON = aString.replace(jsonpRegex, "");
let callbackPadding = aString.match(jsonpRegex);
let jsonScopeName = callbackPadding
? L10N.getFormatStr("jsonpScopeName", callbackPadding[0].slice(0, -1))
: L10N.getStr("jsonScopeName");
let jsonScope = this._json.addScope(jsonScopeName);
jsonScope.addVar().populate(JSON.parse(sanitizedJSON), { expanded: true });
jsonScope.expanded = true;
}
// Handle images.

View File

@ -166,7 +166,8 @@ function test() {
let jsonScope = tabpanel.querySelectorAll(".variables-view-scope")[0];
is(jsonScope.querySelector(".name").getAttribute("value"),
"JSON", "The json scope doesn't have the correct title.");
L10N.getStr("jsonScopeName"),
"The json scope doesn't have the correct title.");
is(jsonScope.querySelectorAll(".variables-view-property .name")[0].getAttribute("value"),
"greeting", "The first json property name was incorrect.");

View File

@ -2,7 +2,7 @@
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Tests if JSONP responses are handled correctly.
* Tests if very long JSON responses are handled correctly.
*/
function test() {
@ -70,7 +70,8 @@ function test() {
let values = ".variables-view-property .value";
is(jsonScope.querySelector(".name").getAttribute("value"),
"JSON", "The json scope doesn't have the correct title.");
L10N.getStr("jsonScopeName"),
"The json scope doesn't have the correct title.");
is(jsonScope.querySelectorAll(names)[0].getAttribute("value"),
"0", "The first json property name was incorrect.");

View File

@ -62,7 +62,8 @@ function test() {
let jsonScope = tabpanel.querySelectorAll(".variables-view-scope")[0];
is(jsonScope.querySelector(".name").getAttribute("value"),
"JSON", "The json scope doesn't have the correct title.");
L10N.getFormatStr("jsonpScopeName", "$_0123Fun"),
"The json scope doesn't have the correct title.");
is(jsonScope.querySelectorAll(".variables-view-property .name")[0].getAttribute("value"),
"greeting", "The first json property name was incorrect.");

View File

@ -89,6 +89,14 @@ responseCookies=Response cookies
# in the response tab of the network details pane for the JSON filtering input.
jsonFilterText=Filter properties
# LOCALIZATION NOTE (jsonScopeName): This is the text displayed
# in the response tab of the network details pane for a JSON scope.
jsonScopeName=JSON
# LOCALIZATION NOTE (jsonpScopeName): This is the text displayed
# in the response tab of the network details pane for a JSONP scope.
jsonpScopeName=JSONP → callback %S()
# LOCALIZATION NOTE (networkMenu.size): This is the label displayed
# in the network menu specifying the size of a request (in kilobytes).
networkMenu.sizeKB=%S KB