Merge m-c to inbound.

This commit is contained in:
Ryan VanderMeulen 2013-05-20 22:28:32 -04:00
commit acb2d9cc01
18 changed files with 277 additions and 51 deletions

View File

@ -70,19 +70,20 @@ function addTab(aURL, aOnload, aWindow) {
targetBrowser.selectedTab = targetBrowser.addTab(aURL);
let tab = targetBrowser.selectedTab;
let win = tab.linkedBrowser.contentWindow;
let browser = tab.linkedBrowser;
let win = browser.contentWindow;
let expectedReadyState = aURL == "about:blank" ? ["interactive", "complete"] : ["complete"];
if (aOnload) {
let handler = function() {
if (tab.linkedBrowser.currentURI.spec != aURL ||
if (browser.currentURI.spec != aURL ||
expectedReadyState.indexOf((win.document || {}).readyState) == -1) {
return;
}
tab.removeEventListener("load", handler, false);
browser.removeEventListener("load", handler, true);
executeSoon(aOnload);
}
tab.addEventListener("load", handler, false);
browser.addEventListener("load", handler, true);
}
return tab;

View File

@ -221,6 +221,7 @@ TabTarget.prototype = {
if (this._tab && this._tab.linkedBrowser) {
return this._tab.linkedBrowser.contentWindow;
}
return null;
},
get name() {

View File

@ -21,7 +21,7 @@ function test() {
statusText: "OK",
type: "xml",
fullMimeType: "text/xml; charset=utf-8",
size: L10N.getFormatStr("networkMenu.sizeKB", 0.04),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.04),
time: true
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(1),
@ -30,7 +30,7 @@ function test() {
statusText: "OK",
type: "css",
fullMimeType: "text/css; charset=utf-8",
size: L10N.getFormatStr("networkMenu.sizeKB", 0.03),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.03),
time: true
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(2),
@ -39,7 +39,7 @@ function test() {
statusText: "OK",
type: "js",
fullMimeType: "application/javascript; charset=utf-8",
size: L10N.getFormatStr("networkMenu.sizeKB", 0.03),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.03),
time: true
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(3),
@ -48,7 +48,7 @@ function test() {
statusText: "OK",
type: "json",
fullMimeType: "application/json; charset=utf-8",
size: L10N.getFormatStr("networkMenu.sizeKB", 0.02),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.02),
time: true
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(4),
@ -57,7 +57,7 @@ function test() {
statusText: "Not Found",
type: "html",
fullMimeType: "text/html; charset=utf-8",
size: L10N.getFormatStr("networkMenu.sizeKB", 0.02),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.02),
time: true
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(5),
@ -66,7 +66,7 @@ function test() {
statusText: "OK",
type: "png",
fullMimeType: "image/png",
size: L10N.getFormatStr("networkMenu.sizeKB", 0.75),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.75),
time: true
});

View File

@ -21,7 +21,7 @@ function test() {
statusText: "OK",
type: "json",
fullMimeType: "text/json; charset=utf-8",
size: L10N.getFormatStr("networkMenu.sizeKB", 0.04),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.04),
time: true
});

View File

@ -22,7 +22,7 @@ function test() {
statusText: "Och Aye",
type: "plain",
fullMimeType: "text/plain; charset=utf-8",
size: L10N.getFormatStr("networkMenu.sizeKB", 0.01),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.01),
time: true
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(1),
@ -31,7 +31,7 @@ function test() {
statusText: "Och Aye",
type: "plain",
fullMimeType: "text/plain; charset=utf-8",
size: L10N.getFormatStr("networkMenu.sizeKB", 0.01),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.01),
time: true
});

View File

@ -166,7 +166,7 @@ function test() {
verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, {
type: "plain",
fullMimeType: "text/plain; charset=utf-8",
size: L10N.getFormatStr("networkMenu.sizeKB", 0.01),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.01),
});
});
@ -185,7 +185,7 @@ function test() {
verifyRequestItemTarget(requestItem, "GET", SIMPLE_SJS, {
type: "plain",
fullMimeType: "text/plain; charset=utf-8",
size: L10N.getFormatStr("networkMenu.sizeKB", 0.01),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.01),
});
});

View File

