Bug 646539 - Track client name pref changes and bump score after change; r=philikon

This commit is contained in:
Gregory Szorc 2011-07-26 21:48:50 -07:00
Родитель 44867ffa14
Коммит 00af4ea676
2 изменённых файлов: 68 добавлений и 1 удалений

Просмотреть файл

@ -20,6 +20,7 @@
* Contributor(s):
* Dan Mills <thunder@mozilla.com>
* Philipp von Weitershausen <philipp@weitershausen.de>
* Gregory Szorc <gps@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -77,6 +78,7 @@ ClientEngine.prototype = {
__proto__: SyncEngine.prototype,
_storeObj: ClientStore,
_recordObj: ClientsRec,
_trackerObj: ClientsTracker,
// Always sync client data as it controls other sync behavior
get enabled() true,
@ -208,7 +210,7 @@ ClientEngine.prototype = {
// Override the default behavior to delete bad records from the server.
handleHMACMismatch: function handleHMACMismatch(item, mayRetry) {
this._log.debug("Handling HMAC mismatch for " + item.id);
let base = SyncEngine.prototype.handleHMACMismatch.call(this, item, mayRetry);
if (base != SyncEngine.kRecoveryStrategy.error)
return base;
@ -267,3 +269,36 @@ ClientStore.prototype = {
this._remoteClients = {};
},
};
function ClientsTracker(name) {
Tracker.call(this, name);
Svc.Obs.add("weave:engine:start-tracking", this);
Svc.Obs.add("weave:engine:stop-tracking", this);
}
ClientsTracker.prototype = {
__proto__: Tracker.prototype,
_enabled: false,
observe: function observe(subject, topic, data) {
switch (topic) {
case "weave:engine:start-tracking":
if (!this._enabled) {
Svc.Prefs.observe("client.name", this);
this._enabled = true;
}
break;
case "weave:engine:stop-tracking":
if (this._enabled) {
Svc.Prefs.ignore("clients.name", this);
this._enabled = false;
}
break;
case "nsPref:changed":
this._log.debug("client.name preference changed");
this.addChangedID(Svc.Prefs.get("client.GUID"));
this.score += SCORE_INCREMENT_XLARGE;
break;
}
}
};

Просмотреть файл

@ -207,6 +207,38 @@ add_test(function test_sync() {
}
});
add_test(function test_client_name_change() {
_("Ensure client name change incurs a client record update.");
let tracker = Clients._tracker;
let localID = Clients.localID;
let initialName = Clients.localName;
Svc.Obs.notify("weave:engine:start-tracking");
_("initial name: " + initialName);
// Tracker already has data, so clear it.
tracker.clearChangedIDs();
let initialScore = tracker.score;
do_check_eq(Object.keys(tracker.changedIDs).length, 0);
Svc.Prefs.set("client.name", "new name");
_("new name: " + Clients.localName);
do_check_neq(initialName, Clients.localName);
do_check_eq(Object.keys(tracker.changedIDs).length, 1);
do_check_true(Clients.localID in tracker.changedIDs);
do_check_true(tracker.score > initialScore);
do_check_true(tracker.score >= SCORE_INCREMENT_XLARGE);
Svc.Obs.notify("weave:engine:stop-tracking");
run_next_test();
});
function run_test() {
initTestLogging("Trace");
Log4Moz.repository.getLogger("Sync.Engine.Clients").level = Log4Moz.Level.Trace;