Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DNT header test #2047

Merged
merged 5 commits into from
Sep 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,19 @@ function Badger() {
});

self.storage = new pbStorage.BadgerPen(function(thisStorage) {
if (self.INITIALIZED) { return; }
if (self.INITIALIZED) {
return;
}

self.heuristicBlocking = new HeuristicBlocking.HeuristicBlocker(thisStorage);
self.updateTabList();
self.initializeDefaultSettings();

try {
self.runMigrations();
} finally {
// TODO "await" to set INITIALIZED until both below async functions resolve?
// see TODO in qunit_config.js
self.loadFirstRunSeedData();
self.initializeYellowlist();
self.initializeDNT();
Expand All @@ -74,7 +80,15 @@ function Badger() {
}
});

// TODO: register all privacy badger listeners here in the storage callback
// start all the listeners
incognito.startListeners();
webrequest.startListeners();
HeuristicBlocking.startListeners();
FirefoxAndroid.startListeners();
startBackgroundListeners();

console.log("Privacy Badger is ready to rock!");
console.log("Set DEBUG=1 to view console messages.");

self.INITIALIZED = true;
});
Expand Down Expand Up @@ -856,21 +870,4 @@ function startBackgroundListeners() {
}
}

/**
* lets get this party started
*/
console.log('Loading badgers into the pen.');
var badger = window.badger = new Badger();

/**
* Start all the listeners
*/
incognito.startListeners();
webrequest.startListeners();
HeuristicBlocking.startListeners();
FirefoxAndroid.startListeners();
startBackgroundListeners();

// TODO move listeners and this message behind INITIALIZED
console.log('Privacy badger is ready to rock!');
console.log('Set DEBUG=1 to view console messages.');
12 changes: 2 additions & 10 deletions src/js/heuristicblocking.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,11 +515,7 @@ function startListeners() {
* Adds heuristicBlockingAccounting as listened to onBeforeSendHeaders request
*/
chrome.webRequest.onBeforeSendHeaders.addListener(function(details) {
if (badger) {
return badger.heuristicBlocking.heuristicBlockingAccounting(details);
} else {
return {};
}
return badger.heuristicBlocking.heuristicBlockingAccounting(details);
}, {urls: ["<all_urls>"]}, ["requestHeaders"]);

/**
Expand All @@ -534,11 +530,7 @@ function startListeners() {
}
}
if (hasSetCookie) {
if (badger) {
return badger.heuristicBlocking.heuristicBlockingAccounting(details);
} else {
return {};
}
return badger.heuristicBlocking.heuristicBlockingAccounting(details);
}
},
{urls: ["<all_urls>"]}, ["responseHeaders"]);
Expand Down
5 changes: 5 additions & 0 deletions tests/selenium/dnt_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ def test_should_not_record_nontracking_domains(self):

def test_first_party_dnt_header(self):
TEST_URL = "https://httpbin.org/get"

self.load_url(self.bg_url)
# wait until DNT-injecting webRequest listeners have been registered
self.wait_for_script("return badger.INITIALIZED")

headers = retry_until(partial(self.get_first_party_headers, TEST_URL),
times=8)
self.assertTrue(headers is not None, "It seems we failed to get DNT headers")
Expand Down