зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1281511 - Add getAndroidSdk() to Mochitest SimpleTest.js, r=gbrown, snorp.
This commit is contained in:
Родитель
50e458a92b
Коммит
d111f0ca3f
|
@ -1626,3 +1626,33 @@ window.onerror = function simpletestOnerror(errorMsg, url, lineNumber,
|
|||
SimpleTest.executeSoon(SimpleTest.finish);
|
||||
}
|
||||
};
|
||||
|
||||
// Lifted from dom/media/test/manifest.js
|
||||
// Make sure to not touch navigator in here, since we want to push prefs that
|
||||
// will affect the APIs it exposes, but the set of exposed APIs is determined
|
||||
// when Navigator.prototype is created. So if we touch navigator before pushing
|
||||
// the prefs, the APIs it exposes will not take those prefs into account. We
|
||||
// work around this by using a navigator object from a different global for our
|
||||
// UA string testing.
|
||||
var gAndroidSdk = null;
|
||||
function getAndroidSdk() {
|
||||
if (gAndroidSdk === null) {
|
||||
var iframe = document.documentElement.appendChild(document.createElement("iframe"));
|
||||
iframe.style.display = "none";
|
||||
var nav = iframe.contentWindow.navigator;
|
||||
if (nav.userAgent.indexOf("Mobile") == -1 &&
|
||||
nav.userAgent.indexOf("Tablet") == -1) {
|
||||
gAndroidSdk = -1;
|
||||
} else {
|
||||
// See nsSystemInfo.cpp, the getProperty('version') returns different value
|
||||
// on each platforms, so we need to distinguish the android and B2G platform.
|
||||
var versionString = nav.userAgent.indexOf("Android") != -1 ?
|
||||
'version' : 'sdk_version';
|
||||
gAndroidSdk = SpecialPowers.Cc['@mozilla.org/system-info;1']
|
||||
.getService(SpecialPowers.Ci.nsIPropertyBag2)
|
||||
.getProperty(versionString);
|
||||
}
|
||||
document.documentElement.removeChild(iframe);
|
||||
}
|
||||
return gAndroidSdk;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче