зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1098470 - Move manifest.* scope from navigator.getFeature to navigator.hasFeature. r=ehsan
This commit is contained in:
Родитель
7bab8ab93e
Коммит
ac0f041896
|
@ -1414,6 +1414,19 @@ Navigator::GetFeature(const nsAString& aName, ErrorResult& aRv)
|
|||
} // hardware.memory
|
||||
#endif
|
||||
|
||||
p->MaybeResolve(JS::UndefinedHandleValue);
|
||||
return p.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
Navigator::HasFeature(const nsAString& aName, ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsIGlobalObject> go = do_QueryInterface(mWindow);
|
||||
nsRefPtr<Promise> p = Promise::Create(go, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Hardcoded manifest features. Some are still b2g specific.
|
||||
const char manifestFeatures[][64] = {
|
||||
"manifest.origin"
|
||||
|
@ -1432,19 +1445,6 @@ Navigator::GetFeature(const nsAString& aName, ErrorResult& aRv)
|
|||
}
|
||||
}
|
||||
|
||||
p->MaybeResolve(JS::UndefinedHandleValue);
|
||||
return p.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
Navigator::HasFeature(const nsAString& aName, ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsIGlobalObject> go = do_QueryInterface(mWindow);
|
||||
nsRefPtr<Promise> p = Promise::Create(go, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NS_NAMED_LITERAL_STRING(apiWindowPrefix, "api.window.");
|
||||
if (StringBeginsWith(aName, apiWindowPrefix)) {
|
||||
const nsAString& featureName = Substring(aName, apiWindowPrefix.Length());
|
||||
|
|
|
@ -51,18 +51,27 @@ function testNotSupported() {
|
|||
ok(typeof tv === 'undefined', "Resolve the Promise with undefined value (hardware.tv)");
|
||||
runNextTest();
|
||||
},function(tv) {
|
||||
ok(false, "The Promise should not be rejected")
|
||||
ok(false, "The Promise should not be rejected");
|
||||
});
|
||||
}
|
||||
|
||||
function testNotSupportedManifest() {
|
||||
navigator.getFeature("manifest.origin").then(function(feature) {
|
||||
ok(typeof feature == 'undefined', "manifest.* resolves with undefined on getFeature");
|
||||
runNextTest();
|
||||
}, function() {
|
||||
ok(false, "The Promise should not be rejected");
|
||||
});
|
||||
}
|
||||
|
||||
function createManifestTest(aFeature) {
|
||||
return function() {
|
||||
var res;
|
||||
navigator.getFeature(aFeature).then(function(res) {
|
||||
navigator.hasFeature(aFeature).then(function(res) {
|
||||
ok(res === true, "Resolve the Promise with 'true' for " + aFeature);
|
||||
runNextTest();
|
||||
},function(tv) {
|
||||
ok(false, "The Promise should not be rejected")
|
||||
}, function(tv) {
|
||||
ok(false, "The Promise should not be rejected");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -70,6 +79,7 @@ function createManifestTest(aFeature) {
|
|||
var currentTest = -1;
|
||||
var tests = [
|
||||
testNotSupported,
|
||||
testNotSupportedManifest,
|
||||
testSupported,
|
||||
createManifestTest("manifest.origin"),
|
||||
createManifestTest("manifest.redirects")
|
||||
|
@ -90,6 +100,7 @@ SpecialPowers.pushPermissions([
|
|||
{type: "feature-detection", allow: 1, context: document}
|
||||
], function() {
|
||||
ok('getFeature' in navigator, "navigator.getFeature should exist");
|
||||
ok('hasFeature' in navigator, "navigator.hasFeature should exist");
|
||||
// B2G specific manifest features.
|
||||
// Touching navigator before pushPermissions makes it fail.
|
||||
if (!navigator.userAgent.contains("Android") &&
|
||||
|
|
Загрузка…
Ссылка в новой задаче