Bug 1301078 - correctly disable pasted commented-out properties; r?pbro draft
authorTom Tromey <tom@tromey.com>
Wed, 07 Sep 2016 11:08:12 -0600
changeset 411152 955bd038f1b632f34c47635789564f76ad337c67
parent 411151 5db21f7f4efa2eb6d8e59beef7f97f64001b2b6f
child 530678 fc6137c351cead141103d864ccf6969529681e86
push id28842
push userbmo:ttromey@mozilla.com
push dateWed, 07 Sep 2016 17:09:16 +0000
reviewerspbro
bugs1301078
milestone51.0a1
Bug 1301078 - correctly disable pasted commented-out properties; r?pbro MozReview-Commit-ID: 97ueaqvYVVN
devtools/client/inspector/rules/models/rule.js
devtools/client/styleeditor/test/browser.ini
devtools/client/styleeditor/test/browser_styleeditor_syncAddProperty.js
--- a/devtools/client/inspector/rules/models/rule.js
+++ b/devtools/client/inspector/rules/models/rule.js
@@ -183,18 +183,28 @@ Rule.prototype = {
     if (siblingProp) {
       ind = this.textProps.indexOf(siblingProp) + 1;
       this.textProps.splice(ind, 0, prop);
     } else {
       ind = this.textProps.length;
       this.textProps.push(prop);
     }
 
-    this.applyProperties((modifications) => {
+    let addPromise = this.applyProperties((modifications) => {
       modifications.createProperty(ind, name, value, priority);
+    });
+
+    // If not enabled, do a second edit to disable the property.
+    if (!enabled) {
+      addPromise = this.applyProperties((modifications) => {
+        modifications.setPropertyEnabled(ind, name, false);
+      });
+    }
+
+    addPromise.then(() => {
       // Now that the rule has been updated, the server might have given us data
       // that changes the state of the property. Update it now.
       prop.updateEditor();
     });
 
     return prop;
   },
 
--- a/devtools/client/styleeditor/test/browser.ini
+++ b/devtools/client/styleeditor/test/browser.ini
@@ -90,14 +90,15 @@ skip-if = e10s && debug # Bug 1252201 - 
 [browser_styleeditor_sv_keynav.js]
 [browser_styleeditor_sv_resize.js]
 [browser_styleeditor_selectstylesheet.js]
 [browser_styleeditor_sourcemaps.js]
 [browser_styleeditor_sourcemaps_inline.js]
 [browser_styleeditor_sourcemap_large.js]
 [browser_styleeditor_sourcemap_watching.js]
 [browser_styleeditor_sync.js]
+[browser_styleeditor_syncAddProperty.js]
 [browser_styleeditor_syncAddRule.js]
 [browser_styleeditor_syncAlreadyOpen.js]
 [browser_styleeditor_syncEditSelector.js]
 [browser_styleeditor_syncIntoRuleView.js]
 [browser_styleeditor_transition_rule.js]
 [browser_styleeditor_xul.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/styleeditor/test/browser_styleeditor_syncAddProperty.js
@@ -0,0 +1,45 @@
+/* vim: set ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+// Test that adding a new rule is synced to the style editor.
+
+const TESTCASE_URI = TEST_BASE_HTTP + "sync.html";
+
+const expectedText = `
+  body {
+    border-width: 15px;
+    color: red;
+  }
+
+  #testid {
+    font-size: 4em;
+    /*! background-color: yellow; */
+  }
+  `;
+
+add_task(function* () {
+  yield addTab(TESTCASE_URI);
+  let { inspector, view } = yield openRuleView();
+  yield selectNode("#testid", inspector);
+
+  info("Focusing a new property name in the rule-view");
+  let ruleEditor = getRuleViewRuleEditor(view, 1);
+  let editor = yield focusEditableField(view, ruleEditor.closeBrace);
+  is(inplaceEditor(ruleEditor.newPropSpan), editor,
+    "The new property editor has focus");
+
+  let input = editor.input;
+  input.value = "/* background-color: yellow; */";
+
+  info("Pressing return to commit and focus the new value field");
+  let onModifications = view.once("ruleview-changed");
+  EventUtils.synthesizeKey("VK_RETURN", {}, view.styleWindow);
+  yield onModifications;
+
+  let { ui } = yield openStyleEditor();
+  let sourceEditor = yield ui.editors[0].getSourceEditor();
+  let text = sourceEditor.sourceEditor.getText();
+  is(text, expectedText, "selector edits are synced");
+});