-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1930458 - Always consume user activation when opending a new wind…
…ow; r=smaug Per whatwg/html#10547, we should always consume the user activation even if the popup blocker is disabled or the window has permission to open a new window. Differential Revision: https://phabricator.services.mozilla.com/D230331
- Loading branch information
Showing
11 changed files
with
134 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
109 changes: 109 additions & 0 deletions
109
dom/base/test/useractivation/test_useractivation_open_new_window.html
This file contains 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,109 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<title>User activation test: consume user activation when opending a new window</title> | ||
<script src="/tests/SimpleTest/SimpleTest.js"></script> | ||
<script src="/tests/SimpleTest/EventUtils.js"></script> | ||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> | ||
</head> | ||
<body> | ||
<a href="file_self_close.html" target="_blank">link</a> | ||
<script> | ||
|
||
const ALLOW_ACTION = SpecialPowers.Ci.nsIPermissionManager.ALLOW_ACTION; | ||
const DENY_ACTION = SpecialPowers.Ci.nsIPermissionManager.DENY_ACTION; | ||
const UNKNOWN_ACTION = SpecialPowers.Ci.nsIPermissionManager.UNKNOWN_ACTION; | ||
|
||
async function test_useractivation_window_open() { | ||
info("Test user activation after calling window.open()") | ||
SpecialPowers.wrap(document).notifyUserGestureActivation(); | ||
// Open a new window | ||
ok(navigator.userActivation.isActive, `has user activation`); | ||
let w = window.open("file_empty.html", "testWindow"); | ||
ok(!navigator.userActivation.isActive, `user activation should be consumed after opening a new window`); | ||
|
||
SpecialPowers.wrap(document).notifyUserGestureActivation(); | ||
ok(navigator.userActivation.isActive, `has user activation`); | ||
let w2 = window.open("file_empty.html", "testWindow"); | ||
ok(w2 == w, "should use the existing window"); | ||
ok(navigator.userActivation.isActive, `user activation should not be consumed if window is existed`); | ||
|
||
if (w2 && w2 !== w) { | ||
w2.close(); | ||
} | ||
if (w) { | ||
w.close(); | ||
} | ||
} | ||
|
||
async function test_useractivation_anchor_blank() { | ||
info("Test user activation after calling window.open()") | ||
let link = document.querySelector("a"); | ||
link.addEventListener("click", () => { | ||
ok(navigator.userActivation.isActive, `has user activation`); | ||
}); | ||
synthesizeMouseAtCenter(link, {}); | ||
await new Promise(resolve => SimpleTest.executeSoon(resolve)); | ||
ok(!navigator.userActivation.isActive, `user activation should be consumed`); | ||
} | ||
|
||
async function test_useractivation() { | ||
await test_useractivation_window_open(); | ||
await test_useractivation_anchor_blank(); | ||
} | ||
|
||
add_task(async function testPopupBlockerDisabled() { | ||
await SpecialPowers.pushPrefEnv({ | ||
set: [ | ||
// Disable popup blocker | ||
["dom.disable_open_during_load", false], | ||
], | ||
}); | ||
await test_useractivation(); | ||
await SpecialPowers.popPrefEnv(); | ||
}); | ||
|
||
add_task(async function testPopupBlockerEnabled() { | ||
await SpecialPowers.pushPrefEnv({ | ||
set: [ | ||
// Enable popup blocker | ||
["dom.disable_open_during_load", true], | ||
], | ||
}); | ||
|
||
await test_useractivation(); | ||
await SpecialPowers.popPrefEnv(); | ||
}); | ||
|
||
add_task(async function testUnknownPermission() { | ||
await SpecialPowers.pushPermissions([ | ||
{'type': 'popup', 'remove': true, 'context': document} | ||
]); | ||
ok(await SpecialPowers.testPermission('popup', UNKNOWN_ACTION, document), | ||
'popup value should have UNKNOWN permission'); | ||
await test_useractivation(); | ||
await SpecialPowers.popPermissions(); | ||
}); | ||
|
||
add_task(async function testAllowPermission() { | ||
await SpecialPowers.pushPermissions([ | ||
{'type': 'popup', 'allow': ALLOW_ACTION, 'context': document} | ||
]); | ||
ok(await SpecialPowers.testPermission('popup', ALLOW_ACTION, document), | ||
'popup value should have ALLOW permission'); | ||
await test_useractivation(); | ||
await SpecialPowers.popPermissions(); | ||
}); | ||
|
||
add_task(async function testDenyPermission() { | ||
await SpecialPowers.pushPermissions([ | ||
{'type': 'popup', 'allow': DENY_ACTION, 'context': document} | ||
]); | ||
ok(await SpecialPowers.testPermission('popup', DENY_ACTION, document), | ||
'popup value should have ALLOW permission'); | ||
await test_useractivation(); | ||
await SpecialPowers.popPermissions(); | ||
}); | ||
|
||
</script> | ||
</body> |
This file contains 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
This file contains 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
3 changes: 0 additions & 3 deletions
3
...tics/forms/form-submission-target/form-target-blank-useractivation-multi-globals.html.ini
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
...eta/html/semantics/forms/form-submission-target/form-target-blank-useractivation.html.ini
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
...semantics/links/links-created-by-a-and-area-elements/target_blank_useractivation.html.ini
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
...s/links-created-by-a-and-area-elements/target_blank_useractivation_multi_globals.html.ini
This file contains 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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
# XXX(edgar): Need to enable popup blocker due to bug 1930458. | ||
prefs: [dom.disable_open_during_load:true] | ||
[target_blank_useractivation_multi_globals.html] | ||
expected: | ||
if not sessionHistoryInParent and not debug: [OK, ERROR] |
3 changes: 0 additions & 3 deletions
3
...g/web-platform/meta/scroll-to-text-fragment/scroll-to-text-fragment-security.sub.html.ini
This file was deleted.
Oops, something went wrong.
This file contains 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