Bug 1026395 - Avoid unhandled rejected promise in browser_ruleview_edit-property-increments.js. r=jwalker

This commit is contained in:
Patrick Brosset 2014-07-02 04:39:00 -04:00
parent d7dc3234af
commit cf180363d5
5 changed files with 43 additions and 29 deletions

View File

@ -155,7 +155,8 @@ AutocompletePopup.prototype = {
* Check if the autocomplete popup is open.
*/
get isOpen() {
return this._panel.state == "open" || this._panel.state == "showing";
return this._panel &&
(this._panel.state == "open" || this._panel.state == "showing");
},
/**

View File

@ -257,7 +257,9 @@ Tooltip.prototype = {
},
isShown: function() {
return this.panel.state !== "closed" && this.panel.state !== "hiding";
return this.panel &&
this.panel.state !== "closed" &&
this.panel.state !== "hiding";
},
setSize: function(width, height) {

View File

@ -167,7 +167,7 @@ ElementStyle.prototype = {
dummyElement.parentNode.removeChild(dummyElement);
}
this.dummyElementPromise = null;
});
}, console.error);
},
/**
@ -511,7 +511,7 @@ Rule.prototype = {
this._originalSourceStrings = sourceStrings;
return sourceStrings;
});
}, console.error);
},
/**
@ -1395,6 +1395,7 @@ CssRuleView.prototype = {
},
destroy: function() {
this.isDestroyed = true;
this.clear();
gDummyPromise = null;
@ -1405,9 +1406,9 @@ CssRuleView.prototype = {
this._prefObserver.destroy();
this.element.removeEventListener("copy", this._onCopy);
delete this._onCopy;
this._onCopy = null;
delete this._outputParser;
this._outputParser = null;
// Remove context menu
if (this._contextmenu) {
@ -1858,7 +1859,7 @@ RuleEditor.prototype = {
this.rule.getOriginalSourceStrings().then((strings) => {
sourceLabel.setAttribute("value", strings.short);
sourceLabel.setAttribute("tooltiptext", strings.full);
})
}, console.error);
}
},
@ -2319,6 +2320,10 @@ TextPropertyEditor.prototype = {
* Populate the span based on changes to the TextProperty.
*/
update: function() {
if (this.ruleEditor.ruleView.isDestroyed) {
return;
}
if (this.prop.enabled) {
this.enable.style.removeProperty("visibility");
this.enable.setAttribute("checked", "");

View File

@ -23,18 +23,22 @@ let test = asyncTest(function*() {
});
function createDocument() {
content.document.body.innerHTML = '<div id="test" style="' +
'margin-top:0px;' +
'padding-top: 0px;' +
'color:#000000;' +
'background-color: #000000;" >'+
'</div>';
content.document.body.innerHTML = '' +
'<style>' +
' #test {' +
' margin-top:0px;' +
' padding-top: 0px;' +
' color:#000000;' +
' background-color: #000000;' +
' }' +
'</style>' +
'<div id="test"></div>';
}
function* testMarginIncrements(view) {
info("Testing keyboard increments on the margin property");
let idRuleEditor = getRuleViewRuleEditor(view, 0);
let idRuleEditor = getRuleViewRuleEditor(view, 1);
let marginPropEditor = idRuleEditor.rule.textProps[0].editor;
yield runIncrementTest(marginPropEditor, view, {
@ -52,7 +56,7 @@ function* testMarginIncrements(view) {
function* testVariousUnitIncrements(view) {
info("Testing keyboard increments on values with various units");
let idRuleEditor = getRuleViewRuleEditor(view, 0);
let idRuleEditor = getRuleViewRuleEditor(view, 1);
let paddingPropEditor = idRuleEditor.rule.textProps[1].editor;
yield runIncrementTest(paddingPropEditor, view, {
@ -71,7 +75,7 @@ function* testVariousUnitIncrements(view) {
function* testHexIncrements(view) {
info("Testing keyboard increments with hex colors");
let idRuleEditor = getRuleViewRuleEditor(view, 0);
let idRuleEditor = getRuleViewRuleEditor(view, 1);
let hexColorPropEditor = idRuleEditor.rule.textProps[2].editor;
yield runIncrementTest(hexColorPropEditor, view, {
@ -87,7 +91,7 @@ function* testHexIncrements(view) {
function* testRgbIncrements(view) {
info("Testing keyboard increments with rgb colors");
let idRuleEditor = getRuleViewRuleEditor(view, 0);
let idRuleEditor = getRuleViewRuleEditor(view, 1);
let rgbColorPropEditor = idRuleEditor.rule.textProps[3].editor;
yield runIncrementTest(rgbColorPropEditor, view, {
@ -103,7 +107,7 @@ function* testRgbIncrements(view) {
function* testShorthandIncrements(view) {
info("Testing keyboard increments within shorthand values");
let idRuleEditor = getRuleViewRuleEditor(view, 0);
let idRuleEditor = getRuleViewRuleEditor(view, 1);
let paddingPropEditor = idRuleEditor.rule.textProps[1].editor;
yield runIncrementTest(paddingPropEditor, view, {
@ -119,7 +123,7 @@ function* testShorthandIncrements(view) {
function* testOddCases(view) {
info("Testing some more odd cases");
let idRuleEditor = getRuleViewRuleEditor(view, 0);
let idRuleEditor = getRuleViewRuleEditor(view, 1);
let marginPropEditor = idRuleEditor.rule.textProps[0].editor;
yield runIncrementTest(marginPropEditor, view, {
@ -144,14 +148,11 @@ function* runIncrementTest(propertyEditor, view, tests) {
let editor = yield focusEditableField(propertyEditor.valueSpan);
for(let test in tests) {
yield testIncrement(editor, tests[test], view);
yield testIncrement(editor, tests[test], view, propertyEditor);
}
// Once properties have been set, wait for the inspector to update
yield view.inspector.once("inspector-updated");
}
function* testIncrement(editor, options, view) {
function* testIncrement(editor, options, view, {ruleEditor}) {
editor.input.value = options.start;
let input = editor.input;
@ -163,14 +164,15 @@ function* testIncrement(editor, options, view) {
is(input.value, options.start, "Value initialized at " + options.start);
let onModifications = ruleEditor.rule._applyingModifications;
let onKeyUp = once(input, "keyup");
let key;
key = options.down ? "VK_DOWN" : "VK_UP";
key = options.pageDown ? "VK_PAGE_DOWN" : options.pageUp ? "VK_PAGE_UP" : key;
EventUtils.synthesizeKey(key, {altKey: options.alt, shiftKey: options.shift}, view.doc.defaultView);
EventUtils.synthesizeKey(key, {altKey: options.alt, shiftKey: options.shift},
view.doc.defaultView);
yield onKeyUp;
input = editor.input;
is(input.value, options.end, "Value changed to " + options.end);
yield onModifications;
is(editor.input.value, options.end, "Value changed to " + options.end);
}

View File

@ -2776,6 +2776,10 @@ function nodeDocument(node) {
* See TreeWalker documentation for explanations of the methods.
*/
function DocumentWalker(aNode, aRootWin, aShow, aFilter, aExpandEntityReferences) {
if (!aRootWin.location) {
throw new Error("Got an invalid root window in DocumentWalker");
}
let doc = nodeDocument(aNode);
this.layoutHelpers = new LayoutHelpers(aRootWin);
this.walker = doc.createTreeWalker(doc,