Bug 1170190 - Part 3: Add tests for the e10s case too; r=mayhemer

This commit is contained in:
Ehsan Akhgari 2016-12-16 17:15:16 -05:00
parent cd895c94f2
commit ad51310cc1
10 changed files with 136 additions and 11 deletions

View File

@ -2903,5 +2903,12 @@ HttpChannelChild::ShouldInterceptURI(nsIURI* aURI,
return ShouldIntercept(upgradedURI ? upgradedURI.get() : aURI);
}
mozilla::ipc::IPCResult
HttpChannelChild::RecvSetPriority(const uint16_t& aPriority)
{
mPriority = aPriority;
return IPC_OK();
}
} // namespace net
} // namespace mozilla

View File

@ -155,6 +155,8 @@ protected:
mozilla::ipc::IPCResult RecvIssueDeprecationWarning(const uint32_t& warning,
const bool& asError) override;
mozilla::ipc::IPCResult RecvSetPriority(const uint16_t& aPriority) override;
bool GetAssociatedContentSecurity(nsIAssociatedContentSecurity** res = nullptr);
virtual void DoNotifyListenerCleanup() override;

View File

@ -1827,5 +1827,13 @@ HttpChannelParent::IssueWarning(uint32_t aWarning, bool aAsError)
return NS_OK;
}
void
HttpChannelParent::DoSendSetPriority(int16_t aValue)
{
if (!mIPCClosed) {
Unused << SendSetPriority(aValue);
}
}
} // namespace net
} // namespace mozilla

View File

@ -99,6 +99,9 @@ public:
nsresult OpenAlternativeOutputStream(const nsACString & type, nsIOutputStream * *_retval);
void InvokeAsyncOpen(nsresult rv);
// Calls SendSetPriority if mIPCClosed is false.
void DoSendSetPriority(int16_t aValue);
protected:
// used to connect redirected-to channel in parent with just created
// ChildChannel. Used during redirects.

View File

@ -31,7 +31,6 @@ parent:
// Note: channels are opened during construction, so no open method here:
// see PNecko.ipdl
async SetPriority(uint16_t priority);
async SetClassOfService(uint32_t cos);
async SetCacheTokenCachedCharset(nsCString charset);
@ -177,6 +176,8 @@ both:
// after that. When receiving this message, the child will call
// Send__delete__() and complete the steps required to finish the redirect.
async FinishInterceptedRedirect();
async SetPriority(uint16_t priority);
};

View File

@ -102,6 +102,7 @@
#include "nsMixedContentBlocker.h"
#include "HSTSPrimerListener.h"
#include "CacheStorageService.h"
#include "HttpChannelParent.h"
#ifdef MOZ_TASK_TRACER
#include "GeckoTaskTracer.h"
@ -6170,6 +6171,16 @@ nsHttpChannel::SetPriority(int32_t value)
mPriority = newValue;
if (mTransaction)
gHttpHandler->RescheduleTransaction(mTransaction, mPriority);
// If this channel is the real channel for an e10s channel, notify the
// child side about the priority change as well.
nsCOMPtr<nsIParentChannel> parentChannel;
NS_QueryNotificationCallbacks(this, parentChannel);
RefPtr<HttpChannelParent> httpParent = do_QueryObject(parentChannel);
if (httpParent) {
httpParent->DoSendSetPriority(newValue);
}
return NS_OK;
}

View File

