Bug 1316287 - Remove test_history_redirects.js as it doesn't actually test anything. r=mak

MozReview-Commit-ID: GkX9yjsXk9G

--HG--
extra : rebase_source : 70b656bc25243c032972a67cc496d6073f080f63
This commit is contained in:
Mark Banner 2016-11-09 11:42:37 +00:00
Родитель f5845ba7b6
Коммит 965963b650
5 изменённых файлов: 0 добавлений и 225 удалений

Просмотреть файл

@ -16,7 +16,6 @@ XPCSHELL_TESTS_MANIFESTS += [
'favicons/xpcshell.ini',
'history/xpcshell.ini',
'migration/xpcshell.ini',
'network/xpcshell.ini',
'queries/xpcshell.ini',
'unifiedcomplete/xpcshell.ini',
'unit/xpcshell.ini',
@ -66,4 +65,3 @@ TEST_HARNESS_FILES.testing.mochitest.tests.toolkit.components.places.tests.chrom
'chrome/rss_as_html.rss^headers^',
'chrome/sample_feed.atom',
]

Просмотреть файл

@ -1,7 +0,0 @@
"use strict";
module.exports = {
"extends": [
"../../../../../testing/xpcshell/xpcshell.eslintrc.js"
]
};

Просмотреть файл

@ -1,22 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;
var Cr = Components.results;
Cu.import("resource://testing-common/httpd.js");
Cu.import("resource://gre/modules/Services.jsm");
// Import common head.
{
let commonFile = do_get_file("../head_common.js", false);
let uri = Services.io.newFileURI(commonFile);
Services.scriptloader.loadSubScript(uri.spec, this);
}
// Put any other stuff relative to this test folder below.

Просмотреть файл

