Bug 737841 - Part 3: remove no more useful redirectsMode query option.

r=dietrich rs=gavin

--HG--
rename : toolkit/components/places/tests/queries/test_redirectsMode.js => toolkit/components/places/tests/queries/test_redirects.js
This commit is contained in:
Marco Bonardo 2012-04-07 01:17:53 +02:00
parent 8087b03ca3
commit 13f1c8ba2e
18 changed files with 118 additions and 214 deletions

View File

@ -507,7 +507,7 @@ function HistoryMenu(aPopupShowingEvent) {
"@mozilla.org/browser/sessionstore;1", "@mozilla.org/browser/sessionstore;1",
"nsISessionStore"); "nsISessionStore");
PlacesMenu.call(this, aPopupShowingEvent, PlacesMenu.call(this, aPopupShowingEvent,
"place:redirectsMode=2&sort=4&maxResults=15"); "place:sort=4&maxResults=15");
} }
HistoryMenu.prototype = { HistoryMenu.prototype = {

View File

@ -1352,7 +1352,7 @@ BrowserGlue.prototype = {
// be set to the version it has been added in, we will compare its value // be set to the version it has been added in, we will compare its value
// to users' smartBookmarksVersion and add new smart bookmarks without // to users' smartBookmarksVersion and add new smart bookmarks without
// recreating old deleted ones. // recreating old deleted ones.
const SMART_BOOKMARKS_VERSION = 3; const SMART_BOOKMARKS_VERSION = 4;
const SMART_BOOKMARKS_ANNO = "Places/SmartBookmark"; const SMART_BOOKMARKS_ANNO = "Places/SmartBookmark";
const SMART_BOOKMARKS_PREF = "browser.places.smartBookmarksVersion"; const SMART_BOOKMARKS_PREF = "browser.places.smartBookmarksVersion";
@ -1380,9 +1380,7 @@ BrowserGlue.prototype = {
let smartBookmarks = { let smartBookmarks = {
MostVisited: { MostVisited: {
title: bundle.GetStringFromName("mostVisitedTitle"), title: bundle.GetStringFromName("mostVisitedTitle"),
uri: NetUtil.newURI("place:redirectsMode=" + uri: NetUtil.newURI("place:sort=" +
Ci.nsINavHistoryQueryOptions.REDIRECTS_MODE_TARGET +
"&sort=" +
Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_DESCENDING + Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_DESCENDING +
"&maxResults=" + MAX_RESULTS), "&maxResults=" + MAX_RESULTS),
parent: PlacesUtils.toolbarFolderId, parent: PlacesUtils.toolbarFolderId,

View File

@ -102,7 +102,7 @@ let (backup_date = new Date().toLocaleFormat("%Y-%m-%d")) {
} }
// Smart bookmarks constants. // Smart bookmarks constants.
const SMART_BOOKMARKS_VERSION = 3; const SMART_BOOKMARKS_VERSION = 4;
const SMART_BOOKMARKS_ON_TOOLBAR = 1; const SMART_BOOKMARKS_ON_TOOLBAR = 1;
const SMART_BOOKMARKS_ON_MENU = 3; // Takes in count the additional separator. const SMART_BOOKMARKS_ON_MENU = 3; // Takes in count the additional separator.

View File

@ -432,9 +432,6 @@ let PlacesProvider = {
// Sort by frecency, descending. // Sort by frecency, descending.
options.sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_FRECENCY_DESCENDING options.sortingMode = Ci.nsINavHistoryQueryOptions.SORT_BY_FRECENCY_DESCENDING
// We don't want source redirects for this query.
options.redirectsMode = Ci.nsINavHistoryQueryOptions.REDIRECTS_MODE_TARGET;
let links = []; let links = [];
let callback = { let callback = {

View File

@ -477,8 +477,6 @@ var WinTaskbarJumpList =
var options = PlacesUtils.history.getNewQueryOptions(); var options = PlacesUtils.history.getNewQueryOptions();
options.maxResults = aLimit; options.maxResults = aLimit;
options.sortingMode = aSortingMode; options.sortingMode = aSortingMode;
// We don't want source redirects for these queries.
options.redirectsMode = Ci.nsINavHistoryQueryOptions.REDIRECTS_MODE_TARGET;
var query = PlacesUtils.history.getNewQuery(); var query = PlacesUtils.history.getNewQuery();
// Return the pending statement to the caller, to allow cancelation. // Return the pending statement to the caller, to allow cancelation.

View File

@ -229,10 +229,10 @@ var gTests = [
path: "123456", path: "123456",
ref: "", ref: "",
nsIURL: false, nsINestedURI: false, immutable: true }, nsIURL: false, nsINestedURI: false, immutable: true },
{ spec: "place:redirectsMode=2&sort=8&maxResults=10", { spec: "place:sort=8&maxResults=10",
scheme: "place", scheme: "place",
prePath: "place:", prePath: "place:",
path: "redirectsMode=2&sort=8&maxResults=10", path: "sort=8&maxResults=10",
ref: "", ref: "",
nsIURL: false, nsINestedURI: false }, nsIURL: false, nsINestedURI: false },
{ spec: "resource://gre/", { spec: "resource://gre/",

View File

@ -73,9 +73,7 @@ add_test(function test_annotation_uploaded() {
_("Create a smart bookmark in the toolbar."); _("Create a smart bookmark in the toolbar.");
let parent = PlacesUtils.toolbarFolderId; let parent = PlacesUtils.toolbarFolderId;
let uri = let uri =
Utils.makeURI("place:redirectsMode=" + Utils.makeURI("place:sort=" +
Ci.nsINavHistoryQueryOptions.REDIRECTS_MODE_TARGET +
"&sort=" +
Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_DESCENDING + Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_DESCENDING +
"&maxResults=10"); "&maxResults=10");
let title = "Most Visited"; let title = "Most Visited";
@ -180,9 +178,7 @@ add_test(function test_smart_bookmarks_duped() {
let parent = PlacesUtils.toolbarFolderId; let parent = PlacesUtils.toolbarFolderId;
let uri = let uri =
Utils.makeURI("place:redirectsMode=" + Utils.makeURI("place:sort=" +
Ci.nsINavHistoryQueryOptions.REDIRECTS_MODE_TARGET +
"&sort=" +
Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_DESCENDING + Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_DESCENDING +
"&maxResults=10"); "&maxResults=10");
let title = "Most Visited"; let title = "Most Visited";

View File

@ -711,6 +711,19 @@ let PlacesDBUtils = {
")"); ")");
cleanupStatements.push(fixVisitStats); cleanupStatements.push(fixVisitStats);
// L.3 recalculate hidden for redirects.
let fixRedirectsHidden = DBConn.createAsyncStatement(
"UPDATE moz_places " +
"SET hidden = 1 " +
"WHERE id IN ( " +
"SELECT h.id FROM moz_places h " +
"JOIN moz_historyvisits src ON src.place_id = h.id " +
"JOIN moz_historyvisits dst ON dst.from_visit = src.id AND dst.visit_type IN (5,6) " +
"LEFT JOIN moz_bookmarks on fk = h.id AND fk ISNULL " +
"GROUP BY src.place_id HAVING count(*) = visit_count " +
")");
cleanupStatements.push(fixRedirectsHidden);
// MAINTENANCE STATEMENTS SHOULD GO ABOVE THIS POINT! // MAINTENANCE STATEMENTS SHOULD GO ABOVE THIS POINT!
return cleanupStatements; return cleanupStatements;

View File

@ -1040,7 +1040,7 @@ interface nsINavHistoryQuery : nsISupports
/** /**
* This object represents the global options for executing a query. * This object represents the global options for executing a query.
*/ */
[scriptable, uuid(d46a1ae7-aef8-47a2-9a5c-e6347253f9b2)] [scriptable, uuid(8198dfa7-8061-4766-95cb-fa86b3c00a47)]
interface nsINavHistoryQueryOptions : nsISupports interface nsINavHistoryQueryOptions : nsISupports
{ {
/** /**
@ -1201,37 +1201,13 @@ interface nsINavHistoryQueryOptions : nsISupports
attribute boolean expandQueries; attribute boolean expandQueries;
/** /**
* Most items in history are marked "hidden." Only toplevel pages that the * Some pages in history are marked "hidden" and thus don't appear by default
* user sees in the URL bar are not hidden. Hidden things include the content * in queries. These include automatic framed visits and redirects. Setting
* of iframes and all images on web pages. Normally, you don't want these * this attribute will return all pages, even hidden ones. Does nothing for
* things. If you do, set this flag and you'll get all items, even hidden * bookmark queries. Defaults to false.
* ones. Does nothing for bookmark queries. Defaults to false.
*/ */
attribute boolean includeHidden; attribute boolean includeHidden;
/**
* Include both redirected-from and redirected-to pages into results.
*/
const unsigned short REDIRECTS_MODE_ALL = 0;
/**
* Query results will not include redirected-to pages, but will include
* redirected-from pages.
*/
const unsigned short REDIRECTS_MODE_SOURCE = 1;
/**
* Query results will not include redirected-from pages but will include
* redirected-to pages.
*/
const unsigned short REDIRECTS_MODE_TARGET = 2;
/**
* Defines how redirects should be handled, see REDIRECTS_MODE_* constants
* above.
* Defaults to REDIRECTS_MODE_ALL.
* Note: this option is effective only on QUERY_TYPE_HISTORY.
*/
attribute unsigned short redirectsMode;
/** /**
* This is the maximum number of results that you want. The query is exeucted, * This is the maximum number of results that you want. The query is exeucted,
* the results are sorted, and then the top 'maxResults' results are taken * the results are sorted, and then the top 'maxResults' results are taken

View File

@ -1632,10 +1632,10 @@ nsNavHistory::ExecuteQueries(nsINavHistoryQuery** aQueries, PRUint32 aQueryCount
// determine from our nsNavHistoryQuery array and nsNavHistoryQueryOptions // determine from our nsNavHistoryQuery array and nsNavHistoryQueryOptions
// if this is the place query from the history menu. // if this is the place query from the history menu.
// from browser-menubar.inc, our history menu query is: // from browser-menubar.inc, our history menu query is:
// place:redirectsMode=2&sort=4&maxResults=10 // place:sort=4&maxResults=10
// note, any maxResult > 0 will still be considered a history menu query // note, any maxResult > 0 will still be considered a history menu query
// or if this is the place query from the "Most Visited" item in the "Smart Bookmarks" folder: // or if this is the place query from the "Most Visited" item in the
// place:redirectsMode=2&sort=8&maxResults=10 // "Smart Bookmarks" folder: place:sort=8&maxResults=10
// note, any maxResult > 0 will still be considered a Most Visited menu query // note, any maxResult > 0 will still be considered a Most Visited menu query
static static
bool IsOptimizableHistoryQuery(const nsCOMArray<nsNavHistoryQuery>& aQueries, bool IsOptimizableHistoryQuery(const nsCOMArray<nsNavHistoryQuery>& aQueries,
@ -1749,7 +1749,6 @@ private:
PRUint16 mResultType; PRUint16 mResultType;
PRUint16 mQueryType; PRUint16 mQueryType;
bool mIncludeHidden; bool mIncludeHidden;
PRUint16 mRedirectsMode;
PRUint16 mSortingMode; PRUint16 mSortingMode;
PRUint32 mMaxResults; PRUint32 mMaxResults;
@ -1772,7 +1771,6 @@ PlacesSQLQueryBuilder::PlacesSQLQueryBuilder(
, mResultType(aOptions->ResultType()) , mResultType(aOptions->ResultType())
, mQueryType(aOptions->QueryType()) , mQueryType(aOptions->QueryType())
, mIncludeHidden(aOptions->IncludeHidden()) , mIncludeHidden(aOptions->IncludeHidden())
, mRedirectsMode(aOptions->RedirectsMode())
, mSortingMode(aOptions->SortingMode()) , mSortingMode(aOptions->SortingMode())
, mMaxResults(aOptions->MaxResults()) , mMaxResults(aOptions->MaxResults())
, mSkipOrderBy(false) , mSkipOrderBy(false)
@ -2249,27 +2247,6 @@ PlacesSQLQueryBuilder::Where()
nsCAutoString additionalVisitsConditions; nsCAutoString additionalVisitsConditions;
nsCAutoString additionalPlacesConditions; nsCAutoString additionalPlacesConditions;
if (mRedirectsMode == nsINavHistoryQueryOptions::REDIRECTS_MODE_SOURCE) {
// At least one visit that is not a redirect target should exist.
additionalVisitsConditions += NS_LITERAL_CSTRING(
"AND visit_type NOT IN ") +
nsPrintfCString("(%d,%d) ", nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT,
nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY);
}
else if (mRedirectsMode == nsINavHistoryQueryOptions::REDIRECTS_MODE_TARGET) {
// At least one visit that is not a redirect source should exist.
additionalPlacesConditions += nsPrintfCString(1024,
"AND EXISTS ( "
"SELECT id "
"FROM moz_historyvisits v "
"WHERE place_id = h.id "
"AND NOT EXISTS(SELECT id FROM moz_historyvisits "
"WHERE from_visit = v.id AND visit_type IN (%d,%d)) "
") ",
nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT,
nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY);
}
if (!mIncludeHidden) { if (!mIncludeHidden) {
additionalPlacesConditions += NS_LITERAL_CSTRING("AND hidden = 0 "); additionalPlacesConditions += NS_LITERAL_CSTRING("AND hidden = 0 ");
} }
@ -2508,33 +2485,7 @@ nsNavHistory::ConstructQueryString(
queryString.AppendInt(aOptions->MaxResults()); queryString.AppendInt(aOptions->MaxResults());
nsCAutoString additionalQueryOptions; nsCAutoString additionalQueryOptions;
if (aOptions->RedirectsMode() ==
nsINavHistoryQueryOptions::REDIRECTS_MODE_SOURCE) {
// At least one visit that is not a redirect target should exist.
additionalQueryOptions += nsPrintfCString(256,
"AND EXISTS ( "
"SELECT id "
"FROM moz_historyvisits "
"WHERE place_id = h.id "
"AND visit_type NOT IN (%d,%d)"
") ",
TRANSITION_REDIRECT_PERMANENT,
TRANSITION_REDIRECT_TEMPORARY);
}
else if (aOptions->RedirectsMode() ==
nsINavHistoryQueryOptions::REDIRECTS_MODE_TARGET) {
// At least one visit that is not a redirect source should exist.
additionalQueryOptions += nsPrintfCString(1024,
"AND EXISTS ( "
"SELECT id "
"FROM moz_historyvisits v "
"WHERE place_id = h.id "
"AND NOT EXISTS(SELECT id FROM moz_historyvisits "
"WHERE from_visit = v.id AND visit_type IN (%d,%d)) "
") ",
TRANSITION_REDIRECT_PERMANENT,
TRANSITION_REDIRECT_TEMPORARY);
}
queryString.ReplaceSubstring("{QUERY_OPTIONS}", queryString.ReplaceSubstring("{QUERY_OPTIONS}",
additionalQueryOptions.get()); additionalQueryOptions.get());
return NS_OK; return NS_OK;

View File

@ -171,7 +171,6 @@ static void SetOptionsKeyUint32(const nsCString& aValue,
#define QUERYKEY_EXPAND_QUERIES "expandQueries" #define QUERYKEY_EXPAND_QUERIES "expandQueries"
#define QUERYKEY_FORCE_ORIGINAL_TITLE "originalTitle" #define QUERYKEY_FORCE_ORIGINAL_TITLE "originalTitle"
#define QUERYKEY_INCLUDE_HIDDEN "includeHidden" #define QUERYKEY_INCLUDE_HIDDEN "includeHidden"
#define QUERYKEY_REDIRECTS_MODE "redirectsMode"
#define QUERYKEY_MAX_RESULTS "maxResults" #define QUERYKEY_MAX_RESULTS "maxResults"
#define QUERYKEY_QUERY_TYPE "queryType" #define QUERYKEY_QUERY_TYPE "queryType"
#define QUERYKEY_TAG "tag" #define QUERYKEY_TAG "tag"
@ -594,13 +593,6 @@ nsNavHistory::QueriesToQueryString(nsINavHistoryQuery **aQueries,
queryString += NS_LITERAL_CSTRING(QUERYKEY_INCLUDE_HIDDEN "=1"); queryString += NS_LITERAL_CSTRING(QUERYKEY_INCLUDE_HIDDEN "=1");
} }
// redirects mode
if (options->RedirectsMode() != nsINavHistoryQueryOptions::REDIRECTS_MODE_ALL) {
AppendAmpersandIfNonempty(queryString);
queryString += NS_LITERAL_CSTRING(QUERYKEY_REDIRECTS_MODE "=");
AppendInt16(queryString, options->RedirectsMode());
}
// max results // max results
if (options->MaxResults()) { if (options->MaxResults()) {
AppendAmpersandIfNonempty(queryString); AppendAmpersandIfNonempty(queryString);
@ -876,10 +868,6 @@ nsNavHistory::TokensToQueries(const nsTArray<QueryKeyValuePair>& aTokens,
} else if (kvp.key.EqualsLiteral(QUERYKEY_INCLUDE_HIDDEN)) { } else if (kvp.key.EqualsLiteral(QUERYKEY_INCLUDE_HIDDEN)) {
SetOptionsKeyBool(kvp.value, aOptions, SetOptionsKeyBool(kvp.value, aOptions,
&nsINavHistoryQueryOptions::SetIncludeHidden); &nsINavHistoryQueryOptions::SetIncludeHidden);
// query type
} else if (kvp.key.EqualsLiteral(QUERYKEY_REDIRECTS_MODE)) {
SetOptionsKeyUint16(kvp.value, aOptions,
&nsINavHistoryQueryOptions::SetRedirectsMode);
// max results // max results
} else if (kvp.key.EqualsLiteral(QUERYKEY_MAX_RESULTS)) { } else if (kvp.key.EqualsLiteral(QUERYKEY_MAX_RESULTS)) {
SetOptionsKeyUint32(kvp.value, aOptions, SetOptionsKeyUint32(kvp.value, aOptions,
@ -1521,20 +1509,6 @@ nsNavHistoryQueryOptions::SetIncludeHidden(bool aIncludeHidden)
return NS_OK; return NS_OK;
} }
// redirectsMode
NS_IMETHODIMP
nsNavHistoryQueryOptions::GetRedirectsMode(PRUint16* _retval)
{
*_retval = mRedirectsMode;
return NS_OK;
}
NS_IMETHODIMP
nsNavHistoryQueryOptions::SetRedirectsMode(PRUint16 aRedirectsMode)
{
mRedirectsMode = aRedirectsMode;
return NS_OK;
}
// maxResults // maxResults
NS_IMETHODIMP NS_IMETHODIMP
nsNavHistoryQueryOptions::GetMaxResults(PRUint32* aMaxResults) nsNavHistoryQueryOptions::GetMaxResults(PRUint32* aMaxResults)

View File

@ -141,7 +141,6 @@ public:
, mExcludeReadOnlyFolders(false) , mExcludeReadOnlyFolders(false)
, mExpandQueries(true) , mExpandQueries(true)
, mIncludeHidden(false) , mIncludeHidden(false)
, mRedirectsMode(nsINavHistoryQueryOptions::REDIRECTS_MODE_ALL)
, mMaxResults(0) , mMaxResults(0)
, mQueryType(nsINavHistoryQueryOptions::QUERY_TYPE_HISTORY) , mQueryType(nsINavHistoryQueryOptions::QUERY_TYPE_HISTORY)
, mAsyncEnabled(false) , mAsyncEnabled(false)
@ -159,7 +158,6 @@ public:
bool ExcludeReadOnlyFolders() const { return mExcludeReadOnlyFolders; } bool ExcludeReadOnlyFolders() const { return mExcludeReadOnlyFolders; }
bool ExpandQueries() const { return mExpandQueries; } bool ExpandQueries() const { return mExpandQueries; }
bool IncludeHidden() const { return mIncludeHidden; } bool IncludeHidden() const { return mIncludeHidden; }
PRUint16 RedirectsMode() const { return mRedirectsMode; }
PRUint32 MaxResults() const { return mMaxResults; } PRUint32 MaxResults() const { return mMaxResults; }
PRUint16 QueryType() const { return mQueryType; } PRUint16 QueryType() const { return mQueryType; }
bool AsyncEnabled() const { return mAsyncEnabled; } bool AsyncEnabled() const { return mAsyncEnabled; }
@ -184,7 +182,6 @@ private:
bool mExcludeReadOnlyFolders; bool mExcludeReadOnlyFolders;
bool mExpandQueries; bool mExpandQueries;
bool mIncludeHidden; bool mIncludeHidden;
PRUint16 mRedirectsMode;
PRUint32 mMaxResults; PRUint32 mMaxResults;
PRUint16 mQueryType; PRUint16 mQueryType;
bool mAsyncEnabled; bool mAsyncEnabled;

View File

@ -882,6 +882,7 @@ NavHistoryResultObserver.prototype = {
* transition: one of the TRANSITION_* from nsINavHistoryService, * transition: one of the TRANSITION_* from nsINavHistoryService,
* [optional] title: title of the page, * [optional] title: title of the page,
* [optional] visitDate: visit date in microseconds from the epoch * [optional] visitDate: visit date in microseconds from the epoch
* [optional] referrer: nsIURI of the referrer for this visit
* } * }
* @param [optional] aCallback * @param [optional] aCallback
* Function to be invoked on completion. * Function to be invoked on completion.
@ -910,7 +911,8 @@ function addVisits(aPlaceInfo, aCallback, aStack)
places[i].visits = [{ places[i].visits = [{
transitionType: places[i].transition === undefined ? TRANSITION_LINK transitionType: places[i].transition === undefined ? TRANSITION_LINK
: places[i].transition, : places[i].transition,
visitDate: places[i].visitDate || (now++) * 1000 visitDate: places[i].visitDate || (now++) * 1000,
referrerURI: places[i].referrer
}]; }];
} }

View File

@ -107,6 +107,25 @@ function populateDB(aArray) {
} }
} }
if (qdata.isRedirect) {
// Redirect sources added through the docshell are properly marked
// as redirects and get hidden state, the API doesn't have that
// power (And actually doesn't make much sense to add redirects
// through the API).
let stmt = DBConn().createStatement(
"UPDATE moz_places SET hidden = 1 WHERE url = :url");
stmt.params.url = qdata.uri;
try {
stmt.execute();
}
catch (ex) {
print("Error while setting visit_count.");
}
finally {
stmt.finalize();
}
}
if (qdata.isDetails) { if (qdata.isDetails) {
// Then we add extraneous page details for testing // Then we add extraneous page details for testing
PlacesUtils.history.addPageWithDetails(uri(qdata.uri), PlacesUtils.history.addPageWithDetails(uri(qdata.uri),

View File

@ -505,23 +505,6 @@ const queryOptionSwitches = [
} }
] ]
}, },
// redirectsMode
{
property: "redirectsMode",
desc: "nsINavHistoryQueryOptions.redirectsMode",
matches: simplePropertyMatches,
runs: [
function (aQuery, aQueryOptions) {
aQueryOptions.redirectsMode = aQueryOptions.REDIRECTS_MODE_ALL;
},
function (aQuery, aQueryOptions) {
aQueryOptions.redirectsMode = aQueryOptions.REDIRECTS_MODE_TARGET;
},
function (aQuery, aQueryOptions) {
aQueryOptions.redirectsMode = aQueryOptions.REDIRECTS_MODE_SOURCE;
}
]
},
]; ];
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -1,40 +1,6 @@
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public
/* vim:set ts=2 sw=2 sts=2 et: */ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
/* ***** BEGIN LICENSE BLOCK ***** * You can obtain one at http://mozilla.org/MPL/2.0/. */
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Places Test Code.
*
* The Initial Developer of the Original Code is Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Marco Bonardo <mak77@bonardo.net> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// Array of visits we will add to the database, will be populated later // Array of visits we will add to the database, will be populated later
// in the test. // in the test.
@ -47,49 +13,37 @@ let visits = [];
* *
* @param aSequence * @param aSequence
* an array that contains query options in the form: * an array that contains query options in the form:
* [includeHidden, redirectsMode, maxResults, sortingMode] * [includeHidden, maxResults, sortingMode]
*/ */
function check_results_callback(aSequence) { function check_results_callback(aSequence) {
// Sanity check: we should receive 3 parameters. // Sanity check: we should receive 3 parameters.
do_check_eq(aSequence.length, 4); do_check_eq(aSequence.length, 3);
let includeHidden = aSequence[0]; let includeHidden = aSequence[0];
let redirectsMode = aSequence[1]; let maxResults = aSequence[1];
let maxResults = aSequence[2]; let sortingMode = aSequence[2];
let sortingMode = aSequence[3];
print("\nTESTING: includeHidden(" + includeHidden + ")," + print("\nTESTING: includeHidden(" + includeHidden + ")," +
" redirectsMode(" + redirectsMode + ")," +
" maxResults(" + maxResults + ")," + " maxResults(" + maxResults + ")," +
" sortingMode(" + sortingMode + ")."); " sortingMode(" + sortingMode + ").");
function isHidden(aVisit) {
return aVisit.transType == Ci.nsINavHistoryService.TRANSITION_FRAMED_LINK ||
aVisit.isRedirect;
}
// Build expectedData array. // Build expectedData array.
let expectedData = visits.filter(function (aVisit, aIndex, aArray) { let expectedData = visits.filter(function (aVisit, aIndex, aArray) {
// Embed visits never appear in results. // Embed visits never appear in results.
if (aVisit.transType == Ci.nsINavHistoryService.TRANSITION_EMBED) if (aVisit.transType == Ci.nsINavHistoryService.TRANSITION_EMBED)
return false; return false;
if (aVisit.transType == Ci.nsINavHistoryService.TRANSITION_FRAMED_LINK && if (!includeHidden && isHidden(aVisit)) {
!includeHidden) {
// If the page has any non-hidden visit, then it's visible. // If the page has any non-hidden visit, then it's visible.
if (visits.filter(function (refVisit) { if (visits.filter(function (refVisit) {
return refVisit.uri == aVisit.uri && return refVisit.uri == aVisit.uri && !isHidden(refVisit);
refVisit.transType != Ci.nsINavHistoryService.TRANSITION_FRAMED_LINK;
}).length == 0) }).length == 0)
return false; return false;
} }
if (redirectsMode == Ci.nsINavHistoryQueryOptions.REDIRECTS_MODE_SOURCE) {
// Filter out any redirect target.
return aVisit.transType != Ci.nsINavHistoryService.TRANSITION_REDIRECT_PERMANENT &&
aVisit.transType != Ci.nsINavHistoryService.TRANSITION_REDIRECT_TEMPORARY;
}
if (redirectsMode == Ci.nsINavHistoryQueryOptions.REDIRECTS_MODE_TARGET) {
// Filter out any entry that is a redirect source.
return visits.filter(function (refVisit) {
return !refVisit.isRedirect && refVisit.uri == aVisit.uri;
}).length > 0;
}
return true; return true;
}); });
@ -129,7 +83,6 @@ function check_results_callback(aSequence) {
let query = PlacesUtils.history.getNewQuery(); let query = PlacesUtils.history.getNewQuery();
let options = PlacesUtils.history.getNewQueryOptions(); let options = PlacesUtils.history.getNewQueryOptions();
options.includeHidden = includeHidden; options.includeHidden = includeHidden;
options.redirectsMode = redirectsMode;
options.sortingMode = sortingMode; options.sortingMode = sortingMode;
if (maxResults) if (maxResults)
options.maxResults = maxResults; options.maxResults = maxResults;
@ -256,6 +209,7 @@ function add_visits_to_database() {
transType: transition, transType: transition,
uri: "http://" + transition + ".example.com/", uri: "http://" + transition + ".example.com/",
title: transition + "-example", title: transition + "-example",
isRedirect: true,
lastVisit: timeInMicroseconds--, lastVisit: timeInMicroseconds--,
visitCount: (transition == Ci.nsINavHistoryService.TRANSITION_EMBED || visitCount: (transition == Ci.nsINavHistoryService.TRANSITION_EMBED ||
transition == Ci.nsINavHistoryService.TRANSITION_FRAMED_LINK) ? 0 : visitCount++, transition == Ci.nsINavHistoryService.TRANSITION_FRAMED_LINK) ? 0 : visitCount++,
@ -303,6 +257,7 @@ function add_visits_to_database() {
uri: "http://" + transition + ".example.com/", uri: "http://" + transition + ".example.com/",
title: getLastValue("http://" + transition + ".example.com/", "title"), title: getLastValue("http://" + transition + ".example.com/", "title"),
lastVisit: getLastValue("http://" + transition + ".example.com/", "lastVisit"), lastVisit: getLastValue("http://" + transition + ".example.com/", "lastVisit"),
isRedirect: true,
referrer: "http://" + transition + ".redirect.perm.example.com/", referrer: "http://" + transition + ".redirect.perm.example.com/",
visitCount: getLastValue("http://" + transition + ".example.com/", "visitCount"), visitCount: getLastValue("http://" + transition + ".example.com/", "visitCount"),
isInQuery: true })); isInQuery: true }));
@ -334,9 +289,6 @@ function run_test() {
// This array will be used by cartProd to generate a matrix of all possible // This array will be used by cartProd to generate a matrix of all possible
// combinations. // combinations.
let includeHidden_options = [true, false]; let includeHidden_options = [true, false];
let redirectsMode_options = [Ci.nsINavHistoryQueryOptions.REDIRECTS_MODE_ALL,
Ci.nsINavHistoryQueryOptions.REDIRECTS_MODE_SOURCE,
Ci.nsINavHistoryQueryOptions.REDIRECTS_MODE_TARGET];
let maxResults_options = [5, 10, 20, null]; let maxResults_options = [5, 10, 20, null];
// These sortingMode are choosen to toggle using special queries for history // These sortingMode are choosen to toggle using special queries for history
// menu and most visited smart bookmark. // menu and most visited smart bookmark.
@ -344,7 +296,7 @@ function run_test() {
Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_DESCENDING, Ci.nsINavHistoryQueryOptions.SORT_BY_VISITCOUNT_DESCENDING,
Ci.nsINavHistoryQueryOptions.SORT_BY_DATE_DESCENDING]; Ci.nsINavHistoryQueryOptions.SORT_BY_DATE_DESCENDING];
// Will execute check_results_callback() for each generated combination. // Will execute check_results_callback() for each generated combination.
cartProd([includeHidden_options, redirectsMode_options, maxResults_options, sorting_options], cartProd([includeHidden_options, maxResults_options, sorting_options],
check_results_callback); check_results_callback);
remove_all_bookmarks(); remove_all_bookmarks();

View File

@ -12,7 +12,7 @@ tail =
[test_history_queries_titles_liveUpdate.js] [test_history_queries_titles_liveUpdate.js]
[test_onlyBookmarked.js] [test_onlyBookmarked.js]
[test_querySerialization.js] [test_querySerialization.js]
[test_redirectsMode.js] [test_redirects.js]
# Bug 676989: test hangs consistently on Android # Bug 676989: test hangs consistently on Android
skip-if = os == "android" skip-if = os == "android"
[test_results-as-tag-contents-query.js] [test_results-as-tag-contents-query.js]

View File

@ -1145,6 +1145,54 @@ tests.push({
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
tests.push({
name: "L.3",
desc: "recalculate hidden for redirects.",
setup: function() {
addVisits([
{ uri: NetUtil.newURI("http://l3.moz.org/"),
transition: TRANSITION_TYPED },
{ uri: NetUtil.newURI("http://l3.moz.org/redirecting/"),
transition: TRANSITION_TYPED },
{ uri: NetUtil.newURI("http://l3.moz.org/redirecting2/"),
transition: TRANSITION_REDIRECT_TEMPORARY,
referrer: NetUtil.newURI("http://l3.moz.org/redirecting/") },
{ uri: NetUtil.newURI("http://l3.moz.org/target/"),
transition: TRANSITION_REDIRECT_PERMANENT,
referrer: NetUtil.newURI("http://l3.moz.org/redirecting2/") },
]);
},
asyncCheck: function(aCallback) {
let stmt = mDBConn.createAsyncStatement(
"SELECT h.url FROM moz_places h WHERE h.hidden = 1"
);
stmt.executeAsync({
_count: 0,
handleResult: function(aResultSet) {
for (let row; (row = aResultSet.getNextRow());) {
let url = row.getResultByIndex(0);
do_check_true(/redirecting/.test(url));
this._count++;
}
},
handleError: function(aError) {
},
handleCompletion: function(aReason) {
dump_table("moz_places");
dump_table("moz_historyvisits");
do_check_eq(aReason, Ci.mozIStorageStatementCallback.REASON_FINISHED);
do_check_eq(this._count, 2);
aCallback();
}
});
stmt.finalize();
}
});
//------------------------------------------------------------------------------
tests.push({ tests.push({
name: "Z", name: "Z",
desc: "Sanity: Preventive maintenance does not touch valid items", desc: "Sanity: Preventive maintenance does not touch valid items",