toolkit/components/places/tests/unit/test_415757.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:40bb4988e726
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 /**
8 * Checks to see that a URI is in the database.
9 *
10 * @param aURI
11 * The URI to check.
12 * @returns true if the URI is in the DB, false otherwise.
13 */
14 function uri_in_db(aURI) {
15 var options = PlacesUtils.history.getNewQueryOptions();
16 options.maxResults = 1;
17 options.resultType = options.RESULTS_AS_URI
18 var query = PlacesUtils.history.getNewQuery();
19 query.uri = aURI;
20 var result = PlacesUtils.history.executeQuery(query, options);
21 var root = result.root;
22 root.containerOpen = true;
23 var cc = root.childCount;
24 root.containerOpen = false;
25 return (cc == 1);
26 }
27
28 const TOTAL_SITES = 20;
29
30 // main
31 function run_test()
32 {
33 run_next_test();
34 }
35
36 add_task(function test_execute()
37 {
38 // add pages to global history
39 for (var i = 0; i < TOTAL_SITES; i++) {
40 let site = "http://www.test-" + i + ".com/";
41 let testURI = uri(site);
42 let when = Date.now() * 1000 + (i * TOTAL_SITES);
43 yield promiseAddVisits({ uri: testURI, visitDate: when });
44 }
45 for (var i = 0; i < TOTAL_SITES; i++) {
46 let site = "http://www.test.com/" + i + "/";
47 let testURI = uri(site);
48 let when = Date.now() * 1000 + (i * TOTAL_SITES);
49 yield promiseAddVisits({ uri: testURI, visitDate: when });
50 }
51
52 // set a page annotation on one of the urls that will be removed
53 var testAnnoDeletedURI = uri("http://www.test.com/1/");
54 var testAnnoDeletedName = "foo";
55 var testAnnoDeletedValue = "bar";
56 PlacesUtils.annotations.setPageAnnotation(testAnnoDeletedURI,
57 testAnnoDeletedName,
58 testAnnoDeletedValue, 0,
59 PlacesUtils.annotations.EXPIRE_WITH_HISTORY);
60
61 // set a page annotation on one of the urls that will NOT be removed
62 var testAnnoRetainedURI = uri("http://www.test-1.com/");
63 var testAnnoRetainedName = "foo";
64 var testAnnoRetainedValue = "bar";
65 PlacesUtils.annotations.setPageAnnotation(testAnnoRetainedURI,
66 testAnnoRetainedName,
67 testAnnoRetainedValue, 0,
68 PlacesUtils.annotations.EXPIRE_WITH_HISTORY);
69
70 // remove pages from www.test.com
71 PlacesUtils.history.removePagesFromHost("www.test.com", false);
72
73 // check that all pages in www.test.com have been removed
74 for (var i = 0; i < TOTAL_SITES; i++) {
75 let site = "http://www.test.com/" + i + "/";
76 let testURI = uri(site);
77 do_check_false(uri_in_db(testURI));
78 }
79
80 // check that all pages in www.test-X.com have NOT been removed
81 for (var i = 0; i < TOTAL_SITES; i++) {
82 let site = "http://www.test-" + i + ".com/";
83 let testURI = uri(site);
84 do_check_true(uri_in_db(testURI));
85 }
86
87 // check that annotation on the removed item does not exists
88 try {
89 PlacesUtils.annotations.getPageAnnotation(testAnnoDeletedURI, testAnnoName);
90 do_throw("fetching page-annotation that doesn't exist, should've thrown");
91 } catch(ex) {}
92
93 // check that annotation on the NOT removed item still exists
94 try {
95 var annoVal = PlacesUtils.annotations.getPageAnnotation(testAnnoRetainedURI,
96 testAnnoRetainedName);
97 } catch(ex) {
98 do_throw("The annotation has been removed erroneously");
99 }
100 do_check_eq(annoVal, testAnnoRetainedValue);
101
102 });

mercurial