@ -1,188 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et: */
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/* Tests history redirects handling */
var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
var bh = hs.QueryInterface(Ci.nsIBrowserHistory);
const PERMA_REDIR_PATH = "/permaredir";
const TEMP_REDIR_PATH = "/tempredir";
const FOUND_PATH = "/found";
const HTTPSVR = new HttpServer();
HTTPSVR.start(-1);
const PORT = HTTPSVR.identity.primaryPort;
HTTPSVR.registerPathHandler(PERMA_REDIR_PATH, permaRedirHandler);
HTTPSVR.registerPathHandler(TEMP_REDIR_PATH, tempRedirHandler);
HTTPSVR.registerPathHandler(FOUND_PATH, foundHandler);
const STATUS = {
REDIRECT_PERMANENT: [301, "Moved Permanently"],
REDIRECT_TEMPORARY: [302, "Moved"],
FOUND: [200, "Found"],
}
const PERMA_REDIR_URL = "http://localhost:" + PORT + PERMA_REDIR_PATH;
const TEMP_REDIR_URL = "http://localhost:" + PORT + TEMP_REDIR_PATH;
const FOUND_URL = "http://localhost:" + PORT + FOUND_PATH;
// PERMANENT REDIRECT
function permaRedirHandler(aMeta, aResponse) {
// Redirect permanently to TEMP_REDIR_URL
PathHandler(aMeta, aResponse, "REDIRECT_PERMANENT", TEMP_REDIR_URL);
}
// TEMPORARY REDIRECT
function tempRedirHandler(aMeta, aResponse) {
// Redirect temporarily to FOUND_URL
PathHandler(aMeta, aResponse, "REDIRECT_TEMPORARY", FOUND_URL);
}
// FOUND
function foundHandler(aMeta, aResponse) {
PathHandler(aMeta, aResponse, "FOUND");
}
function PathHandler(aMeta, aResponse, aChannelEvent, aRedirURL) {
aResponse.setStatusLine(aMeta.httpVersion,
STATUS[aChannelEvent][0], // Code
STATUS[aChannelEvent][1]); // Text
if (aRedirURL)
aResponse.setHeader("Location", aRedirURL, false);
// aResponse.setHeader("Content-Type", "text/html", false);
let body = STATUS[aChannelEvent][1] + "\r\n";
aResponse.bodyOutputStream.write(body, body.length);
}
function run_test() {
do_test_pending();
var chan = NetUtil.newChannel({
uri: uri(PERMA_REDIR_URL),
loadUsingSystemPrincipal: true
});
var listener = new ChannelListener();
chan.notificationCallbacks = listener;
chan.asyncOpen2(listener);
// The test will continue on onStopRequest.
}
function continue_test() {
let stmt = DBConn().createStatement(
"SELECT v.id, h.url, v.from_visit, v.visit_date, v.visit_type " +
"FROM moz_historyvisits v " +
"JOIN moz_places h on h.id = v.place_id " +
"ORDER BY v.id ASC");
const EXPECTED = [
{ id: 1,
url: PERMA_REDIR_URL,
from_visit: 0,
visit_type: Ci.nsINavHistoryService.TRANSITION_LINK },
{ id: 2,
url: TEMP_REDIR_URL,
from_visit: 1,
visit_type: Ci.nsINavHistoryService.TRANSITION_REDIRECT_PERMANENT },
{ id: 3,
url: FOUND_URL,
from_visit: 2,
visit_type: Ci.nsINavHistoryService.TRANSITION_REDIRECT_TEMPORARY },
];
try {
while (stmt.executeStep()) {
let comparator = EXPECTED.shift();
do_print("Checking that '" + comparator.url +
"' was entered into the DB correctly");
do_check_eq(stmt.row.id, comparator.id);
do_check_eq(stmt.row.url, comparator.url);
do_check_eq(stmt.row.from_visit, comparator.from_visit);
do_check_eq(stmt.row.visit_type, comparator.visit_type);
}
}
finally {
stmt.finalize();
}
HTTPSVR.stop(do_test_finished);
}
/**
* Read count bytes from stream and return as a String object
*/
function read_stream(stream, count) {
/* assume stream has non-ASCII data */
var wrapper =
Components.classes["@mozilla.org/binaryinputstream;1"]
.createInstance(Components.interfaces.nsIBinaryInputStream);
wrapper.setInputStream(stream);
/* JS methods can be called with a maximum of 65535 arguments, and input
streams don't have to return all the data they make .available() when
asked to .read() that number of bytes. */
var data = [];
while (count > 0) {
var bytes = wrapper.readByteArray(Math.min(65535, count));
data.push(String.fromCharCode.apply(null, bytes));
count -= bytes.length;
if (bytes.length == 0)
do_throw("Nothing read from input stream!");
}
return data.join('');
}
function ChannelListener() {
}
ChannelListener.prototype = {
_buffer: "",
_got_onstartrequest: false,
_got_onchannelredirect: false,
QueryInterface: XPCOMUtils.generateQI([
Ci.nsIStreamListener,
Ci.nsIRequestObserver,
Ci.nsIInterfaceRequestor,
Ci.nsIChannelEventSink,
]),
// nsIInterfaceRequestor
getInterface: function (aIID) {
try {
return this.QueryInterface(aIID);
} catch (e) {
throw Components.results.NS_NOINTERFACE;
}
},
onStartRequest: function(request, context) {
do_print("onStartRequest");
this._got_onstartrequest = true;
},
onDataAvailable: function(request, context, stream, offset, count) {
this._buffer = this._buffer.concat(read_stream(stream, count));
},
onStopRequest: function(request, context, status) {
do_print("onStopRequest");
this._got_onstoprequest++;
let success = Components.isSuccessCode(status);
do_check_true(success);
do_check_true(this._got_onstartrequest);
do_check_true(this._got_onchannelredirect);
do_check_true(this._buffer.length > 0);
continue_test();
},
// nsIChannelEventSink
asyncOnChannelRedirect: function (aOldChannel, aNewChannel, aFlags, callback) {
do_print("onChannelRedirect");
this._got_onchannelredirect = true;
callback.onRedirectVerifyCallback(Components.results.NS_OK);
},
};

Просмотреть файл

@ -1,6 +0,0 @@
[DEFAULT]
head = head_network.js
tail =
skip-if = toolkit == 'android'
[test_history_redirects.js]