mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-26 04:09:50 +00:00
Bug 924442 - Disallow pretty printing when a source is black boxed; r=vporof
This commit is contained in:
parent
5494868ee2
commit
4481a8549b
@ -1153,17 +1153,27 @@ SourceScripts.prototype = {
|
||||
* The source form.
|
||||
* @param bool aBlackBoxFlag
|
||||
* True to black box the source, false to un-black box it.
|
||||
* @returns Promise
|
||||
* A promize that resolves to [aSource, isBlackBoxed] or rejects to
|
||||
* [aSource, error].
|
||||
*/
|
||||
blackBox: function(aSource, aBlackBoxFlag) {
|
||||
const sourceClient = this.activeThread.source(aSource);
|
||||
sourceClient[aBlackBoxFlag ? "blackBox" : "unblackBox"](({ error, message }) => {
|
||||
const deferred = promise.defer();
|
||||
|
||||
sourceClient[aBlackBoxFlag ? "blackBox" : "unblackBox"](aPacket => {
|
||||
const { error, message } = aPacket;
|
||||
if (error) {
|
||||
let msg = "Couldn't toggle black boxing for " + aSource.url + ": " + message;
|
||||
dumpn(msg);
|
||||
Cu.reportError(msg);
|
||||
return;
|
||||
deferred.reject([aSource, msg]);
|
||||
} else {
|
||||
deferred.resolve([aSource, sourceClient.isBlackBoxed]);
|
||||
}
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -383,6 +383,10 @@ SourcesView.prototype = Heritage.extend(WidgetMethods, {
|
||||
* Pretty print the selected source.
|
||||
*/
|
||||
prettyPrint: function() {
|
||||
if (this._prettyPrintButton.hasAttribute("disabled")) {
|
||||
return;
|
||||
}
|
||||
|
||||
const resetEditor = ([{ url }]) => {
|
||||
// Only set the text when the source is still selected.
|
||||
if (url == this.selectedValue) {
|
||||
@ -691,6 +695,20 @@ SourcesView.prototype = Heritage.extend(WidgetMethods, {
|
||||
document.title = L10N.getFormatStr("DebuggerWindowScriptTitle", script);
|
||||
|
||||
this.maybeShowBlackBoxMessage();
|
||||
this._updatePrettyPrintButtonState();
|
||||
},
|
||||
|
||||
/**
|
||||
* Enable or disable the pretty print button depending on whether the selected
|
||||
* source is black boxed or not.
|
||||
*/
|
||||
_updatePrettyPrintButtonState: function() {
|
||||
const { source } = this.selectedItem.attachment;
|
||||
if (gThreadClient.source(source).isBlackBoxed) {
|
||||
this._prettyPrintButton.setAttribute("disabled", true);
|
||||
} else {
|
||||
this._prettyPrintButton.removeAttribute("disabled");
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@ -715,8 +733,23 @@ SourcesView.prototype = Heritage.extend(WidgetMethods, {
|
||||
* The check listener for the sources container.
|
||||
*/
|
||||
_onSourceCheck: function({ detail: { checked }, target }) {
|
||||
let item = this.getItemForElement(target);
|
||||
DebuggerController.SourceScripts.blackBox(item.attachment.source, !checked);
|
||||
const shouldBlackBox = !checked;
|
||||
|
||||
// Be optimistic that the (un-)black boxing will succeed and enable/disable
|
||||
// the pretty print button immediately. Then, once we actually get the
|
||||
// results from the server, make sure that it is in the correct state again
|
||||
// by calling `_updatePrettyPrintButtonState`.
|
||||
|
||||
if (shouldBlackBox) {
|
||||
this._prettyPrintButton.setAttribute("disabled", true);
|
||||
} else {
|
||||
this._prettyPrintButton.removeAttribute("disabled");
|
||||
}
|
||||
|
||||
const { source } = this.getItemForElement(target).attachment;
|
||||
DebuggerController.SourceScripts.blackBox(source, shouldBlackBox)
|
||||
.then(this._updatePrettyPrintButtonState,
|
||||
this._updatePrettyPrintButtonState);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -122,6 +122,7 @@ support-files =
|
||||
[browser_dbg_pretty-print-07.js]
|
||||
[browser_dbg_pretty-print-08.js]
|
||||
[browser_dbg_pretty-print-09.js]
|
||||
[browser_dbg_pretty-print-10.js]
|
||||
[browser_dbg_progress-listener-bug.js]
|
||||
[browser_dbg_reload-preferred-script-01.js]
|
||||
[browser_dbg_reload-preferred-script-02.js]
|
||||
|
@ -0,0 +1,67 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
/**
|
||||
* Make sure that we disable the pretty print button for black boxed sources,
|
||||
* and that clicking it doesn't do anything.
|
||||
*/
|
||||
|
||||
const TAB_URL = EXAMPLE_URL + "doc_pretty-print.html";
|
||||
|
||||
let gTab, gDebuggee, gPanel, gDebugger;
|
||||
let gEditor, gSources;
|
||||
|
||||
function test() {
|
||||
initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
|
||||
gTab = aTab;
|
||||
gDebuggee = aDebuggee;
|
||||
gPanel = aPanel;
|
||||
gDebugger = gPanel.panelWin;
|
||||
gEditor = gDebugger.DebuggerView.editor;
|
||||
gSources = gDebugger.DebuggerView.Sources;
|
||||
|
||||
waitForSourceShown(gPanel, "code_ugly.js")
|
||||
.then(testSourceIsUgly)
|
||||
.then(blackBoxSource)
|
||||
.then(waitForThreadEvents.bind(null, gPanel, "blackboxchange"))
|
||||
.then(clickPrettyPrintButton)
|
||||
.then(testSourceIsStillUgly)
|
||||
.then(() => closeDebuggerAndFinish(gPanel))
|
||||
.then(null, aError => {
|
||||
ok(false, "Got an error: " + DevToolsUtils.safeErrorString(aError));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function testSourceIsUgly() {
|
||||
ok(!gEditor.getText().contains("\n "),
|
||||
"The source shouldn't be pretty printed yet.");
|
||||
}
|
||||
|
||||
function blackBoxSource() {
|
||||
const checkbox = gDebugger.document.querySelector(
|
||||
".selected .side-menu-widget-item-checkbox");
|
||||
checkbox.click();
|
||||
}
|
||||
|
||||
function clickPrettyPrintButton() {
|
||||
EventUtils.sendMouseEvent({ type: "click" },
|
||||
gDebugger.document.getElementById("pretty-print"),
|
||||
gDebugger);
|
||||
}
|
||||
|
||||
function testSourceIsStillUgly() {
|
||||
const { source } = gSources.selectedItem.attachment;
|
||||
return gDebugger.DebuggerController.SourceScripts.getText(source).then(([, text]) => {
|
||||
ok(!text.contains("\n "));
|
||||
});
|
||||
}
|
||||
|
||||
registerCleanupFunction(function() {
|
||||
gTab = null;
|
||||
gDebuggee = null;
|
||||
gPanel = null;
|
||||
gDebugger = null;
|
||||
gEditor = null;
|
||||
gSources = null;
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user