2008-08-20 08:11:39 +04:00
|
|
|
/* Check for the correct behaviour of the report web forgery/not a web forgery
|
|
|
|
menu items.
|
|
|
|
|
|
|
|
Mac makes this astonishingly painful to test since their help menu is special magic,
|
|
|
|
but we can at least test it on the other platforms.*/
|
|
|
|
|
2016-02-11 22:10:04 +03:00
|
|
|
const NORMAL_PAGE = "http://example.com";
|
|
|
|
const PHISH_PAGE = "http://www.itisatrap.org/firefox/its-a-trap.html";
|
2010-03-13 19:55:44 +03:00
|
|
|
|
2016-02-11 22:10:04 +03:00
|
|
|
/**
|
|
|
|
* Opens a new tab and browses to some URL, tests for the existence
|
|
|
|
* of the phishing menu items, and then runs a test function to check
|
|
|
|
* the state of the menu once opened. This function will take care of
|
|
|
|
* opening and closing the menu.
|
|
|
|
*
|
|
|
|
* @param url (string)
|
|
|
|
* The URL to browse the tab to.
|
|
|
|
* @param testFn (function)
|
|
|
|
* The function to run once the menu has been opened. This
|
|
|
|
* function will be passed the "reportMenu" and "errorMenu"
|
|
|
|
* DOM nodes as arguments, in that order. This function
|
|
|
|
* should not yield anything.
|
|
|
|
* @returns Promise
|
|
|
|
*/
|
|
|
|
function check_menu_at_page(url, testFn) {
|
|
|
|
return BrowserTestUtils.withNewTab(
|
|
|
|
{
|
|
|
|
gBrowser,
|
|
|
|
url: "about:blank",
|
2017-05-12 15:42:39 +03:00
|
|
|
},
|
|
|
|
async function(browser) {
|
2016-02-11 22:10:04 +03:00
|
|
|
// We don't get load events when the DocShell redirects to error
|
|
|
|
// pages, but we do get DOMContentLoaded, so we'll wait for that.
|
2019-12-13 23:36:16 +03:00
|
|
|
let dclPromise = SpecialPowers.spawn(browser, [], async function() {
|
2017-05-12 15:42:39 +03:00
|
|
|
await ContentTaskUtils.waitForEvent(this, "DOMContentLoaded", false);
|
2016-02-11 22:10:04 +03:00
|
|
|
});
|
2018-08-29 17:44:56 +03:00
|
|
|
BrowserTestUtils.loadURI(browser, url);
|
2017-05-12 15:42:39 +03:00
|
|
|
await dclPromise;
|
2008-08-20 08:11:39 +04:00
|
|
|
|
2016-02-11 22:10:04 +03:00
|
|
|
let menu = document.getElementById("menu_HelpPopup");
|
|
|
|
ok(menu, "Help menu should exist");
|
2010-03-13 19:55:44 +03:00
|
|
|
|
2016-02-11 22:10:04 +03:00
|
|
|
let reportMenu = document.getElementById(
|
|
|
|
"menu_HelpPopup_reportPhishingtoolmenu"
|
|
|
|
);
|
|
|
|
ok(reportMenu, "Report phishing menu item should exist");
|
2016-02-04 01:22:33 +03:00
|
|
|
|
2016-02-11 22:10:04 +03:00
|
|
|
let errorMenu = document.getElementById(
|
|
|
|
"menu_HelpPopup_reportPhishingErrortoolmenu"
|
|
|
|
);
|
|
|
|
ok(errorMenu, "Report phishing error menu item should exist");
|
2008-08-20 08:11:39 +04:00
|
|
|
|
2016-02-11 22:10:04 +03:00
|
|
|
let menuOpen = BrowserTestUtils.waitForEvent(menu, "popupshown");
|
|
|
|
menu.openPopup(null, "", 0, 0, false, null);
|
2017-05-12 15:42:39 +03:00
|
|
|
await menuOpen;
|
2016-02-04 01:22:33 +03:00
|
|
|
|
2016-02-11 22:10:04 +03:00
|
|
|
testFn(reportMenu, errorMenu);
|
2016-02-04 01:22:33 +03:00
|
|
|
|
2016-02-11 22:10:04 +03:00
|
|
|
let menuClose = BrowserTestUtils.waitForEvent(menu, "popuphidden");
|
|
|
|
menu.hidePopup();
|
2017-05-12 15:42:39 +03:00
|
|
|
await menuClose;
|
2016-02-11 22:10:04 +03:00
|
|
|
}
|
|
|
|
);
|
2008-08-20 08:11:39 +04:00
|
|
|
}
|
|
|
|
|
2016-02-11 22:10:04 +03:00
|
|
|
/**
|
|
|
|
* Tests that we show the "Report this page" menu item at a normal
|
|
|
|
* page.
|
|
|
|
*/
|
2017-05-12 15:42:39 +03:00
|
|
|
add_task(async function() {
|
|
|
|
await check_menu_at_page(NORMAL_PAGE, (reportMenu, errorMenu) => {
|
2016-02-11 22:10:04 +03:00
|
|
|
ok(
|
|
|
|
!reportMenu.hidden,
|
|
|
|
"Report phishing menu should be visible on normal sites"
|
|
|
|
);
|
|
|
|
ok(
|
|
|
|
errorMenu.hidden,
|
|
|
|
"Report error menu item should be hidden on normal sites"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2013-12-15 23:05:53 +04:00
|
|
|
|
2016-02-11 22:10:04 +03:00
|
|
|
/**
|
|
|
|
* Tests that we show the "Report this page is okay" menu item at
|
|
|
|
* a reported attack site.
|
|
|
|
*/
|
2017-05-12 15:42:39 +03:00
|
|
|
add_task(async function() {
|
|
|
|
await check_menu_at_page(PHISH_PAGE, (reportMenu, errorMenu) => {
|
2016-02-11 22:10:04 +03:00
|
|
|
ok(
|
|
|
|
reportMenu.hidden,
|
|
|
|
"Report phishing menu should be hidden on phishing sites"
|
|
|
|
);
|
|
|
|
ok(
|
|
|
|
!errorMenu.hidden,
|
|
|
|
"Report error menu item should be visible on phishing sites"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|