Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests for NavigatorID #3881

Merged
merged 2 commits into from
Oct 10, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ function run_test() {
}, "appCodeName");

test(function() {
assert_equals(typeof navigator.appName, "string",
"navigator.appName should be a string");
assert_equals(navigator.appName, "Netscape");
}, "appName");

test(function() {
Expand All @@ -23,31 +22,25 @@ function run_test() {
}, "product");

test(function() {
// See https://www.w3.org/Bugs/Public/show_bug.cgi?id=22555
if ("window" in self) {
// If you identify as WebKit, taintEnabled should not exist.
if (navigator.userAgent.indexOf("WebKit") != -1) {
assert_false("taintEnabled" in navigator);
}
// Otherwise it should exist and return false.
else {
assert_false(navigator.taintEnabled());
if (navigator.userAgent.indexOf("Chrome") != -1 ||
Copy link
Member

@domenic domenic Oct 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this could be navigator.userAgent.includes("Chrome") for clarity.

navigator.userAgent.indexOf("WebKit") != -1) {
// "If the navigator compatibility mode is Chrome or WebKit"
assert_equals(navigator.productSub, "20030107");
} else {
// "If the navigator compatibility mode is Gecko"
assert_equals(navigator.productSub, "20100101");
}
} else {
// taintEnabled should not exist in workers.
assert_false("taintEnabled" in navigator);
assert_false("productSub" in navigator);
}
}, "taintEnabled");
}, "productSub");

test(function() {
assert_equals(typeof navigator.userAgent, "string",
"navigator.userAgent should be a string");
}, "userAgent type");

test(function() {
assert_equals(navigator.vendorSub, "");
}, "vendorSub");

async_test(function() {
var request = new XMLHttpRequest();
request.onload = this.step_func_done(function() {
Expand All @@ -60,4 +53,51 @@ function run_test() {
"filter_name=User-Agent");
request.send();
}, "userAgent value");

test(function() {
if ("window" in self) {
if (navigator.userAgent.indexOf("Chrome") != -1) {
// "If the navigator compatibility mode is Chrome"
assert_equals(navigator.vendor, "Google Inc.");
} else if (navigator.userAgent.indexOf("WebKit") != -1) {
// "If the navigator compatibility mode is WebKit"
assert_equals(navigator.vendor, "Apple Computer, Inc.");
} else {
// "If the navigator compatibility mode is Gecko"
assert_equals(navigator.vendor, "");
}
} else {
assert_false("vendor" in navigator);
}
}, "vendor");

test(function() {
if ("window" in self) {
assert_equals(navigator.vendorSub, "");
} else {
assert_false("vendorSub" in navigator);
}
}, "vendorSub");

// "If the navigator compatibility mode is Gecko, then the user agent must
// also support the following partial interface" (taintEnabled() and oscpu)
// See https://www.w3.org/Bugs/Public/show_bug.cgi?id=22555 and
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=27820

test(function() {
if ("window" in self && navigator.userAgent.indexOf("WebKit") == -1) {
Copy link
Member

@domenic domenic Oct 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file uses several different ways of testing navigator compatibility mode, not all of which are compatible. E.g. here Gecko means "does not have the string WebKit", where above Gecko means "does not have the string WebKit or the string Chrome".

It would be good to factor this out into a variable (in the test file) that is one of "Chrome", "WebKit", or "Gecko", and then the test code proper could say if ("window" in self && navigatorCompatibilityMode === "Gecko"). Then you wouldn't need the spec quotes as much.

assert_false(navigator.taintEnabled());
} else {
assert_false("taintEnabled" in navigator);
}
}, "taintEnabled");

test(function() {
if ("window" in self && navigator.userAgent.indexOf("WebKit") == -1) {
assert_equals(typeof navigator.oscpu, "string",
"navigator.oscpu should be a string");
} else {
assert_false("oscpu" in navigator);
}
}, "oscpu");
}
22 changes: 0 additions & 22 deletions workers/interfaces/WorkerUtils/navigator/window-only.worker.js

This file was deleted.