@ -176,7 +176,7 @@ function test() {
statusText: "Switching Protocols",
type: "plain",
fullMimeType: "text/plain; charset=utf-8",
size: L10N.getFormatStr("networkMenu.sizeKB", 0),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0),
time: true
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(b),
@ -185,7 +185,7 @@ function test() {
statusText: "Created",
type: "plain",
fullMimeType: "text/plain; charset=utf-8",
size: L10N.getFormatStr("networkMenu.sizeKB", 0.02),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.02),
time: true
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(c),
@ -194,7 +194,7 @@ function test() {
statusText: "See Other",
type: "plain",
fullMimeType: "text/plain; charset=utf-8",
size: L10N.getFormatStr("networkMenu.sizeKB", 0),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0),
time: true
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(d),
@ -203,7 +203,7 @@ function test() {
statusText: "Not Found",
type: "plain",
fullMimeType: "text/plain; charset=utf-8",
size: L10N.getFormatStr("networkMenu.sizeKB", 0.02),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.02),
time: true
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(e),
@ -212,7 +212,7 @@ function test() {
statusText: "Not Implemented",
type: "plain",
fullMimeType: "text/plain; charset=utf-8",
size: L10N.getFormatStr("networkMenu.sizeKB", 0.02),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.02),
time: true
});

View File

@ -181,7 +181,7 @@ function test() {
statusText: "Meh",
type: "1",
fullMimeType: "text/1",
size: L10N.getFormatStr("networkMenu.sizeKB", 0),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0),
time: true
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(b),
@ -191,7 +191,7 @@ function test() {
statusText: "Meh",
type: "2",
fullMimeType: "text/2",
size: L10N.getFormatStr("networkMenu.sizeKB", 0.01),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.01),
time: true
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(c),
@ -201,7 +201,7 @@ function test() {
statusText: "Meh",
type: "3",
fullMimeType: "text/3",
size: L10N.getFormatStr("networkMenu.sizeKB", 0.02),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.02),
time: true
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(d),
@ -211,7 +211,7 @@ function test() {
statusText: "Meh",
type: "4",
fullMimeType: "text/4",
size: L10N.getFormatStr("networkMenu.sizeKB", 0.03),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.03),
time: true
});
verifyRequestItemTarget(RequestsMenu.getItemAtIndex(e),
@ -221,7 +221,7 @@ function test() {
statusText: "Meh",
type: "5",
fullMimeType: "text/5",
size: L10N.getFormatStr("networkMenu.sizeKB", 0.04),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.04),
time: true
});

View File

@ -118,7 +118,7 @@ function test() {
statusText: "Meh",
type: "1",
fullMimeType: "text/1",
size: L10N.getFormatStr("networkMenu.sizeKB", 0),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0),
time: true
});
}
@ -130,7 +130,7 @@ function test() {
statusText: "Meh",
type: "2",
fullMimeType: "text/2",
size: L10N.getFormatStr("networkMenu.sizeKB", 0.01),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.01),
time: true
});
}
@ -142,7 +142,7 @@ function test() {
statusText: "Meh",
type: "3",
fullMimeType: "text/3",
size: L10N.getFormatStr("networkMenu.sizeKB", 0.02),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.02),
time: true
});
}
@ -154,7 +154,7 @@ function test() {
statusText: "Meh",
type: "4",
fullMimeType: "text/4",
size: L10N.getFormatStr("networkMenu.sizeKB", 0.03),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.03),
time: true
});
}
@ -166,7 +166,7 @@ function test() {
statusText: "Meh",
type: "5",
fullMimeType: "text/5",
size: L10N.getFormatStr("networkMenu.sizeKB", 0.04),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.04),
time: true
});
}

View File

