Bug 1045809: mixedContentChannel is set to null and page is reloaded to re-engage mixed content blocking r=jaws

This commit is contained in:
Georgios Kontaxis 2014-08-22 20:26:14 -07:00
parent cd6f7af784
commit cd563545d7
6 changed files with 112 additions and 0 deletions

View File

@ -86,6 +86,8 @@ support-files =
test_no_mcb_on_http_site_font2.html
test_no_mcb_on_http_site_font2.css
xul_tooltiptext.xhtml
file_bug1045809_1.html
file_bug1045809_2.html
[browser_URLBarSetURI.js]
skip-if = (os == "linux" || os == "mac") && debug # bug 970052, bug 970053
@ -459,3 +461,4 @@ skip-if = e10s # Bug 516755 - SessionStore disabled for e10s
[browser_bug1025195_switchToTabHavingURI_ignoreFragment.js]
[browser_addCertException.js]
skip-if = e10s # Bug ?????? - test directly manipulates content (content.document.getElementById)
[browser_bug1045809.js]

View File

@ -0,0 +1,77 @@
// Test that the Mixed Content Doorhanger Action to re-enable protection works
const PREF_ACTIVE = "security.mixed_content.block_active_content";
var origBlockActive;
add_task(function* () {
registerCleanupFunction(function() {
Services.prefs.setBoolPref(PREF_ACTIVE, origBlockActive);
gBrowser.removeCurrentTab();
});
// Store original preferences so we can restore settings after testing
origBlockActive = Services.prefs.getBoolPref(PREF_ACTIVE);
// Make sure mixed content blocking is on
Services.prefs.setBoolPref(PREF_ACTIVE, true);
var url =
"https://test1.example.com/browser/browser/base/content/test/general/" +
"file_bug1045809_1.html";
let tab = gBrowser.selectedTab = gBrowser.addTab();
// Test 1: mixed content must be blocked
yield promiseTabLoadEvent(tab, url);
test1(gBrowser.getBrowserForTab(tab));
yield promiseTabLoadEvent(tab);
// Test 2: mixed content must NOT be blocked
test2(gBrowser.getBrowserForTab(tab));
// Test 3: mixed content must be blocked again
yield promiseTabLoadEvent(tab);
test3(gBrowser.getBrowserForTab(tab));
});
function test1(gTestBrowser) {
var notification =
PopupNotifications.getNotification("bad-content", gTestBrowser);
isnot(notification, null, "Mixed Content Doorhanger did appear in Test1");
notification.reshow();
isnot(PopupNotifications.panel.firstChild.isMixedContentBlocked, 0,
"Mixed Content is being blocked in Test1");
var x = content.document.getElementsByTagName('iframe')[0].contentDocument.getElementById('mixedContentContainer');
is(x, null, "Mixed Content is NOT to be found in Test1");
// Disable Mixed Content Protection for the page (and reload)
PopupNotifications.panel.firstChild.disableMixedContentProtection();
}
function test2(gTestBrowser) {
var notification =
PopupNotifications.getNotification("bad-content", gTestBrowser);
isnot(notification, null, "Mixed Content Doorhanger did appear in Test2");
notification.reshow();
is(PopupNotifications.panel.firstChild.isMixedContentBlocked, 0,
"Mixed Content is NOT being blocked in Test2");
var x = content.document.getElementsByTagName('iframe')[0].contentDocument.getElementById('mixedContentContainer');
isnot(x, null, "Mixed Content is to be found in Test2");
// Re-enable Mixed Content Protection for the page (and reload)
PopupNotifications.panel.firstChild.enableMixedContentProtection();
}
function test3(gTestBrowser) {
var notification =
PopupNotifications.getNotification("bad-content", gTestBrowser);
isnot(notification, null, "Mixed Content Doorhanger did appear in Test3");
notification.reshow();
isnot(PopupNotifications.panel.firstChild.isMixedContentBlocked, 0,
"Mixed Content is being blocked in Test3");
var x = content.document.getElementsByTagName('iframe')[0].contentDocument.getElementById('mixedContentContainer');
is(x, null, "Mixed Content is NOT to be found in Test3");
}

View File

@ -0,0 +1,7 @@
<html>
<head>
</head>
<body>
<iframe src="http://test1.example.com/browser/browser/base/content/test/general/file_bug1045809_2.html"></iframe>
</body>
</html>

View File

@ -0,0 +1,7 @@
<html>
<head>
</head>
<body>
<div id="mixedContentContainer">Mixed Content is here</div>
</body>
</html>

View File

@ -1614,6 +1614,10 @@
hidden="true" label="&mixedContentBlocked2.unblock.label;"
accesskey="&mixedContentBlocked2.unblock.accesskey;"
oncommand="document.getBindingParent(this).disableMixedContentProtection();"/>
<xul:menuitem anonid="mixedContentAction.block"
hidden="true" label="&mixedContentBlocked2.block.label;"
accesskey="&mixedContentBlocked2.block.accesskey;"
oncommand="document.getBindingParent(this).enableMixedContentProtection();"/>
</xul:menupopup>
</xul:button>
</xul:hbox>
@ -1646,6 +1650,10 @@
document.getAnonymousElementByAttribute(this, "anonid",
"mixedContentAction.unblock")
</field>
<field name="_mixedContentBlock">
document.getAnonymousElementByAttribute(this, "anonid",
"mixedContentAction.block");
</field>
<field name="_mixedContentProtectionDisabledWarning">
document.getAnonymousElementByAttribute(this, "anonid",
"mixedContentProtectionDisabled")
@ -1680,6 +1688,7 @@
if (this.notification.options.state &
Ci.nsIWebProgressListener.STATE_LOADED_MIXED_ACTIVE_CONTENT) {
_mixedContent.hidden = false;
_mixedContentBlock.hidden = false;
_mixedContentProtectionDisabledWarning.hidden = false;
_mixedContentHelpLink.href =
Services.urlFormatter.formatURLPref("app.support.baseURL")
@ -1699,6 +1708,13 @@
nsIWebNavigation.LOAD_FLAGS_ALLOW_MIXED_CONTENT);
]]></body>
</method>
<method name="enableMixedContentProtection">
<body><![CDATA[
let docShell = gBrowser.webNavigation.QueryInterface(Ci.nsIDocShell);
docShell.mixedContentChannel = null;
BrowserReload();
]]></body>
</method>
</implementation>
</binding>

View File

@ -733,6 +733,8 @@ just addresses the organization to follow, e.g. "This site is run by " -->
<!ENTITY mixedContentBlocked2.options "Options">
<!ENTITY mixedContentBlocked2.unblock.label "Disable protection for now">
<!ENTITY mixedContentBlocked2.unblock.accesskey "D">
<!ENTITY mixedContentBlocked2.block.label "Enable protection">
<!ENTITY mixedContentBlocked2.block.accesskey "B">
<!ENTITY mixedContentBlocked2.disabled.message "Protection is disabled">
<!ENTITY pointerLock.notification.message "Press ESC at any time to show it again.">