mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 418354 - Allow Mixed Content Blocker to handle redirects - testcases. r=smaug
This commit is contained in:
parent
fe101603e9
commit
8bdb978066
@ -89,6 +89,9 @@ support-files =
|
||||
test_no_mcb_on_http_site_font.css
|
||||
test_no_mcb_on_http_site_font2.html
|
||||
test_no_mcb_on_http_site_font2.css
|
||||
test_mcb_redirect.html
|
||||
test_mcb_redirect.js
|
||||
test_mcb_redirect.sjs
|
||||
xul_tooltiptext.xhtml
|
||||
file_bug1045809_1.html
|
||||
file_bug1045809_2.html
|
||||
@ -503,3 +506,4 @@ skip-if = e10s # Bug 1068360 - [e10s] Mixed content blocker doorhanger doesn't w
|
||||
[browser_e10s_switchbrowser.js]
|
||||
[browser_blockHPKP.js]
|
||||
skip-if = e10s # bug ?????? - test directly manipulates content (content.document.getElementById)
|
||||
[browser_mcb_redirect.js]
|
||||
|
110
browser/base/content/test/general/browser_mcb_redirect.js
Normal file
110
browser/base/content/test/general/browser_mcb_redirect.js
Normal file
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Description of the Tests for
|
||||
* - Bug 418354 - Call Mixed content blocking on redirects
|
||||
*
|
||||
* 1. Load a script over https inside an https page
|
||||
* - the server responds with a 302 redirect to a >> HTTP << script
|
||||
* - the doorhanger should appear!
|
||||
*
|
||||
* 2. Load a script over https inside an http page
|
||||
* - the server responds with a 302 redirect to a >> HTTP << script
|
||||
* - the doorhanger should not appear!
|
||||
*/
|
||||
|
||||
const PREF_ACTIVE = "security.mixed_content.block_active_content";
|
||||
const gHttpsTestRoot = "https://example.com/browser/browser/base/content/test/general/";
|
||||
const gHttpTestRoot = "http://example.com/browser/browser/base/content/test/general/";
|
||||
|
||||
let origBlockActive;
|
||||
var gTestBrowser = null;
|
||||
|
||||
//------------------------ Helper Functions ---------------------
|
||||
|
||||
registerCleanupFunction(function() {
|
||||
// Set preferences back to their original values
|
||||
Services.prefs.setBoolPref(PREF_ACTIVE, origBlockActive);
|
||||
});
|
||||
|
||||
function cleanUpAfterTests() {
|
||||
gBrowser.removeCurrentTab();
|
||||
window.focus();
|
||||
finish();
|
||||
}
|
||||
|
||||
function waitForCondition(condition, nextTest, errorMsg, okMsg) {
|
||||
var tries = 0;
|
||||
var interval = setInterval(function() {
|
||||
if (tries >= 30) {
|
||||
ok(false, errorMsg);
|
||||
moveOn();
|
||||
}
|
||||
if (condition()) {
|
||||
ok(true, okMsg)
|
||||
moveOn();
|
||||
}
|
||||
tries++;
|
||||
}, 100);
|
||||
var moveOn = function() {
|
||||
clearInterval(interval); nextTest();
|
||||
};
|
||||
}
|
||||
|
||||
//------------------------ Test 1 ------------------------------
|
||||
|
||||
function test1() {
|
||||
gTestBrowser.addEventListener("load", checkPopUpNotificationsForTest1, true);
|
||||
var url = gHttpsTestRoot + "test_mcb_redirect.html"
|
||||
gTestBrowser.contentWindow.location = url;
|
||||
}
|
||||
|
||||
function checkPopUpNotificationsForTest1() {
|
||||
gTestBrowser.removeEventListener("load", checkPopUpNotificationsForTest1, true);
|
||||
|
||||
var notification = PopupNotifications.getNotification("bad-content", gTestBrowser.selectedBrowser);
|
||||
ok(notification, "OK: Mixed Content Doorhanger appeared in Test1!");
|
||||
|
||||
var expected = "script blocked";
|
||||
waitForCondition(
|
||||
function() content.document.getElementById('mctestdiv').innerHTML == expected,
|
||||
test2, "Error: Waited too long for status in Test 1!",
|
||||
"OK: Expected result in innerHTML for Test1!");
|
||||
}
|
||||
|
||||
//------------------------ Test 2 ------------------------------
|
||||
|
||||
function test2() {
|
||||
gTestBrowser.addEventListener("load", checkPopUpNotificationsForTest2, true);
|
||||
var url = gHttpTestRoot + "test_mcb_redirect.html"
|
||||
gTestBrowser.contentWindow.location = url;
|
||||
}
|
||||
|
||||
function checkPopUpNotificationsForTest2() {
|
||||
gTestBrowser.removeEventListener("load", checkPopUpNotificationsForTest2, true);
|
||||
|
||||
var notification = PopupNotifications.getNotification("bad-content", gTestBrowser.selectedBrowser);
|
||||
ok(!notification, "OK: Mixed Content Doorhanger did not appear in 2!");
|
||||
|
||||
var expected = "script executed";
|
||||
waitForCondition(
|
||||
function() content.document.getElementById('mctestdiv').innerHTML == expected,
|
||||
cleanUpAfterTests, "Error: Waited too long for status in Test 2!",
|
||||
"OK: Expected result in innerHTML for Test2!");
|
||||
}
|
||||
|
||||
//------------------------ SETUP ------------------------------
|
||||
|
||||
function test() {
|
||||
// Performing async calls, e.g. 'onload', we have to wait till all of them finished
|
||||
waitForExplicitFinish();
|
||||
|
||||
// Store original preferences so we can restore settings after testing
|
||||
origBlockActive = Services.prefs.getBoolPref(PREF_ACTIVE);
|
||||
Services.prefs.setBoolPref(PREF_ACTIVE, true);
|
||||
|
||||
var newTab = gBrowser.addTab();
|
||||
gBrowser.selectedTab = newTab;
|
||||
gTestBrowser = gBrowser.selectedBrowser;
|
||||
newTab.linkedBrowser.stop();
|
||||
|
||||
executeSoon(test1);
|
||||
}
|
15
browser/base/content/test/general/test_mcb_redirect.html
Normal file
15
browser/base/content/test/general/test_mcb_redirect.html
Normal file
@ -0,0 +1,15 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
Test 1 for Bug 418354 - See file browser_mcb_redirect.js for description.
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=418354
|
||||
-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Bug 418354</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="mctestdiv">script blocked</div>
|
||||
<script src="https://example.com/browser/browser/base/content/test/general/test_mcb_redirect.sjs" ></script>
|
||||
</body>
|
||||
</html>
|
5
browser/base/content/test/general/test_mcb_redirect.js
Normal file
5
browser/base/content/test/general/test_mcb_redirect.js
Normal file
@ -0,0 +1,5 @@
|
||||
/*
|
||||
* Once the mixed content blocker is disabled for the page, this scripts loads
|
||||
* and updates the text inside the div container.
|
||||
*/
|
||||
document.getElementById("mctestdiv").innerHTML = "script executed";
|
11
browser/base/content/test/general/test_mcb_redirect.sjs
Normal file
11
browser/base/content/test/general/test_mcb_redirect.sjs
Normal file
@ -0,0 +1,11 @@
|
||||
function handleRequest(request, response) {
|
||||
var page = "<!DOCTYPE html><html><body>bug 418354</body></html>";
|
||||
|
||||
var redirect = "http://example.com/browser/browser/base/content/test/general/test_mcb_redirect.js";
|
||||
|
||||
response.setHeader("Cache-Control", "no-cache", false);
|
||||
response.setHeader("Content-Type", "text/html", false);
|
||||
response.setStatusLine(request.httpVersion, "302", "Found");
|
||||
response.setHeader("Location", redirect, false);
|
||||
response.write(page);
|
||||
}
|
Loading…
Reference in New Issue
Block a user