@ -24,7 +24,7 @@ function test() {
statusText: "Switching Protocols",
type: "plain",
fullMimeType: "text/plain; charset=utf-8",
size: L10N.getFormatStr("networkMenu.sizeKB", 0),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0),
time: true
});
verifyRequestItemTarget(requestItems[1] = RequestsMenu.getItemAtIndex(1),
@ -33,7 +33,7 @@ function test() {
statusText: "Created",
type: "plain",
fullMimeType: "text/plain; charset=utf-8",
size: L10N.getFormatStr("networkMenu.sizeKB", 0.02),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.02),
time: true
});
verifyRequestItemTarget(requestItems[2] = RequestsMenu.getItemAtIndex(2),
@ -42,7 +42,7 @@ function test() {
statusText: "See Other",
type: "plain",
fullMimeType: "text/plain; charset=utf-8",
size: L10N.getFormatStr("networkMenu.sizeKB", 0),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0),
time: true
});
verifyRequestItemTarget(requestItems[3] = RequestsMenu.getItemAtIndex(3),
@ -51,7 +51,7 @@ function test() {
statusText: "Not Found",
type: "plain",
fullMimeType: "text/plain; charset=utf-8",
size: L10N.getFormatStr("networkMenu.sizeKB", 0.02),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.02),
time: true
});
verifyRequestItemTarget(requestItems[4] = RequestsMenu.getItemAtIndex(4),
@ -60,7 +60,7 @@ function test() {
statusText: "Not Implemented",
type: "plain",
fullMimeType: "text/plain; charset=utf-8",
size: L10N.getFormatStr("networkMenu.sizeKB", 0.02),
size: L10N.getFormatStrWithNumbers("networkMenu.sizeKB", 0.02),
time: true
});

View File

