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: michael@0: // This test ensures that the date and site type of |place:| query maintains michael@0: // its quantifications correctly. Namely, it ensures that the date part of the michael@0: // query is not lost when the domain queries are made. michael@0: michael@0: // We specifically craft these entries so that if a by Date and Site sorting is michael@0: // applied, we find one domain in the today range, and two domains in the older michael@0: // than six months range. michael@0: // The correspondence between item in |testData| and date range is stored in michael@0: // leveledTestData. michael@0: let testData = [ michael@0: { michael@0: isVisit: true, michael@0: uri: "file:///directory/1", michael@0: lastVisit: today, michael@0: title: "test visit", michael@0: isInQuery: true michael@0: }, michael@0: { michael@0: isVisit: true, michael@0: uri: "http://example.com/1", michael@0: lastVisit: today, michael@0: title: "test visit", michael@0: isInQuery: true michael@0: }, michael@0: { michael@0: isVisit: true, michael@0: uri: "http://example.com/2", michael@0: lastVisit: today, michael@0: title: "test visit", michael@0: isInQuery: true michael@0: }, michael@0: { michael@0: isVisit: true, michael@0: uri: "file:///directory/2", michael@0: lastVisit: olderthansixmonths, michael@0: title: "test visit", michael@0: isInQuery: true michael@0: }, michael@0: { michael@0: isVisit: true, michael@0: uri: "http://example.com/3", michael@0: lastVisit: olderthansixmonths, michael@0: title: "test visit", michael@0: isInQuery: true michael@0: }, michael@0: { michael@0: isVisit: true, michael@0: uri: "http://example.com/4", michael@0: lastVisit: olderthansixmonths, michael@0: title: "test visit", michael@0: isInQuery: true michael@0: }, michael@0: { michael@0: isVisit: true, michael@0: uri: "http://example.net/1", michael@0: lastVisit: olderthansixmonths + 1, michael@0: title: "test visit", michael@0: isInQuery: true michael@0: } michael@0: ]; michael@0: let domainsInRange = [2, 3]; michael@0: let leveledTestData = [// Today michael@0: [[0], // Today, local files michael@0: [1,2]], // Today, example.com michael@0: // Older than six months michael@0: [[3], // Older than six months, local files michael@0: [4,5], // Older than six months, example.com michael@0: [6] // Older than six months, example.net michael@0: ]]; michael@0: michael@0: // This test data is meant for live updating. The |levels| property indicates michael@0: // date range index and then domain index. michael@0: let testDataAddedLater = [ michael@0: { michael@0: isVisit: true, michael@0: uri: "http://example.com/5", michael@0: lastVisit: olderthansixmonths, michael@0: title: "test visit", michael@0: isInQuery: true, michael@0: levels: [1,1] michael@0: }, michael@0: { michael@0: isVisit: true, michael@0: uri: "http://example.com/6", michael@0: lastVisit: olderthansixmonths, michael@0: title: "test visit", michael@0: isInQuery: true, michael@0: levels: [1,1] michael@0: }, michael@0: { michael@0: isVisit: true, michael@0: uri: "http://example.com/7", michael@0: lastVisit: today, michael@0: title: "test visit", michael@0: isInQuery: true, michael@0: levels: [0,1] michael@0: }, michael@0: { michael@0: isVisit: true, michael@0: uri: "file:///directory/3", michael@0: lastVisit: today, michael@0: title: "test visit", michael@0: isInQuery: true, michael@0: levels: [0,0] michael@0: } michael@0: ]; michael@0: michael@0: function run_test() michael@0: { michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_task(function test_sort_date_site_grouping() michael@0: { michael@0: yield task_populateDB(testData); michael@0: michael@0: // On Linux, the (local files) folder is shown after sites unlike Mac/Windows. michael@0: // Thus, we avoid running this test on Linux but this should be re-enabled michael@0: // after bug 624024 is resolved. michael@0: let isLinux = ("@mozilla.org/gnome-gconf-service;1" in Components.classes); michael@0: if (isLinux) michael@0: return; michael@0: michael@0: // In this test, there are three levels of results: michael@0: // 1st: Date queries. e.g., today, last week, or older than 6 months. michael@0: // 2nd: Domain queries restricted to a date. e.g. mozilla.com today. michael@0: // 3rd: Actual visits. e.g. mozilla.com/index.html today. michael@0: // michael@0: // We store all the third level result roots so that we can easily close all michael@0: // containers and test live updating into specific results. michael@0: let roots = []; michael@0: michael@0: let query = PlacesUtils.history.getNewQuery(); michael@0: let options = PlacesUtils.history.getNewQueryOptions(); michael@0: options.resultType = Ci.nsINavHistoryQueryOptions.RESULTS_AS_DATE_SITE_QUERY; michael@0: michael@0: let root = PlacesUtils.history.executeQuery(query, options).root; michael@0: root.containerOpen = true; michael@0: michael@0: // This corresponds to the number of date ranges. michael@0: do_check_eq(root.childCount, leveledTestData.length); michael@0: michael@0: // We pass off to |checkFirstLevel| to check the first level of results. michael@0: for (let index = 0; index < leveledTestData.length; index++) { michael@0: let node = root.getChild(index); michael@0: checkFirstLevel(index, node, roots); michael@0: } michael@0: michael@0: // Test live updating. michael@0: testDataAddedLater.forEach(function(visit) { michael@0: yield task_populateDB([visit]); michael@0: let oldLength = testData.length; michael@0: let i = visit.levels[0]; michael@0: let j = visit.levels[1]; michael@0: testData.push(visit); michael@0: leveledTestData[i][j].push(oldLength); michael@0: compareArrayToResult(leveledTestData[i][j]. michael@0: map(function(x) testData[x]), roots[i][j]); michael@0: }); michael@0: michael@0: for (let i = 0; i < roots.length; i++) { michael@0: for (let j = 0; j < roots[i].length; j++) michael@0: roots[i][j].containerOpen = false; michael@0: } michael@0: michael@0: root.containerOpen = false; michael@0: }); michael@0: michael@0: function checkFirstLevel(index, node, roots) { michael@0: PlacesUtils.asContainer(node).containerOpen = true; michael@0: michael@0: do_check_true(PlacesUtils.nodeIsDay(node)); michael@0: PlacesUtils.asQuery(node); michael@0: let queries = node.getQueries(); michael@0: let options = node.queryOptions; michael@0: michael@0: do_check_eq(queries.length, 1); michael@0: let query = queries[0]; michael@0: michael@0: do_check_true(query.hasBeginTime && query.hasEndTime); michael@0: michael@0: // Here we check the second level of results. michael@0: let root = PlacesUtils.history.executeQuery(query, options).root; michael@0: roots.push([]); michael@0: root.containerOpen = true; michael@0: michael@0: do_check_eq(root.childCount, leveledTestData[index].length); michael@0: for (var secondIndex = 0; secondIndex < root.childCount; secondIndex++) { michael@0: let child = PlacesUtils.asQuery(root.getChild(secondIndex)); michael@0: checkSecondLevel(index, secondIndex, child, roots); michael@0: } michael@0: root.containerOpen = false; michael@0: node.containerOpen = false; michael@0: } michael@0: michael@0: function checkSecondLevel(index, secondIndex, child, roots) { michael@0: let queries = child.getQueries(); michael@0: let options = child.queryOptions; michael@0: michael@0: do_check_eq(queries.length, 1); michael@0: let query = queries[0]; michael@0: michael@0: do_check_true(query.hasDomain); michael@0: do_check_true(query.hasBeginTime && query.hasEndTime); michael@0: michael@0: let root = PlacesUtils.history.executeQuery(query, options).root; michael@0: // We should now have that roots[index][secondIndex] is set to the second michael@0: // level's results root. michael@0: roots[index].push(root); michael@0: michael@0: // We pass off to compareArrayToResult to check the third level of michael@0: // results. michael@0: root.containerOpen = true; michael@0: compareArrayToResult(leveledTestData[index][secondIndex]. michael@0: map(function(x) testData[x]), root); michael@0: // We close |root|'s container later so that we can test live michael@0: // updates into it. michael@0: }