Closed
Bug 1421588
Opened 8 years ago
Closed 8 years ago
Tracking Protection is not active when explicitly enabled in Selenium
Categories
(Remote Protocol :: Marionette, defect)
Tracking
(Not tracked)
RESOLVED
INVALID
People
(Reporter: gertjan.franken, Unassigned)
Details
Attachments
(4 files)
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36
Steps to reproduce:
I want to test a webpage using Selenium, more specifically I want to test how it works when Tracking Protection in Firefox is enabled. There are multiple ways to do this:
Scenario 1:
1) Make a new Firefox profile, go to the Tracking Protection preferences and tick the "Always" options.
2) Use this profile in the Selenium tests
Scenario 2:
Use the following code:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("privacy.trackingprotection.enabled", true);
//profile.setPreference("urlclassifier.trackingTable", "test-track-simple,base-track-digest256,content-track-digest256");
//options.addArguments("-private");
FirefoxDriver driver = new FirefoxDriver(options);
The commented lines aren't really necessary, but I also tried these just to be thorough.
I included an HTML file in which is referenced to a known tracking domain (see index.html). This can be used to reproduce the problem by visiting it with Firefox manually and automated through Selenium.
Actual results:
The automated Firefox instance has successfully started and when checking the preferences, they are exactly like I want them to be. However, Firefox does not behave like these preferences. By using the Network Monitor, I saw that requests blocked by a manually operated Firefox browser (with Tracking Protection enabled) were not blocked by the Selenium operated Firefox browser.
Expected results:
Requests to tracking domains should be blocked like in a manually operated Firefox instance. Tracking Protection is still not active when explicitly enabled using Selenium.
The above code doesn't show me that you are using that new profile. You are creating the the driver and passing in the options, but not the profile instance.
Beside that there is no need to actually create a new profile yourself if you only want to add preferences. For that simply do it via the firefox options. See https://github.com/mozilla/geckodriver/#capabilities-example as an example.
Further please show some code which is failing for you, as best also attaching the trace log (https://firefox-source-docs.mozilla.org/testing/geckodriver/geckodriver/TraceLogs.html) for a failure.
Btw. when I open your attached index.html file, I do not see that tracking protection has found any elements.
Flags: needinfo?(gertjan.franken)
Screenshot of the manually operated Firefox browser, indicating that Tracking Protection blocked requests to adition.com.
Screenshot of the automated Firefox browser, indicating that requests to adition.com are not blocked by Tracking Protection.
Thank you for your reaction.
Yes, you are right. In this example, I forgot the line of code which passes the profile instance, I will correct this in the bug report. However in my code used for testing this line was present so the problem remains the same.
There is no failure when running the code, only the outcome is not as it should be. I added some screenshots of both the manually operated Firefox and the automated Firefox. Clearly, the Tracking Protection of the former blocks requests aimed at adition.com while the latter does not.
When I open https://bug1421588.bmoattachments.org/attachment.cgi?id=8932826 with Firefox Tracking Protection enabled (strict protection), Firefox indicates that requests to adition.com are blocked.
Flags: needinfo?(gertjan.franken)
Apparently I cannot edit the bug report so I will update the code for scenario 2 here:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("privacy.trackingprotection.enabled", true);
//profile.setPreference("urlclassifier.trackingTable", "test-track-simple,base-track-digest256,content-track-digest256");
//options.addArguments("-private");
options.setProfile(profile);
FirefoxDriver driver = new FirefoxDriver(options);
I also attached the TRACE log (log.txt).
Ok, so I had a look and the issue here has nothing to do with Marionette/Geckodriver or Firefox' tracking protection support. It is your test which needs to be expanded, because the entries from the URLclassifier tracking table are not available directly after starting the browser. Those would have to be downloaded first by Firefox, which happens with a slight delay. Have a look at the following test for Marionette in how a download gets requested:
https://dxr.mozilla.org/mozilla-central/source/testing/firefox-ui/tests/functional/safebrowsing/test_initial_download.py
The downside here is that via Selenium you cannot restart the browser. So the preference for the update timer would have to be set before you start the browser. Then it might work, and Firefox downloads the tables immediately.
Status: UNCONFIRMED → RESOLVED
Closed: 8 years ago
Resolution: --- → INVALID
I added the following line in order to force the update immediately:
profile.setPreference("browser.safebrowsing.provider.mozilla.nextupdatetime", 1);
Unfortunately, it does not solve the problem. I even use a delay of a few seconds between the successful initiation of the Firefox instance and the start of the test.
For the test we have it can take up to 60s, and even more in the worst case scenario. Try to wait for the file being present, and test how long it takes. As best enable logging as we do in the test, to see that the files are getting downloaded.
| Reporter | ||
Comment 10•8 years ago
|
||
Okay, will do. Thanks for the help!
Updated•3 years ago
|
Product: Testing → Remote Protocol
You need to log in
before you can comment on or make changes to this bug.
Description
•