@ -52,9 +52,10 @@ function addTab(aUrl, aWindow) {
targetWindow.focus();
let tab = targetBrowser.selectedTab = targetBrowser.addTab(aUrl);
let browser = tab.linkedBrowser;
tab.addEventListener("load", function onLoad() {
tab.removeEventListener("load", onLoad, true);
browser.addEventListener("load", function onLoad() {
browser.removeEventListener("load", onLoad, true);
deferred.resolve(tab);
}, true);

View File

@ -203,6 +203,20 @@ ViewHelpers.L10N.prototype = {
return this.stringBundle.formatStringFromName(aName, aArgs, aArgs.length);
},
/**
* L10N shortcut function for numeric arguments that need to be formatted.
* All numeric arguments will be fixed to 2 decimals and given a localized
* decimal separator. Other arguments will be left alone.
* @param string aName
* @param array aArgs
* @return string
*/
getFormatStrWithNumbers: function(aName, ...aArgs) {
let newArgs = aArgs.map(x => (typeof x == 'number' ?
this.numberWithDecimals(x, 2) : x));
return this.stringBundle.formatStringFromName(aName, newArgs, newArgs.length);
},
/**
* Converts a number to a locale-aware string format and keeps a certain
* number of decimals.

View File

@ -1381,10 +1381,13 @@ PauseScopedActor.prototype = {
* The url of the source we are representing.
* @param aThreadActor ThreadActor
* The current thread actor.
* @param aSourceMap SourceMapConsumer
* Optional. The source map that introduced this source, if available.
*/
function SourceActor(aUrl, aThreadActor) {
function SourceActor(aUrl, aThreadActor, aSourceMap=null) {
this._threadActor = aThreadActor;
this._url = aUrl;
this._sourceMap = aSourceMap;
}
SourceActor.prototype = {
@ -1412,17 +1415,33 @@ SourceActor.prototype = {
* Handler for the "source" packet.
*/
onSource: function SA_onSource(aRequest) {
return fetch(this._url)
.then(function(aSource) {
let sourceContent = null;
if (this._sourceMap) {
sourceContent = this._sourceMap.sourceContentFor(this._url);
}
if (sourceContent) {
return {
from: this.actorID,
source: this.threadActor.createValueGrip(
sourceContent, this.threadActor.threadLifetimePool)
};
}
// XXX bug 865252: Don't load from the cache if this is a source mapped
// source because we can't guarantee that the cache has the most up to date
// content for this source like we can if it isn't source mapped.
return fetch(this._url, { loadFromCache: !this._sourceMap })
.then((aSource) => {
return this.threadActor.createValueGrip(
aSource, this.threadActor.threadLifetimePool);
}.bind(this))
.then(function (aSourceGrip) {
})
.then((aSourceGrip) => {
return {
from: this.actorID,
source: aSourceGrip
};
}.bind(this), function (aError) {
}, (aError) => {
let msg = "Got an exception during SA_onSource: " + aError +
"\n" + aError.stack;
Cu.reportError(msg);
@ -1432,7 +1451,7 @@ SourceActor.prototype = {
"error": "loadSourceError",
"message": "Could not load the source for " + this._url + "."
};
}.bind(this));
});
}
};
@ -2435,10 +2454,13 @@ ThreadSources.prototype = {
* Right now this takes a URL, but in the future it should
* take a Debugger.Source. See bug 637572.
*
* @param string the source URL.
* @param String aURL
* The source URL.
* @param optional SourceMapConsumer aSourceMap
* The source map that introduced this source.
* @returns a SourceActor representing the source or null.
*/
source: function TS_source(aURL) {
source: function TS_source(aURL, aSourceMap=null) {
if (!this._allow(aURL)) {
return null;
}
@ -2447,7 +2469,7 @@ ThreadSources.prototype = {
return this._sourceActors[aURL];
}
let actor = new SourceActor(aURL, this._thread);
let actor = new SourceActor(aURL, this._thread, aSourceMap);
this._thread.threadLifetimePool.addActor(actor);
this._sourceActors[aURL] = actor;
try {
@ -2469,7 +2491,7 @@ ThreadSources.prototype = {
return this.sourceMap(aScript)
.then((aSourceMap) => {
return [
this.source(s) for (s of aSourceMap.sources)
this.source(s, aSourceMap) for (s of aSourceMap.sources)
];
}, (e) => {
reportError(e);
@ -2643,7 +2665,7 @@ function isNotNull(aThing) {
* without relying on caching when we can (not for eval, etc.):
* http://www.softwareishard.com/blog/firebug/nsitraceablechannel-intercept-http-traffic/
*/
function fetch(aURL) {
function fetch(aURL, aOptions={ loadFromCache: true }) {
let deferred = defer();
let scheme;
let url = aURL.split(" -> ").pop();
@ -2710,7 +2732,9 @@ function fetch(aURL) {
}
};
channel.loadFlags = channel.LOAD_FROM_CACHE;
channel.loadFlags = aOptions.loadFromCache
? channel.LOAD_FROM_CACHE
: channel.LOAD_BYPASS_CACHE;
channel.asyncOpen(streamListener, null);
break;
}

View File

@ -207,3 +207,18 @@ function readFile(aFileName) {
s.close();
}
}
function writeFile(aFileName, aContent) {
let file = do_get_file(aFileName, true);
let stream = Cc["@mozilla.org/network/file-output-stream;1"]
.createInstance(Ci.nsIFileOutputStream);
stream.init(file, -1, -1, 0);
try {
do {
let numWritten = stream.write(aContent, aContent.length);
aContent = aContent.slice(numWritten);
} while (aContent.length > 0);
} finally {
stream.close();
}
}

View File

@ -0,0 +1,86 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Check that we can load sources whose content is embedded in the
* "sourcesContent" field of a source map.
*/
var gDebuggee;
var gClient;
var gThreadClient;
Components.utils.import("resource:///modules/devtools/SourceMap.jsm");
function run_test()
{
initTestDebuggerServer();
gDebuggee = addTestGlobal("test-source-map");
gClient = new DebuggerClient(DebuggerServer.connectPipe());
gClient.connect(function() {
attachTestTabAndResume(gClient, "test-source-map", function(aResponse, aTabClient, aThreadClient) {
gThreadClient = aThreadClient;
test_source_content();
});
});
do_test_pending();
}
function test_source_content()
{
let numNewSources = 0;
gClient.addListener("newSource", function _onNewSource(aEvent, aPacket) {
if (++numNewSources !== 3) {
return;
}
gClient.removeListener("newSource", _onNewSource);
gThreadClient.getSources(function (aResponse) {
do_check_true(!aResponse.error, "Should not get an error");
testContents(aResponse.sources, () => {
finishClient(gClient);
});
});
});
let node = new SourceNode(null, null, null, [
new SourceNode(1, 0, "a.js", "function a() { return 'a'; }\n"),
new SourceNode(1, 0, "b.js", "function b() { return 'b'; }\n"),
new SourceNode(1, 0, "c.js", "function c() { return 'c'; }\n"),
]);
node.setSourceContent("a.js", "content for a.js");
node.setSourceContent("b.js", "content for b.js");
node.setSourceContent("c.js", "content for c.js");
let { code, map } = node.toStringWithSourceMap({
file: "abc.js"
});
code += "//@ sourceMappingURL=data:text/json;base64," + btoa(map.toString());
Components.utils.evalInSandbox(code, gDebuggee, "1.8",
"http://example.com/www/js/abc.js", 1);
}
function testContents(aSources, aCallback) {
if (aSources.length === 0) {
return aCallback();
}
let source = aSources[0];
let sourceClient = gThreadClient.source(aSources[0]);
sourceClient.source((aResponse) => {
do_check_true(!aResponse.error,
"Should not get an error loading the source from sourcesContent");
let expectedContent = "content for " + source.url;
do_check_eq(aResponse.source, expectedContent,
"Should have the expected source content");
testContents(aSources.slice(1), aCallback);
});
}

View File

@ -0,0 +1,67 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Test that we don't permanently cache sources from source maps.
*/
var gDebuggee;
var gClient;
var gThreadClient;
Components.utils.import("resource:///modules/devtools/SourceMap.jsm");
function run_test()
{
initTestDebuggerServer();
gDebuggee = addTestGlobal("test-source-map");
gClient = new DebuggerClient(DebuggerServer.connectPipe());
gClient.connect(function() {
attachTestTabAndResume(gClient, "test-source-map", function(aResponse, aTabClient, aThreadClient) {
gThreadClient = aThreadClient;
test_cached_original_sources();
});
});
do_test_pending();
}
function test_cached_original_sources()
{
writeFile("temp.foobar", "initial content");
gClient.addOneTimeListener("newSource", onNewSource);
let node = new SourceNode(1, 0,
getFileUrl("temp.foobar"),
"function funcFromTemp() {}\n");
let { code, map } = node.toStringWithSourceMap({
file: "abc.js"
});
code += "//@ sourceMappingURL=data:text/json;base64," + btoa(map.toString());
Components.utils.evalInSandbox(code, gDebuggee, "1.8",
"http://example.com/www/js/abc.js", 1);
}
function onNewSource(aEvent, aPacket) {
let sourceClient = gThreadClient.source(aPacket.source);
sourceClient.source(function (aResponse) {
do_check_true(!aResponse.error,
"Should not be an error grabbing the source");
do_check_eq(aResponse.source, "initial content",
"The correct source content should be sent");
writeFile("temp.foobar", "new content");
sourceClient.source(function (aResponse) {
do_check_true(!aResponse.error,
"Should not be an error grabbing the source");
do_check_eq(aResponse.source, "new content",
"The correct source content should not be cached, so we should get the new content");
do_get_file("temp.foobar").remove(false);
finishClient(gClient);
});
});
}

View File

@ -87,6 +87,10 @@ reason = bug 820380
[test_sourcemaps-05.js]
skip-if = toolkit == "gonk"
reason = bug 820380
[test_sourcemaps-06.js]
[test_sourcemaps-07.js]
skip-if = toolkit == "gonk"
reason = bug 820380
[test_objectgrips-01.js]
[test_objectgrips-02.js]
[test_objectgrips-03.js]

View File

@ -56,13 +56,26 @@ function WebConsoleActor(aConnection, aParentActor)
if (aParentActor instanceof BrowserTabActor &&
aParentActor.browser instanceof Ci.nsIDOMWindow) {
this._window = aParentActor.browser;
// B2G tab actor |this.browser| points to a DOM chrome window, not
// a xul:browser element.
//
// TODO: bug 802246 - b2g has only one tab actor, the shell.xul, which is
// not properly supported by the console actor - see bug for details.
//
// Below we work around the problem: selecting the shell.xul tab actor
// behaves as if the user picked the global console actor.
//this._window = aParentActor.browser;
this._window = Services.wm.getMostRecentWindow("navigator:browser");
this._isGlobalActor = true;
}
else if (aParentActor instanceof BrowserTabActor &&
aParentActor.browser instanceof Ci.nsIDOMElement) {
// Firefox for desktop tab actor |this.browser| points to the xul:browser
// element.
this._window = aParentActor.browser.contentWindow;
}
else {
// In all other cases we should behave as the global console actor.
this._window = Services.wm.getMostRecentWindow("navigator:browser");
this._isGlobalActor = true;
}