Skip to content

Commit

Permalink
Backed out changeset 9ff60304993b (bug 1643205) for multiple failures…
Browse files Browse the repository at this point in the history
… e.g. share-consume-activation.https.html. CLOSED TREE
  • Loading branch information
ncsoregi committed Jun 17, 2020
1 parent b082565 commit 5fc3f25
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 147 deletions.
24 changes: 13 additions & 11 deletions dom/base/Navigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1374,17 +1374,6 @@ Promise* Navigator::Share(const ShareData& aData, ErrorResult& aRv) {
return nullptr;
}

// null checked above
auto* doc = mWindow->GetExtantDoc();

if (StaticPrefs::dom_webshare_requireinteraction() &&
!doc->ConsumeTransientUserGestureActivation()) {
aRv.ThrowNotAllowedError(
"User activation was already consumed "
"or share() was not activated by a user gesture.");
return nullptr;
}

// If none of data's members title, text, or url are present, reject p with
// TypeError, and abort these steps.
bool someMemberPassed = aData.mTitle.WasPassed() || aData.mText.WasPassed() ||
Expand All @@ -1395,6 +1384,9 @@ Promise* Navigator::Share(const ShareData& aData, ErrorResult& aRv) {
return nullptr;
}

// null checked above
auto doc = mWindow->GetExtantDoc();

// If data's url member is present, try to resolve it...
nsCOMPtr<nsIURI> url;
if (aData.mUrl.WasPassed()) {
Expand Down Expand Up @@ -1423,6 +1415,16 @@ Promise* Navigator::Share(const ShareData& aData, ErrorResult& aRv) {
text.SetIsVoid(true);
}

// The spec does the "triggered by user activation" after the data checks.
// Unfortunately, both Chrome and Safari behave this way, so interop wins.
// https://github.com/w3c/web-share/pull/118
if (StaticPrefs::dom_webshare_requireinteraction() &&
!UserActivation::IsHandlingUserInput()) {
NS_WARNING("Attempt to share not triggered by user activation");
aRv.Throw(NS_ERROR_DOM_NOT_ALLOWED_ERR);
return nullptr;
}

// Let mSharePromise be a new promise.
mSharePromise = Promise::Create(mWindow->AsGlobal(), aRv);
if (aRv.Failed()) {
Expand Down
1 change: 0 additions & 1 deletion dom/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ DIRS += [
'url',
'webauthn',
'webidl',
'webshare',
'xml',
'xslt',
'xul',
Expand Down
11 changes: 0 additions & 11 deletions dom/webshare/moz.build

This file was deleted.

5 changes: 0 additions & 5 deletions dom/webshare/test/mochitest/mochitest.ini

This file was deleted.

This file was deleted.

This file was deleted.

41 changes: 13 additions & 28 deletions testing/web-platform/tests/web-share/share-empty.https.html
Original file line number Diff line number Diff line change
@@ -1,49 +1,34 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta charset="utf-8">
<title>WebShare Test: Share no known fields</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/manual-helper.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/resources/testdriver.js"></script>
</head>
<body>
<script>
promise_test(async t => {
await test_driver.bless("web share", () => {
promise_test(t => {
return promise_rejects_js(t, TypeError, navigator.share());
});
}, "share with no arguments (same as empty dictionary)");
}, 'share with no arguments (same as empty dictionary)');

promise_test(async t => {
await test_driver.bless("web share", () => {
promise_test(t => {
return promise_rejects_js(t, TypeError, navigator.share({}));
});
}, "share with an empty dictionary");
}, 'share with an empty dictionary');

promise_test(async t => {
await test_driver.bless("web share", () => {
promise_test(t => {
return promise_rejects_js(t, TypeError, navigator.share(undefined));
});
}, "share with a undefined argument (same as empty dictionary)");
}, 'share with a undefined argument (same as empty dictionary)');

promise_test(async t => {
await test_driver.bless("web share", () => {
promise_test(t => {
return promise_rejects_js(t, TypeError, navigator.share(null));
});
}, "share with a null argument (same as empty dictionary)");
}, 'share with a null argument (same as empty dictionary)');

promise_test(async t => {
await test_driver.bless("web share", () => {
return promise_rejects_js(
t,
TypeError,
navigator.share({ unused: "unexpected field" })
);
});
}, "share with a dictionary containing only surplus fields");
promise_test(t => {
return promise_rejects_js(t,
TypeError, navigator.share({unused: 'unexpected field'}));
}, 'share with a dictionary containing only surplus fields');
</script>
</body>
</html>
23 changes: 8 additions & 15 deletions testing/web-platform/tests/web-share/share-url-invalid.https.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta charset="utf-8">
<title>WebShare Test: Share with an invalid URL</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="/resources/testdriver.js"></script>
</head>
<body>
<script>
promise_test(async t => {
// URL is invalid in that the URL Parser returns failure (port is too
// large).
const url = "http://example.com:65536";
await test_driver.bless(
"web share",
() => {
return promise_rejects_js(t, TypeError, navigator.share({ url }));
},
"share with an invalid URL"
);
});
promise_test(t => {
// URL is invalid in that the URL Parser returns failure (port is too
// large).
const url = 'http://example.com:65536';
return promise_rejects_js(
t, TypeError, navigator.share({url}));
}, 'share with an invalid URL');
</script>
</body>
</html>

0 comments on commit 5fc3f25

Please sign in to comment.