Bug 415846 - "can't report a page as not actually being a web forgery" (Restore the correct menu behaviour) [r=dcamp r=Pike r=gavin]

This commit is contained in:
Johnathan Nightingale 2008-08-19 23:11:39 -05:00
parent a4e006d515
commit a44c0684f5
4 changed files with 94 additions and 5 deletions

View File

@ -38,13 +38,15 @@
<!DOCTYPE overlay [ <!DOCTYPE overlay [
<!ENTITY % reportphishDTD SYSTEM "chrome://browser/locale/safebrowsing/report-phishing.dtd"> <!ENTITY % reportphishDTD SYSTEM "chrome://browser/locale/safebrowsing/report-phishing.dtd">
%reportphishDTD; %reportphishDTD;
<!ENTITY % safebrowsingDTD SYSTEM "chrome://browser/locale/safebrowsing/phishing-afterload-warning-message.dtd">
%safebrowsingDTD;
]> ]>
<overlay id="reportPhishingMenuOverlay" <overlay id="reportPhishingMenuOverlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<broadcasterset id="mainBroadcasterSet"> <broadcasterset id="mainBroadcasterSet">
<broadcaster id="reportPhishingBroadcaster" disabled="true"/> <broadcaster id="reportPhishingBroadcaster" disabled="true"/>
<!--<broadcaster id="reportPhishingErrorBroadcaster" disabled="true"/>--> <broadcaster id="reportPhishingErrorBroadcaster" disabled="true"/>
</broadcasterset> </broadcasterset>
<menupopup id="menu_HelpPopup"> <menupopup id="menu_HelpPopup">
<menuitem id="menu_HelpPopup_reportPhishingtoolmenu" <menuitem id="menu_HelpPopup_reportPhishingtoolmenu"
@ -54,13 +56,12 @@
observes="reportPhishingBroadcaster" observes="reportPhishingBroadcaster"
oncommand="openUILink(safebrowsing.getReportURL('Phish'), event);" oncommand="openUILink(safebrowsing.getReportURL('Phish'), event);"
onclick="checkForMiddleClick(this, event);"/> onclick="checkForMiddleClick(this, event);"/>
<!-- XXX Bug 415846
<menuitem id="menu_HelpPopup_reportPhishingErrortoolmenu" <menuitem id="menu_HelpPopup_reportPhishingErrortoolmenu"
label="&safeb.palm.notforgery.label2;" label="&safeb.palm.notforgery.label2;"
accesskey="&reportPhishSiteMenu.accesskey;" accesskey="&reportPhishSiteMenu.accesskey;"
insertbefore="updateSeparator" insertbefore="updateSeparator"
observes="reportPhishingErrorBroadcaster" observes="reportPhishingErrorBroadcaster"
oncommand="openUILinkIn(safebrowsing.getReportURL('Error'), 'tab');" oncommand="openUILinkIn(safebrowsing.getReportURL('Error'), 'tab');"
onclick="checkForMiddleClick(this, event);"/>--> onclick="checkForMiddleClick(this, event);"/>
</menupopup> </menupopup>
</overlay> </overlay>

View File

@ -49,12 +49,29 @@ var safebrowsing = {
}, },
setReportPhishingMenu: function() { setReportPhishingMenu: function() {
// A phishing page will have a specific about:blocked content documentURI
var isPhishingPage = /^about:blocked\?e=phishingBlocked/.test(content.document.documentURI);
// Show/hide the appropriate menu item.
document.getElementById("menu_HelpPopup_reportPhishingtoolmenu")
.hidden = isPhishingPage;
document.getElementById("menu_HelpPopup_reportPhishingErrortoolmenu")
.hidden = !isPhishingPage;
var broadcasterId = isPhishingPage
? "reportPhishingErrorBroadcaster"
: "reportPhishingBroadcaster";
var broadcaster = document.getElementById(broadcasterId);
if (!broadcaster)
return;
var uri = getBrowser().currentURI; var uri = getBrowser().currentURI;
var broadcaster = document.getElementById("reportPhishingBroadcaster");
if (uri && (uri.schemeIs("http") || uri.schemeIs("https"))) if (uri && (uri.schemeIs("http") || uri.schemeIs("https")))
broadcaster.removeAttribute("disabled"); broadcaster.removeAttribute("disabled");
else else
broadcaster.disabled = true; broadcaster.setAttribute("disabled", true);
}, },
/** /**

View File

@ -45,7 +45,14 @@ relativesrcdir = browser/components/safebrowsing/content/test
include $(DEPTH)/config/autoconf.mk include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk include $(topsrcdir)/config/rules.mk
# The browser chrome test for bug 415846 doesn't run on Mac because of its
# bizarre special-and-unique snowflake of a help menu.
ifeq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
_NON_MAC_BROWSER_TESTS = browser_bug415846.js
endif
_BROWSER_FILES = browser_bug400731.js \ _BROWSER_FILES = browser_bug400731.js \
$(_NON_MAC_BROWSER_TESTS) \
$(NULL) $(NULL)
libs:: $(_BROWSER_FILES) libs:: $(_BROWSER_FILES)

View File

@ -0,0 +1,64 @@
/* 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.*/
var newBrowser;
var menu;
function test() {
waitForExplicitFinish();
var newTab = gBrowser.addTab();
gBrowser.selectedTab = newTab;
newBrowser = gBrowser.getBrowserForTab(newTab);
// Navigate to a normal site
gBrowser.addEventListener("load", testNormal, false);
newBrowser.contentWindow.location = 'http://example.com/';
}
function testNormal() {
gBrowser.removeEventListener("load", testNormal, false);
// open the menu, to force it to update
menu = document.getElementById("menu_HelpPopup");
ok(menu, "Help menu should exist!");
menu.addEventListener("popupshown", testNormal_PopupListener, false);
menu.openPopup(null, "", 0, 0, false, null);
}
function testNormal_PopupListener() {
menu.removeEventListener("popupshown", testNormal_PopupListener, false);
var reportMenu = document.getElementById("menu_HelpPopup_reportPhishingtoolmenu");
var errorMenu = document.getElementById("menu_HelpPopup_reportPhishingErrortoolmenu");
is(reportMenu.hidden, false, "Report phishing menu should be visible on normal sites");
is(errorMenu.hidden, true, "Report error menu item should be hidden on normal sites");
menu.hidePopup();
// Now launch the phishing test. Can't use onload here because error pages don't
// fire normal load events.
newBrowser.contentWindow.location = 'http://www.mozilla.com/firefox/its-a-trap.html';
window.setTimeout(testPhishing, 2000);
}
function testPhishing() {
menu.addEventListener("popupshown", testPhishing_PopupListener, false);
menu.openPopup(null, "", 0, 0, false, null);
}
function testPhishing_PopupListener() {
menu.removeEventListener("popupshown", testPhishing_PopupListener, false);
var reportMenu = document.getElementById("menu_HelpPopup_reportPhishingtoolmenu");
var errorMenu = document.getElementById("menu_HelpPopup_reportPhishingErrortoolmenu");
is(reportMenu.hidden, true, "Report phishing menu should be hidden on phishing sites");
is(errorMenu.hidden, false, "Report error menu item should be visible on phishing sites");
menu.hidePopup();
gBrowser.removeCurrentTab();
finish();
}