Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: os == 'android'
- Manifest: toolkit/components/url-classifier/tests/mochitest/chrome.toml
<!DOCTYPE HTML>
<!-- Any copyright is dedicated to the Public Domain.
<html>
<head>
<title>Test advisory link (Bug #1366384)</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 {TestUtils} = ChromeUtils.importESModule(
);
const {BrowserTestUtils} = ChromeUtils.importESModule(
);
var mainWindow = window.browsingContext.topChromeWindow;
var testDatas = [
{ url: "itisaphishingsite.org/phishing.html",
list: "mochi1-phish-simple",
provider: "google",
},
{ url: "fakeitisaphishingsite.org/phishing.html",
list: "fake1-phish-simple",
provider: "mozilla",
},
{ url: "phishing.example.com/test.html",
list: "mochi2-phish-simple",
provider: "google4",
},
];
let 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";
promises.push(pushPrefs([providerList, data.list]));
let activeTablePref = "urlclassifier.phishTable";
let activeTable = SpecialPowers.getCharPref(activeTablePref);
activeTable += "," + data.list;
promises.push(pushPrefs([activeTablePref, activeTable]));
promises.push(addUrlToDB(data.list, data.url));
return Promise.all(promises);
}
function testOnWindow(aTestData) {
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;
BrowserTestUtils.startLoadingURIString(browser, aTestData.url);
await BrowserTestUtils.waitForContentEvent(browser, "DOMContentLoaded");
let doc = win.gBrowser.contentDocument;
// This test works on a document which uses Fluent.
// Fluent localization may finish later than DOMContentLoaded,
// so let's wait for `document.l10n.ready` promise to resolve.
await doc.l10n.ready;
let advisoryEl = doc.getElementById("advisory_provider");
if (aTestData.provider != "google" && aTestData.provider != "google4") {
ok(!advisoryEl, "Advisory should not be shown");
} else {
ok(advisoryEl, "Advisory element should exist");
let expectedUrl =
SpecialPowers.getCharPref("browser.safebrowsing.provider." +
aTestData.provider +
".advisoryURL");
is(advisoryEl.href, expectedUrl, "Correct advisory url");
let expectedText =
SpecialPowers.getCharPref("browser.safebrowsing.provider." +
aTestData.provider +
".advisoryName");
is(advisoryEl.text, expectedText, "correct advisory text");
}
win.close();
resolve();
})();
});
}
SpecialPowers.pushPrefEnv(
{"set": [["browser.safebrowsing.phishing.enabled", true]]},
test);
function test() {
(async function() {
await classifierHelper.waitForInit();
for (let testData of testDatas) {
await setupTestData(testData);
await testOnWindow(testData);
await classifierHelper._cleanup();
}
SimpleTest.finish();
})();
}
SimpleTest.waitForExplicitFinish();
</script>
</pre>
<iframe id="testFrame" width="100%" height="100%" onload=""></iframe>
</body>
</html>