Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 2 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /web-share/canShare.https.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>WebShare Test: canShare method tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
test(() => {
assert_false(
navigator.canShare(),
"no arguments (uses default argument value, which is empty dictionary)"
);
assert_false(navigator.canShare({}), "empty dictionary not allowed");
assert_false(navigator.canShare(undefined), "empty dictionary not allowed");
assert_false(navigator.canShare(null), "empty dictionary not allowed");
assert_false(
navigator.canShare({ unused: "unexpected field" }),
"results in empty dictionary, which is not allowed"
);
}, "canShare() empty and default dictionary");
test(() => {
assert_false(
"URL is invalid"
);
assert_false(
navigator.canShare({ url: "data:the url" }),
"data URL is not allowed"
);
assert_false(
"file URL is not allowed"
);
assert_true(
navigator.canShare({
}),
"canShare with URL"
);
assert_true(
navigator.canShare({
url: {
toString() {
},
},
}),
"canShare URL as with object with stringifier"
);
assert_true(
navigator.canShare(
{ url: "" },
"canShare with empty URL, which resolves as the doc's base URL"
)
);
assert_true(
navigator.canShare({
url: "//a.b/path?query#fragment",
}),
"canShare with URL having no scheme"
);
assert_true(
navigator.canShare({
url: "relative",
}),
"canShare relative URL, resolved against API base URL"
);
}, "canShare() url member");
test(() => {
assert_false(
navigator.canShare({ title: undefined }),
"canShare with attribute undefined is equivalent to omitting the attribute"
);
assert_true(navigator.canShare({ title: "subject" }), "canShare with title");
assert_true(navigator.canShare({ title: null }), "stringified null");
}, "canShare() title member");
test(() => {
assert_true(navigator.canShare({ text: "" }), "ok to share empty text");
assert_true(
navigator.canShare({ text: "some text 🤔" }),
"ok to share unicode"
);
assert_true(navigator.canShare({ text: 123 }), "number is stringified");
}, "canShare() text member");
test(() => {
const file = new File(["hello"], "file", { type: "text/plain" });
const file2 = new File([], "file2");
assert_false(navigator.canShare({ files: [] }), "empty list is not allowed");
assert_false(
navigator.canShare({
files: [file, file2],
}),
"invalid URL invalidates the share"
);
assert_true(
navigator.canShare({ files: [file] }),
"single file is ok to share"
);
assert_true(
navigator.canShare({ files: [file, file2, file] }),
"repeated files is ok to share"
);
assert_true(
navigator.canShare({
files: [file, file2],
text: "some texts",
}),
"is ok to share files, text, and url together"
);
}, "canShare() files member");
test(() => {
assert_true(
navigator.canShare({
title: "subject",
text: "body",
files: [new File([], "file")],
unused: "unexpected field",
}),
"canShare with unexpected field"
);
}, "canShare() multiple members");
</script>
</body>
</html>