1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/unit/test_PlacesUtils_asyncGetBookmarkIds.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,86 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/** 1.8 + * This file tests PlacesUtils.asyncGetBookmarkIds method. 1.9 + */ 1.10 + 1.11 +const TEST_URL = "http://www.example.com/"; 1.12 + 1.13 +[ 1.14 + 1.15 + function test_no_bookmark() { 1.16 + PlacesUtils.asyncGetBookmarkIds(TEST_URL, (aItemIds, aURI) => { 1.17 + do_check_eq(aItemIds.length, 0); 1.18 + do_check_eq(aURI, TEST_URL); 1.19 + run_next_test(); 1.20 + }); 1.21 + }, 1.22 + 1.23 + function test_one_bookmark_nsIURI() { 1.24 + let uri = NetUtil.newURI(TEST_URL); 1.25 + let itemId = PlacesUtils.bookmarks.insertBookmark( 1.26 + PlacesUtils.unfiledBookmarksFolderId, uri, "test", 1.27 + PlacesUtils.bookmarks.DEFAULT_INDEX 1.28 + ); 1.29 + PlacesUtils.asyncGetBookmarkIds(uri, (aItemIds, aURI) => { 1.30 + do_check_eq(aItemIds.length, 1); 1.31 + do_check_eq(aItemIds[0], itemId); 1.32 + do_check_true(aURI.equals(uri)); 1.33 + PlacesUtils.bookmarks.removeItem(itemId); 1.34 + run_next_test(); 1.35 + }); 1.36 + }, 1.37 + 1.38 + function test_one_bookmark_spec() { 1.39 + let uri = NetUtil.newURI(TEST_URL); 1.40 + let itemId = PlacesUtils.bookmarks.insertBookmark( 1.41 + PlacesUtils.unfiledBookmarksFolderId, uri, "test", 1.42 + PlacesUtils.bookmarks.DEFAULT_INDEX 1.43 + ); 1.44 + PlacesUtils.asyncGetBookmarkIds(TEST_URL, (aItemIds, aURI) => { 1.45 + do_check_eq(aItemIds.length, 1); 1.46 + do_check_eq(aItemIds[0], itemId); 1.47 + do_check_eq(aURI, TEST_URL); 1.48 + PlacesUtils.bookmarks.removeItem(itemId); 1.49 + run_next_test(); 1.50 + }); 1.51 + }, 1.52 + 1.53 + function test_multiple_bookmarks() { 1.54 + let uri = NetUtil.newURI(TEST_URL); 1.55 + let itemIds = []; 1.56 + itemIds.push(PlacesUtils.bookmarks.insertBookmark( 1.57 + PlacesUtils.unfiledBookmarksFolderId, uri, "test", 1.58 + PlacesUtils.bookmarks.DEFAULT_INDEX 1.59 + )); 1.60 + itemIds.push(PlacesUtils.bookmarks.insertBookmark( 1.61 + PlacesUtils.unfiledBookmarksFolderId, uri, "test", 1.62 + PlacesUtils.bookmarks.DEFAULT_INDEX 1.63 + )); 1.64 + PlacesUtils.asyncGetBookmarkIds(uri, (aItemIds, aURI) => { 1.65 + do_check_eq(aItemIds.length, 2); 1.66 + do_check_true(do_compare_arrays(itemIds, aItemIds)); 1.67 + do_check_true(aURI.equals(uri)); 1.68 + itemIds.forEach(PlacesUtils.bookmarks.removeItem); 1.69 + run_next_test(); 1.70 + }); 1.71 + }, 1.72 + 1.73 + function test_cancel() { 1.74 + let pending = PlacesUtils.asyncGetBookmarkIds(TEST_URL, (aItemIds, aURI) => { 1.75 + do_throw("A canceled pending statement should not be invoked"); 1.76 + }); 1.77 + pending.cancel(); 1.78 + PlacesUtils.asyncGetBookmarkIds(TEST_URL, (aItemIds, aURI) => { 1.79 + do_check_eq(aItemIds.length, 0); 1.80 + do_check_eq(aURI, TEST_URL); 1.81 + run_next_test(); 1.82 + }); 1.83 + }, 1.84 + 1.85 +].forEach(add_test); 1.86 + 1.87 +function run_test() { 1.88 + run_next_test(); 1.89 +}