michael@0: /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ michael@0: /* ***** BEGIN LICENSE BLOCK ***** michael@0: Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ michael@0: * ***** END LICENSE BLOCK ***** */ michael@0: var beginTime = Date.now(); michael@0: var testData = [ michael@0: { michael@0: isVisit: true, michael@0: title: "page 0", michael@0: uri: "http://mozilla.com/", michael@0: transType: Ci.nsINavHistoryService.TRANSITION_TYPED michael@0: }, michael@0: { michael@0: isVisit: true, michael@0: title: "page 1", michael@0: uri: "http://google.com/", michael@0: transType: Ci.nsINavHistoryService.TRANSITION_DOWNLOAD michael@0: }, michael@0: { michael@0: isVisit: true, michael@0: title: "page 2", michael@0: uri: "http://microsoft.com/", michael@0: transType: Ci.nsINavHistoryService.TRANSITION_DOWNLOAD michael@0: }, michael@0: { michael@0: isVisit: true, michael@0: title: "page 3", michael@0: uri: "http://en.wikipedia.org/", michael@0: transType: Ci.nsINavHistoryService.TRANSITION_BOOKMARK michael@0: }, michael@0: { michael@0: isVisit: true, michael@0: title: "page 4", michael@0: uri: "http://fr.wikipedia.org/", michael@0: transType: Ci.nsINavHistoryService.TRANSITION_DOWNLOAD michael@0: }, michael@0: { michael@0: isVisit: true, michael@0: title: "page 5", michael@0: uri: "http://apple.com/", michael@0: transType: Ci.nsINavHistoryService.TRANSITION_TYPED michael@0: }, michael@0: { michael@0: isVisit: true, michael@0: title: "page 6", michael@0: uri: "http://campus-bike-store.com/", michael@0: transType: Ci.nsINavHistoryService.TRANSITION_DOWNLOAD michael@0: }, michael@0: { michael@0: isVisit: true, michael@0: title: "page 7", michael@0: uri: "http://uwaterloo.ca/", michael@0: transType: Ci.nsINavHistoryService.TRANSITION_TYPED michael@0: }, michael@0: { michael@0: isVisit: true, michael@0: title: "page 8", michael@0: uri: "http://pugcleaner.com/", michael@0: transType: Ci.nsINavHistoryService.TRANSITION_BOOKMARK michael@0: }, michael@0: { michael@0: isVisit: true, michael@0: title: "page 9", michael@0: uri: "http://de.wikipedia.org/", michael@0: transType: Ci.nsINavHistoryService.TRANSITION_TYPED michael@0: }, michael@0: { michael@0: isVisit: true, michael@0: title: "arewefastyet", michael@0: uri: "http://arewefastyet.com/", michael@0: transType: Ci.nsINavHistoryService.TRANSITION_DOWNLOAD michael@0: }, michael@0: { michael@0: isVisit: true, michael@0: title: "arewefastyet", michael@0: uri: "http://arewefastyet.com/", michael@0: transType: Ci.nsINavHistoryService.TRANSITION_BOOKMARK michael@0: }]; michael@0: // sets of indices of testData array by transition type michael@0: var testDataTyped = [0, 5, 7, 9]; michael@0: var testDataDownload = [1, 2, 4, 6, 10]; michael@0: var testDataBookmark = [3, 8, 11]; michael@0: michael@0: /** michael@0: * run_test is where the magic happens. This is automatically run by the test michael@0: * harness. It is where you do the work of creating the query, running it, and michael@0: * playing with the result set. michael@0: */ michael@0: function run_test() michael@0: { michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_task(function test_transitions() michael@0: { michael@0: let timeNow = Date.now(); michael@0: for each (let item in testData) { michael@0: yield promiseAddVisits({ michael@0: uri: uri(item.uri), michael@0: transition: item.transType, michael@0: visitDate: timeNow++ * 1000, michael@0: title: item.title michael@0: }); michael@0: } michael@0: michael@0: //dump_table("moz_places"); michael@0: //dump_table("moz_historyvisits"); michael@0: michael@0: var numSortFunc = function (a,b) { return (a - b); }; michael@0: var arrs = testDataTyped.concat(testDataDownload).concat(testDataBookmark) michael@0: .sort(numSortFunc); michael@0: michael@0: // Four tests which compare the result of a query to an expected set. michael@0: var data = arrs.filter(function (index) { michael@0: return (testData[index].uri.match(/arewefastyet\.com/) && michael@0: testData[index].transType == michael@0: Ci.nsINavHistoryService.TRANSITION_DOWNLOAD); michael@0: }); michael@0: michael@0: compareQueryToTestData("place:domain=arewefastyet.com&transition=" + michael@0: Ci.nsINavHistoryService.TRANSITION_DOWNLOAD, michael@0: data.slice()); michael@0: michael@0: compareQueryToTestData("place:transition=" + michael@0: Ci.nsINavHistoryService.TRANSITION_DOWNLOAD, michael@0: testDataDownload.slice()); michael@0: michael@0: compareQueryToTestData("place:transition=" + michael@0: Ci.nsINavHistoryService.TRANSITION_TYPED, michael@0: testDataTyped.slice()); michael@0: michael@0: compareQueryToTestData("place:transition=" + michael@0: Ci.nsINavHistoryService.TRANSITION_DOWNLOAD + michael@0: "&transition=" + michael@0: Ci.nsINavHistoryService.TRANSITION_BOOKMARK, michael@0: data); michael@0: michael@0: // Tests the live update property of transitions. michael@0: var query = {}; michael@0: var options = {}; michael@0: PlacesUtils.history. michael@0: queryStringToQueries("place:transition=" + michael@0: Ci.nsINavHistoryService.TRANSITION_DOWNLOAD, michael@0: query, {}, options); michael@0: query = (query.value)[0]; michael@0: options = PlacesUtils.history.getNewQueryOptions(); michael@0: var result = PlacesUtils.history.executeQuery(query, options); michael@0: var root = result.root; michael@0: root.containerOpen = true; michael@0: do_check_eq(testDataDownload.length, root.childCount); michael@0: yield promiseAddVisits({ michael@0: uri: uri("http://getfirefox.com"), michael@0: transition: TRANSITION_DOWNLOAD michael@0: }); michael@0: do_check_eq(testDataDownload.length + 1, root.childCount); michael@0: root.containerOpen = false; michael@0: }); michael@0: michael@0: /* michael@0: * Takes a query and a set of indices. The indices correspond to elements michael@0: * of testData that are the result of the query. michael@0: */ michael@0: function compareQueryToTestData(queryStr, data) { michael@0: var query = {}; michael@0: var options = {}; michael@0: PlacesUtils.history.queryStringToQueries(queryStr, query, {}, options); michael@0: query = query.value[0]; michael@0: options = options.value; michael@0: var result = PlacesUtils.history.executeQuery(query, options); michael@0: var root = result.root; michael@0: for (var i = 0; i < data.length; i++) { michael@0: data[i] = testData[data[i]]; michael@0: data[i].isInQuery = true; michael@0: } michael@0: compareArrayToResult(data, root); michael@0: }