blob: d5d943639351992562dc70a085d9093d5d689189 [file] [log] [blame]
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../resources/mojo-helpers.js"></script>
<script src="resources/mock-share-service.js"></script>
<script>
function getAbsoluteUrl(url) {
return new URL(url, location).toString();
}
share_test((t, mock) => {
let url = 'https://www.example.com/some/path?some_query#some_fragment';
mock.pushShareResult('the title', 'the message', getAbsoluteUrl(url), null);
return callWithKeyDown(() => navigator.share(
{title: 'the title', text: 'the message', url: url}));
}, 'successful share');
share_test((t, mock) => {
mock.pushShareResult('', '', '', null);
return callWithKeyDown(() => navigator.share({}));
}, 'successful share with empty ShareData');
share_test((t, mock) => {
let url = '//www.example.com/some/path?some_query#some_fragment';
mock.pushShareResult('', '', getAbsoluteUrl(url), null);
return callWithKeyDown(() => navigator.share({url: url}));
}, 'successful share with URL without a scheme');
share_test((t, mock) => {
let url = '/some/path?some_query#some_fragment';
mock.pushShareResult('', '', getAbsoluteUrl(url), null);
return callWithKeyDown(() => navigator.share({url: url}));
}, 'successful share with a path-only URL');
share_test((t, mock) => {
let url = 'foo';
mock.pushShareResult('', '', getAbsoluteUrl(url), null);
return callWithKeyDown(() => navigator.share({url: url}));
}, 'successful share with a relative URL');
share_test((t, mock) => {
let url = '';
mock.pushShareResult('', '', getAbsoluteUrl(url), null);
return callWithKeyDown(() => navigator.share({url: url}));
}, 'successful share with an empty URL');
share_test((t, mock) => {
let url = 'data:foo';
mock.pushShareResult('', '', getAbsoluteUrl(url), null);
return callWithKeyDown(() => navigator.share({url: url}));
}, 'successful share with a data URL');
</script>