2019-01-17 21:18:31 +03:00
|
|
|
const {HttpServer} = ChromeUtils.import("resource://testing-common/httpd.js");
|
|
|
|
var {Services} = ChromeUtils.import('resource://gre/modules/Services.jsm');
|
2019-05-02 15:34:52 +03:00
|
|
|
const ReferrerInfo = Components.Constructor("@mozilla.org/referrer-info;1",
|
|
|
|
"nsIReferrerInfo",
|
|
|
|
"init");
|
2015-06-18 12:23:00 +03:00
|
|
|
|
|
|
|
var running_single_process = false;
|
2013-10-26 01:56:51 +04:00
|
|
|
|
2014-06-04 00:37:46 +04:00
|
|
|
var predictor = null;
|
2015-06-18 12:23:00 +03:00
|
|
|
|
|
|
|
function is_child_process() {
|
|
|
|
return Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).processType == Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT;
|
|
|
|
}
|
2013-10-26 01:56:51 +04:00
|
|
|
|
|
|
|
function extract_origin(uri) {
|
|
|
|
var o = uri.scheme + "://" + uri.asciiHost;
|
|
|
|
if (uri.port !== -1) {
|
|
|
|
o = o + ":" + uri.port;
|
|
|
|
}
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2017-02-03 06:17:00 +03:00
|
|
|
var origin_attributes = {};
|
2013-10-26 01:56:51 +04:00
|
|
|
|
2016-04-15 05:26:58 +03:00
|
|
|
var ValidityChecker = function(verifier, httpStatus) {
|
|
|
|
this.verifier = verifier;
|
|
|
|
this.httpStatus = httpStatus;
|
|
|
|
};
|
|
|
|
|
|
|
|
ValidityChecker.prototype = {
|
|
|
|
verifier: null,
|
|
|
|
httpStatus: 0,
|
|
|
|
|
|
|
|
QueryInterface: function listener_qi(iid) {
|
|
|
|
if (iid.equals(Ci.nsISupports) ||
|
|
|
|
iid.equals(Ci.nsICacheEntryOpenCallback)) {
|
|
|
|
return this;
|
|
|
|
}
|
2018-02-28 20:51:33 +03:00
|
|
|
throw Cr.NS_ERROR_NO_INTERFACE;
|
2016-04-15 05:26:58 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onCacheEntryCheck: function(entry, appCache)
|
|
|
|
{
|
|
|
|
return Ci.nsICacheEntryOpenCallback.ENTRY_WANTED;
|
|
|
|
},
|
|
|
|
|
|
|
|
onCacheEntryAvailable: function(entry, isnew, appCache, status)
|
|
|
|
{
|
|
|
|
// Check if forced valid
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.equal(entry.isForcedValid, this.httpStatus === 200);
|
2016-04-15 05:26:58 +03:00
|
|
|
this.verifier.maybe_run_next_test();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var Verifier = function _verifier(testing, expected_prefetches, expected_preconnects, expected_preresolves) {
|
2013-10-26 01:56:51 +04:00
|
|
|
this.verifying = testing;
|
2016-04-15 05:26:58 +03:00
|
|
|
this.expected_prefetches = expected_prefetches;
|
2013-10-26 01:56:51 +04:00
|
|
|
this.expected_preconnects = expected_preconnects;
|
|
|
|
this.expected_preresolves = expected_preresolves;
|
|
|
|
};
|
|
|
|
|
|
|
|
Verifier.prototype = {
|
2015-01-15 00:59:04 +03:00
|
|
|
complete: false,
|
2013-10-26 01:56:51 +04:00
|
|
|
verifying: null,
|
2016-04-15 05:26:58 +03:00
|
|
|
expected_prefetches: null,
|
2013-10-26 01:56:51 +04:00
|
|
|
expected_preconnects: null,
|
|
|
|
expected_preresolves: null,
|
|
|
|
|
|
|
|
getInterface: function verifier_getInterface(iid) {
|
|
|
|
return this.QueryInterface(iid);
|
|
|
|
},
|
|
|
|
|
|
|
|
QueryInterface: function verifier_QueryInterface(iid) {
|
2014-06-04 00:37:46 +04:00
|
|
|
if (iid.equals(Ci.nsINetworkPredictorVerifier) ||
|
2013-10-26 01:56:51 +04:00
|
|
|
iid.equals(Ci.nsISupports)) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw Cr.NS_ERROR_NO_INTERFACE;
|
|
|
|
},
|
|
|
|
|
|
|
|
maybe_run_next_test: function verifier_maybe_run_next_test() {
|
2016-04-15 05:26:58 +03:00
|
|
|
if (this.expected_prefetches.length === 0 &&
|
|
|
|
this.expected_preconnects.length === 0 &&
|
2015-01-15 00:59:04 +03:00
|
|
|
this.expected_preresolves.length === 0 &&
|
|
|
|
!this.complete) {
|
|
|
|
this.complete = true;
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.ok(true, "Well this is unexpected...");
|
2015-01-15 00:59:04 +03:00
|
|
|
// This kicks off the ability to run the next test
|
|
|
|
reset_predictor();
|
2013-10-26 01:56:51 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-04-15 05:26:58 +03:00
|
|
|
onPredictPrefetch: function verifier_onPredictPrefetch(uri, status) {
|
|
|
|
var index = this.expected_prefetches.indexOf(uri.asciiSpec);
|
|
|
|
if (index == -1 && !this.complete) {
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.ok(false, "Got prefetch for unexpected uri " + uri.asciiSpec);
|
2016-04-15 05:26:58 +03:00
|
|
|
} else {
|
|
|
|
this.expected_prefetches.splice(index, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
dump("checking validity of entry for " + uri.spec + "\n");
|
|
|
|
var checker = new ValidityChecker(this, status);
|
|
|
|
asyncOpenCacheEntry(uri.spec, "disk",
|
2018-01-31 20:46:46 +03:00
|
|
|
Ci.nsICacheStorage.OPEN_NORMALLY, Services.loadContextInfo.default,
|
2016-04-15 05:26:58 +03:00
|
|
|
checker);
|
|
|
|
},
|
|
|
|
|
2013-10-26 01:56:51 +04:00
|
|
|
onPredictPreconnect: function verifier_onPredictPreconnect(uri) {
|
|
|
|
var origin = extract_origin(uri);
|
|
|
|
var index = this.expected_preconnects.indexOf(origin);
|
2015-01-15 00:59:04 +03:00
|
|
|
if (index == -1 && !this.complete) {
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.ok(false, "Got preconnect for unexpected uri " + origin);
|
2013-10-26 01:56:51 +04:00
|
|
|
} else {
|
|
|
|
this.expected_preconnects.splice(index, 1);
|
|
|
|
}
|
|
|
|
this.maybe_run_next_test();
|
|
|
|
},
|
|
|
|
|
|
|
|
onPredictDNS: function verifier_onPredictDNS(uri) {
|
|
|
|
var origin = extract_origin(uri);
|
|
|
|
var index = this.expected_preresolves.indexOf(origin);
|
2015-01-15 00:59:04 +03:00
|
|
|
if (index == -1 && !this.complete) {
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.ok(false, "Got preresolve for unexpected uri " + origin);
|
2013-10-26 01:56:51 +04:00
|
|
|
} else {
|
|
|
|
this.expected_preresolves.splice(index, 1);
|
|
|
|
}
|
|
|
|
this.maybe_run_next_test();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-04 00:37:46 +04:00
|
|
|
function reset_predictor() {
|
2015-06-18 12:23:00 +03:00
|
|
|
if (running_single_process || is_child_process()) {
|
|
|
|
predictor.reset();
|
|
|
|
} else {
|
|
|
|
sendCommand("predictor.reset();");
|
|
|
|
}
|
2013-10-26 01:56:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function newURI(s) {
|
2017-01-09 22:27:26 +03:00
|
|
|
return Services.io.newURI(s);
|
2013-10-26 01:56:51 +04:00
|
|
|
}
|
|
|
|
|
2015-01-15 00:59:04 +03:00
|
|
|
var prepListener = {
|
|
|
|
numEntriesToOpen: 0,
|
|
|
|
numEntriesOpened: 0,
|
|
|
|
continueCallback: null,
|
|
|
|
|
|
|
|
QueryInterface: function (iid) {
|
|
|
|
if (iid.equals(Ci.nsICacheEntryOpenCallback)) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
throw Cr.NS_ERROR_NO_INTERFACE;
|
|
|
|
},
|
|
|
|
|
|
|
|
init: function (entriesToOpen, cb) {
|
|
|
|
this.numEntriesOpened = 0;
|
|
|
|
this.numEntriesToOpen = entriesToOpen;
|
|
|
|
this.continueCallback = cb;
|
|
|
|
},
|
|
|
|
|
|
|
|
onCacheEntryCheck: function (entry, appCache) {
|
|
|
|
return Ci.nsICacheEntryOpenCallback.ENTRY_WANTED;
|
|
|
|
},
|
|
|
|
|
|
|
|
onCacheEntryAvailable: function (entry, isNew, appCache, result) {
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.equal(result, Cr.NS_OK);
|
2015-01-15 00:59:04 +03:00
|
|
|
entry.setMetaDataElement("predictor_test", "1");
|
|
|
|
entry.metaDataReady();
|
|
|
|
this.numEntriesOpened++;
|
|
|
|
if (this.numEntriesToOpen == this.numEntriesOpened) {
|
|
|
|
this.continueCallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function open_and_continue(uris, continueCallback) {
|
2018-01-31 20:46:46 +03:00
|
|
|
var ds = Services.cache2.diskCacheStorage(Services.loadContextInfo.default, false);
|
2015-01-15 00:59:04 +03:00
|
|
|
|
|
|
|
prepListener.init(uris.length, continueCallback);
|
|
|
|
for (var i = 0; i < uris.length; ++i) {
|
|
|
|
ds.asyncOpenURI(uris[i], "", Ci.nsICacheStorage.OPEN_NORMALLY,
|
|
|
|
prepListener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-26 01:56:51 +04:00
|
|
|
function test_link_hover() {
|
2015-06-18 12:23:00 +03:00
|
|
|
if (!running_single_process && !is_child_process()) {
|
|
|
|
// This one we can just proxy to the child and be done with, no extra setup
|
|
|
|
// is necessary.
|
|
|
|
sendCommand("test_link_hover();");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-26 01:56:51 +04:00
|
|
|
var uri = newURI("http://localhost:4444/foo/bar");
|
|
|
|
var referrer = newURI("http://localhost:4444/foo");
|
|
|
|
var preconns = ["http://localhost:4444"];
|
|
|
|
|
2016-04-15 05:26:58 +03:00
|
|
|
var verifier = new Verifier("hover", [], preconns, []);
|
2017-02-03 06:17:00 +03:00
|
|
|
predictor.predict(uri, referrer, predictor.PREDICT_LINK, origin_attributes, verifier);
|
2013-10-26 01:56:51 +04:00
|
|
|
}
|
|
|
|
|
2015-06-18 12:23:00 +03:00
|
|
|
const pageload_toplevel = newURI("http://localhost:4444/index.html");
|
|
|
|
|
|
|
|
function continue_test_pageload() {
|
2013-10-26 01:56:51 +04:00
|
|
|
var subresources = [
|
|
|
|
"http://localhost:4444/style.css",
|
|
|
|
"http://localhost:4443/jquery.js",
|
|
|
|
"http://localhost:4444/image.png"
|
|
|
|
];
|
|
|
|
|
2015-06-18 12:23:00 +03:00
|
|
|
// This is necessary to learn the origin stuff
|
2017-02-03 06:17:00 +03:00
|
|
|
predictor.learn(pageload_toplevel, null, predictor.LEARN_LOAD_TOPLEVEL, origin_attributes);
|
2017-04-18 03:22:46 +03:00
|
|
|
do_timeout(0, () => { // allow the learn() to run on the main thread
|
2015-06-18 12:23:00 +03:00
|
|
|
var preconns = [];
|
2017-04-18 03:22:46 +03:00
|
|
|
|
|
|
|
var sruri = newURI(subresources[0]);
|
|
|
|
predictor.learn(sruri, pageload_toplevel, predictor.LEARN_LOAD_SUBRESOURCE, origin_attributes);
|
|
|
|
do_timeout(0, () => {
|
|
|
|
preconns.push(extract_origin(sruri));
|
|
|
|
|
|
|
|
sruri = newURI(subresources[1]);
|
|
|
|
predictor.learn(sruri, pageload_toplevel, predictor.LEARN_LOAD_SUBRESOURCE, origin_attributes);
|
|
|
|
do_timeout(0, () => {
|
|
|
|
preconns.push(extract_origin(sruri));
|
|
|
|
|
|
|
|
sruri = newURI(subresources[2]);
|
|
|
|
predictor.learn(sruri, pageload_toplevel, predictor.LEARN_LOAD_SUBRESOURCE, origin_attributes);
|
|
|
|
do_timeout(0, () => {
|
|
|
|
preconns.push(extract_origin(sruri));
|
2015-06-18 12:23:00 +03:00
|
|
|
|
2016-04-15 05:26:58 +03:00
|
|
|
var verifier = new Verifier("pageload", [], preconns, []);
|
2017-02-03 06:17:00 +03:00
|
|
|
predictor.predict(pageload_toplevel, null, predictor.PREDICT_LOAD, origin_attributes, verifier);
|
2017-04-18 03:22:46 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2015-06-18 12:23:00 +03:00
|
|
|
}
|
2013-10-26 01:56:51 +04:00
|
|
|
|
2015-06-18 12:23:00 +03:00
|
|
|
function test_pageload() {
|
|
|
|
open_and_continue([pageload_toplevel], function () {
|
|
|
|
if (running_single_process) {
|
|
|
|
continue_test_pageload();
|
|
|
|
} else {
|
|
|
|
sendCommand("continue_test_pageload();");
|
|
|
|
}
|
2015-01-15 00:59:04 +03:00
|
|
|
});
|
2013-10-26 01:56:51 +04:00
|
|
|
}
|
|
|
|
|
2015-06-18 12:23:00 +03:00
|
|
|
const redirect_inituri = newURI("http://localhost:4443/redirect");
|
|
|
|
const redirect_targeturi = newURI("http://localhost:4444/index.html");
|
|
|
|
|
|
|
|
function continue_test_redrect() {
|
2013-10-26 01:56:51 +04:00
|
|
|
var subresources = [
|
|
|
|
"http://localhost:4444/style.css",
|
|
|
|
"http://localhost:4443/jquery.js",
|
|
|
|
"http://localhost:4444/image.png"
|
|
|
|
];
|
|
|
|
|
2017-02-03 06:17:00 +03:00
|
|
|
predictor.learn(redirect_inituri, null, predictor.LEARN_LOAD_TOPLEVEL, origin_attributes);
|
2017-04-18 03:22:46 +03:00
|
|
|
do_timeout(0, () => {
|
2017-02-03 06:17:00 +03:00
|
|
|
predictor.learn(redirect_targeturi, null, predictor.LEARN_LOAD_TOPLEVEL, origin_attributes);
|
2017-04-18 03:22:46 +03:00
|
|
|
do_timeout(0, () => {
|
2017-02-03 06:17:00 +03:00
|
|
|
predictor.learn(redirect_targeturi, redirect_inituri, predictor.LEARN_LOAD_REDIRECT, origin_attributes);
|
2017-04-18 03:22:46 +03:00
|
|
|
do_tiemout(0, () => {
|
2015-06-18 12:23:00 +03:00
|
|
|
|
|
|
|
var preconns = [];
|
|
|
|
preconns.push(extract_origin(redirect_targeturi));
|
2017-04-18 03:22:46 +03:00
|
|
|
|
|
|
|
var sruri = newURI(subresources[0]);
|
|
|
|
predictor.learn(sruri, redirect_targeturi, predictor.LEARN_LOAD_SUBRESOURCE, origin_attributes);
|
|
|
|
do_timeout(0, () => {
|
|
|
|
preconns.push(extract_origin(sruri));
|
|
|
|
|
|
|
|
sruri = newURI(subresources[1]);
|
|
|
|
predictor.learn(sruris[1], redirect_targeturi, predictor.LEARN_LOAD_SUBRESOURCE, origin_attributes);
|
|
|
|
do_timeout(0, () => {
|
|
|
|
preconns.push(extract_origin(sruri));
|
|
|
|
|
|
|
|
sruri = newURI(subresources[2]);
|
|
|
|
predictor.learn(sruris[2], redirect_targeturi, predictor.LEARN_LOAD_SUBRESOURCE, origin_attributes);
|
|
|
|
do_timeout(0, () => {
|
|
|
|
preconns.push(extract_origin(sruri));
|
2015-06-18 12:23:00 +03:00
|
|
|
|
2016-04-15 05:26:58 +03:00
|
|
|
var verifier = new Verifier("redirect", [], preconns, []);
|
2017-02-03 06:17:00 +03:00
|
|
|
predictor.predict(redirect_inituri, null, predictor.PREDICT_LOAD, origin_attributes, verifier);
|
2017-04-18 03:22:46 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2015-06-18 12:23:00 +03:00
|
|
|
}
|
2013-10-26 01:56:51 +04:00
|
|
|
|
2015-06-18 12:23:00 +03:00
|
|
|
function test_redirect() {
|
|
|
|
open_and_continue([redirect_inituri, redirect_targeturi], function () {
|
|
|
|
if (running_single_process) {
|
|
|
|
continue_test_redirect();
|
|
|
|
} else {
|
|
|
|
sendCommand("continue_test_redirect();");
|
|
|
|
}
|
2015-01-15 00:59:04 +03:00
|
|
|
});
|
2013-10-26 01:56:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function test_startup() {
|
2015-06-18 12:23:00 +03:00
|
|
|
if (!running_single_process && !is_child_process()) {
|
|
|
|
// This one we can just proxy to the child and be done with, no extra setup
|
|
|
|
// is necessary.
|
|
|
|
sendCommand("test_startup();");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-26 01:56:51 +04:00
|
|
|
var uris = [
|
|
|
|
"http://localhost:4444/startup",
|
|
|
|
"http://localhost:4443/startup"
|
|
|
|
];
|
|
|
|
var preconns = [];
|
2017-04-18 03:22:46 +03:00
|
|
|
var uri = newURI(uris[0]);
|
|
|
|
predictor.learn(uri, null, predictor.LEARN_STARTUP, origin_attributes);
|
|
|
|
do_timeout(0, () => {
|
|
|
|
preconns.push(extract_origin(uri));
|
|
|
|
|
|
|
|
uri = newURI(uris[1]);
|
|
|
|
predictor.learn(uri, null, predictor.LEARN_STARTUP, origin_attributes);
|
|
|
|
do_timeout(0, () => {
|
|
|
|
preconns.push(extract_origin(uri));
|
2013-10-26 01:56:51 +04:00
|
|
|
|
2016-04-15 05:26:58 +03:00
|
|
|
var verifier = new Verifier("startup", [], preconns, []);
|
2017-02-03 06:17:00 +03:00
|
|
|
predictor.predict(null, null, predictor.PREDICT_STARTUP, origin_attributes, verifier);
|
2017-04-18 03:22:46 +03:00
|
|
|
});
|
|
|
|
});
|
2013-10-26 01:56:51 +04:00
|
|
|
}
|
|
|
|
|
2015-06-18 12:23:00 +03:00
|
|
|
const dns_toplevel = newURI("http://localhost:4444/index.html");
|
|
|
|
|
|
|
|
function continue_test_dns() {
|
2013-10-26 01:56:51 +04:00
|
|
|
var subresource = "http://localhost:4443/jquery.js";
|
|
|
|
|
2017-02-03 06:17:00 +03:00
|
|
|
predictor.learn(dns_toplevel, null, predictor.LEARN_LOAD_TOPLEVEL, origin_attributes);
|
2017-04-18 03:22:46 +03:00
|
|
|
do_timeout(0, () => {
|
2015-06-18 12:23:00 +03:00
|
|
|
var sruri = newURI(subresource);
|
2017-02-03 06:17:00 +03:00
|
|
|
predictor.learn(sruri, dns_toplevel, predictor.LEARN_LOAD_SUBRESOURCE, origin_attributes);
|
2017-04-18 03:22:46 +03:00
|
|
|
do_timeout(0, () => {
|
2015-01-15 00:59:04 +03:00
|
|
|
|
2015-06-18 12:23:00 +03:00
|
|
|
var preresolves = [extract_origin(sruri)];
|
2016-04-15 05:26:58 +03:00
|
|
|
var verifier = new Verifier("dns", [], [], preresolves);
|
2017-02-03 06:17:00 +03:00
|
|
|
predictor.predict(dns_toplevel, null, predictor.PREDICT_LOAD, origin_attributes, verifier);
|
2017-04-18 03:22:46 +03:00
|
|
|
});
|
|
|
|
});
|
2015-06-18 12:23:00 +03:00
|
|
|
}
|
2015-01-15 00:59:04 +03:00
|
|
|
|
2015-06-18 12:23:00 +03:00
|
|
|
function test_dns() {
|
|
|
|
open_and_continue([dns_toplevel], function () {
|
|
|
|
// Ensure that this will do preresolves
|
|
|
|
Services.prefs.setIntPref("network.predictor.preconnect-min-confidence", 101);
|
|
|
|
if (running_single_process) {
|
|
|
|
continue_test_dns();
|
|
|
|
} else {
|
|
|
|
sendCommand("continue_test_dns();");
|
|
|
|
}
|
2015-01-15 00:59:04 +03:00
|
|
|
});
|
2013-10-26 01:56:51 +04:00
|
|
|
}
|
|
|
|
|
2015-06-18 12:23:00 +03:00
|
|
|
const origin_toplevel = newURI("http://localhost:4444/index.html");
|
|
|
|
|
|
|
|
function continue_test_origin() {
|
2013-10-26 01:56:51 +04:00
|
|
|
var subresources = [
|
|
|
|
"http://localhost:4444/style.css",
|
|
|
|
"http://localhost:4443/jquery.js",
|
|
|
|
"http://localhost:4444/image.png"
|
|
|
|
];
|
2017-02-03 06:17:00 +03:00
|
|
|
predictor.learn(origin_toplevel, null, predictor.LEARN_LOAD_TOPLEVEL, origin_attributes);
|
2017-04-18 03:22:46 +03:00
|
|
|
do_timeout(0, () => {
|
2015-06-18 12:23:00 +03:00
|
|
|
var preconns = [];
|
2017-04-18 03:22:46 +03:00
|
|
|
|
|
|
|
var sruri = newURI(subresources[0]);
|
|
|
|
predictor.learn(sruri, origin_toplevel, predictor.LEARN_LOAD_SUBRESOURCE, origin_attributes);
|
|
|
|
do_timeout(0, () => {
|
|
|
|
var origin = extract_origin(sruri);
|
2018-02-01 22:45:22 +03:00
|
|
|
if (!preconns.includes(origin)) {
|
2017-04-18 03:22:46 +03:00
|
|
|
preconns.push(origin);
|
|
|
|
}
|
|
|
|
|
|
|
|
sruri = newURI(subresources[1]);
|
|
|
|
predictor.learn(sruri, origin_toplevel, predictor.LEARN_LOAD_SUBRESOURCE, origin_attributes);
|
|
|
|
do_timeout(0, () => {
|
|
|
|
var origin = extract_origin(sruri);
|
2018-02-01 22:45:22 +03:00
|
|
|
if (!preconns.includes(origin)) {
|
2017-04-18 03:22:46 +03:00
|
|
|
preconns.push(origin);
|
|
|
|
}
|
|
|
|
|
|
|
|
sruri = newURI(subresources[2]);
|
|
|
|
predictor.learn(sruri, origin_toplevel, predictor.LEARN_LOAD_SUBRESOURCE, origin_attributes);
|
|
|
|
do_timeout(0, () => {
|
|
|
|
var origin = extract_origin(sruri);
|
2018-02-01 22:45:22 +03:00
|
|
|
if (!preconns.includes(origin)) {
|
2017-04-18 03:22:46 +03:00
|
|
|
preconns.push(origin);
|
2015-06-18 12:23:00 +03:00
|
|
|
}
|
2013-10-26 01:56:51 +04:00
|
|
|
|
2015-06-18 12:23:00 +03:00
|
|
|
var loaduri = newURI("http://localhost:4444/anotherpage.html");
|
2016-04-15 05:26:58 +03:00
|
|
|
var verifier = new Verifier("origin", [], preconns, []);
|
2017-02-03 06:17:00 +03:00
|
|
|
predictor.predict(loaduri, null, predictor.PREDICT_LOAD, origin_attributes, verifier);
|
2017-04-18 03:22:46 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2013-10-26 01:56:51 +04:00
|
|
|
}
|
|
|
|
|
2015-06-18 12:23:00 +03:00
|
|
|
function test_origin() {
|
|
|
|
open_and_continue([origin_toplevel], function () {
|
|
|
|
if (running_single_process) {
|
|
|
|
continue_test_origin();
|
|
|
|
} else {
|
|
|
|
sendCommand("continue_test_origin();");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-05-08 00:03:00 +04:00
|
|
|
|
2016-04-15 05:26:58 +03:00
|
|
|
var httpserv = null;
|
|
|
|
var prefetch_tluri;
|
|
|
|
var prefetch_sruri;
|
|
|
|
|
|
|
|
function prefetchHandler(metadata, response) {
|
|
|
|
response.setStatusLine(metadata.httpVersion, 200, "OK");
|
|
|
|
var body = "Success (meow meow meow).";
|
|
|
|
|
|
|
|
response.bodyOutputStream.write(body, body.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
var prefetchListener = {
|
2019-02-28 02:41:54 +03:00
|
|
|
onStartRequest: function(request) {
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.equal(request.status, Cr.NS_OK);
|
2016-04-15 05:26:58 +03:00
|
|
|
},
|
|
|
|
|
2019-02-28 02:42:27 +03:00
|
|
|
onDataAvailable: function(request, stream, offset, cnt) {
|
2016-04-15 05:26:58 +03:00
|
|
|
read_stream(stream, cnt);
|
|
|
|
},
|
|
|
|
|
2019-02-28 02:41:54 +03:00
|
|
|
onStopRequest: function(request, status) {
|
2016-04-15 05:26:58 +03:00
|
|
|
run_next_test();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function test_prefetch_setup() {
|
|
|
|
// Disable preconnects and preresolves
|
|
|
|
Services.prefs.setIntPref("network.predictor.preconnect-min-confidence", 101);
|
|
|
|
Services.prefs.setIntPref("network.predictor.preresolve-min-confidence", 101);
|
|
|
|
|
|
|
|
Services.prefs.setBoolPref("network.predictor.enable-prefetch", true);
|
|
|
|
|
|
|
|
// Makes it so we only have to call test_prefetch_prime twice to make prefetch
|
|
|
|
// do its thing.
|
|
|
|
Services.prefs.setIntPref("network.predictor.prefetch-rolling-load-count", 2);
|
|
|
|
|
|
|
|
// This test does not run in e10s-mode, so we'll just go ahead and skip it.
|
|
|
|
// We've left the e10s test code in below, just in case someone wants to try
|
|
|
|
// to make it work at some point in the future.
|
|
|
|
if (!running_single_process) {
|
|
|
|
dump("skipping test_prefetch_setup due to e10s\n");
|
|
|
|
run_next_test();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
httpserv = new HttpServer();
|
|
|
|
httpserv.registerPathHandler("/cat.jpg", prefetchHandler);
|
|
|
|
httpserv.start(-1);
|
|
|
|
|
|
|
|
var tluri = "http://127.0.0.1:" + httpserv.identity.primaryPort + "/index.html";
|
|
|
|
var sruri = "http://127.0.0.1:" + httpserv.identity.primaryPort + "/cat.jpg";
|
|
|
|
prefetch_tluri = newURI(tluri);
|
|
|
|
prefetch_sruri = newURI(sruri);
|
|
|
|
if (!running_single_process && !is_child_process()) {
|
|
|
|
// Give the child process access to these values
|
|
|
|
sendCommand("prefetch_tluri = newURI(\"" + tluri + "\");");
|
|
|
|
sendCommand("prefetch_sruri = newURI(\"" + sruri + "\");");
|
|
|
|
}
|
|
|
|
|
|
|
|
run_next_test();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Used to "prime the pump" for prefetch - it makes sure all our learns go
|
|
|
|
// through as expected so that prefetching will happen.
|
|
|
|
function test_prefetch_prime() {
|
|
|
|
// This test does not run in e10s-mode, so we'll just go ahead and skip it.
|
|
|
|
// We've left the e10s test code in below, just in case someone wants to try
|
|
|
|
// to make it work at some point in the future.
|
|
|
|
if (!running_single_process) {
|
|
|
|
dump("skipping test_prefetch_prime due to e10s\n");
|
|
|
|
run_next_test();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
open_and_continue([prefetch_tluri], function() {
|
|
|
|
if (running_single_process) {
|
2017-02-03 06:17:00 +03:00
|
|
|
predictor.learn(prefetch_tluri, null, predictor.LEARN_LOAD_TOPLEVEL, origin_attributes);
|
|
|
|
predictor.learn(prefetch_sruri, prefetch_tluri, predictor.LEARN_LOAD_SUBRESOURCE, origin_attributes);
|
2016-04-15 05:26:58 +03:00
|
|
|
} else {
|
2017-02-03 06:17:00 +03:00
|
|
|
sendCommand("predictor.learn(prefetch_tluri, null, predictor.LEARN_LOAD_TOPLEVEL, origin_attributes);");
|
|
|
|
sendCommand("predictor.learn(prefetch_sruri, prefetch_tluri, predictor.LEARN_LOAD_SUBRESOURCE, origin_attributes);");
|
2016-04-15 05:26:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// This runs in the parent or only process
|
2016-04-27 17:59:30 +03:00
|
|
|
var channel = NetUtil.newChannel({
|
|
|
|
uri: prefetch_sruri.asciiSpec,
|
2019-05-02 15:34:52 +03:00
|
|
|
loadUsingSystemPrincipal: true,
|
2016-04-27 17:59:30 +03:00
|
|
|
}).QueryInterface(Ci.nsIHttpChannel);
|
2016-04-15 05:26:58 +03:00
|
|
|
channel.requestMethod = "GET";
|
2019-05-02 15:34:52 +03:00
|
|
|
channel.referrerInfo = new ReferrerInfo(Ci.nsIHttpChannel.REFERRER_POLICY_UNSET, true, prefetch_tluri);
|
2019-02-12 19:08:25 +03:00
|
|
|
channel.asyncOpen(prefetchListener);
|
2016-04-15 05:26:58 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_prefetch() {
|
|
|
|
// This test does not run in e10s-mode, so we'll just go ahead and skip it.
|
|
|
|
// We've left the e10s test code in below, just in case someone wants to try
|
|
|
|
// to make it work at some point in the future.
|
|
|
|
if (!running_single_process) {
|
|
|
|
dump("skipping test_prefetch due to e10s\n");
|
|
|
|
run_next_test();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup for this has all been taken care of by test_prefetch_prime, so we can
|
|
|
|
// continue on without pausing here.
|
|
|
|
if (running_single_process) {
|
|
|
|
continue_test_prefetch();
|
|
|
|
} else {
|
|
|
|
sendCommand("continue_test_prefetch();");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function continue_test_prefetch() {
|
|
|
|
var prefetches = [prefetch_sruri.asciiSpec];
|
|
|
|
var verifier = new Verifier("prefetch", prefetches, [], []);
|
2017-02-03 06:17:00 +03:00
|
|
|
predictor.predict(prefetch_tluri, null, predictor.PREDICT_LOAD, origin_attributes, verifier);
|
2016-04-15 05:26:58 +03:00
|
|
|
}
|
|
|
|
|
2014-05-08 00:03:00 +04:00
|
|
|
function cleanup() {
|
2015-01-15 00:59:04 +03:00
|
|
|
observer.cleaningUp = true;
|
2016-04-15 05:26:58 +03:00
|
|
|
if (running_single_process) {
|
|
|
|
// The http server is required (and started) by the prefetch test, which
|
|
|
|
// only runs in single-process mode, so don't try to shut it down if we're
|
|
|
|
// in e10s mode.
|
|
|
|
do_test_pending();
|
|
|
|
httpserv.stop(do_test_finished);
|
|
|
|
}
|
2015-06-18 12:23:00 +03:00
|
|
|
reset_predictor();
|
2014-05-08 00:03:00 +04:00
|
|
|
}
|
|
|
|
|
2013-10-26 01:56:51 +04:00
|
|
|
var tests = [
|
2015-01-15 00:59:04 +03:00
|
|
|
// This must ALWAYS come first, to ensure a clean slate
|
|
|
|
reset_predictor,
|
2013-10-26 01:56:51 +04:00
|
|
|
test_link_hover,
|
|
|
|
test_pageload,
|
2015-01-15 00:59:04 +03:00
|
|
|
// TODO: These are disabled until the features are re-written
|
|
|
|
//test_redirect,
|
|
|
|
//test_startup,
|
|
|
|
// END DISABLED TESTS
|
|
|
|
test_origin,
|
2013-10-26 01:56:51 +04:00
|
|
|
test_dns,
|
2016-04-15 05:26:58 +03:00
|
|
|
test_prefetch_setup,
|
|
|
|
test_prefetch_prime,
|
|
|
|
test_prefetch_prime,
|
|
|
|
test_prefetch,
|
2015-01-15 00:59:04 +03:00
|
|
|
// This must ALWAYS come last, to ensure we clean up after ourselves
|
|
|
|
cleanup
|
2013-10-26 01:56:51 +04:00
|
|
|
];
|
|
|
|
|
2015-01-15 00:59:04 +03:00
|
|
|
var observer = {
|
|
|
|
cleaningUp: false,
|
|
|
|
|
|
|
|
QueryInterface: function (iid) {
|
|
|
|
if (iid.equals(Ci.nsIObserver) ||
|
|
|
|
iid.equals(Ci.nsISupports)) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw Cr.NS_ERROR_NO_INTERFACE;
|
|
|
|
},
|
|
|
|
|
|
|
|
observe: function (subject, topic, data) {
|
|
|
|
if (topic != "predictor-reset-complete") {
|
|
|
|
return;
|
|
|
|
}
|
2015-06-18 12:23:00 +03:00
|
|
|
|
2015-01-15 00:59:04 +03:00
|
|
|
if (this.cleaningUp) {
|
|
|
|
unregisterObserver();
|
|
|
|
}
|
2015-06-18 12:23:00 +03:00
|
|
|
|
2015-01-15 00:59:04 +03:00
|
|
|
run_next_test();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function registerObserver() {
|
2017-04-14 22:51:38 +03:00
|
|
|
Services.obs.addObserver(observer, "predictor-reset-complete");
|
2015-01-15 00:59:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function unregisterObserver() {
|
2015-06-18 12:23:00 +03:00
|
|
|
Services.obs.removeObserver(observer, "predictor-reset-complete");
|
2015-01-15 00:59:04 +03:00
|
|
|
}
|
|
|
|
|
2015-06-18 12:23:00 +03:00
|
|
|
function run_test_real() {
|
2018-03-19 01:27:04 +03:00
|
|
|
tests.forEach(f => add_test(f));
|
2015-07-21 23:20:20 +03:00
|
|
|
do_get_profile();
|
2015-06-18 12:23:00 +03:00
|
|
|
|
|
|
|
Services.prefs.setBoolPref("network.predictor.enabled", true);
|
|
|
|
Services.prefs.setBoolPref("network.predictor.cleaned-up", true);
|
2016-06-09 00:13:39 +03:00
|
|
|
Services.prefs.setBoolPref("network.predictor.doing-tests", true);
|
2015-07-21 23:20:20 +03:00
|
|
|
|
|
|
|
predictor = Cc["@mozilla.org/network/predictor;1"].getService(Ci.nsINetworkPredictor);
|
|
|
|
|
|
|
|
registerObserver();
|
|
|
|
|
2017-12-21 13:10:23 +03:00
|
|
|
registerCleanupFunction(() => {
|
2015-06-18 12:23:00 +03:00
|
|
|
Services.prefs.clearUserPref("network.predictor.preconnect-min-confidence");
|
|
|
|
Services.prefs.clearUserPref("network.predictor.enabled");
|
|
|
|
Services.prefs.clearUserPref("network.predictor.cleaned-up");
|
2016-04-15 05:26:58 +03:00
|
|
|
Services.prefs.clearUserPref("network.predictor.preresolve-min-confidence");
|
|
|
|
Services.prefs.clearUserPref("network.predictor.enable-prefetch");
|
|
|
|
Services.prefs.clearUserPref("network.predictor.prefetch-rolling-load-count");
|
2016-06-09 00:13:39 +03:00
|
|
|
Services.prefs.clearUserPref("network.predictor.doing-tests");
|
2015-06-18 12:23:00 +03:00
|
|
|
});
|
|
|
|
|
2013-10-26 01:56:51 +04:00
|
|
|
run_next_test();
|
|
|
|
}
|
2015-06-18 12:23:00 +03:00
|
|
|
|
|
|
|
function run_test() {
|
|
|
|
// This indirection is necessary to make e10s tests work as expected
|
|
|
|
running_single_process = true;
|
|
|
|
run_test_real();
|
|
|
|
}
|