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; import org.mozilla.gecko.util.GeckoBundle;
public class testTrackingProtection extends JavascriptTest implements BundleEventListener { public class testTrackingProtection extends JavascriptTest implements BundleEventListener {
private String mLastTracking; private String mLastTracking = "unknown"; // Default value if no events received yet
public testTrackingProtection() { public testTrackingProtection() {
super("testTrackingProtection.js"); super("testTrackingProtection.js");
@ -23,16 +23,14 @@ public class testTrackingProtection extends JavascriptTest implements BundleEven
@Override // BundleEventListener @Override // BundleEventListener
public void handleMessage(final String event, final GeckoBundle message, public void handleMessage(final String event, final GeckoBundle message,
final EventCallback callback) { final EventCallback callback) {
if ("Content:SecurityChange".equals(event)) { if ("Content:ContentBlockingEvent".equals(event)) {
final GeckoBundle identity = message.getBundle("identity"); mLastTracking = message.getString("tracking");
final GeckoBundle mode = identity.getBundle("mode");
mLastTracking = mode.getString("tracking");
mAsserter.dumpLog("Security change (tracking): " + mLastTracking); mAsserter.dumpLog("Security change (tracking): " + mLastTracking);
} else if ("Test:Expected".equals(event)) { } else if ("Test:Expected".equals(event)) {
final String expected = message.getString("expected"); final String expected = message.getString("expected");
mAsserter.dumpLog("Testing (tracking): 2" + mLastTracking + " = " + expected);
mAsserter.is(mLastTracking, expected, "Tracking matched expectation"); 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(); super.setUp();
EventDispatcher.getInstance().registerUiThreadListener(this, EventDispatcher.getInstance().registerUiThreadListener(this,
"Content:SecurityChange", "Content:ContentBlockingEvent",
"Test:Expected"); "Test:Expected");
} }
@ -50,7 +48,7 @@ public class testTrackingProtection extends JavascriptTest implements BundleEven
super.tearDown(); super.tearDown();
EventDispatcher.getInstance().unregisterUiThreadListener(this, EventDispatcher.getInstance().unregisterUiThreadListener(this,
"Content:SecurityChange", "Content:ContentBlockingEvent",
"Test:Expected"); "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 // 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: // Code is mostly stolen from:
// http://dxr.mozilla.org/mozilla-central/source/browser/base/content/test/general/browser_trackingUI.js // http://dxr.mozilla.org/mozilla-central/source/browser/base/content/test/general/browser_trackingUI.js