Bug 888778 - Custom binding not applied to inline settings; r=Unfocused
☠☠ backed out by 5e3890536f45 ☠ ☠
authorGeoff Lankow <geoff@darktrojan.net>
Wed, 03 Jul 2013 00:20:51 +1200
changeset 153207 c482e61af458dacec258e6ee060d9d93aeec1ca1
parent 153099 05d3797276d3d8c7d10ddc66e95c99352c2e3cc9
child 153208 5e3890536f457b37bf1ae0876a7f44d53c277c31
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersUnfocused
bugs888778
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 888778 - Custom binding not applied to inline settings; r=Unfocused
toolkit/mozapps/extensions/content/extensions.js
toolkit/mozapps/extensions/test/browser/Makefile.in
toolkit/mozapps/extensions/test/browser/addons/browser_inlinesettings1_custom/binding.xml
toolkit/mozapps/extensions/test/browser/addons/browser_inlinesettings1_custom/bootstrap.js
toolkit/mozapps/extensions/test/browser/addons/browser_inlinesettings1_custom/chrome.manifest
toolkit/mozapps/extensions/test/browser/addons/browser_inlinesettings1_custom/install.rdf
toolkit/mozapps/extensions/test/browser/addons/browser_inlinesettings1_custom/options.xul
toolkit/mozapps/extensions/test/browser/addons/browser_inlinesettings1_custom/string.dtd
toolkit/mozapps/extensions/test/browser/browser_inlinesettings_custom.js
--- a/toolkit/mozapps/extensions/content/extensions.js
+++ b/toolkit/mozapps/extensions/content/extensions.js
@@ -2968,26 +2968,33 @@ var gDetailView = {
       var xhr = new XMLHttpRequest();
       xhr.open("GET", this._addon.optionsURL, true);
       xhr.responseType = "xml";
       xhr.onload = (function fillSettingsRows_onload() {
         var xml = xhr.responseXML;
         var settings = xml.querySelectorAll(":root > setting");
 
         var firstSetting = null;
-        for (let setting of settings) {
+        for (var xmlSetting of settings) {
+          var setting = document.importNode(xmlSetting, true);
 
           var desc = stripTextNodes(setting).trim();
           if (!setting.hasAttribute("desc"))
             setting.setAttribute("desc", desc);
 
           var type = setting.getAttribute("type");
           if (type == "file" || type == "directory")
             setting.setAttribute("fullpath", "true");
 
+          var style = setting.getAttribute("style");
+          if (style) {
+            setting.removeAttribute("style");
+            setting.setAttribute("style", style);
+          }
+
           rows.appendChild(setting);
           var visible = window.getComputedStyle(setting, null).getPropertyValue("display") != "none";
           if (!firstSetting && visible) {
             setting.setAttribute("first-row", true);
             firstSetting = setting;
           }
         }
 
--- a/toolkit/mozapps/extensions/test/browser/Makefile.in
+++ b/toolkit/mozapps/extensions/test/browser/Makefile.in
@@ -54,16 +54,17 @@ MOCHITEST_BROWSER_MAIN = \
   browser_globalwarnings.js \
   browser_globalinformations.js \
   browser_eula.js \
   browser_updateid.js \
   browser_purchase.js \
   browser_openDialog.js \
   browser_types.js \
   browser_inlinesettings.js \
+  browser_inlinesettings_custom.js \
   browser_inlinesettings_info.js \
   browser_tabsettings.js \
   browser_pluginprefs.js \
   browser_CTP_plugins.js \
   $(NULL)
 
 MOCHITEST_BROWSER_SECONDARY = \
   head.js \
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/browser/addons/browser_inlinesettings1_custom/binding.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0"?>
+<bindings xmlns="http://www.mozilla.org/xbl"
+          xmlns:xbl="http://www.mozilla.org/xbl"
+          xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+  <binding id="custom"
+           extends="chrome://mozapps/content/extensions/setting.xml#setting-base">
+    <content>
+      <xul:vbox>
+        <xul:hbox class="preferences-alignment">
+          <xul:label anonid="label" class="preferences-title" flex="1" xbl:inherits="xbl:text=title"/>
+        </xul:hbox>
+        <xul:description class="preferences-description" flex="1" xbl:inherits="xbl:text=desc"/>
+      </xul:vbox>
+      <xul:hbox class="preferences-alignment">
+        <xul:label anonid="input" value="Woah!"/>
+      </xul:hbox>
+    </content>
+  </binding>
+</bindings>
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/browser/addons/browser_inlinesettings1_custom/bootstrap.js
@@ -0,0 +1,8 @@
+function install (params, aReason) {
+}
+function uninstall (params, aReason) {
+}
+function startup (params, aReason) {
+}
+function shutdown (params, aReason) {
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/browser/addons/browser_inlinesettings1_custom/chrome.manifest
@@ -0,0 +1,2 @@
+content inlinesettings ./
+locale inlinesettings en-US ./
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/browser/addons/browser_inlinesettings1_custom/install.rdf
@@ -0,0 +1,19 @@
+<?xml version="1.0" ?>
+<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">
+
+  <Description about="urn:mozilla:install-manifest">
+    <em:id>inlinesettings1@tests.mozilla.org</em:id>
+    <em:name>Inline Settings (Bootstrap)</em:name>
+    <em:version>1</em:version>
+    <em:bootstrap>true</em:bootstrap>
+
+    <em:targetApplication>
+      <Description>
+        <em:id>toolkit@mozilla.org</em:id>
+        <em:minVersion>0</em:minVersion>
+        <em:maxVersion>*</em:maxVersion>
+      </Description>
+    </em:targetApplication>
+  </Description>
+
+</RDF>
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/browser/addons/browser_inlinesettings1_custom/options.xul
@@ -0,0 +1,5 @@
+<?xml version="1.0" ?>
+<!DOCTYPE vbox SYSTEM "chrome://inlinesettings/locale/string.dtd">
+<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+  <setting type="custom" title="&custom.title;" style="background-color: blue; display: -moz-grid-line; -moz-binding: url('chrome://inlinesettings/content/binding.xml#custom');"/>
+</vbox>
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/browser/addons/browser_inlinesettings1_custom/string.dtd
@@ -0,0 +1,1 @@
+<!ENTITY custom.title "Custom">
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/browser/browser_inlinesettings_custom.js
@@ -0,0 +1,92 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+// Tests various aspects of the details view
+
+var gManagerWindow;
+var gCategoryUtilities;
+
+function installAddon(aCallback) {
+  AddonManager.getInstallForURL(TESTROOT + "addons/browser_inlinesettings1_custom.xpi",
+                                function(aInstall) {
+    aInstall.addListener({
+      onInstallEnded: function() {
+        executeSoon(aCallback);
+      }
+    });
+    aInstall.install();
+  }, "application/x-xpinstall");
+}
+
+function test() {
+  waitForExplicitFinish();
+
+  installAddon(function () {
+    open_manager("addons://list/extension", function(aWindow) {
+      gManagerWindow = aWindow;
+      gCategoryUtilities = new CategoryUtilities(gManagerWindow);
+
+      run_next_test();
+    });
+  });
+}
+
+function end_test() {
+  close_manager(gManagerWindow, function() {
+    AddonManager.getAddonByID("inlinesettings1@tests.mozilla.org", function(aAddon) {
+      aAddon.uninstall();
+      finish();
+    });
+  });
+}
+
+// Addon with options.xul, with custom <setting> binding
+add_test(function() {
+  var addon = get_addon_element(gManagerWindow, "inlinesettings1@tests.mozilla.org");
+  is(addon.mAddon.optionsType, AddonManager.OPTIONS_TYPE_INLINE, "Options should be inline type");
+  addon.parentNode.ensureElementIsVisible(addon);
+
+  var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn");
+  is_element_visible(button, "Preferences button should be visible");
+
+  run_next_test();
+});
+
+// Addon with options.xul, also a test for the setting.xml bindings
+add_test(function() {
+  var addon = get_addon_element(gManagerWindow, "inlinesettings1@tests.mozilla.org");
+  addon.parentNode.ensureElementIsVisible(addon);
+
+  var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn");
+  EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
+
+  wait_for_view_load(gManagerWindow, function() {
+    is(gManagerWindow.gViewController.currentViewId,
+       "addons://detail/inlinesettings1%40tests.mozilla.org/preferences",
+       "Current view should scroll to preferences");
+
+    var grid = gManagerWindow.document.getElementById("detail-grid");
+    var settings = grid.querySelectorAll("rows > setting");
+    is(settings.length, 1, "Grid should have settings children");
+
+    ok(settings[0].hasAttribute("first-row"), "First visible row should have first-row attribute");
+
+    var style = window.getComputedStyle(settings[0], null);
+    is(style.getPropertyValue("background-color"), "rgb(0, 0, 255)", "Background color should be set");
+    is(style.getPropertyValue("display"), "-moz-grid-line", "Display should be set");
+    is(style.getPropertyValue("-moz-binding"), 'url("chrome://inlinesettings/content/binding.xml#custom")', "Binding should be set");
+
+    var label = gManagerWindow.document.getAnonymousElementByAttribute(settings[0], "anonid", "label");
+    is(label.textContent, "Custom", "Localized string should be shown");
+
+    var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[0], "anonid", "input");
+    isnot(input, null, "Binding should be applied");
+    is(input.value, "Woah!", "Binding should be applied");
+
+    button = gManagerWindow.document.getElementById("detail-prefs-btn");
+    is_element_hidden(button, "Preferences button should not be visible");
+
+    gCategoryUtilities.openType("extension", run_next_test);
+  });
+});