Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: os == 'android' OR verify
- Manifest: toolkit/components/url-classifier/tests/mochitest/chrome.toml
<!DOCTYPE HTML>
<!-- Any copyright is dedicated to the Public Domain.
<html>
<head>
<title>Test report matched URL info (Bug #1288633)</title>
<script type="text/javascript" src="classifierHelper.js"></script>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
const {BrowserTestUtils} = ChromeUtils.importESModule(
);
;
const {TestUtils} = ChromeUtils.importESModule(
);
var mainWindow = window.browsingContext.topChromeWindow;
const SJS = "mochi.test:8888/chrome/toolkit/components/url-classifier/tests/mochitest/report.sjs";
const BASE_URL = "http://" + SJS + "?";
var pushPrefs = (...p) => SpecialPowers.pushPrefEnv({set: p});
function addUrlToDB(list, url) {
let testData = [{ db: list, url}];
return classifierHelper.addUrlToDB(testData)
.catch(function(err) {
ok(false, "Couldn't update classifier. Error code: " + err);
// Abort test.
SimpleTest.finish();
});
}
function setupTestData(data) {
let promises = [];
let providerList = "browser.safebrowsing.provider." + data.provider + ".lists";
if (!Services.prefs.prefHasUserValue(providerList)) {
promises.push(pushPrefs([providerList, data.list]));
} else {
let pref = SpecialPowers.getCharPref(providerList);
pref += "," + data.list;
promises.push(pushPrefs([providerList, pref]));
}
let activeTablePref = "urlclassifier.phishTable";
let activeTable = SpecialPowers.getCharPref(activeTablePref);
activeTable += "," + data.list;
promises.push(pushPrefs([activeTablePref, activeTable]));
promises.push(addUrlToDB(data.list, data.testUrl));
return Promise.all(promises);
}
function testOnWindow(aTestData, aCallback, aTestCreater) {
return new Promise(resolve => {
let win = mainWindow.OpenBrowserWindow();
(async function() {
await TestUtils.topicObserved("browser-delayed-startup-finished",
subject => subject == win);
let browser = win.gBrowser.selectedBrowser;
aTestCreater(win, browser, aTestData.topUrl, aTestData.testUrl);
let notification = await BrowserTestUtils.waitForNotificationBar(win.gBrowser, browser, "blocked-badware-page");
ok(notification, "Notification box should be displayed");
let buttons = notification.buttonContainer.getElementsByTagName("button");
let button = buttons[1];
if (aTestData.provider != "google" && aTestData.provider != "google4") {
is(button, undefined, "Report button should not be showed");
win.close();
resolve();
return;
}
button.click();
let newTabBrowser = win.gBrowser.selectedTab.linkedBrowser;
await BrowserTestUtils.browserLoaded(newTabBrowser);
aCallback(newTabBrowser);
win.close();
resolve();
})();
});
}
var createBlockedIframe = function(aWindow, aBrowser, aTopUrl, aUrl) {
(async function() {
BrowserTestUtils.startLoadingURIString(aBrowser, aTopUrl);
await BrowserTestUtils.browserLoaded(aBrowser);
await SpecialPowers.spawn(aBrowser, [aUrl], async function(url) {
return new Promise(resolve => {
let listener = () => {
docShell.chromeEventHandler.removeEventListener("AboutBlockedLoaded", listener, false, true);
resolve();
};
docShell.chromeEventHandler.addEventListener("AboutBlockedLoaded", listener, false, true);
let frame = content.document.getElementById("phishingFrame");
frame.setAttribute("src", "http://" + url);
});
});
let doc = aWindow.gBrowser.contentDocument.getElementsByTagName("iframe")[0].contentDocument;
let ignoreWarningLink = doc.getElementById("ignore_warning_link");
ok(ignoreWarningLink, "Ignore warning link should exist");
ignoreWarningLink.click();
})();
};
var createBlockedPage = function(aWindow, aBrowser, aTopUrl) {
(async function() {
BrowserTestUtils.startLoadingURIString(aBrowser, aTopUrl);
await BrowserTestUtils.waitForContentEvent(aBrowser, "DOMContentLoaded");
let doc = aWindow.gBrowser.contentDocument;
let ignoreWarningLink = doc.getElementById("ignore_warning_link");
ok(ignoreWarningLink, "Ignore warning link should exist");
ignoreWarningLink.click();
})();
};
function checkReportURL(aReportBrowser, aUrl) {
let expectedReportUrl = BASE_URL + "action=reporturl&reporturl=" + encodeURIComponent(aUrl);
is(aReportBrowser.contentDocument.location.href, expectedReportUrl, "Correct report URL");
}
var testDatas = [
testUrl: "itisaphishingsite.org/phishing.html",
list: "mochi1-phish-simple",
provider: "google",
blockCreater: createBlockedPage,
},
// Non-google provider, no report button is showed.
// Test provider needs a valid update URL (mozilla for example) otherwise
// the updates inserting the test data will fail.
testUrl: "fakeitisaphishingsite.org/phishing.html",
list: "fake-phish-simple",
provider: "mozilla",
blockCreater: createBlockedPage,
},
// Iframe case:
// A top level page at
testUrl: "phishing.example.com/test.html",
list: "mochi2-phish-simple",
provider: "google4",
blockCreater: createBlockedIframe,
},
// Redirect case:
// A top level page at
// will get redirected to
testUrl: "prefixexample.com/chrome/toolkit/components/url-classifier/tests/mochitest/report.sjs?action=create-blocked-redirect",
list: "mochi3-phish-simple",
provider: "google4",
blockCreater: createBlockedPage,
expectedReportUri: "http://prefixexample.com/chrome/toolkit/components/url-classifier/tests/mochitest/report.sjs",
},
];
SpecialPowers.pushPrefEnv(
{"set": [["browser.safebrowsing.provider.google.reportPhishMistakeURL", BASE_URL + "action=reporturl&reporturl="],
["browser.safebrowsing.provider.google4.reportPhishMistakeURL", BASE_URL + "action=reporturl&reporturl="],
["browser.safebrowsing.phishing.enabled", true]]},
test);
function test() {
(async function() {
await classifierHelper.waitForInit();
for (let testData of testDatas) {
await setupTestData(testData);
await testOnWindow(testData, function(browser) {
checkReportURL(browser, testData.expectedReportUri);
}, testData.blockCreater);
await classifierHelper._cleanup();
}
SimpleTest.finish();
})();
}
SimpleTest.waitForExplicitFinish();
</script>
</pre>
<iframe id="testFrame" width="100%" height="100%" onload=""></iframe>
</body>
</html>