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: // 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, embed search term michael@0: {isInQuery: true, isVisit: true, isDetails: true, michael@0: uri: "ftp://foo.com/ftp", lastVisit: lastweek, michael@0: title: "hugelongconfmozlagurationofwordswithasearchtermsinit whoo-hoo"}, michael@0: michael@0: // Test flat domain with annotation, search term in sentence michael@0: {isInQuery: true, isVisit: true, isDetails: true, isPageAnnotation: true, michael@0: uri: "http://foo.com/", annoName: "moz/test", annoVal: "val", michael@0: lastVisit: lastweek, title: "you know, moz is cool"}, michael@0: michael@0: // Test subdomain included with isRedirect=true, different transtype michael@0: {isInQuery: true, isVisit: true, isDetails: true, title: "amozzie", michael@0: isRedirect: true, uri: "http://mail.foo.com/redirect", lastVisit: old, michael@0: referrer: "http://myreferrer.com", transType: PlacesUtils.history.TRANSITION_LINK}, michael@0: michael@0: // Test subdomain inclued, search term at end michael@0: {isInQuery: true, isVisit: true, isDetails: true, michael@0: uri: "http://mail.foo.com/yiihah", title: "blahmoz", lastVisit: daybefore}, michael@0: michael@0: // Test www. style URI is included, with a tag michael@0: {isInQuery: true, isVisit: true, isDetails: true, isTag: true, michael@0: uri: "http://www.foo.com/yiihah", tagArray: ["moz"], michael@0: lastVisit: yesterday, title: "foo"}, michael@0: michael@0: // Test https protocol michael@0: {isInQuery: true, isVisit: true, isDetails: true, title: "moz", michael@0: uri: "https://foo.com/", lastVisit: today}, michael@0: michael@0: // Begin the invalid queries: wrong search term michael@0: {isInQuery: false, isVisit:true, isDetails: true, title: "m o z", michael@0: uri: "http://foo.com/tooearly.php", lastVisit: today}, michael@0: michael@0: // Test bad URI michael@0: {isInQuery: false, isVisit:true, isDetails: true, title: "moz", michael@0: uri: "http://sffoo.com/justwrong.htm", lastVisit: tomorrow}, michael@0: michael@0: // Test what we do with escaping in titles michael@0: {isInQuery: false, isVisit:true, isDetails: true, title: "m%0o%0z", michael@0: uri: "http://foo.com/changeme1.htm", lastVisit: yesterday}, michael@0: michael@0: // Test another invalid title - for updating later michael@0: {isInQuery: false, isVisit:true, isDetails: true, title: "m,oz", michael@0: uri: "http://foo.com/changeme2.htm", lastVisit: tomorrow}]; michael@0: michael@0: /** michael@0: * This test will test Queries that use relative search terms and domain options michael@0: */ michael@0: function run_test() michael@0: { michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_task(function test_searchterms_domain() michael@0: { michael@0: yield task_populateDB(testData); michael@0: var query = PlacesUtils.history.getNewQuery(); michael@0: query.searchTerms = "moz"; michael@0: query.domain = "foo.com"; michael@0: query.domainIsHost = false; michael@0: michael@0: // Options michael@0: var options = PlacesUtils.history.getNewQueryOptions(); michael@0: options.sortingMode = options.SORT_BY_DATE_ASCENDING; michael@0: options.resultType = options.RESULTS_AS_URI; 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: LOG("Number of items in result set: " + root.childCount); michael@0: for(var i=0; i < root.childCount; ++i) { michael@0: LOG("result: " + root.getChild(i).uri + " Title: " + root.getChild(i).title); michael@0: } michael@0: michael@0: // Check our inital result set michael@0: compareArrayToResult(testData, root); michael@0: michael@0: // If that passes, check liveupdate michael@0: // Add to the query set michael@0: LOG("Adding item to query") michael@0: var change1 = [{isVisit: true, isDetails: true, uri: "http://foo.com/added.htm", michael@0: title: "moz", transType: PlacesUtils.history.TRANSITION_LINK}]; michael@0: yield task_populateDB(change1); michael@0: do_check_true(isInResult(change1, root)); michael@0: michael@0: // Update an existing URI michael@0: LOG("Updating Item"); michael@0: var change2 = [{isDetails: true, uri: "http://foo.com/changeme1.htm", michael@0: title: "moz" }]; michael@0: yield task_populateDB(change2); michael@0: do_check_true(isInResult(change2, root)); michael@0: michael@0: // Add one and take one out of query set, and simply change one so that it michael@0: // still applies to the query. michael@0: LOG("Updating More Items"); michael@0: var change3 = [{isDetails: true, uri:"http://foo.com/changeme2.htm", michael@0: title: "moz"}, michael@0: {isDetails: true, uri: "http://mail.foo.com/yiihah", michael@0: title: "moz now updated"}, michael@0: {isDetails: true, uri: "ftp://foo.com/ftp", title: "gone"}]; michael@0: yield task_populateDB(change3); michael@0: do_check_true(isInResult({uri: "http://foo.com/changeme2.htm"}, root)); michael@0: do_check_true(isInResult({uri: "http://mail.foo.com/yiihah"}, root)); michael@0: do_check_false(isInResult({uri: "ftp://foo.com/ftp"}, root)); michael@0: michael@0: // And now, delete one michael@0: LOG("Deleting items"); michael@0: var change4 = [{isDetails: true, uri: "https://foo.com/", michael@0: title: "mo,z"}]; michael@0: yield task_populateDB(change4); michael@0: do_check_false(isInResult(change4, root)); michael@0: michael@0: root.containerOpen = false; michael@0: });