Backout cset b2bae68e3809 / bug 1055319 due to test failures

This commit is contained in:
Mark Banner 2014-09-01 22:11:03 +01:00
parent 2a773ccbab
commit 122b3557d6
5 changed files with 3 additions and 254 deletions

View File

@ -1582,12 +1582,8 @@ pref("image.mem.max_decoded_image_kb", 256000);
// Enable by default development builds up until early beta
#ifdef EARLY_BETA_OR_EARLIER
pref("loop.enabled", true);
pref("loop.throttled", false);
#else
pref("loop.enabled", true);
pref("loop.throttled", true);
pref("loop.soft_start_ticket_number", -1);
pref("loop.soft_start_hostname", "soft-start.loop-dev.stage.mozaws.net");
pref("loop.enabled", false);
#endif
pref("loop.server", "https://loop.services.mozilla.com");

View File

@ -36,16 +36,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "PanelFrame", "resource:///modules/Panel
* delayedStartup.
*/
initialize: function() {
let buttonNode = CustomizableUI.getWidget("loop-call-button").forWindow(window).node;
if (!Services.prefs.getBoolPref("loop.enabled")) {
buttonNode.hidden = true;
return;
}
if (Services.prefs.getBoolPref("loop.throttled")) {
buttonNode.hidden = true;
MozLoopService.checkSoftStart(buttonNode);
CustomizableUI.getWidget("loop-call-button").forWindow(window).node.hidden = true;
return;
}

View File

@ -10,11 +10,6 @@ const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
// https://github.com/mozilla-services/loop-server/blob/45787d34108e2f0d87d74d4ddf4ff0dbab23501c/loop/errno.json#L6
const INVALID_AUTH_TOKEN = 110;
// Ticket numbers are 24 bits in length.
// The highest valid ticket number is 16777214 (2^24 - 2), so that a "now
// serving" number of 2^24 - 1 is greater than it.
const MAX_SOFT_START_TICKET_NUMBER = 16777214;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Promise.jsm");
@ -54,11 +49,6 @@ XPCOMUtils.defineLazyServiceGetter(this, "uuidgen",
"@mozilla.org/uuid-generator;1",
"nsIUUIDGenerator");
XPCOMUtils.defineLazyServiceGetter(this, "gDNSService",
"@mozilla.org/network/dns-service;1",
"nsIDNSService");
// The current deferred for the registration process. This is set if in progress
// or the registration was successful. This is null if a registration attempt was
// unsuccessful.
@ -615,8 +605,6 @@ this.MozLoopService = {
},
#endif
_DNSService: gDNSService,
set initializeTimerFunc(value) {
gInitializeTimerFunc = value;
},
@ -627,8 +615,7 @@ this.MozLoopService = {
*/
initialize: function() {
// Don't do anything if loop is not enabled.
if (!Services.prefs.getBoolPref("loop.enabled") ||
Services.prefs.getBoolPref("loop.throttled")) {
if (!Services.prefs.getBoolPref("loop.enabled")) {
return;
}
@ -638,97 +625,6 @@ this.MozLoopService = {
}
},
/**
* If we're operating the service in "soft start" mode, and this browser
* isn't already activated, check whether it's time for it to become active.
* If so, activate the loop service.
*
* @param {Object} buttonNode DOM node representing the Loop button -- if we
* change from inactive to active, we need this
* in order to unhide the Loop button.
* @param {Function} doneCb [optional] Callback that is called when the
* check has completed.
*/
checkSoftStart(buttonNode, doneCb) {
if (!Services.prefs.getBoolPref("loop.throttled")) {
if (typeof(doneCb) == "function") {
doneCb(new Error("Throttling is not active"));
}
return;
}
let ticket = Services.prefs.getIntPref("loop.soft_start_ticket_number");
if (!ticket || ticket > MAX_SOFT_START_TICKET_NUMBER || ticket < 0) {
// Ticket value isn't valid (probably isn't set up yet) -- pick a random
// number from 1 to MAX_SOFT_START_TICKET_NUMBER, inclusive, and write it
// into prefs.
ticket = Math.floor(Math.random() * MAX_SOFT_START_TICKET_NUMBER) + 1;
// Floating point numbers can be imprecise, so we need to deal with
// the case that Math.random() effectively rounds to 1.0
if (ticket > MAX_SOFT_START_TICKET_NUMBER) {
ticket = MAX_SOFT_START_TICKET_NUMBER;
}
Services.prefs.setIntPref("loop.soft_start_ticket_number", ticket);
}
let onLookupComplete = (request, record, status) => {
// We don't bother checking errors -- if the DNS query fails,
// we just don't activate this time around. We'll check again on
// next startup.
if (!Components.isSuccessCode(status)) {
if (typeof(doneCb) == "function") {
doneCb(new Error("Error in DNS Lookup: " + status));
}
return;
}
let address = record.getNextAddrAsString().split(".");
if (address.length != 4) {
if (typeof(doneCb) == "function") {
doneCb(new Error("Invalid IP address"));
}
return;
}
if (address[0] != 127) {
if (typeof(doneCb) == "function") {
doneCb(new Error("Throttling IP address is not on localhost subnet"));
}
return
}
// Can't use bitwise operations here because JS treats all bitwise
// operations as 32-bit *signed* integers.
let now_serving = ((parseInt(address[1]) * 0x10000) +
(parseInt(address[2]) * 0x100) +
parseInt(address[3]));
if (now_serving > ticket) {
// Hot diggity! It's our turn! Activate the service.
console.log("MozLoopService: Activating Loop via soft-start");
Services.prefs.setBoolPref("loop.throttled", false);
buttonNode.hidden = false;
this.initialize();
}
if (typeof(doneCb) == "function") {
doneCb(null);
}
};
// We use DNS to propagate the slow-start value, since it has well-known
// scaling properties. Ideally, this would use something more semantic,
// like a TXT record; but we don't support TXT in our DNS resolution (see
// Bug 14328), so we instead treat the lowest 24 bits of the IP address
// corresponding to our "slow start DNS name" as a 24-bit integer. To
// ensure that these addresses aren't routable, the highest 8 bits must
// be "127" (reserved for localhost).
let host = Services.prefs.getCharPref("loop.soft_start_hostname");
let task = this._DNSService.asyncResolve(host,
this._DNSService.RESOLVE_DISABLE_IPV6,
onLookupComplete,
Services.tm.mainThread);
},
/**
* Starts registration of Loop with the push server, and then will register
* with the Loop server. It will return early if already registered.
@ -744,10 +640,6 @@ this.MozLoopService = {
throw new Error("Loop is not enabled");
}
if (Services.prefs.getBoolPref("loop.throttled")) {
throw new Error("Loop is disabled by the soft-start mechanism");
}
return MozLoopServiceInternal.promiseRegisteredWithServers(mockPushHandler);
},

View File

@ -12,6 +12,5 @@ skip-if = !debug
[browser_mozLoop_appVersionInfo.js]
[browser_mozLoop_prefs.js]
[browser_mozLoop_doNotDisturb.js]
[browser_mozLoop_softStart.js]
skip-if = buildapp == 'mulet'
[browser_mozLoop_pluralStrings.js]

View File

@ -1,130 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const SOFT_START_HOSTNAME = "soft-start.example.invalid";
let MockDNSService = {
RESOLVE_DISABLE_IPV6: 32,
nowServing: 0,
resultCode: 0,
ipFirstOctet: 127,
getNowServingAddress: function() {
let ip = this.ipFirstOctet + "." +
((this.nowServing >>> 16) & 0xFF) + "." +
((this.nowServing >>> 8) & 0xFF) + "." +
((this.nowServing) & 0xFF);
info("Using 'now serving' of " + this.nowServing + " (" + ip + ")");
return ip;
},
asyncResolve: function(host, flags, callback) {
let mds = this;
Assert.equal(flags, this.RESOLVE_DISABLE_IPV6,
"AAAA lookup should be disabled");
Assert.equal(host, SOFT_START_HOSTNAME,
"Configured hostname should be used");
callback(null,
{getNextAddrAsString: mds.getNowServingAddress.bind(mds)},
this.resultCode);
}
};
// We need an unfrozen copy of the LoopService so we can monkeypatch it.
let LoopService = {};
for (var prop in MozLoopService) {
if (MozLoopService.hasOwnProperty(prop)) {
LoopService[prop] = MozLoopService[prop];
}
}
LoopService._DNSService = MockDNSService;
let MockButton = {
hidden: true
};
let runCheck = function(expectError) {
return new Promise((resolve, reject) => {
LoopService.checkSoftStart(MockButton, error => {
if ((!!error) != (!!expectError)) {
reject(error);
} else {
resolve(error);
}
})
});
}
add_task(function* test_mozLoop_softStart() {
// Set associated variables to proper values
Services.prefs.setBoolPref("loop.throttled", true);
Services.prefs.setCharPref("loop.soft_start_hostname", SOFT_START_HOSTNAME);
Services.prefs.setIntPref("loop.soft_start_ticket_number", -1);
let throttled;
let ticket;
info("Ensure that we pick a valid ticket number.");
yield runCheck();
throttled = Services.prefs.getBoolPref("loop.throttled");
ticket = Services.prefs.getIntPref("loop.soft_start_ticket_number");
Assert.equal(MockButton.hidden, true, "Button should still be hidden");
Assert.equal(throttled, true, "Feature should still be throttled");
Assert.notEqual(ticket, -1, "Ticket should be changed");
Assert.ok((ticket < 16777214 && ticket > 0), "Ticket should be in range");
// Try some "interesting" ticket numbers
for (ticket of [1, 256, 65535, 10000000, 16777214]) {
MockButton.hidden = true;
Services.prefs.setBoolPref("loop.throttled", true);
Services.prefs.setBoolPref("loop.soft_start", true);
Services.prefs.setIntPref("loop.soft_start_ticket_number", ticket);
info("Ensure that we don't activate when the now serving " +
"number is less than our value.");
MockDNSService.nowServing = ticket - 1;
yield runCheck();
throttled = Services.prefs.getBoolPref("loop.throttled");
Assert.equal(MockButton.hidden, true, "Button should still be hidden");
Assert.equal(throttled, true, "Feature should still be throttled");
info("Ensure that we don't activate when the now serving " +
"number is equal to our value");
MockDNSService.nowServing = ticket;
yield runCheck();
throttled = Services.prefs.getBoolPref("loop.throttled");
Assert.equal(MockButton.hidden, true, "Button should still be hidden");
Assert.equal(throttled, true, "Feature should still be throttled");
info("Ensure that we *do* activate when the now serving " +
"number is greater than our value");
MockDNSService.nowServing = ticket + 1;
yield runCheck();
throttled = Services.prefs.getBoolPref("loop.throttled");
Assert.equal(MockButton.hidden, false, "Button should not be hidden");
Assert.equal(throttled, false, "Feature should be unthrottled");
}
info("Check DNS error behavior");
MockDNSService.nowServing = 0;
MockDNSService.resultCode = 0x80000000;
Services.prefs.setBoolPref("loop.throttled", true);
Services.prefs.setBoolPref("loop.soft_start", true);
MockButton.hidden = true;
yield runCheck(true);
throttled = Services.prefs.getBoolPref("loop.throttled");
Assert.equal(MockButton.hidden, true, "Button should be hidden");
Assert.equal(throttled, true, "Feature should be throttled");
info("Check DNS misconfiguration behavior");
MockDNSService.nowServing = ticket + 1;
MockDNSService.resultCode = 0;
MockDNSService.ipFirstOctet = 6;
Services.prefs.setBoolPref("loop.throttled", true);
Services.prefs.setBoolPref("loop.soft_start", true);
MockButton.hidden = true;
yield runCheck(true);
throttled = Services.prefs.getBoolPref("loop.throttled");
Assert.equal(MockButton.hidden, true, "Button should be hidden");
Assert.equal(throttled, true, "Feature should be throttled");
});