browser_bug415846.js (3091B)
1 /* Check for the correct behaviour of the report web forgery/not a web forgery 2 menu items. 3 4 Mac makes this astonishingly painful to test since their help menu is special magic, 5 but we can at least test it on the other platforms.*/ 6 7 const NORMAL_PAGE = "http://example.com"; 8 const PHISH_PAGE = "http://www.itisatrap.org/firefox/its-a-trap.html"; 9 10 /** 11 * Opens a new tab and browses to some URL, tests for the existence 12 * of the phishing menu items, and then runs a test function to check 13 * the state of the menu once opened. This function will take care of 14 * opening and closing the menu. 15 * 16 * @param url (string) 17 * The URL to browse the tab to. 18 * @param testFn (function) 19 * The function to run once the menu has been opened. This 20 * function will be passed the "reportMenu" and "errorMenu" 21 * DOM nodes as arguments, in that order. This function 22 * should not yield anything. 23 * @returns Promise 24 */ 25 function check_menu_at_page(url, testFn) { 26 return BrowserTestUtils.withNewTab( 27 { 28 gBrowser, 29 url: "about:blank", 30 }, 31 async function (browser) { 32 // We don't get load events when the DocShell redirects to error 33 // pages, but we do get DOMContentLoaded, so we'll wait for that. 34 let dclPromise = SpecialPowers.spawn(browser, [], async function () { 35 await ContentTaskUtils.waitForEvent(this, "DOMContentLoaded", false); 36 }); 37 BrowserTestUtils.startLoadingURIString(browser, url); 38 await dclPromise; 39 40 let menu = document.getElementById("menu_HelpPopup"); 41 ok(menu, "Help menu should exist"); 42 43 let reportMenu = document.getElementById( 44 "menu_HelpPopup_reportPhishingtoolmenu" 45 ); 46 ok(reportMenu, "Report phishing menu item should exist"); 47 48 let errorMenu = document.getElementById( 49 "menu_HelpPopup_reportPhishingErrortoolmenu" 50 ); 51 ok(errorMenu, "Report phishing error menu item should exist"); 52 53 let menuOpen = BrowserTestUtils.waitForEvent(menu, "popupshown"); 54 menu.openPopup(null, "", 0, 0, false, null); 55 await menuOpen; 56 57 testFn(reportMenu, errorMenu); 58 59 let menuClose = BrowserTestUtils.waitForEvent(menu, "popuphidden"); 60 menu.hidePopup(); 61 await menuClose; 62 } 63 ); 64 } 65 66 /** 67 * Tests that we show the "Report this page" menu item at a normal 68 * page. 69 */ 70 add_task(async function () { 71 await check_menu_at_page(NORMAL_PAGE, (reportMenu, errorMenu) => { 72 ok( 73 !reportMenu.hidden, 74 "Report phishing menu should be visible on normal sites" 75 ); 76 ok( 77 errorMenu.hidden, 78 "Report error menu item should be hidden on normal sites" 79 ); 80 }); 81 }); 82 83 /** 84 * Tests that we show the "Report this page is okay" menu item at 85 * a reported attack site. 86 */ 87 add_task(async function () { 88 await check_menu_at_page(PHISH_PAGE, (reportMenu, errorMenu) => { 89 ok( 90 reportMenu.hidden, 91 "Report phishing menu should be hidden on phishing sites" 92 ); 93 ok( 94 !errorMenu.hidden, 95 "Report error menu item should be visible on phishing sites" 96 ); 97 }); 98 });