Bug 1399356: Test for anti-clickjacking r=zbraniecki

Depends on D79775

Differential Revision: https://phabricator.services.mozilla.com/D80229
This commit is contained in:
Adam Roach [:abr] 2020-06-27 02:12:02 +00:00
Родитель b601853466
Коммит db58b108c2
3 изменённых файлов: 77 добавлений и 2 удалений

Просмотреть файл

@ -27,3 +27,5 @@ skip-if = !debug && os == "mac" # perma-fail see Bug 1600059
skip-if = !debug && os == "mac" # perma-fail see Bug 1600059
[browser_update_doorhanger.js]
skip-if = true # bug 1426981 # Bug 1445538
[browser_anti_clickjacking.js]
skip-if = !debug && os == "mac" # perma-fail see Bug 1600059

Просмотреть файл

@ -0,0 +1,62 @@
"use strict";
const URL =
"http://example.org/browser/browser/extensions/formautofill/test/browser/autocomplete_basic.html";
add_task(async function setup_storage() {
await saveAddress(TEST_ADDRESS_1);
await saveAddress(TEST_ADDRESS_2);
await saveAddress(TEST_ADDRESS_3);
});
add_task(async function test_active_delay() {
await SpecialPowers.pushPrefEnv({
set: [["security.notification_enable_delay", 500]],
});
await BrowserTestUtils.withNewTab({ gBrowser, url: URL }, async function(
browser
) {
const focusInput = "#organization";
// Open the popup -- we don't use openPopupOn() because there
// are things we need to check between these steps.
await SimpleTest.promiseFocus(browser);
await focusAndWaitForFieldsIdentified(browser, focusInput);
const start = Date.now();
await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
await expectPopupOpen(browser);
const firstItem = getDisplayedPopupItems(browser)[0];
ok(firstItem.disabled, "Popup should be disbled upon opening.");
is(
browser.autoCompletePopup.selectedIndex,
-1,
"No item selected at first"
);
// Check that clicking on menu doesn't do anything while
// it is disabled
firstItem.click();
is(
browser.autoCompletePopup.selectedIndex,
-1,
"No item selected after clicking on disabled item"
);
// Check that the delay before enabling is as long as expected
await waitForPopupEnabled(browser);
const delta = Date.now() - start;
info(`Popup was disabled for ${delta} ms`);
ok(delta >= 500, "Popup was disabled for at least 500 ms");
// Check the clicking on the menu works now
firstItem.click();
is(
browser.autoCompletePopup.selectedIndex,
0,
"First item selected after clicking on enabled item"
);
// Clean up
await closePopup(browser);
});
});

Просмотреть файл

@ -8,7 +8,7 @@
SYNC_USERNAME_PREF, SYNC_ADDRESSES_PREF, SYNC_CREDITCARDS_PREF, SYNC_CREDITCARDS_AVAILABLE_PREF, CREDITCARDS_USED_STATUS_PREF,
sleep, expectPopupOpen, openPopupOn, openPopupForSubframe, expectPopupClose, closePopup, closePopupForSubframe,
clickDoorhangerButton, getAddresses, saveAddress, removeAddresses, saveCreditCard,
getDisplayedPopupItems, getDoorhangerCheckbox,
getDisplayedPopupItems, getDoorhangerCheckbox, waitForPopupEnabled,
getNotification, getDoorhangerButton, removeAllRecords, expectWarningText, testDialog */
"use strict";
@ -298,6 +298,17 @@ async function expectPopupOpen(browser) {
}, "The popup should be a form autofill one");
}
async function waitForPopupEnabled(browser) {
const {
autoCompletePopup: { richlistbox: itemsBox },
} = browser;
const listItemElems = itemsBox.querySelectorAll(".autocomplete-richlistitem");
await TestUtils.waitForCondition(
() => !listItemElems[0].disabled,
"Wait for list elements to become enabled"
);
}
async function openPopupOn(browser, selector) {
await SimpleTest.promiseFocus(browser);
await focusAndWaitForFieldsIdentified(browser, selector);
@ -309,7 +320,7 @@ async function openPopupOn(browser, selector) {
async function openPopupForSubframe(browser, frameBrowsingContext, selector) {
await SimpleTest.promiseFocus(browser);
await focusAndWaitForFieldsIdentified(frameBrowsingContext, selector);
info("openPopupOn: before VK_DOWN");
info("openPopupForSubframe: before VK_DOWN");
await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, frameBrowsingContext);
await expectPopupOpen(browser);
}