@ -3,7 +3,26 @@ Cu.import("resource://testing-common/UrlClassifierTestUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://testing-common/httpd.js");
do_get_profile();
// This test supports both e10s and non-e10s mode. In non-e10s mode, this test
// drives itself by creating a profile directory, setting up the URL classifier
// test tables and adjusting the prefs which are necessary to do the testing.
// In e10s mode however, some of these operations such as creating a profile
// directory, setting up the URL classifier test tables and setting prefs
// aren't supported in the content process, so we split the test into two
// parts, the part testing the normal priority case by setting both prefs to
// false (test_trackingProtection_annotateChannels_wrap1.js), and the part
// testing the lowest priority case by setting both prefs to true
// (test_trackingProtection_annotateChannels_wrap2.js). These wrapper scripts
// are also in charge of creating the profile directory and setting up the URL
// classifier test tables.
//
// Below where we need to take different actions based on the process type we're
// in, we use runtime.processType to take the correct actions.
const runtime = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime);
if (runtime.processType == runtime.PROCESS_TYPE_DEFAULT) {
do_get_profile();
}
var Ci = Components.interfaces;
@ -31,6 +50,14 @@ var httpServer;
var normalOrigin, trackingOrigin;
var testPriorityMap;
var currentTest;
// When this test is running in e10s mode, the parent process is in charge of
// setting the prefs for us, so here we merely read our prefs, and if they have
// been set we skip the normal priority test and only test the lowest priority
// case, and if it they have not been set we skip the lowest priority test and
// only test the normal priority case.
// In non-e10s mode, both of these will remain false and we adjust the prefs
// ourselves and test both of the cases in one go.
var skipNormalPriority = false, skipLowestPriority = false;
function setup_test() {
httpServer = new HttpServer();
@ -40,6 +67,15 @@ function setup_test() {
normalOrigin = "http://localhost:" + httpServer.identity.primaryPort;
trackingOrigin = "http://tracking.example.com:" + httpServer.identity.primaryPort;
if (runtime.processType == runtime.PROCESS_TYPE_CONTENT) {
if (Services.prefs.getBoolPref("privacy.trackingprotection.annotate_channels") &&
Services.prefs.getBoolPref("privacy.trackingprotection.lower_network_priority")) {
skipNormalPriority = true;
} else {
skipLowestPriority = true;
}
}
runTests();
}
@ -73,15 +109,25 @@ var tests =[
// Add the test table into tracking protection table.
function addTestTrackers() {
UrlClassifierTestUtils.addTestTrackers().then(() => {
if (runtime.processType == runtime.PROCESS_TYPE_DEFAULT) {
UrlClassifierTestUtils.addTestTrackers().then(() => {
runTests();
});
} else {
runTests();
});
}
},
// With the pref off, the priority of channel should be normal.
function setupNormalPriority() {
Services.prefs.setBoolPref("privacy.trackingprotection.annotate_channels", false);
Services.prefs.setBoolPref("privacy.trackingprotection.lower_network_priority", false);
if (skipNormalPriority) {
runTests();
return;
}
if (runtime.processType == runtime.PROCESS_TYPE_DEFAULT) {
Services.prefs.setBoolPref("privacy.trackingprotection.annotate_channels", false);
Services.prefs.setBoolPref("privacy.trackingprotection.lower_network_priority", false);
}
testPriorityMap = [
{
path: normalOrigin + "/innocent.css",
@ -104,14 +150,22 @@ var tests =[
expectedPriority: Ci.nsISupportsPriority.PRIORITY_NORMAL
},
];
// We add the doPriorityTest test here so that it only gets injected in the
// test list if we're not skipping over this test.
tests.unshift(doPriorityTest);
runTests();
},
doPriorityTest,
// With the pref on, the priority of channel should be lowest.
function setupLowestPriority() {
Services.prefs.setBoolPref("privacy.trackingprotection.annotate_channels", true);
Services.prefs.setBoolPref("privacy.trackingprotection.lower_network_priority", true);
if (skipLowestPriority) {
runTests();
return;
}
if (runtime.processType == runtime.PROCESS_TYPE_DEFAULT) {
Services.prefs.setBoolPref("privacy.trackingprotection.annotate_channels", true);
Services.prefs.setBoolPref("privacy.trackingprotection.lower_network_priority", true);
}
testPriorityMap = [
{
path: normalOrigin + "/innocent.css",
@ -134,13 +188,17 @@ var tests =[
expectedPriority: Ci.nsISupportsPriority.PRIORITY_LOWEST
},
];
// We add the doPriorityTest test here so that it only gets injected in the
// test list if we're not skipping over this test.
tests.unshift(doPriorityTest);
runTests();
},
doPriorityTest,
function cleanUp() {
httpServer.stop(do_test_finished);
UrlClassifierTestUtils.cleanupTestTrackers();
if (runtime.processType == runtime.PROCESS_TYPE_DEFAULT) {
UrlClassifierTestUtils.cleanupTestTrackers();
}
runTests();
}
];

View File

@ -0,0 +1,16 @@
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://testing-common/UrlClassifierTestUtils.jsm");
function run_test() {
do_get_profile();
Services.prefs.setBoolPref("privacy.trackingprotection.annotate_channels", false);
Services.prefs.setBoolPref("privacy.trackingprotection.lower_network_priority", false);
do_test_pending();
UrlClassifierTestUtils.addTestTrackers().then(() => {
run_test_in_child("../unit/test_trackingProtection_annotateChannels.js", () => {
UrlClassifierTestUtils.cleanupTestTrackers();
do_test_finished();
});
do_test_finished();
});
}

View File

@ -0,0 +1,16 @@
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://testing-common/UrlClassifierTestUtils.jsm");
function run_test() {
do_get_profile();
Services.prefs.setBoolPref("privacy.trackingprotection.annotate_channels", true);
Services.prefs.setBoolPref("privacy.trackingprotection.lower_network_priority", true);
do_test_pending();
UrlClassifierTestUtils.addTestTrackers().then(() => {
run_test_in_child("../unit/test_trackingProtection_annotateChannels.js", () => {
UrlClassifierTestUtils.cleanupTestTrackers();
do_test_finished();
});
do_test_finished();
});
}

View File

@ -38,6 +38,7 @@ support-files =
!/netwerk/test/unit/test_resumable_channel.js
!/netwerk/test/unit/test_simple.js
!/netwerk/test/unit/test_synthesized_response.js
!/netwerk/test/unit/test_trackingProtection_annotateChannels.js
!/netwerk/test/unit/test_xmlhttprequest.js
!/netwerk/test/unit/head_channels.js
!/netwerk/test/unit/head_cache2.js
@ -97,3 +98,5 @@ skip-if = true
[test_alt-data_stream_wrap.js]
[test_original_sent_received_head_wrap.js]
[test_channel_id.js]
[test_trackingProtection_annotateChannels_wrap1.js]
[test_trackingProtection_annotateChannels_wrap2.js]