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: /** michael@0: * Checks to see that a URI is in the database. michael@0: * michael@0: * @param aURI michael@0: * The URI to check. michael@0: * @returns true if the URI is in the DB, false otherwise. michael@0: */ michael@0: function uri_in_db(aURI) { michael@0: var options = PlacesUtils.history.getNewQueryOptions(); michael@0: options.maxResults = 1; michael@0: options.resultType = options.RESULTS_AS_URI michael@0: var query = PlacesUtils.history.getNewQuery(); michael@0: query.uri = aURI; michael@0: var result = PlacesUtils.history.executeQuery(query, options); michael@0: var root = result.root; michael@0: root.containerOpen = true; michael@0: var cc = root.childCount; michael@0: root.containerOpen = false; michael@0: return (cc == 1); michael@0: } michael@0: michael@0: const TOTAL_SITES = 20; michael@0: michael@0: // main michael@0: function run_test() michael@0: { michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_task(function test_execute() michael@0: { michael@0: // add pages to global history michael@0: for (var i = 0; i < TOTAL_SITES; i++) { michael@0: let site = "http://www.test-" + i + ".com/"; michael@0: let testURI = uri(site); michael@0: let when = Date.now() * 1000 + (i * TOTAL_SITES); michael@0: yield promiseAddVisits({ uri: testURI, visitDate: when }); michael@0: } michael@0: for (var i = 0; i < TOTAL_SITES; i++) { michael@0: let site = "http://www.test.com/" + i + "/"; michael@0: let testURI = uri(site); michael@0: let when = Date.now() * 1000 + (i * TOTAL_SITES); michael@0: yield promiseAddVisits({ uri: testURI, visitDate: when }); michael@0: } michael@0: michael@0: // set a page annotation on one of the urls that will be removed michael@0: var testAnnoDeletedURI = uri("http://www.test.com/1/"); michael@0: var testAnnoDeletedName = "foo"; michael@0: var testAnnoDeletedValue = "bar"; michael@0: PlacesUtils.annotations.setPageAnnotation(testAnnoDeletedURI, michael@0: testAnnoDeletedName, michael@0: testAnnoDeletedValue, 0, michael@0: PlacesUtils.annotations.EXPIRE_WITH_HISTORY); michael@0: michael@0: // set a page annotation on one of the urls that will NOT be removed michael@0: var testAnnoRetainedURI = uri("http://www.test-1.com/"); michael@0: var testAnnoRetainedName = "foo"; michael@0: var testAnnoRetainedValue = "bar"; michael@0: PlacesUtils.annotations.setPageAnnotation(testAnnoRetainedURI, michael@0: testAnnoRetainedName, michael@0: testAnnoRetainedValue, 0, michael@0: PlacesUtils.annotations.EXPIRE_WITH_HISTORY); michael@0: michael@0: // remove pages from www.test.com michael@0: PlacesUtils.history.removePagesFromHost("www.test.com", false); michael@0: michael@0: // check that all pages in www.test.com have been removed michael@0: for (var i = 0; i < TOTAL_SITES; i++) { michael@0: let site = "http://www.test.com/" + i + "/"; michael@0: let testURI = uri(site); michael@0: do_check_false(uri_in_db(testURI)); michael@0: } michael@0: michael@0: // check that all pages in www.test-X.com have NOT been removed michael@0: for (var i = 0; i < TOTAL_SITES; i++) { michael@0: let site = "http://www.test-" + i + ".com/"; michael@0: let testURI = uri(site); michael@0: do_check_true(uri_in_db(testURI)); michael@0: } michael@0: michael@0: // check that annotation on the removed item does not exists michael@0: try { michael@0: PlacesUtils.annotations.getPageAnnotation(testAnnoDeletedURI, testAnnoName); michael@0: do_throw("fetching page-annotation that doesn't exist, should've thrown"); michael@0: } catch(ex) {} michael@0: michael@0: // check that annotation on the NOT removed item still exists michael@0: try { michael@0: var annoVal = PlacesUtils.annotations.getPageAnnotation(testAnnoRetainedURI, michael@0: testAnnoRetainedName); michael@0: } catch(ex) { michael@0: do_throw("The annotation has been removed erroneously"); michael@0: } michael@0: do_check_eq(annoVal, testAnnoRetainedValue); michael@0: michael@0: });