Bug 1257547 - Fix some tests draft
authorMathieu Leplatre <mathieu@mozilla.com>
Tue, 19 Apr 2016 23:35:29 +0200
changeset 353782 facbef60b99b951cbdb79ba6fa2772130a851a85
parent 352726 d2d5316553886726b6dbab9f94a47d1225f73105
child 354202 8002f099c350de8421433ffd5e28807a547d9375
push id15941
push usermleplatre@mozilla.com
push dateTue, 19 Apr 2016 21:42:47 +0000
bugs1257547
milestone48.0a1
Bug 1257547 - Fix some tests MozReview-Commit-ID: 4nFS8C8VcoE
toolkit/mozapps/extensions/nsBlocklistService.js
toolkit/mozapps/extensions/test/xpcshell/test_blocklist_gfx.js
toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini
widget/GfxInfoBase.cpp
--- a/toolkit/mozapps/extensions/nsBlocklistService.js
+++ b/toolkit/mozapps/extensions/nsBlocklistService.js
@@ -655,16 +655,17 @@ Blocklist.prototype = {
         (request.status != 200 && request.status != 0)) {
       LOG("Blocklist::onXMLLoad: there was an error during load");
       return;
     }
 
     var oldAddonEntries = this._addonEntries;
     var oldPluginEntries = this._pluginEntries;
     this._addonEntries = [];
+    this._gfxEntries = [];
     this._pluginEntries = [];
 
     this._loadBlocklistFromString(request.responseText);
     this._blocklistUpdated(oldAddonEntries, oldPluginEntries);
 
     try {
       let path = OS.Path.join(OS.Constants.Path.profileDir, FILE_BLOCKLIST);
       yield OS.File.writeAtomic(path, request.responseText, {tmpPath: path + ".tmp"});
@@ -943,17 +944,19 @@ Blocklist.prototype = {
           break;
         default:
           LOG("Blocklist::_loadBlocklistFromString: ignored entries " + element.localName);
         }
       }
       if (populateCertBlocklist) {
         gCertBlocklistService.saveEntries();
       }
-      this._notifyObserversBlocklistGFX();
+      if (this._gfxEntries.length > 0) {
+        this._notifyObserversBlocklistGFX();
+      }
     }
     catch (e) {
       LOG("Blocklist::_loadBlocklistFromFile: Error constructing blocklist " + e);
       return;
     }
   },
 
   _processItemNodes: function(itemNodes, itemName, handler) {
@@ -1092,16 +1095,17 @@ Blocklist.prototype = {
     blockEntry.blockID = blocklistElement.getAttribute("blockID");
 
     result.push(blockEntry);
   },
 
   // <gfxBlacklistEntry>
   //   <os>WINNT 6.0</os>
   //   <osversion>14</osversion> currently only used for Android
+  //   <versionRange minVersion="42.0" maxVersion="13.0b2"/>
   //   <vendor>0x8086</vendor>
   //   <devices>
   //     <device>0x2582</device>
   //     <device>0x2782</device>
   //   </devices>
   //   <feature> DIRECT3D_10_LAYERS </feature>
   //   <featureStatus> BLOCKED_DRIVER_VERSION </featureStatus>
   //   <driverVersion> 8.52.322.2202 </driverVersion>
@@ -1127,19 +1131,19 @@ Blocklist.prototype = {
         value = [];
         for (let j = 0; j < matchElement.childNodes.length; j++) {
           const childElement = matchElement.childNodes.item(j);
           const childValue = strip(childElement.textContent);
           if (childValue) {
             value.push(childValue);
           }
         }
-      } else if (matchElement.hasAttribute("minVersion")) {
-        value = {minVersion: strip(matchElement.getAttribute("minVersion")),
-                 maxVersion: strip(matchElement.getAttribute("maxVersion"))};
+      } else if (matchElement.localName === "versionRange") {
+        value = {minVersion: strip(matchElement.getAttribute("minVersion") || "*"),
+                 maxVersion: strip(matchElement.getAttribute("maxVersion") || "*")};
       } else {
         value = strip(matchElement.textContent);
       }
       blockEntry[matchElement.localName] = value;
     }
     result.push(blockEntry);
   },
 
