1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/unit/test_415757.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,102 @@ 1.4 +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +/** 1.11 + * Checks to see that a URI is in the database. 1.12 + * 1.13 + * @param aURI 1.14 + * The URI to check. 1.15 + * @returns true if the URI is in the DB, false otherwise. 1.16 + */ 1.17 +function uri_in_db(aURI) { 1.18 + var options = PlacesUtils.history.getNewQueryOptions(); 1.19 + options.maxResults = 1; 1.20 + options.resultType = options.RESULTS_AS_URI 1.21 + var query = PlacesUtils.history.getNewQuery(); 1.22 + query.uri = aURI; 1.23 + var result = PlacesUtils.history.executeQuery(query, options); 1.24 + var root = result.root; 1.25 + root.containerOpen = true; 1.26 + var cc = root.childCount; 1.27 + root.containerOpen = false; 1.28 + return (cc == 1); 1.29 +} 1.30 + 1.31 +const TOTAL_SITES = 20; 1.32 + 1.33 +// main 1.34 +function run_test() 1.35 +{ 1.36 + run_next_test(); 1.37 +} 1.38 + 1.39 +add_task(function test_execute() 1.40 +{ 1.41 + // add pages to global history 1.42 + for (var i = 0; i < TOTAL_SITES; i++) { 1.43 + let site = "http://www.test-" + i + ".com/"; 1.44 + let testURI = uri(site); 1.45 + let when = Date.now() * 1000 + (i * TOTAL_SITES); 1.46 + yield promiseAddVisits({ uri: testURI, visitDate: when }); 1.47 + } 1.48 + for (var i = 0; i < TOTAL_SITES; i++) { 1.49 + let site = "http://www.test.com/" + i + "/"; 1.50 + let testURI = uri(site); 1.51 + let when = Date.now() * 1000 + (i * TOTAL_SITES); 1.52 + yield promiseAddVisits({ uri: testURI, visitDate: when }); 1.53 + } 1.54 + 1.55 + // set a page annotation on one of the urls that will be removed 1.56 + var testAnnoDeletedURI = uri("http://www.test.com/1/"); 1.57 + var testAnnoDeletedName = "foo"; 1.58 + var testAnnoDeletedValue = "bar"; 1.59 + PlacesUtils.annotations.setPageAnnotation(testAnnoDeletedURI, 1.60 + testAnnoDeletedName, 1.61 + testAnnoDeletedValue, 0, 1.62 + PlacesUtils.annotations.EXPIRE_WITH_HISTORY); 1.63 + 1.64 + // set a page annotation on one of the urls that will NOT be removed 1.65 + var testAnnoRetainedURI = uri("http://www.test-1.com/"); 1.66 + var testAnnoRetainedName = "foo"; 1.67 + var testAnnoRetainedValue = "bar"; 1.68 + PlacesUtils.annotations.setPageAnnotation(testAnnoRetainedURI, 1.69 + testAnnoRetainedName, 1.70 + testAnnoRetainedValue, 0, 1.71 + PlacesUtils.annotations.EXPIRE_WITH_HISTORY); 1.72 + 1.73 + // remove pages from www.test.com 1.74 + PlacesUtils.history.removePagesFromHost("www.test.com", false); 1.75 + 1.76 + // check that all pages in www.test.com have been removed 1.77 + for (var i = 0; i < TOTAL_SITES; i++) { 1.78 + let site = "http://www.test.com/" + i + "/"; 1.79 + let testURI = uri(site); 1.80 + do_check_false(uri_in_db(testURI)); 1.81 + } 1.82 + 1.83 + // check that all pages in www.test-X.com have NOT been removed 1.84 + for (var i = 0; i < TOTAL_SITES; i++) { 1.85 + let site = "http://www.test-" + i + ".com/"; 1.86 + let testURI = uri(site); 1.87 + do_check_true(uri_in_db(testURI)); 1.88 + } 1.89 + 1.90 + // check that annotation on the removed item does not exists 1.91 + try { 1.92 + PlacesUtils.annotations.getPageAnnotation(testAnnoDeletedURI, testAnnoName); 1.93 + do_throw("fetching page-annotation that doesn't exist, should've thrown"); 1.94 + } catch(ex) {} 1.95 + 1.96 + // check that annotation on the NOT removed item still exists 1.97 + try { 1.98 + var annoVal = PlacesUtils.annotations.getPageAnnotation(testAnnoRetainedURI, 1.99 + testAnnoRetainedName); 1.100 + } catch(ex) { 1.101 + do_throw("The annotation has been removed erroneously"); 1.102 + } 1.103 + do_check_eq(annoVal, testAnnoRetainedValue); 1.104 + 1.105 +});