-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Added new tests directory: webshare. #6287
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
82da2c6
Added new tests directory: webshare.
mgiuca e1a672b
idlharness test loads IDL from a separate file.
mgiuca 346bc0b
Remove 'Manual' from test page titles.
mgiuca 15aaea0
manual-helper: Reject promise if an exception is thrown.
mgiuca 9425bc3
share-simple-manual: Check that promise is resolved with undefined.
mgiuca f25a35a
share-non-string-manual: Test url field, and toString method.
mgiuca 4cf66de
share-unicode-strings-manual: Use Unicode escape.
mgiuca 8d6deab
share-unicode-strings-nonutf8-manual: Assert character encoding.
mgiuca bcf2933
URL expectations: Use document.baseURI, not location.
mgiuca c07c63f
share-url-relative-manual: Add a <base> URL.
mgiuca b6f403a
Renamed directory from webshare to web-share.
mgiuca 8762cd9
Added @marcoscaceres as co-OWNER.
mgiuca 2bb1b0a
Use JavaScript short-hand for dictionary keys with the same name as v…
mgiuca 814078b
Respond to Marcos' review.
mgiuca 6d2ac87
Line wrapping.
mgiuca 0d799e2
idlharness: Use async/await syntax for easier reading.
mgiuca d472f84
web-share helper: Split setupManualShareTest into separate functions …
mgiuca 1795dd8
web-share helper: setupManualShareTest now takes a single dict rather…
mgiuca File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// https://wicg.github.io/web-share/ | ||
|
||
partial interface Navigator { | ||
[SecureContext] | ||
Promise<void> share(ShareData data); | ||
}; | ||
|
||
dictionary ShareData { | ||
USVString title; | ||
USVString text; | ||
USVString url; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@mgiuca | ||
@marcoscaceres |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>WebShare IDL test</title> | ||
<link rel="help" href="https://wicg.github.io/web-share/"> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<script src=/resources/WebIDLParser.js></script> | ||
<script src=/resources/idlharness.js></script> | ||
</head> | ||
<body> | ||
<script> | ||
"use strict"; | ||
var idl_array = new IdlArray(); | ||
|
||
function doTest(idl) { | ||
idl_array.add_untested_idls('interface Navigator {};'); | ||
idl_array.add_idls(idl); | ||
idl_array.add_objects({ | ||
Navigator: ['navigator'] | ||
}); | ||
idl_array.test(); | ||
} | ||
|
||
promise_test(async () => { | ||
const response = await fetch('../interfaces/web-share.idl'); | ||
doTest(await response.text()); | ||
}, 'Test driver'); | ||
</script> | ||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Internal function. Returns [instruction, list] DOM elements. | ||
function setupManualShareTestCommon() { | ||
const div = document.createElement('div'); | ||
document.body.appendChild(div); | ||
|
||
const instruction = document.createElement('div'); | ||
instruction.id = 'instruction'; | ||
div.appendChild(instruction); | ||
|
||
const shareButton = document.createElement('input'); | ||
shareButton.id = 'share_button'; | ||
shareButton.value = 'Share button'; | ||
shareButton.type = 'button'; | ||
div.appendChild(shareButton); | ||
|
||
let heading = document.createElement('h2'); | ||
heading.innerText = 'Instructions:'; | ||
instruction.appendChild(heading); | ||
let list = document.createElement('ol'); | ||
instruction.appendChild(list); | ||
let item = document.createElement('li'); | ||
list.appendChild(item); | ||
item.innerText = 'Click the Share button.'; | ||
|
||
return [instruction, list]; | ||
} | ||
|
||
// Sets up the page for running manual tests. Automatically creates the | ||
// instructions (based on the parameters) and the share button. | ||
function setupManualShareTest(expected_share_data) { | ||
const {title, text, url} = expected_share_data; | ||
let [instruction, list] = setupManualShareTestCommon(); | ||
let item = document.createElement('li'); | ||
list.appendChild(item); | ||
item.innerText = 'Choose a valid share target.'; | ||
|
||
heading = document.createElement('h2'); | ||
heading.innerText = 'Pass the test iff the target app received:'; | ||
instruction.appendChild(heading); | ||
|
||
list = document.createElement('ul'); | ||
instruction.appendChild(list); | ||
|
||
item = document.createElement('li'); | ||
list.appendChild(item); | ||
item.innerText = `title = "${title}"`; | ||
item = document.createElement('li'); | ||
list.appendChild(item); | ||
item.innerText = `text = "${text}"`; | ||
item = document.createElement('li'); | ||
list.appendChild(item); | ||
item.innerText = `url = "${url}"`; | ||
} | ||
|
||
function setupManualShareTestRequiringCancellation() { | ||
const [instruction, list] = setupManualShareTestCommon(); | ||
const item = document.createElement('li'); | ||
list.appendChild(item); | ||
item.innerText = 'Cancel the share dialog.'; | ||
} | ||
|
||
// Returns a promise. When the user clicks the button, calls | ||
// |click_handler| and resolves the promise with the result. | ||
function callWhenButtonClicked(click_handler) { | ||
return new Promise((resolve, reject) => { | ||
document.querySelector('#share_button').onclick = () => { | ||
try { | ||
resolve(click_handler()); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
}; | ||
}); | ||
} | ||
|
||
function getAbsoluteUrl(url) { | ||
return new URL(url, document.baseURI).toString(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>WebShare Test: Share cancelled by user</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="resources/manual-helper.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
setup({explicit_timeout: true}); | ||
|
||
setupManualShareTestRequiringCancellation(); | ||
|
||
promise_test(t => { | ||
return callWhenButtonClicked(() => promise_rejects( | ||
t, 'AbortError', | ||
navigator.share({title: 'the title', text: 'the message', | ||
url: 'data:the url'}))); | ||
}, 'share with user cancellation'); | ||
</script> | ||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>WebShare Test: Share with empty ShareData</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="resources/manual-helper.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
setup({explicit_timeout: true}); | ||
|
||
setupManualShareTest({title: '', text: '', url: ''}); | ||
callWhenButtonClicked(() => navigator.share({})); | ||
</script> | ||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>WebShare Test: Surplus arguments ignored</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="resources/manual-helper.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
setup({explicit_timeout: true}); | ||
|
||
setupManualShareTest( | ||
{title: 'the title', text: 'the message', url: 'data:the url'}); | ||
callWhenButtonClicked(() => navigator.share( | ||
{title: 'the title', text: 'the message', url: 'data:the url'}, | ||
'more than required')); | ||
</script> | ||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>WebShare Test: Surplus fields ignored</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="resources/manual-helper.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
setup({explicit_timeout: true}); | ||
|
||
setupManualShareTest( | ||
{title: 'the title', text: 'the message', url: 'data:the url'}); | ||
callWhenButtonClicked(() => navigator.share( | ||
{title: 'the title', text: 'the message', url: 'data:the url', | ||
unused: 'unexpected field'})); | ||
</script> | ||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>WebShare Test: Share non-string types (test implicit conversion)</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="resources/manual-helper.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
setup({explicit_timeout: true}); | ||
|
||
// Expect that each of the non-string values is converted into a string. | ||
setupManualShareTest( | ||
{title: 'true', text: 'the object', url: getAbsoluteUrl('384957')}); | ||
|
||
const objectWithToString = {toString() { return 'the object'; }}; | ||
callWhenButtonClicked(() => navigator.share( | ||
{title: true, text: objectWithToString, url: 384957})); | ||
</script> | ||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>WebShare Test: Share null and undefined values</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="resources/manual-helper.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
setup({explicit_timeout: true}); | ||
|
||
// Expect null to be converted into the string 'null'. On the other | ||
// hand, undefined should be equivalent to omitting the attribute. | ||
setupManualShareTest( | ||
{title: 'null', text: '', url: getAbsoluteUrl('null')}); | ||
callWhenButtonClicked(() => navigator.share( | ||
{title: null, text: undefined, url: null})); | ||
</script> | ||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>WebShare Test: Share from non-secure context</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
test(() => { | ||
assert_false('share' in navigator, 'navigator has attribute \'share\'.'); | ||
}, 'navigator.share must be undefined in non-secure context'); | ||
</script> | ||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>WebShare Test: Simple share</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="resources/manual-helper.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
setup({explicit_timeout: true}); | ||
|
||
const url = 'https://www.example.com/some/path?some_query#some_fragment'; | ||
setupManualShareTest({title: 'the title', text: 'the message', url}); | ||
callWhenButtonClicked(() => navigator.share( | ||
{title: 'the title', text: 'the message', url})).then( | ||
result => { | ||
// Check that promise resolved with undefined. This is guarded | ||
// by an if statement because we do not want it to register as a | ||
// test if it passes (since this is a manual test). | ||
if (result !== undefined) { | ||
assert_equals(result, undefined); | ||
} | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>WebShare Test: Share with non-ASCII Unicode strings</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="resources/manual-helper.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
setup({explicit_timeout: true}); | ||
|
||
// Title is a string with BMP and non-BMP characters. | ||
// Text contains invalid surrogates which should be converted into U+FFFD. | ||
// URL contains non-ASCII characters in host and path. | ||
const title = 'fáncy 写作 😱'; | ||
const url = 'https://测试.example.com/📄'; | ||
// Host is IDNA-encoded. Path is percent-encoded. | ||
const url_ascii = 'https://xn--0zwm56d.example.com/%F0%9F%93%84'; | ||
setupManualShareTest({title, text: '\ufffdx', url: url_ascii}); | ||
callWhenButtonClicked(() => navigator.share({title, text: '\ud9a3x', url})); | ||
</script> | ||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="windows-1252"> | ||
<title>WebShare Test: Share with non-ASCII Unicode strings in a Latin-1-encoded page</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="resources/manual-helper.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
setup({explicit_timeout: true}); | ||
|
||
assert_equals(document.characterSet, 'windows-1252'); | ||
|
||
// Exact same test as in share-unicode-strings-manual.html, with same | ||
// expectations. This tests that the page's encoding (ISO-8859-1) is | ||
// ignored and Unicode characters are always percent-encoded in UTF-8. | ||
const title = 'f\xe1ncy \u5199\u4f5c \ud83d\ude31'; | ||
const url = 'https://\u6d4b\u8bd5.example.com/\ud83d\udcc4'; | ||
// Host is IDNA-encoded. Path is percent-encoded with UTF-8. | ||
const url_ascii = 'https://xn--0zwm56d.example.com/%F0%9F%93%84'; | ||
setupManualShareTest({title, text: '\ufffdx', url: url_ascii}); | ||
callWhenButtonClicked(() => navigator.share({title, text: '\ud9a3x', url})); | ||
</script> | ||
</body> | ||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>WebShare Test: Share with data URL</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="resources/manual-helper.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
setup({explicit_timeout: true}); | ||
|
||
const url = 'data:foo'; | ||
setupManualShareTest({title: '', text: '', url: getAbsoluteUrl(url)}); | ||
callWhenButtonClicked(() => navigator.share({url})); | ||
</script> | ||
</body> | ||
</html> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you want to test for this. This might cause issues if we need to extend the API later and it's outside the scope of the API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense to test this.
Surely if we extend the API later, we'll also extend the test? More importantly, this tests that a valid implementation allows us to extend the API later without breaking backwards-compatibility.
(The tests don't need to be forwards-compatible, but we do need to test that the implementation is forwards-compatible.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we get a second opinion from another peer? @foolip maybe? I don't feel too strongly, just don't want us to get into trouble later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignoring extra attributes is the standard behavior of WebIDL, so that seems OK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should expect standards and tests to co-evolve, and that changing both is low friction, so I don't worry about the tests constraining changes. However, if an implementation did have an optional second string argument, this test wouldn't necessarily fail. Passing in
{ toString() { throw Error(); } }
would catch it, but is there an object that will throw whatever the argument type is, including a dictionary? I suspect not.If that can be solved generically, I think that something in idlharness.js might make sense. So, the value of this test probably isn't super high, and I would lean towards removing.
(Looking at this I noticed w3c/web-share#47)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I would have suggested except afaik we don't have a good story for using idlharness on manual tests for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@foolip: Point taken, but I think your argument is that it won't necessarily catch implementations that are actually making use of a second argument (that's correct). I think there's still utility here, though, to catch implementations that throw an exception if they receive too many arguments.
Maybe the chance of that is low (since it's atypical for JavaScript code to care if there is excess arguments) but it's still a part of the IDL interface that's worth testing since it isn't (and can't be, for manual tests) tested by idlharness.