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: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const DAY_MSEC = 86400000; michael@0: const MIN_MSEC = 60000; michael@0: const HOUR_MSEC = 3600000; michael@0: // Jan 6 2008 at 8am is our begin edge of the query michael@0: var beginTimeDate = new Date(2008, 0, 6, 8, 0, 0, 0); michael@0: // Jan 15 2008 at 9:30pm is our ending edge of the query michael@0: var endTimeDate = new Date(2008, 0, 15, 21, 30, 0, 0); michael@0: michael@0: // These as millisecond values michael@0: var beginTime = beginTimeDate.getTime(); michael@0: var endTime = endTimeDate.getTime(); michael@0: michael@0: // Some range dates inside our query - mult by 1000 to convert to PRTIME michael@0: var jan7_800 = (beginTime + DAY_MSEC) * 1000; michael@0: var jan6_815 = (beginTime + (MIN_MSEC * 15)) * 1000; michael@0: var jan11_800 = (beginTime + (DAY_MSEC * 5)) * 1000; michael@0: var jan14_2130 = (endTime - DAY_MSEC) * 1000; michael@0: var jan15_2045 = (endTime - (MIN_MSEC * 45)) * 1000; michael@0: var jan12_1730 = (endTime - (DAY_MSEC * 3) - (HOUR_MSEC*4)) * 1000; michael@0: michael@0: // Dates outside our query - mult by 1000 to convert to PRTIME michael@0: var jan6_700 = (beginTime - HOUR_MSEC) * 1000; michael@0: var jan5_800 = (beginTime - DAY_MSEC) * 1000; michael@0: var dec27_800 = (beginTime - (DAY_MSEC * 10)) * 1000; michael@0: var jan15_2145 = (endTime + (MIN_MSEC * 15)) * 1000; michael@0: var jan16_2130 = (endTime + (DAY_MSEC)) * 1000; michael@0: var jan25_2130 = (endTime + (DAY_MSEC * 10)) * 1000; michael@0: michael@0: // So that we can easily use these too, convert them to PRTIME michael@0: beginTime *= 1000; michael@0: endTime *= 1000; michael@0: michael@0: /** michael@0: * Array of objects to build our test database michael@0: */ michael@0: var goodAnnoName = "moz-test-places/testing123"; michael@0: var val = "test"; michael@0: var badAnnoName = "text/foo"; michael@0: michael@0: // The test data for our database, note that the ordering of the results that michael@0: // will be returned by the query (the isInQuery: true objects) is IMPORTANT. michael@0: // see compareArrayToResult in head_queries.js for more info. michael@0: var testData = [ michael@0: // Test ftp protocol - vary the title length michael@0: {isInQuery: true, isVisit: true, isDetails: true, michael@0: uri: "ftp://foo.com/ftp", lastVisit: jan12_1730, michael@0: title: "hugelongconfmozlagurationofwordswithasearchtermsinit whoo-hoo"}, michael@0: michael@0: // Test flat domain with annotation michael@0: {isInQuery: true, isVisit: true, isDetails: true, isPageAnnotation: true, michael@0: uri: "http://foo.com/", annoName: goodAnnoName, annoVal: val, michael@0: lastVisit: jan14_2130, title: "moz"}, michael@0: michael@0: // Test subdomain included with isRedirect=true, different transtype michael@0: {isInQuery: true, isVisit: true, isDetails: true, title: "moz", michael@0: isRedirect: true, uri: "http://mail.foo.com/redirect", lastVisit: jan11_800, michael@0: transType: PlacesUtils.history.TRANSITION_LINK}, michael@0: michael@0: // Test subdomain inclued at the leading time edge michael@0: {isInQuery: true, isVisit: true, isDetails: true, michael@0: uri: "http://mail.foo.com/yiihah", title: "moz", lastVisit: jan6_815}, michael@0: michael@0: // Test www. style URI is included, with an annotation michael@0: {isInQuery: true, isVisit: true, isDetails: true, isPageAnnotation: true, michael@0: uri: "http://www.foo.com/yiihah", annoName: goodAnnoName, annoVal: val, michael@0: lastVisit: jan7_800, title: "moz"}, michael@0: michael@0: // Test https protocol michael@0: {isInQuery: true, isVisit: true, isDetails: true, title: "moz", michael@0: uri: "https://foo.com/", lastVisit: jan15_2045}, michael@0: michael@0: // Test begin edge of time michael@0: {isInQuery: true, isVisit: true, isDetails: true, title: "moz mozilla", michael@0: uri: "https://foo.com/begin.html", lastVisit: beginTime}, michael@0: michael@0: //Test end edge of time michael@0: {isInQuery: true, isVisit: true, isDetails: true, title: "moz mozilla", michael@0: uri: "https://foo.com/end.html", lastVisit: endTime}, michael@0: michael@0: // Test an image link, with annotations michael@0: {isInQuery: true, isVisit: true, isDetails: true, isPageAnnotation: true, michael@0: title: "mozzie the dino", uri: "https://foo.com/mozzie.png", michael@0: annoName: goodAnnoName, annoVal: val, lastVisit: jan14_2130}, michael@0: michael@0: // Begin the invalid queries: Test too early michael@0: {isInQuery: false, isVisit:true, isDetails: true, title: "moz", michael@0: uri: "http://foo.com/tooearly.php", lastVisit: jan6_700}, michael@0: michael@0: // Test Bad Annotation michael@0: {isInQuery: false, isVisit:true, isDetails: true, isPageAnnotation: true, michael@0: title: "moz", uri: "http://foo.com/badanno.htm", lastVisit: jan12_1730, michael@0: annoName: badAnnoName, annoVal: val}, michael@0: michael@0: // Test bad URI michael@0: {isInQuery: false, isVisit:true, isDetails: true, title: "moz", michael@0: uri: "http://somefoo.com/justwrong.htm", lastVisit: jan11_800}, michael@0: michael@0: // Test afterward, one to update michael@0: {isInQuery: false, isVisit:true, isDetails: true, title: "changeme", michael@0: uri: "http://foo.com/changeme1.htm", lastVisit: jan12_1730}, michael@0: michael@0: // Test invalid title michael@0: {isInQuery: false, isVisit:true, isDetails: true, title: "changeme2", michael@0: uri: "http://foo.com/changeme2.htm", lastVisit: jan7_800}, michael@0: michael@0: // Test changing the lastVisit michael@0: {isInQuery: false, isVisit:true, isDetails: true, title: "moz", michael@0: uri: "http://foo.com/changeme3.htm", lastVisit: dec27_800}]; michael@0: michael@0: /** michael@0: * This test will test a Query using several terms and do a bit of negative michael@0: * testing for items that should be ignored while querying over history. michael@0: * The Query:WHERE absoluteTime(matches) AND searchTerms AND URI michael@0: * AND annotationIsNot(match) GROUP BY Domain, Day SORT BY uri,ascending michael@0: * excludeITems(should be ignored) michael@0: */ michael@0: function run_test() michael@0: { michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_task(function test_abstime_annotation_domain() michael@0: { michael@0: //Initialize database michael@0: yield task_populateDB(testData); michael@0: michael@0: // Query michael@0: var query = PlacesUtils.history.getNewQuery(); michael@0: query.beginTime = beginTime; michael@0: query.endTime = endTime; michael@0: query.beginTimeReference = PlacesUtils.history.TIME_RELATIVE_EPOCH; michael@0: query.endTimeReference = PlacesUtils.history.TIME_RELATIVE_EPOCH; michael@0: query.searchTerms = "moz"; michael@0: query.domain = "foo.com"; michael@0: query.domainIsHost = false; michael@0: query.annotation = "text/foo"; michael@0: query.annotationIsNot = true; michael@0: michael@0: // Options michael@0: var options = PlacesUtils.history.getNewQueryOptions(); michael@0: options.sortingMode = options.SORT_BY_URI_ASCENDING; michael@0: options.resultType = options.RESULTS_AS_URI; michael@0: // The next two options should be ignored michael@0: // can't use this one, breaks test - bug 419779 michael@0: // options.excludeItems = true; michael@0: michael@0: // Results michael@0: var result = PlacesUtils.history.executeQuery(query, options); michael@0: var root = result.root; michael@0: root.containerOpen = true; michael@0: michael@0: // Ensure the result set is correct michael@0: compareArrayToResult(testData, root); michael@0: michael@0: // Make some changes to the result set michael@0: // Let's add something first michael@0: var addItem = [{isInQuery: true, isVisit: true, isDetails: true, title: "moz", michael@0: uri: "http://www.foo.com/i-am-added.html", lastVisit: jan11_800}]; michael@0: yield task_populateDB(addItem); michael@0: LOG("Adding item foo.com/i-am-added.html"); michael@0: do_check_eq(isInResult(addItem, root), true); michael@0: michael@0: // Let's update something by title michael@0: var change1 = [{isDetails: true, uri: "http://foo.com/changeme1", michael@0: lastVisit: jan12_1730, title: "moz moz mozzie"}]; michael@0: yield task_populateDB(change1); michael@0: LOG("LiveUpdate by changing title"); michael@0: do_check_eq(isInResult(change1, root), true); michael@0: michael@0: // Let's update something by annotation michael@0: // Updating a page by removing an annotation does not cause it to join this michael@0: // query set. I tend to think that it should cause that page to join this michael@0: // query set, because this visit fits all theother specified criteria once the michael@0: // annotation is removed. Uncommenting this will fail the test. michael@0: // Bug 424050 michael@0: /*var change2 = [{isPageAnnotation: true, uri: "http://foo.com/badannotaion.html", michael@0: annoName: "text/mozilla", annoVal: "test"}]; michael@0: yield task_populateDB(change2); michael@0: LOG("LiveUpdate by removing annotation"); michael@0: do_check_eq(isInResult(change2, root), true);*/ michael@0: michael@0: // Let's update by adding a visit in the time range for an existing URI michael@0: var change3 = [{isDetails: true, uri: "http://foo.com/changeme3.htm", michael@0: title: "moz", lastVisit: jan15_2045}]; michael@0: yield task_populateDB(change3); michael@0: LOG("LiveUpdate by adding visit within timerange"); michael@0: do_check_eq(isInResult(change3, root), true); michael@0: michael@0: // And delete something from the result set - using annotation michael@0: // Once again, bug 424050 prevents this from passing michael@0: /*var change4 = [{isPageAnnotation: true, uri: "ftp://foo.com/ftp", michael@0: annoVal: "test", annoName: badAnnoName}]; michael@0: yield task_populateDB(change4); michael@0: LOG("LiveUpdate by deleting item from set by adding annotation"); michael@0: do_check_eq(isInResult(change4, root), false);*/ michael@0: michael@0: // Delete something by changing the title michael@0: var change5 = [{isDetails: true, uri: "http://foo.com/end.html", title: "deleted"}]; michael@0: yield task_populateDB(change5); michael@0: LOG("LiveUpdate by deleting item by changing title"); michael@0: do_check_eq(isInResult(change5, root), false); michael@0: michael@0: root.containerOpen = false; michael@0: });