Bug 1577175 - Part 2: Add tests; r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D44360

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Edgar Chen 2019-09-02 22:45:11 +00:00
parent 463e0e6d20
commit d9f0623861
6 changed files with 81 additions and 1 deletions

View File

@ -24,7 +24,8 @@ BROWSER_CHROME_MANIFESTS += [
TEST_DIRS += [
'gtest',
'jsmodules'
'jsmodules',
'useractivation',
]
TEST_HARNESS_FILES.testing.mochitest.tests.dom.base.test.chrome += [

View File

@ -0,0 +1,5 @@
[DEFAULT]
support-files =
file_empty.html
[test_useractivation_has_been_activated.html]

View File

@ -0,0 +1,9 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
MOCHITEST_MANIFESTS += [
'mochitest.ini',
]

View File

@ -0,0 +1,63 @@
<!DOCTYPE HTML>
<html>
<head>
<title>User activation test: has been user gesture activated</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>
<iframe></iframe>
<iframe></iframe>
<script>
function waitForEvent(aTarget, aEvent) {
return new Promise((aResolve) => {
aTarget.addEventListener(aEvent, function listener(event) {
aResolve();
}, { once: true });
});
}
add_task(async function checkInitialStatus() {
ok(!SpecialPowers.wrap(document).hasBeenUserGestureActivated,
"check has-been-user-activated on top-level document");
ok(!SpecialPowers.wrap(frames[0].document).hasBeenUserGestureActivated,
"check has-been-user-activated on first iframe");
ok(!SpecialPowers.wrap(frames[1].document).hasBeenUserGestureActivated,
"check has-been-user-activated on second iframe");
});
add_task(async function triggerUserActivation() {
// Trigger user activation on the first iframe.
SpecialPowers.wrap(frames[0].document).notifyUserGestureActivation();
// We should also propagate to all the ancestors.
ok(SpecialPowers.wrap(document).hasBeenUserGestureActivated,
"check has-been-user-activated on the top-level document");
ok(SpecialPowers.wrap(frames[0].document).hasBeenUserGestureActivated,
"check has-been-user-activated on the first iframe");
ok(!SpecialPowers.wrap(frames[1].document).hasBeenUserGestureActivated,
"check has-been-user-activated on the second iframe");
});
add_task(async function iframeNavigation() {
frames[0].frameElement.src = "file_empty.html";
await waitForEvent(frames[0].frameElement, "load");
// We should reset the flag on iframe that navigates away from current page,
// but the flag on its ancestor isn't changed.
ok(SpecialPowers.wrap(document).hasBeenUserGestureActivated,
"check has-been-user-activated on the top-level document");
ok(!SpecialPowers.wrap(frames[0].document).hasBeenUserGestureActivated,
"check has-been-user-activated on the first iframe");
ok(!SpecialPowers.wrap(frames[1].document).hasBeenUserGestureActivated,
"check has-been-user-activated on the second iframe");
});
add_task(async function endTests() {
// Reset the activation flag in order not to interfere following test in the
// verify mode which would run the test using same document couple times.
SpecialPowers.wrap(document).clearUserGestureActivation();
});
</script>
</body>

View File

@ -563,6 +563,8 @@ partial interface Document {
// For testing only.
[ChromeOnly]
void clearUserGestureActivation();
[ChromeOnly]
readonly attribute boolean hasBeenUserGestureActivated;
};
// Extension to give chrome JS the ability to set an event handler which is