Bug 816306: Part 2 - Report update HTTP errors to Gaia, and accompanying tests. r=fabrice

This commit is contained in:
Marshall Culpepper 2013-01-10 18:13:39 +01:00
Родитель 938ddccb0b
Коммит 1430f80313
6 изменённых файлов: 102 добавлений и 2 удалений

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

@ -23,6 +23,7 @@ const PREF_APPLY_IDLE_TIMEOUT = "b2g.update.apply-idle-timeout";
const NETWORK_ERROR_OFFLINE = 111;
const FILE_ERROR_TOO_BIG = 112;
const HTTP_ERROR_OFFSET = 1000;
const STATE_DOWNLOADING = 'downloading';
@ -72,8 +73,18 @@ UpdateCheckListener.prototype = {
},
onError: function UCL_onError(request, update) {
if (update.errorCode == NETWORK_ERROR_OFFLINE) {
// nsIUpdate uses a signed integer for errorCode while any platform errors
// require all 32 bits.
let errorCode = update.errorCode >>> 0;
let isNSError = (errorCode >>> 31) == 1;
if (errorCode == NETWORK_ERROR_OFFLINE) {
this._updatePrompt.setUpdateStatus("retry-when-online");
} else if (isNSError) {
this._updatePrompt.setUpdateStatus("check-error-" + errorCode);
} else if (errorCode > HTTP_ERROR_OFFSET) {
let httpErrorCode = errorCode - HTTP_ERROR_OFFSET;
this._updatePrompt.setUpdateStatus("check-error-http-" + httpErrorCode);
}
Services.aus.QueryInterface(Ci.nsIUpdateCheckListener);

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

@ -0,0 +1 @@
<updates

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

@ -0,0 +1,2 @@
#!/system/bin/sh
print "Status: $QUERY_STRING\r\n\r\n"

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

@ -2,6 +2,7 @@
smoketest = false
[update_test_ota_simple.py]
[update_test_status.py]
; smoketests
[include:update-smoketests.ini]

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

@ -0,0 +1,56 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
const TEST_URL = "http://localhost";
setPref("b2g.update.apply-idle-timeout", 0);
setPref("app.update.backgroundErrors", 0);
setPref("app.update.backgroundMaxErrors", 100);
function forceCheckAndTestStatus(status, next) {
let mozSettings = window.navigator.mozSettings;
let forceSent = false;
mozSettings.addObserver("gecko.updateStatus", function statusObserver(setting) {
if (!forceSent) {
return;
}
mozSettings.removeObserver("gecko.updateStatus", statusObserver);
is(setting.settingValue, status, "gecko.updateStatus");
next();
});
sendContentEvent("force-update-check");
forceSent = true;
}
function testBadXml() {
setPref("app.update.url.override", TEST_URL + "/bad.xml");
forceCheckAndTestStatus("check-error-http-200", testAccessDenied);
}
function testAccessDenied() {
setPref("app.update.url.override", TEST_URL + "/cgi-bin/err.cgi?403");
forceCheckAndTestStatus("check-error-http-403", testNoUpdateXml);
}
function testNoUpdateXml() {
setPref("app.update.url.override", TEST_URL + "/none.html");
forceCheckAndTestStatus("check-error-http-404", testInternalServerError);
}
function testInternalServerError() {
setPref("app.update.url.override", TEST_URL + "/cgi-bin/err.cgi?500");
forceCheckAndTestStatus("check-error-http-500", testBadHostStatus);
}
function testBadHostStatus() {
setPref("app.update.url.override", "http://bad-host-doesnt-exist-sorry.com");
forceCheckAndTestStatus("check-error-" + Cr.NS_ERROR_UNKNOWN_HOST, cleanUp);
}
// Update test functions
function preUpdate() {
testBadXml();
}

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

@ -0,0 +1,29 @@
from b2g_update_test import B2GUpdateTestCase, OTA, FOTA
import os
this_dir = os.path.abspath(os.path.dirname(__file__))
update_test_dir = os.path.dirname(this_dir)
class UpdateTestStatus(B2GUpdateTestCase):
B2G_UPDATES = "/data/local/b2g-updates"
def setUp(self):
# Stage a phony update to get the http server up and running
mar_path = os.path.join(update_test_dir, "unit", "data", "simple.mar")
self.stage_update(complete_mar=mar_path)
bad_xml = os.path.join(this_dir, "data", "bad.xml")
err_cgi = os.path.join(this_dir, "data", "err.cgi")
self.runner.adb.push(bad_xml, self.B2G_UPDATES + "/bad.xml")
self.runner.adb.shell("mkdir " + self.B2G_UPDATES + "/cgi-bin")
self.runner.adb.push(err_cgi, self.B2G_UPDATES + "/cgi-bin/err.cgi")
self.runner.adb.shell("chmod 755 " + self.B2G_UPDATES + "/cgi-bin/err.cgi")
B2GUpdateTestCase.setUp(self)
def test_status(self):
self.marionette.set_script_timeout(30 * 1000)
status_js = os.path.join(os.path.dirname(__file__),
"update_test_status.js")
self.execute_update_test(status_js)