Backed out changeset 6cdc38306375 (bug 1522630) for mochitest-chrome failure at toolkit/components/url-classifier/tests/mochitest/test_threathit_report.html on a CLOSED TREE

This commit is contained in:
Daniel Varga 2019-01-26 01:52:46 +02:00
Родитель 78fdef6013
Коммит b48100112a
6 изменённых файлов: 102 добавлений и 156 удалений

Просмотреть файл

@ -7,14 +7,12 @@ const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/
const BENIGN_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/benignPage.html";
const TP_PREF = "privacy.trackingprotection.enabled";
const ANIMATIONS_PREF = "toolkit.cosmeticAnimations.enabled";
const DTSCBN_PREF = "dom.testing.sync-content-blocking-notifications";
// Test that the shield icon animation can be controlled by the cosmetic
// animations pref and that one of the icons is visible in each case.
add_task(async function testShieldAnimation() {
await UrlClassifierTestUtils.addTestTrackers();
Services.prefs.setBoolPref(TP_PREF, true);
Services.prefs.setBoolPref(DTSCBN_PREF, true);
let tab = gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
@ -22,8 +20,7 @@ add_task(async function testShieldAnimation() {
let noAnimationIcon = document.getElementById("tracking-protection-icon");
Services.prefs.setBoolPref(ANIMATIONS_PREF, true);
await Promise.all([promiseTabLoadEvent(tab, TRACKING_PAGE),
waitForContentBlockingEvent(2, tab.linkedBrowser.ownerGlobal)]);
await promiseTabLoadEvent(tab, TRACKING_PAGE);
ok(BrowserTestUtils.is_hidden(noAnimationIcon), "the default icon is hidden when animations are enabled");
ok(BrowserTestUtils.is_visible(animationIcon), "the animated icon is shown when animations are enabled");
@ -32,14 +29,12 @@ add_task(async function testShieldAnimation() {
ok(BrowserTestUtils.is_hidden(noAnimationIcon), "the default icon is hidden");
Services.prefs.setBoolPref(ANIMATIONS_PREF, false);
await Promise.all([promiseTabLoadEvent(tab, TRACKING_PAGE),
waitForContentBlockingEvent(2, tab.linkedBrowser.ownerGlobal)]);
await promiseTabLoadEvent(tab, TRACKING_PAGE);
ok(BrowserTestUtils.is_visible(noAnimationIcon), "the default icon is shown when animations are disabled");
ok(BrowserTestUtils.is_hidden(animationIcon), "the animated icon is hidden when animations are disabled");
gBrowser.removeCurrentTab();
Services.prefs.clearUserPref(ANIMATIONS_PREF);
Services.prefs.clearUserPref(TP_PREF);
Services.prefs.clearUserPref(DTSCBN_PREF);
UrlClassifierTestUtils.cleanupTestTrackers();
});

Просмотреть файл

@ -11,7 +11,6 @@ const NCB_PREF = "network.cookie.cookieBehavior";
const BENIGN_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/benignPage.html";
const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html";
const COOKIE_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/cookiePage.html";
const DTSCBN_PREF = "dom.testing.sync-content-blocking-notifications";
requestLongerTimeout(2);
@ -20,13 +19,10 @@ registerCleanupFunction(function() {
Services.prefs.clearUserPref(TP_PREF);
Services.prefs.clearUserPref(TP_PB_PREF);
Services.prefs.clearUserPref(NCB_PREF);
Services.prefs.clearUserPref(DTSCBN_PREF);
Services.prefs.clearUserPref(ContentBlocking.prefIntroCount);
});
async function testTrackingProtectionAnimation(tabbrowser) {
Services.prefs.setBoolPref(DTSCBN_PREF, true);
info("Load a test page not containing tracking elements");
let benignTab = await BrowserTestUtils.openNewForegroundTab(tabbrowser, BENIGN_PAGE);
let ContentBlocking = tabbrowser.ownerGlobal.ContentBlocking;

Просмотреть файл

@ -6,14 +6,12 @@
const TP_PB_PREF = "privacy.trackingprotection.enabled";
const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html";
const DTSCBN_PREF = "dom.testing.sync-content-blocking-notifications";
var TrackingProtection = null;
var ContentBlocking = null;
var browser = null;
registerCleanupFunction(function() {
Services.prefs.clearUserPref(TP_PB_PREF);
Services.prefs.clearUserPref(DTSCBN_PREF);
ContentBlocking = TrackingProtection = browser = null;
UrlClassifierTestUtils.cleanupTestTrackers();
});
@ -81,7 +79,6 @@ function testTrackingPageUnblocked() {
add_task(async function testExceptionAddition() {
await UrlClassifierTestUtils.addTestTrackers();
Services.prefs.setBoolPref(DTSCBN_PREF, true);
let privateWin = await BrowserTestUtils.openNewBrowserWindow({private: true});
browser = privateWin.gBrowser;
let tab = await BrowserTestUtils.openNewForegroundTab({ gBrowser: browser, waitForLoad: true, waitForStateStop: true });
@ -95,8 +92,7 @@ add_task(async function testExceptionAddition() {
ok(TrackingProtection.enabled, "TP is enabled after setting the pref");
info("Load a test page containing tracking elements");
await Promise.all([promiseTabLoadEvent(tab, TRACKING_PAGE),
waitForContentBlockingEvent(2, tab.ownerGlobal)]);
await promiseTabLoadEvent(tab, TRACKING_PAGE);
testTrackingPage(tab.ownerGlobal);
@ -132,8 +128,7 @@ add_task(async function testExceptionPersistence() {
ok(TrackingProtection.enabled, "TP is still enabled");
info("Load a test page containing tracking elements");
await Promise.all([promiseTabLoadEvent(tab, TRACKING_PAGE),
waitForContentBlockingEvent(2, tab.ownerGlobal)]);
await promiseTabLoadEvent(tab, TRACKING_PAGE);
testTrackingPage(tab.ownerGlobal);
@ -142,8 +137,7 @@ add_task(async function testExceptionPersistence() {
clickButton("#tracking-action-unblock");
is(identityPopupState(), "closed", "Identity popup is closed");
await Promise.all([tabReloadPromise,
waitForContentBlockingEvent(2, tab.ownerGlobal)]);
await tabReloadPromise;
testTrackingPageUnblocked();
privateWin.close();

Просмотреть файл

@ -17,7 +17,6 @@
const TP_PREF = "privacy.trackingprotection.enabled";
const TP_PB_PREF = "privacy.trackingprotection.pbmode.enabled";
const TPC_PREF = "network.cookie.cookieBehavior";
const DTSCBN_PREF = "dom.testing.sync-content-blocking-notifications";
const BENIGN_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/benignPage.html";
const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/trackingUI/trackingPage.html";
const COOKIE_PAGE = "http://not-tracking.example.com/browser/browser/base/content/test/trackingUI/cookiePage.html";
@ -34,7 +33,6 @@ registerCleanupFunction(function() {
Services.prefs.clearUserPref(TP_PREF);
Services.prefs.clearUserPref(TP_PB_PREF);
Services.prefs.clearUserPref(TPC_PREF);
Services.prefs.clearUserPref(DTSCBN_PREF);
});
// This is a special version of "hidden" that doesn't check for item
@ -108,8 +106,8 @@ function testTrackingPage(window) {
ok(ContentBlocking.content.hasAttribute("detected"), "trackers are detected");
ok(!ContentBlocking.content.hasAttribute("hasException"), "content shows no exception");
let isWindowPrivate = PrivateBrowsingUtils.isWindowPrivate(window);
let blockedByTP = areTrackersBlocked(isWindowPrivate);
let isPrivateBrowsing = PrivateBrowsingUtils.isWindowPrivate(window);
let blockedByTP = areTrackersBlocked(isPrivateBrowsing);
is(BrowserTestUtils.is_visible(ContentBlocking.iconBox), blockedByTP,
"icon box is" + (blockedByTP ? "" : " not") + " visible");
is(ContentBlocking.iconBox.hasAttribute("active"), blockedByTP,
@ -121,6 +119,7 @@ function testTrackingPage(window) {
ok(hidden("#tracking-action-block"), "blockButton is hidden");
let isWindowPrivate = PrivateBrowsingUtils.isWindowPrivate(window);
if (isWindowPrivate) {
ok(hidden("#tracking-action-unblock"), "unblockButton is hidden");
is(!hidden("#tracking-action-unblock-private"), blockedByTP,
@ -219,8 +218,6 @@ async function testContentBlocking(tab) {
add_task(async function testNormalBrowsing() {
await UrlClassifierTestUtils.addTestTrackers();
Services.prefs.setBoolPref(DTSCBN_PREF, true);
tabbrowser = gBrowser;
let tab = tabbrowser.selectedTab = BrowserTestUtils.addTab(tabbrowser);

Просмотреть файл

@ -8,7 +8,6 @@ const BENIGN_PAGE = "http://tracking.example.org/browser/browser/base/content/te
const TP_PREF = "privacy.trackingprotection.enabled";
const COOKIE_PREF = "network.cookie.cookieBehavior";
const ANIMATIONS_PREF = "toolkit.cosmeticAnimations.enabled";
const DTSCBN_PREF = "dom.testing.sync-content-blocking-notifications";
// Check that the shield icon is always hidden when all content blocking
// categories are turned off, even when content blocking is on.
@ -16,7 +15,6 @@ add_task(async function testContentBlockingAllDisabled() {
await SpecialPowers.pushPrefEnv({set: [
[TP_PREF, false],
[COOKIE_PREF, Ci.nsICookieService.BEHAVIOR_ACCEPT],
[DTSCBN_PREF, true],
]});
await UrlClassifierTestUtils.addTestTrackers();
@ -32,8 +30,7 @@ add_task(async function testContentBlockingAllDisabled() {
let animationIcon = document.getElementById("tracking-protection-icon-animatable-image");
let noAnimationIcon = document.getElementById("tracking-protection-icon");
await Promise.all([promiseTabLoadEvent(tab, TRACKING_PAGE),
waitForContentBlockingEvent(2, tab.ownerGlobal)]);
await promiseTabLoadEvent(tab, TRACKING_PAGE);
ok(BrowserTestUtils.is_hidden(noAnimationIcon), "the default icon is hidden");
ok(BrowserTestUtils.is_hidden(animationIcon), "the animated icon is hidden");
@ -50,7 +47,6 @@ add_task(async function testContentBlockingAllDisabled() {
await SpecialPowers.pushPrefEnv({set: [
[TP_PREF, true],
]});
await Promise.all([promiseTabLoadEvent(tab, TRACKING_PAGE),
waitForContentBlockingEvent(2, tab.ownerGlobal)]);
await promiseTabLoadEvent(tab, TRACKING_PAGE);
ok(BrowserTestUtils.is_visible(noAnimationIcon), "the default icon is shown");
});

Просмотреть файл

@ -319,8 +319,6 @@ static LazyLogModule gDOMLeakPRLogOuter("DOMLeakOuter");
static int32_t gOpenPopupSpamCount = 0;
static bool gSyncContentBlockingNotifications = false;
nsGlobalWindowOuter::OuterWindowByIdTable*
nsGlobalWindowOuter::sOuterWindowsById = nullptr;
@ -5407,130 +5405,100 @@ void nsGlobalWindowOuter::NotifyContentBlockingEvent(unsigned aEvent,
nsCOMPtr<Document> doc = docShell->GetDocument();
NS_ENSURE_TRUE_VOID(doc);
nsCOMPtr<nsIURI> uri(aURIHint);
nsCOMPtr<nsIChannel> channel(aChannel);
static bool prefInitialized = false;
if (!prefInitialized) {
Preferences::AddBoolVarCache(
&gSyncContentBlockingNotifications,
"dom.testing.sync-content-blocking-notifications", false);
prefInitialized = true;
}
nsCOMPtr<nsIRunnable> func = NS_NewRunnableFunction(
"NotifyContentBlockingEventDelayed",
[doc, docShell, uri, channel, aEvent, aBlocked]() {
// This event might come after the user has navigated to another
// page. To prevent showing the TrackingProtection UI on the wrong
// page, we need to check that the loading URI for the channel is
// the same as the URI currently loaded in the document.
if (!SameLoadingURI(doc, channel) &&
aEvent == nsIWebProgressListener::STATE_BLOCKED_TRACKING_CONTENT) {
return;
}
// Notify nsIWebProgressListeners of this content blocking event.
// Can be used to change the UI state.
nsresult rv = NS_OK;
nsCOMPtr<nsISecurityEventSink> eventSink =
do_QueryInterface(docShell, &rv);
NS_ENSURE_SUCCESS_VOID(rv);
uint32_t event = 0;
nsCOMPtr<nsISecureBrowserUI> securityUI;
docShell->GetSecurityUI(getter_AddRefs(securityUI));
if (!securityUI) {
return;
}
securityUI->GetContentBlockingEvent(&event);
nsAutoCString origin;
nsContentUtils::GetASCIIOrigin(uri, origin);
bool blockedValue = aBlocked;
bool unblocked = false;
if (aEvent == nsIWebProgressListener::STATE_BLOCKED_TRACKING_CONTENT) {
doc->SetHasTrackingContentBlocked(aBlocked, origin);
if (!aBlocked) {
unblocked = !doc->GetHasTrackingContentBlocked();
}
} else if (aEvent ==
nsIWebProgressListener::STATE_LOADED_TRACKING_CONTENT) {
doc->SetHasTrackingContentLoaded(aBlocked, origin);
if (!aBlocked) {
unblocked = !doc->GetHasTrackingContentLoaded();
}
} else if (aEvent == nsIWebProgressListener::
STATE_COOKIES_BLOCKED_BY_PERMISSION) {
doc->SetHasCookiesBlockedByPermission(aBlocked, origin);
if (!aBlocked) {
unblocked = !doc->GetHasCookiesBlockedByPermission();
}
} else if (aEvent ==
nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER) {
doc->SetHasTrackingCookiesBlocked(aBlocked, origin);
if (!aBlocked) {
unblocked = !doc->GetHasTrackingCookiesBlocked();
}
} else if (aEvent ==
nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL) {
doc->SetHasAllCookiesBlocked(aBlocked, origin);
if (!aBlocked) {
unblocked = !doc->GetHasAllCookiesBlocked();
}
} else if (aEvent ==
nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN) {
doc->SetHasForeignCookiesBlocked(aBlocked, origin);
if (!aBlocked) {
unblocked = !doc->GetHasForeignCookiesBlocked();
}
} else if (aEvent == nsIWebProgressListener::STATE_COOKIES_LOADED) {
MOZ_ASSERT(!aBlocked,
"We don't expected to see blocked STATE_COOKIES_LOADED");
// Note that the logic in this branch is the logical negation of
// the logic in other branches, since the Document API we have is
// phrased in "loaded" terms as opposed to "blocked" terms.
blockedValue = !aBlocked;
doc->SetHasCookiesLoaded(blockedValue, origin);
if (!aBlocked) {
unblocked = !doc->GetHasCookiesLoaded();
}
} else {
// Ignore nsIWebProgressListener::STATE_BLOCKED_UNSAFE_CONTENT;
}
const uint32_t oldEvent = event;
if (blockedValue) {
event |= aEvent;
} else if (unblocked) {
event &= ~aEvent;
}
if (event == oldEvent
#ifdef ANDROID
// GeckoView always needs to notify about blocked trackers,
// since the GeckoView API always needs to report the URI and
// type of any blocked tracker. We use a platform-dependent code
// path here because reporting this notification on desktop
// platforms isn't necessary and doing so can have a big
// performance cost.
&& aEvent != nsIWebProgressListener::STATE_BLOCKED_TRACKING_CONTENT
#endif
) {
// Avoid dispatching repeated notifications when nothing has
// changed
return;
}
eventSink->OnContentBlockingEvent(channel, event);
});
nsresult rv;
if (gSyncContentBlockingNotifications) {
rv = func->Run();
} else {
rv = NS_IdleDispatchToCurrentThread(func.forget(), 100);
}
if (NS_WARN_IF(NS_FAILED(rv))) {
// This event might come after the user has navigated to another page.
// To prevent showing the TrackingProtection UI on the wrong page, we need to
// check that the loading URI for the channel is the same as the URI currently
// loaded in the document.
if (!SameLoadingURI(doc, aChannel) &&
aEvent == nsIWebProgressListener::STATE_BLOCKED_TRACKING_CONTENT) {
return;
}
// Notify nsIWebProgressListeners of this content blocking event.
// Can be used to change the UI state.
nsresult rv = NS_OK;
nsCOMPtr<nsISecurityEventSink> eventSink = do_QueryInterface(docShell, &rv);
NS_ENSURE_SUCCESS_VOID(rv);
uint32_t event = 0;
nsCOMPtr<nsISecureBrowserUI> securityUI;
docShell->GetSecurityUI(getter_AddRefs(securityUI));
if (!securityUI) {
return;
}
securityUI->GetContentBlockingEvent(&event);
nsAutoCString origin;
nsContentUtils::GetASCIIOrigin(aURIHint, origin);
bool blockedValue = aBlocked;
bool unblocked = false;
if (aEvent == nsIWebProgressListener::STATE_BLOCKED_TRACKING_CONTENT) {
doc->SetHasTrackingContentBlocked(aBlocked, origin);
if (!aBlocked) {
unblocked = !doc->GetHasTrackingContentBlocked();
}
} else if (aEvent == nsIWebProgressListener::STATE_LOADED_TRACKING_CONTENT) {
doc->SetHasTrackingContentLoaded(aBlocked, origin);
if (!aBlocked) {
unblocked = !doc->GetHasTrackingContentLoaded();
}
} else if (aEvent ==
nsIWebProgressListener::STATE_COOKIES_BLOCKED_BY_PERMISSION) {
doc->SetHasCookiesBlockedByPermission(aBlocked, origin);
if (!aBlocked) {
unblocked = !doc->GetHasCookiesBlockedByPermission();
}
} else if (aEvent == nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER) {
doc->SetHasTrackingCookiesBlocked(aBlocked, origin);
if (!aBlocked) {
unblocked = !doc->GetHasTrackingCookiesBlocked();
}
} else if (aEvent == nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL) {
doc->SetHasAllCookiesBlocked(aBlocked, origin);
if (!aBlocked) {
unblocked = !doc->GetHasAllCookiesBlocked();
}
} else if (aEvent == nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN) {
doc->SetHasForeignCookiesBlocked(aBlocked, origin);
if (!aBlocked) {
unblocked = !doc->GetHasForeignCookiesBlocked();
}
} else if (aEvent == nsIWebProgressListener::STATE_COOKIES_LOADED) {
MOZ_ASSERT(!aBlocked,
"We don't expected to see blocked STATE_COOKIES_LOADED");
// Note that the logic in this branch is the logical negation of the logic
// in other branches, since the Document API we have is phrased in
// "loaded" terms as opposed to "blocked" terms.
blockedValue = !aBlocked;
doc->SetHasCookiesLoaded(blockedValue, origin);
if (!aBlocked) {
unblocked = !doc->GetHasCookiesLoaded();
}
} else {
// Ignore nsIWebProgressListener::STATE_BLOCKED_UNSAFE_CONTENT;
}
const uint32_t oldEvent = event;
if (blockedValue) {
event |= aEvent;
} else if (unblocked) {
event &= ~aEvent;
}
if (event == oldEvent
#ifdef ANDROID
// GeckoView always needs to notify about blocked trackers, since the
// GeckoView API always needs to report the URI and type of any blocked
// tracker.
// We use a platform-dependent code path here because reporting this
// notification on desktop platforms isn't necessary and doing so can have
// a big performance cost.
&& aEvent != nsIWebProgressListener::STATE_BLOCKED_TRACKING_CONTENT
#endif
) {
// Avoid dispatching repeated notifications when nothing has changed
return;
}
eventSink->OnContentBlockingEvent(aChannel, event);
}
// static