summaryrefslogtreecommitdiffstats
path: root/browser/components/safebrowsing/content/test
diff options
context:
space:
mode:
Diffstat (limited to 'browser/components/safebrowsing/content/test')
-rw-r--r--browser/components/safebrowsing/content/test/.eslintrc.js7
-rw-r--r--browser/components/safebrowsing/content/test/browser.ini8
-rw-r--r--browser/components/safebrowsing/content/test/browser_bug400731.js58
-rw-r--r--browser/components/safebrowsing/content/test/browser_bug415846.js86
-rw-r--r--browser/components/safebrowsing/content/test/browser_whitelisted.js41
-rw-r--r--browser/components/safebrowsing/content/test/head.js55
6 files changed, 255 insertions, 0 deletions
diff --git a/browser/components/safebrowsing/content/test/.eslintrc.js b/browser/components/safebrowsing/content/test/.eslintrc.js
new file mode 100644
index 000000000..7c8021192
--- /dev/null
+++ b/browser/components/safebrowsing/content/test/.eslintrc.js
@@ -0,0 +1,7 @@
+"use strict";
+
+module.exports = {
+ "extends": [
+ "../../../../../testing/mochitest/browser.eslintrc.js"
+ ]
+};
diff --git a/browser/components/safebrowsing/content/test/browser.ini b/browser/components/safebrowsing/content/test/browser.ini
new file mode 100644
index 000000000..1ce19118e
--- /dev/null
+++ b/browser/components/safebrowsing/content/test/browser.ini
@@ -0,0 +1,8 @@
+[DEFAULT]
+support-files = head.js
+
+[browser_bug400731.js]
+[browser_bug415846.js]
+# Disabled on Mac because of its bizarre special-and-unique snowflake of a help menu.
+skip-if = os == "mac" || e10s # e10s: Bug 1248632
+[browser_whitelisted.js]
diff --git a/browser/components/safebrowsing/content/test/browser_bug400731.js b/browser/components/safebrowsing/content/test/browser_bug400731.js
new file mode 100644
index 000000000..fac187753
--- /dev/null
+++ b/browser/components/safebrowsing/content/test/browser_bug400731.js
@@ -0,0 +1,58 @@
+/* Check presence of the "Ignore this warning" button */
+
+function onDOMContentLoaded(callback) {
+ function complete({ data }) {
+ mm.removeMessageListener("Test:DOMContentLoaded", complete);
+ callback(data);
+ }
+
+ let mm = gBrowser.selectedBrowser.messageManager;
+ mm.addMessageListener("Test:DOMContentLoaded", complete);
+
+ function contentScript() {
+ let listener = function () {
+ removeEventListener("DOMContentLoaded", listener);
+
+ let button = content.document.getElementById("ignoreWarningButton");
+
+ sendAsyncMessage("Test:DOMContentLoaded", { buttonPresent: !!button });
+ };
+ addEventListener("DOMContentLoaded", listener);
+ }
+ mm.loadFrameScript("data:,(" + contentScript.toString() + ")();", true);
+}
+
+function test() {
+ waitForExplicitFinish();
+
+ gBrowser.selectedTab = gBrowser.addTab("http://www.itisatrap.org/firefox/its-an-attack.html");
+ onDOMContentLoaded(testMalware);
+}
+
+function testMalware(data) {
+ ok(data.buttonPresent, "Ignore warning button should be present for malware");
+
+ Services.prefs.setBoolPref("browser.safebrowsing.allowOverride", false);
+
+ // Now launch the unwanted software test
+ onDOMContentLoaded(testUnwanted);
+ gBrowser.loadURI("http://www.itisatrap.org/firefox/unwanted.html");
+}
+
+function testUnwanted(data) {
+ // Confirm that "Ignore this warning" is visible - bug 422410
+ ok(!data.buttonPresent, "Ignore warning button should be missing for unwanted software");
+
+ Services.prefs.setBoolPref("browser.safebrowsing.allowOverride", true);
+
+ // Now launch the phishing test
+ onDOMContentLoaded(testPhishing);
+ gBrowser.loadURI("http://www.itisatrap.org/firefox/its-a-trap.html");
+}
+
+function testPhishing(data) {
+ ok(data.buttonPresent, "Ignore warning button should be present for phishing");
+
+ gBrowser.removeCurrentTab();
+ finish();
+}
diff --git a/browser/components/safebrowsing/content/test/browser_bug415846.js b/browser/components/safebrowsing/content/test/browser_bug415846.js
new file mode 100644
index 000000000..fc2e3472f
--- /dev/null
+++ b/browser/components/safebrowsing/content/test/browser_bug415846.js
@@ -0,0 +1,86 @@
+/* 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.*/
+
+const NORMAL_PAGE = "http://example.com";
+const PHISH_PAGE = "http://www.itisatrap.org/firefox/its-a-trap.html";
+
+/**
+ * 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",
+ }, function*(browser) {
+ // We don't get load events when the DocShell redirects to error
+ // pages, but we do get DOMContentLoaded, so we'll wait for that.
+ let dclPromise = ContentTask.spawn(browser, null, function*() {
+ yield ContentTaskUtils.waitForEvent(this, "DOMContentLoaded", false);
+ });
+ browser.loadURI(url);
+ yield dclPromise;
+
+ let menu = document.getElementById("menu_HelpPopup");
+ ok(menu, "Help menu should exist");
+
+ let reportMenu =
+ document.getElementById("menu_HelpPopup_reportPhishingtoolmenu");
+ ok(reportMenu, "Report phishing menu item should exist");
+
+ let errorMenu =
+ document.getElementById("menu_HelpPopup_reportPhishingErrortoolmenu");
+ ok(errorMenu, "Report phishing error menu item should exist");
+
+ let menuOpen = BrowserTestUtils.waitForEvent(menu, "popupshown");
+ menu.openPopup(null, "", 0, 0, false, null);
+ yield menuOpen;
+
+ testFn(reportMenu, errorMenu);
+
+ let menuClose = BrowserTestUtils.waitForEvent(menu, "popuphidden");
+ menu.hidePopup();
+ yield menuClose;
+ });
+}
+
+/**
+ * Tests that we show the "Report this page" menu item at a normal
+ * page.
+ */
+add_task(function*() {
+ yield check_menu_at_page(NORMAL_PAGE, (reportMenu, errorMenu) => {
+ 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");
+ });
+});
+
+/**
+ * Tests that we show the "Report this page is okay" menu item at
+ * a reported attack site.
+ */
+add_task(function*() {
+ yield check_menu_at_page(PHISH_PAGE, (reportMenu, errorMenu) => {
+ 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");
+ });
+});
+
diff --git a/browser/components/safebrowsing/content/test/browser_whitelisted.js b/browser/components/safebrowsing/content/test/browser_whitelisted.js
new file mode 100644
index 000000000..afb647a81
--- /dev/null
+++ b/browser/components/safebrowsing/content/test/browser_whitelisted.js
@@ -0,0 +1,41 @@
+/* Ensure that hostnames in the whitelisted pref are not blocked. */
+
+const PREF_WHITELISTED_HOSTNAMES = "urlclassifier.skipHostnames";
+const TEST_PAGE = "http://www.itisatrap.org/firefox/its-an-attack.html";
+var tabbrowser = null;
+
+registerCleanupFunction(function() {
+ tabbrowser = null;
+ Services.prefs.clearUserPref(PREF_WHITELISTED_HOSTNAMES);
+ while (gBrowser.tabs.length > 1) {
+ gBrowser.removeCurrentTab();
+ }
+});
+
+function testBlockedPage(window) {
+ info("Non-whitelisted pages must be blocked");
+ ok(true, "about:blocked was shown");
+}
+
+function testWhitelistedPage(window) {
+ info("Whitelisted pages must be skipped");
+ var getmeout_button = window.document.getElementById("getMeOutButton");
+ var ignorewarning_button = window.document.getElementById("ignoreWarningButton");
+ ok(!getmeout_button, "GetMeOut button not present");
+ ok(!ignorewarning_button, "IgnoreWarning button not present");
+}
+
+add_task(function* testNormalBrowsing() {
+ tabbrowser = gBrowser;
+ let tab = tabbrowser.selectedTab = tabbrowser.addTab();
+
+ info("Load a test page that's whitelisted");
+ Services.prefs.setCharPref(PREF_WHITELISTED_HOSTNAMES, "example.com,www.ItIsaTrap.org,example.net");
+ yield promiseTabLoadEvent(tab, TEST_PAGE, "load");
+ testWhitelistedPage(tab.ownerGlobal);
+
+ info("Load a test page that's no longer whitelisted");
+ Services.prefs.setCharPref(PREF_WHITELISTED_HOSTNAMES, "");
+ yield promiseTabLoadEvent(tab, TEST_PAGE, "AboutBlockedLoaded");
+ testBlockedPage(tab.ownerGlobal);
+});
diff --git a/browser/components/safebrowsing/content/test/head.js b/browser/components/safebrowsing/content/test/head.js
new file mode 100644
index 000000000..90eef0a3f
--- /dev/null
+++ b/browser/components/safebrowsing/content/test/head.js
@@ -0,0 +1,55 @@
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this, "Promise",
+ "resource://gre/modules/Promise.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "Task",
+ "resource://gre/modules/Task.jsm");
+
+/**
+ * Waits for a load (or custom) event to finish in a given tab. If provided
+ * load an uri into the tab.
+ *
+ * @param tab
+ * The tab to load into.
+ * @param [optional] url
+ * The url to load, or the current url.
+ * @param [optional] event
+ * The load event type to wait for. Defaults to "load".
+ * @return {Promise} resolved when the event is handled.
+ * @resolves to the received event
+ * @rejects if a valid load event is not received within a meaningful interval
+ */
+function promiseTabLoadEvent(tab, url, eventType="load")
+{
+ info(`Wait tab event: ${eventType}`);
+
+ function handle(loadedUrl) {
+ if (loadedUrl === "about:blank" || (url && loadedUrl !== url)) {
+ info(`Skipping spurious load event for ${loadedUrl}`);
+ return false;
+ }
+
+ info("Tab event received: load");
+ return true;
+ }
+
+ let loaded;
+ if (eventType === "load") {
+ loaded = BrowserTestUtils.browserLoaded(tab.linkedBrowser, false, handle);
+ } else {
+ // No need to use handle.
+ loaded =
+ BrowserTestUtils.waitForContentEvent(tab.linkedBrowser, eventType,
+ true, undefined, true);
+ }
+
+ if (url)
+ BrowserTestUtils.loadURI(tab.linkedBrowser, url);
+
+ return loaded;
+}
+
+Services.prefs.setCharPref("urlclassifier.malwareTable", "test-malware-simple,test-unwanted-simple");
+Services.prefs.setCharPref("urlclassifier.phishTable", "test-phish-simple");
+Services.prefs.setCharPref("urlclassifier.blockedTable", "test-block-simple");
+SafeBrowsing.init();