зеркало из https://github.com/mozilla/pjs.git
Родитель
cb02f04a5a
Коммит
afa0536229
|
@ -1120,7 +1120,7 @@ private:
|
|||
}
|
||||
|
||||
if (!aPlace.hidden) {
|
||||
// Now, mark the page as not hidden if the frecency is now nonzero.
|
||||
// Mark the page as not hidden if the frecency is now nonzero.
|
||||
nsCOMPtr<mozIStorageStatement> stmt;
|
||||
if (aPlace.placeId) {
|
||||
stmt = mHistory->GetStatement(
|
||||
|
|
|
@ -48,12 +48,14 @@ include $(topsrcdir)/config/rules.mk
|
|||
_BROWSER_FILES = \
|
||||
head.js \
|
||||
browser_bug399606.js \
|
||||
browser_bug646422.js \
|
||||
browser_bug680727.js \
|
||||
browser_notfound.js \
|
||||
browser_redirect.js \
|
||||
browser_visituri.js \
|
||||
browser_visituri_nohistory.js \
|
||||
browser_visituri_privatebrowsing.js \
|
||||
browser_settitle.js \
|
||||
browser_bug646422.js \
|
||||
browser_bug680727.js \
|
||||
$(NULL)
|
||||
|
||||
# These are files that need to be loaded via the HTTP proxy server
|
||||
|
@ -65,12 +67,14 @@ _HTTP_FILES = \
|
|||
bug_399606/399606-window.location.href.html \
|
||||
bug_399606/399606-window.location.html \
|
||||
bug_399606/399606-history.go-0.html \
|
||||
redirect.sjs \
|
||||
redirect-target.html \
|
||||
settitle/title1.html \
|
||||
settitle/title2.html \
|
||||
visituri/begin.html \
|
||||
visituri/redirect_twice.sjs \
|
||||
visituri/redirect_once.sjs \
|
||||
visituri/final.html \
|
||||
settitle/title1.html \
|
||||
settitle/title2.html \
|
||||
$(NULL)
|
||||
|
||||
libs:: $(_BROWSER_FILES)
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/* 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/. */
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
registerCleanupFunction(function() {
|
||||
gBrowser.removeCurrentTab();
|
||||
});
|
||||
gBrowser.selectedTab.linkedBrowser.loadURI("http://mochi.test:8888/notFoundPage.html");
|
||||
|
||||
// Create and add history observer.
|
||||
let historyObserver = {
|
||||
onVisit: function (aURI, aVisitID, aTime, aSessionID, aReferringID,
|
||||
aTransitionType) {
|
||||
PlacesUtils.history.removeObserver(historyObserver);
|
||||
info("Received onVisit: " + aURI.spec);
|
||||
fieldForUrl(aURI, "frecency", function (aFrecency) {
|
||||
is(aFrecency, 0, "Frecency should be 0");
|
||||
fieldForUrl(aURI, "hidden", function (aHidden) {
|
||||
is(aHidden, 0, "Page should not be hidden");
|
||||
waitForClearHistory(finish);
|
||||
});
|
||||
});
|
||||
},
|
||||
onBeginUpdateBatch: function () {},
|
||||
onEndUpdateBatch: function () {},
|
||||
onTitleChanged: function () {},
|
||||
onBeforeDeleteURI: function () {},
|
||||
onDeleteURI: function () {},
|
||||
onClearHistory: function () {},
|
||||
onPageChanged: function () {},
|
||||
onDeleteVisits: function () {},
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsINavHistoryObserver])
|
||||
};
|
||||
PlacesUtils.history.addObserver(historyObserver, false);
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/* 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/. */
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
const REDIRECT_URI = NetUtil.newURI("http://mochi.test:8888/tests/toolkit/components/places/tests/browser/redirect.sjs");
|
||||
const TARGET_URI = NetUtil.newURI("http://mochi.test:8888/tests/toolkit/components/places/tests/browser/redirect-target.html");
|
||||
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
registerCleanupFunction(function() {
|
||||
gBrowser.removeCurrentTab();
|
||||
});
|
||||
gBrowser.selectedTab.linkedBrowser.loadURI(REDIRECT_URI.spec);
|
||||
|
||||
// Create and add history observer.
|
||||
let historyObserver = {
|
||||
onVisit: function (aURI, aVisitID, aTime, aSessionID, aReferringID,
|
||||
aTransitionType) {
|
||||
info("Received onVisit: " + aURI.spec);
|
||||
PlacesUtils.history.removeObserver(historyObserver);
|
||||
|
||||
ok(aURI.equals(TARGET_URI), "The redirect source should not be notified");
|
||||
|
||||
fieldForUrl(REDIRECT_URI, "frecency", function (aFrecency) {
|
||||
ok(aFrecency != 0, "Frecency or the redirecting page should not be 0");
|
||||
|
||||
fieldForUrl(REDIRECT_URI, "hidden", function (aHidden) {
|
||||
is(aHidden, 1, "The redirecting page should be hidden");
|
||||
|
||||
fieldForUrl(TARGET_URI, "frecency", function (aFrecency) {
|
||||
ok(aFrecency != 0, "Frecency of the target page should not be 0");
|
||||
|
||||
fieldForUrl(TARGET_URI, "hidden", function (aHidden) {
|
||||
is(aHidden, 0, "The target page should not be hidden");
|
||||
|
||||
waitForClearHistory(finish);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
onBeginUpdateBatch: function () {},
|
||||
onEndUpdateBatch: function () {},
|
||||
onTitleChanged: function () {},
|
||||
onBeforeDeleteURI: function () {},
|
||||
onDeleteURI: function () {},
|
||||
onClearHistory: function () {},
|
||||
onPageChanged: function () {},
|
||||
onDeleteVisits: function () {},
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsINavHistoryObserver])
|
||||
};
|
||||
PlacesUtils.history.addObserver(historyObserver, false);
|
||||
}
|
|
@ -3,6 +3,13 @@
|
|||
|
||||
Components.utils.import("resource://gre/modules/NetUtil.jsm");
|
||||
|
||||
/**
|
||||
* Waits for completion of a clear history operation, before
|
||||
* proceeding with aCallback.
|
||||
*
|
||||
* @param aCallback
|
||||
* Function to be called when done.
|
||||
*/
|
||||
function waitForClearHistory(aCallback) {
|
||||
Services.obs.addObserver(function observeCH(aSubject, aTopic, aData) {
|
||||
Services.obs.removeObserver(observeCH, PlacesUtils.TOPIC_EXPIRATION_FINISHED);
|
||||
|
@ -11,6 +18,79 @@ function waitForClearHistory(aCallback) {
|
|||
PlacesUtils.bhistory.removeAllPages();
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for all pending async statements on the default connection, before
|
||||
* proceeding with aCallback.
|
||||
*
|
||||
* @param aCallback
|
||||
* Function to be called when done.
|
||||
* @param aScope
|
||||
* Scope for the callback.
|
||||
* @param aArguments
|
||||
* Arguments array for the callback.
|
||||
*
|
||||
* @note The result is achieved by asynchronously executing a query requiring
|
||||
* a write lock. Since all statements on the same connection are
|
||||
* serialized, the end of this write operation means that all writes are
|
||||
* complete. Note that WAL makes so that writers don't block readers, but
|
||||
* this is a problem only across different connections.
|
||||
*/
|
||||
function waitForAsyncUpdates(aCallback, aScope, aArguments)
|
||||
{
|
||||
let scope = aScope || this;
|
||||
let args = aArguments || [];
|
||||
let db = PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase)
|
||||
.DBConnection;
|
||||
let begin = db.createAsyncStatement("BEGIN EXCLUSIVE");
|
||||
begin.executeAsync();
|
||||
begin.finalize();
|
||||
|
||||
let commit = db.createAsyncStatement("COMMIT");
|
||||
commit.executeAsync({
|
||||
handleResult: function() {},
|
||||
handleError: function() {},
|
||||
handleCompletion: function(aReason)
|
||||
{
|
||||
aCallback.apply(scope, args);
|
||||
}
|
||||
});
|
||||
commit.finalize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a moz_places field value for a url.
|
||||
*
|
||||
* @param aURI
|
||||
* The URI or spec to get field for.
|
||||
* param aCallback
|
||||
* Callback function that will get the property value.
|
||||
*/
|
||||
function fieldForUrl(aURI, aFieldName, aCallback)
|
||||
{
|
||||
let url = aURI instanceof Ci.nsIURI ? aURI.spec : aURI;
|
||||
let stmt = PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase)
|
||||
.DBConnection.createAsyncStatement(
|
||||
"SELECT " + aFieldName + " FROM moz_places WHERE url = :page_url"
|
||||
);
|
||||
stmt.params.page_url = url;
|
||||
stmt.executeAsync({
|
||||
_value: -1,
|
||||
handleResult: function(aResultSet) {
|
||||
let row = aResultSet.getNextRow();
|
||||
if (!row)
|
||||
ok(false, "The page should exist in the database");
|
||||
this._value = row.getResultByName(aFieldName);
|
||||
},
|
||||
handleError: function() {},
|
||||
handleCompletion: function(aReason) {
|
||||
if (aReason != Ci.mozIStorageStatementCallback.REASON_FINISHED)
|
||||
ok(false, "The statement should properly succeed");
|
||||
aCallback(this._value);
|
||||
}
|
||||
});
|
||||
stmt.finalize();
|
||||
}
|
||||
|
||||
function waitForAsyncUpdates(aCallback, aScope, aArguments)
|
||||
{
|
||||
let scope = aScope || this;
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<!DOCTYPE html><html><body><p>Ciao!</p></body></html>
|
|
@ -0,0 +1,14 @@
|
|||
/* 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/. */
|
||||
|
||||
function handleRequest(request, response)
|
||||
{
|
||||
let page = "<!DOCTYPE html><html><body><p>Redirecting...</p></body></html>";
|
||||
|
||||
response.setStatusLine(request.httpVersion, "301", "Moved Permanently");
|
||||
response.setHeader("Content-Type", "text/html", false);
|
||||
response.setHeader("Content-Length", page.length + "", false);
|
||||
response.setHeader("Location", "redirect-target.html", false);
|
||||
response.write(page);
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
/* 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/. */
|
||||
|
||||
// Ensure inline autocomplete doesn't return zero frecency pages.
|
||||
|
||||
add_autocomplete_test([
|
||||
"Searching for zero frecency domain should not autoFill it",
|
||||
"moz",
|
||||
"moz",
|
||||
function () {
|
||||
Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false);
|
||||
addVisits({ uri: NetUtil.newURI("http://mozilla.org/framed_link/"),
|
||||
transition: TRANSITION_FRAMED_LINK });
|
||||
}
|
||||
]);
|
||||
|
||||
add_autocomplete_test([
|
||||
"Searching for zero frecency url should not autoFill it",
|
||||
"mozilla.org/f",
|
||||
"mozilla.org/f",
|
||||
function () {
|
||||
Services.prefs.setBoolPref("browser.urlbar.autoFill.typed", false);
|
||||
addVisits({ uri: NetUtil.newURI("http://mozilla.org/framed_link/"),
|
||||
transition: TRANSITION_FRAMED_LINK });
|
||||
}
|
||||
]);
|
|
@ -7,3 +7,4 @@ tail =
|
|||
[test_do_not_trim.js]
|
||||
[test_keywords.js]
|
||||
[test_typed.js]
|
||||
[test_zero_frecency.js]
|
||||
|
|
|
@ -37,7 +37,8 @@ function isHostInMozHosts(aURI, aTyped)
|
|||
let stmt = DBConn().createStatement(
|
||||
"SELECT host, typed "
|
||||
+ "FROM moz_hosts "
|
||||
+ "WHERE host = fixup_url(:host)"
|
||||
+ "WHERE host = fixup_url(:host) "
|
||||
+ "AND frecency NOTNULL "
|
||||
);
|
||||
let result = false;
|
||||
stmt.params.host = aURI.host;
|
||||
|
|
|
@ -387,6 +387,31 @@ var gTests = [
|
|||
run_next_test();
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
desc: "Remove some visits from a zero frecency URI retains zero frecency",
|
||||
run: function () {
|
||||
do_log_info("Add some visits for the URI.");
|
||||
addVisits([{ uri: TEST_URI, transition: TRANSITION_FRAMED_LINK,
|
||||
visitDate: (NOW - 86400000000) },
|
||||
{ uri: TEST_URI, transition: TRANSITION_FRAMED_LINK,
|
||||
visitDate: NOW }],
|
||||
this.continue_run.bind(this));
|
||||
},
|
||||
continue_run: function () {
|
||||
do_log_info("Remove newer visit.");
|
||||
histsvc.QueryInterface(Ci.nsIBrowserHistory).
|
||||
removeVisitsByTimeframe(NOW - 10, NOW);
|
||||
|
||||
waitForAsyncUpdates(function() {
|
||||
do_log_info("URI should still exist in moz_places.");
|
||||
do_check_true(page_in_database(TEST_URL));
|
||||
do_log_info("Frecency should be zero.")
|
||||
do_check_eq(frecencyForUrl(TEST_URI), 0);
|
||||
run_next_test();
|
||||
});
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче