Bug 1520520 - Part 2 - Refactor testTrackingProtection to listen for ContentBlockingEvent; r=esawin,ehsan

After the changes from bug 1514340 the app is now informed about tracking with
Content:ContentBlockingEvent instead of Content:SecurityChange
Also initialized mLastTracking with unknown as that is the default value
when no tracking event has been received (eg: no tracking elements on the page)

Depends on D16822

Differential Revision: https://phabricator.services.mozilla.com/D16823
This commit is contained in:
Petru-Mugurel Lingurar 2019-01-21 10:03:52 -05:00 коммит произвёл Ehsan Akhgari
Родитель 095fa60743
Коммит d587b36c42
2 изменённых файлов: 7 добавлений и 9 удалений

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

@ -14,7 +14,7 @@ import org.mozilla.gecko.util.EventCallback;
import org.mozilla.gecko.util.GeckoBundle;
public class testTrackingProtection extends JavascriptTest implements BundleEventListener {
private String mLastTracking;
private String mLastTracking = "unknown"; // Default value if no events received yet
public testTrackingProtection() {
super("testTrackingProtection.js");
@ -23,16 +23,14 @@ public class testTrackingProtection extends JavascriptTest implements BundleEven
@Override // BundleEventListener
public void handleMessage(final String event, final GeckoBundle message,
final EventCallback callback) {
if ("Content:SecurityChange".equals(event)) {
final GeckoBundle identity = message.getBundle("identity");
final GeckoBundle mode = identity.getBundle("mode");
mLastTracking = mode.getString("tracking");
if ("Content:ContentBlockingEvent".equals(event)) {
mLastTracking = message.getString("tracking");
mAsserter.dumpLog("Security change (tracking): " + mLastTracking);
} else if ("Test:Expected".equals(event)) {
final String expected = message.getString("expected");
mAsserter.dumpLog("Testing (tracking): 2" + mLastTracking + " = " + expected);
mAsserter.is(mLastTracking, expected, "Tracking matched expectation");
mAsserter.dumpLog("Testing (tracking): " + mLastTracking + " = " + expected);
}
}
@ -41,7 +39,7 @@ public class testTrackingProtection extends JavascriptTest implements BundleEven
super.setUp();
EventDispatcher.getInstance().registerUiThreadListener(this,
"Content:SecurityChange",
"Content:ContentBlockingEvent",
"Test:Expected");
}
@ -50,7 +48,7 @@ public class testTrackingProtection extends JavascriptTest implements BundleEven
super.tearDown();
EventDispatcher.getInstance().unregisterUiThreadListener(this,
"Content:SecurityChange",
"Content:ContentBlockingEvent",
"Test:Expected");
}
}

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

@ -36,7 +36,7 @@ function promiseLoadEvent(browser, url, eventType = "load", runBeforeLoad) {
}
// Test that the Tracking Protection is active and has the correct state when
// tracking content is blocked (Bug 1063831)
// tracking content is blocked (Bug 1063831 + Bug 1520520)
// Code is mostly stolen from:
// http://dxr.mozilla.org/mozilla-central/source/browser/base/content/test/general/browser_trackingUI.js