@@ -1284,22 +1288,22 @@ Blocklist.prototype = {
 
     return blockEntry.infoURL;
   },
 
   _notifyObserversBlocklistGFX: function () {
     // Notify `GfxInfoBase`, by passing a string serialization.
     // This way we avoid spreading XML structure logics there.
     const payload = this._gfxEntries.map((r) => {
-      return Object.keys(r).map((key) => {
+      return Object.keys(r).sort().filter((k) => !/id|last_modified/.test(k)).map((key) => {
         let value = r[key];
         if (Array.isArray(value)) {
           value = value.join(",");
         } else if (value.hasOwnProperty("minVersion")) {
-          value = `${value.minVersion},${value.maxVersion}`;
+          value = `${value.minVersion || ''},${value.maxVersion || ''}`;
         }
         return `${key}:${value}`;
       }).join("\t");
     }).join("\n");
     Services.obs.notifyObservers(null, "blocklist-data-gfxItems", payload);
   },
 
   _notifyObserversBlocklistUpdated: function() {
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_blocklist_gfx.js
@@ -0,0 +1,52 @@
+const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
+
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+const TEST_APP_ID            = "xpcshell@tests.mozilla.org";
+
+
+const SAMPLE_GFX_RECORD = {
+  "driverVersionComparator": "LESS_THAN_OR_EQUAL",
+  "driverVersion": "8.17.12.5896",
+  "vendor": "0x10de",
+  "blockID": "g36",
+  "feature": "DIRECT3D_9_LAYERS",
+  "devices": ["0x0a6c", "geforce"],
+  "featureStatus": "BLOCKED_DRIVER_VERSION",
+  "last_modified": 1458035931837,
+  "os": "WINNT 6.1",
+  "id": "3f947f16-37c2-4e96-d356-78b26363729b",
+  "versionRange": {"minVersion": null, "maxVersion": "*"}
+};
+
+
+function Blocklist() {
+  let blocklist = Cc["@mozilla.org/extensions/blocklist;1"].
+                  getService().wrappedJSObject;
+  blocklist._clear();
+  return blocklist;
+}
+
+
+function run_test() {
+  run_next_test();
+}
+
+
+add_task(function* test_sends_serialized_data() {
+  const blocklist = Blocklist();
+  blocklist._gfxEntries = [SAMPLE_GFX_RECORD];
+
+  const eventName = "blocklist-data-gfxItems";
+  const expected = "blockID:g36\tdevices:0x0a6c,geforce\tdriverVersion:8.17.12.5896\t" +
+                   "driverVersionComparator:LESS_THAN_OR_EQUAL\tfeature:DIRECT3D_9_LAYERS\t" +
+                   "featureStatus:BLOCKED_DRIVER_VERSION\tos:WINNT 6.1\tvendor:0x10de\t" +
+                   "versionRange:,*";
+  let received;
+  const observe = (subject, topic, data) => { received = data };
+  Services.obs.addObserver(observe, eventName, false);
+  blocklist._notifyObserversBlocklistGFX();
+  equal(received, expected);
+  Services.obs.removeObserver(observe, eventName);
+});
--- a/toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini
+++ b/toolkit/mozapps/extensions/test/xpcshell/xpcshell.ini
@@ -6,16 +6,17 @@ tail =
 firefox-appdir = browser
 dupe-manifest =
 support-files =
   data/**
   xpcshell-shared.ini
 
 [test_addon_path_service.js]
 [test_asyncBlocklistLoad.js]
+[test_blocklist_gfx.js]
 [test_cache_certdb.js]
 run-if = addon_signing
 [test_cacheflush.js]
 [test_DeferredSave.js]
 [test_gmpProvider.js]
 skip-if = appname != "firefox"
 [test_hotfix_cert.js]
 [test_isReady.js]
--- a/widget/GfxInfoBase.cpp
+++ b/widget/GfxInfoBase.cpp
@@ -509,17 +509,21 @@ BlacklistEntriesToDriverInfo(nsTArray<ns
 
 NS_IMETHODIMP
 GfxInfoBase::Observe(nsISupports* aSubject, const char* aTopic,
                      const char16_t* aData)
 {
   if (strcmp(aTopic, "blocklist-data-gfxItems") == 0) {
     nsTArray<GfxDriverInfo> driverInfo;
     nsTArray<nsCString> blacklistEntries;
-    ParseString(NS_ConvertUTF16toUTF8(aData), '\n', blacklistEntries);
+    nsCString utf8Data = NS_ConvertUTF16toUTF8(aData);
+    gfxWarning() << "Received data: " << utf8Data.get();
+    if (utf8Data.Length() > 0) {
+      ParseString(utf8Data, '\n', blacklistEntries);
+    }
     BlacklistEntriesToDriverInfo(blacklistEntries, driverInfo);
     EvaluateDownloadedBlacklist(driverInfo);
   }
 
   return NS_OK;
 }
 
 GfxInfoBase::GfxInfoBase()