Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim:set ts=2 sw=2 sts=2 et: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | const LOAD_IN_SIDEBAR_ANNO = "bookmarkProperties/loadInSidebar"; |
michael@0 | 8 | const DESCRIPTION_ANNO = "bookmarkProperties/description"; |
michael@0 | 9 | |
michael@0 | 10 | // An object representing the contents of bookmarks.preplaces.html. |
michael@0 | 11 | let test_bookmarks = { |
michael@0 | 12 | menu: [ |
michael@0 | 13 | { title: "Mozilla Firefox", |
michael@0 | 14 | children: [ |
michael@0 | 15 | { title: "Help and Tutorials", |
michael@0 | 16 | url: "http://en-us.www.mozilla.com/en-US/firefox/help/", |
michael@0 | 17 | icon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAHWSURBVHjaYvz//z8DJQAggJiQOe/fv2fv7Oz8rays/N+VkfG/iYnJfyD/1+rVq7ffu3dPFpsBAAHEAHIBCJ85c8bN2Nj4vwsDw/8zQLwKiO8CcRoQu0DxqlWrdsHUwzBAAIGJmTNnPgYa9j8UqhFElwPxf2MIDeIrKSn9FwSJoRkAEEAM0DD4DzMAyPi/G+QKY4hh5WAXGf8PDQ0FGwJ22d27CjADAAIIrLmjo+MXA9R2kAHvGBA2wwx6B8W7od6CeQcggKCmCEL8bgwxYCbUIGTDVkHDBia+CuotgACCueD3TDQN75D4xmAvCoK9ARMHBzAw0AECiBHkAlC0Mdy7x9ABNA3obAZXIAa6iKEcGlMVQHwWyjYuL2d4v2cPg8vZswx7gHyAAAK7AOif7SAbOqCmn4Ha3AHFsIDtgPq/vLz8P4MSkJ2W9h8ggBjevXvHDo4FQUQg/kdypqCg4H8lUIACnQ/SOBMYI8bAsAJFPcj1AAEEjwVQqLpAbXmH5BJjqI0gi9DTAAgDBBCcAVLkgmQ7yKCZxpCQxqUZhAECCJ4XgMl493ug21ZD+aDAXH0WLM4A9MZPXJkJIIAwTAR5pQMalaCABQUULttBGCCAGCnNzgABBgAMJ5THwGvJLAAAAABJRU5ErkJggg==" |
michael@0 | 18 | }, |
michael@0 | 19 | { title: "Customize Firefox", |
michael@0 | 20 | url: "http://en-us.www.mozilla.com/en-US/firefox/customize/", |
michael@0 | 21 | icon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAHWSURBVHjaYvz//z8DJQAggJiQOe/fv2fv7Oz8rays/N+VkfG/iYnJfyD/1+rVq7ffu3dPFpsBAAHEAHIBCJ85c8bN2Nj4vwsDw/8zQLwKiO8CcRoQu0DxqlWrdsHUwzBAAIGJmTNnPgYa9j8UqhFElwPxf2MIDeIrKSn9FwSJoRkAEEAM0DD4DzMAyPi/G+QKY4hh5WAXGf8PDQ0FGwJ22d27CjADAAIIrLmjo+MXA9R2kAHvGBA2wwx6B8W7od6CeQcggKCmCEL8bgwxYCbUIGTDVkHDBia+CuotgACCueD3TDQN75D4xmAvCoK9ARMHBzAw0AECiBHkAlC0Mdy7x9ABNA3obAZXIAa6iKEcGlMVQHwWyjYuL2d4v2cPg8vZswx7gHyAAAK7AOif7SAbOqCmn4Ha3AHFsIDtgPq/vLz8P4MSkJ2W9h8ggBjevXvHDo4FQUQg/kdypqCg4H8lUIACnQ/SOBMYI8bAsAJFPcj1AAEEjwVQqLpAbXmH5BJjqI0gi9DTAAgDBBCcAVLkgmQ7yKCZxpCQxqUZhAECCJ4XgMl493ug21ZD+aDAXH0WLM4A9MZPXJkJIIAwTAR5pQMalaCABQUULttBGCCAGCnNzgABBgAMJ5THwGvJLAAAAABJRU5ErkJggg==" |
michael@0 | 22 | }, |
michael@0 | 23 | { title: "Get Involved", |
michael@0 | 24 | url: "http://en-us.www.mozilla.com/en-US/firefox/community/", |
michael@0 | 25 | icon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAHWSURBVHjaYvz//z8DJQAggJiQOe/fv2fv7Oz8rays/N+VkfG/iYnJfyD/1+rVq7ffu3dPFpsBAAHEAHIBCJ85c8bN2Nj4vwsDw/8zQLwKiO8CcRoQu0DxqlWrdsHUwzBAAIGJmTNnPgYa9j8UqhFElwPxf2MIDeIrKSn9FwSJoRkAEEAM0DD4DzMAyPi/G+QKY4hh5WAXGf8PDQ0FGwJ22d27CjADAAIIrLmjo+MXA9R2kAHvGBA2wwx6B8W7od6CeQcggKCmCEL8bgwxYCbUIGTDVkHDBia+CuotgACCueD3TDQN75D4xmAvCoK9ARMHBzAw0AECiBHkAlC0Mdy7x9ABNA3obAZXIAa6iKEcGlMVQHwWyjYuL2d4v2cPg8vZswx7gHyAAAK7AOif7SAbOqCmn4Ha3AHFsIDtgPq/vLz8P4MSkJ2W9h8ggBjevXvHDo4FQUQg/kdypqCg4H8lUIACnQ/SOBMYI8bAsAJFPcj1AAEEjwVQqLpAbXmH5BJjqI0gi9DTAAgDBBCcAVLkgmQ7yKCZxpCQxqUZhAECCJ4XgMl493ug21ZD+aDAXH0WLM4A9MZPXJkJIIAwTAR5pQMalaCABQUULttBGCCAGCnNzgABBgAMJ5THwGvJLAAAAABJRU5ErkJggg==" |
michael@0 | 26 | }, |
michael@0 | 27 | { title: "About Us", |
michael@0 | 28 | url: "http://en-us.www.mozilla.com/en-US/about/", |
michael@0 | 29 | icon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAHWSURBVHjaYvz//z8DJQAggJiQOe/fv2fv7Oz8rays/N+VkfG/iYnJfyD/1+rVq7ffu3dPFpsBAAHEAHIBCJ85c8bN2Nj4vwsDw/8zQLwKiO8CcRoQu0DxqlWrdsHUwzBAAIGJmTNnPgYa9j8UqhFElwPxf2MIDeIrKSn9FwSJoRkAEEAM0DD4DzMAyPi/G+QKY4hh5WAXGf8PDQ0FGwJ22d27CjADAAIIrLmjo+MXA9R2kAHvGBA2wwx6B8W7od6CeQcggKCmCEL8bgwxYCbUIGTDVkHDBia+CuotgACCueD3TDQN75D4xmAvCoK9ARMHBzAw0AECiBHkAlC0Mdy7x9ABNA3obAZXIAa6iKEcGlMVQHwWyjYuL2d4v2cPg8vZswx7gHyAAAK7AOif7SAbOqCmn4Ha3AHFsIDtgPq/vLz8P4MSkJ2W9h8ggBjevXvHDo4FQUQg/kdypqCg4H8lUIACnQ/SOBMYI8bAsAJFPcj1AAEEjwVQqLpAbXmH5BJjqI0gi9DTAAgDBBCcAVLkgmQ7yKCZxpCQxqUZhAECCJ4XgMl493ug21ZD+aDAXH0WLM4A9MZPXJkJIIAwTAR5pQMalaCABQUULttBGCCAGCnNzgABBgAMJ5THwGvJLAAAAABJRU5ErkJggg==" |
michael@0 | 30 | } |
michael@0 | 31 | ] |
michael@0 | 32 | }, |
michael@0 | 33 | { |
michael@0 | 34 | type: Ci.nsINavHistoryResultNode.RESULT_TYPE_SEPARATOR |
michael@0 | 35 | }, |
michael@0 | 36 | { title: "test", |
michael@0 | 37 | description: "folder test comment", |
michael@0 | 38 | dateAdded: 1177541020000000, |
michael@0 | 39 | lastModified: 1177541050000000, |
michael@0 | 40 | children: [ |
michael@0 | 41 | { title: "test post keyword", |
michael@0 | 42 | description: "item description", |
michael@0 | 43 | dateAdded: 1177375336000000, |
michael@0 | 44 | lastModified: 1177375423000000, |
michael@0 | 45 | keyword: "test", |
michael@0 | 46 | sidebar: true, |
michael@0 | 47 | postData: "hidden1%3Dbar&text1%3D%25s", |
michael@0 | 48 | charset: "ISO-8859-1" |
michael@0 | 49 | } |
michael@0 | 50 | ] |
michael@0 | 51 | } |
michael@0 | 52 | ], |
michael@0 | 53 | toolbar: [ |
michael@0 | 54 | { title: "Getting Started", |
michael@0 | 55 | url: "http://en-us.www.mozilla.com/en-US/firefox/central/", |
michael@0 | 56 | icon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAHWSURBVHjaYvz//z8DJQAggJiQOe/fv2fv7Oz8rays/N+VkfG/iYnJfyD/1+rVq7ffu3dPFpsBAAHEAHIBCJ85c8bN2Nj4vwsDw/8zQLwKiO8CcRoQu0DxqlWrdsHUwzBAAIGJmTNnPgYa9j8UqhFElwPxf2MIDeIrKSn9FwSJoRkAEEAM0DD4DzMAyPi/G+QKY4hh5WAXGf8PDQ0FGwJ22d27CjADAAIIrLmjo+MXA9R2kAHvGBA2wwx6B8W7od6CeQcggKCmCEL8bgwxYCbUIGTDVkHDBia+CuotgACCueD3TDQN75D4xmAvCoK9ARMHBzAw0AECiBHkAlC0Mdy7x9ABNA3obAZXIAa6iKEcGlMVQHwWyjYuL2d4v2cPg8vZswx7gHyAAAK7AOif7SAbOqCmn4Ha3AHFsIDtgPq/vLz8P4MSkJ2W9h8ggBjevXvHDo4FQUQg/kdypqCg4H8lUIACnQ/SOBMYI8bAsAJFPcj1AAEEjwVQqLpAbXmH5BJjqI0gi9DTAAgDBBCcAVLkgmQ7yKCZxpCQxqUZhAECCJ4XgMl493ug21ZD+aDAXH0WLM4A9MZPXJkJIIAwTAR5pQMalaCABQUULttBGCCAGCnNzgABBgAMJ5THwGvJLAAAAABJRU5ErkJggg==" |
michael@0 | 57 | }, |
michael@0 | 58 | { title: "Latest Headlines", |
michael@0 | 59 | url: "http://en-us.fxfeeds.mozilla.com/en-US/firefox/livebookmarks/", |
michael@0 | 60 | feedUrl: "http://en-us.fxfeeds.mozilla.com/en-US/firefox/headlines.xml" |
michael@0 | 61 | } |
michael@0 | 62 | ], |
michael@0 | 63 | unfiled: [ |
michael@0 | 64 | { title: "Example.tld", |
michael@0 | 65 | url: "http://example.tld/" |
michael@0 | 66 | } |
michael@0 | 67 | ] |
michael@0 | 68 | }; |
michael@0 | 69 | |
michael@0 | 70 | // Pre-Places bookmarks.html file pointer. |
michael@0 | 71 | let gBookmarksFileOld; |
michael@0 | 72 | // Places bookmarks.html file pointer. |
michael@0 | 73 | let gBookmarksFileNew; |
michael@0 | 74 | |
michael@0 | 75 | Cu.import("resource://gre/modules/BookmarkHTMLUtils.jsm"); |
michael@0 | 76 | |
michael@0 | 77 | function run_test() |
michael@0 | 78 | { |
michael@0 | 79 | run_next_test(); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | add_task(function setup() { |
michael@0 | 83 | // Avoid creating smart bookmarks during the test. |
michael@0 | 84 | Services.prefs.setIntPref("browser.places.smartBookmarksVersion", -1); |
michael@0 | 85 | |
michael@0 | 86 | // File pointer to legacy bookmarks file. |
michael@0 | 87 | gBookmarksFileOld = do_get_file("bookmarks.preplaces.html"); |
michael@0 | 88 | |
michael@0 | 89 | // File pointer to a new Places-exported bookmarks file. |
michael@0 | 90 | gBookmarksFileNew = Services.dirsvc.get("ProfD", Ci.nsILocalFile); |
michael@0 | 91 | gBookmarksFileNew.append("bookmarks.exported.html"); |
michael@0 | 92 | if (gBookmarksFileNew.exists()) { |
michael@0 | 93 | gBookmarksFileNew.remove(false); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | // This test must be the first one, since it setups the new bookmarks.html. |
michael@0 | 97 | // Test importing a pre-Places canonical bookmarks file. |
michael@0 | 98 | // 1. import bookmarks.preplaces.html |
michael@0 | 99 | // 2. run the test-suite |
michael@0 | 100 | // Note: we do not empty the db before this import to catch bugs like 380999 |
michael@0 | 101 | yield BookmarkHTMLUtils.importFromFile(gBookmarksFileOld, true); |
michael@0 | 102 | yield promiseAsyncUpdates(); |
michael@0 | 103 | yield testImportedBookmarks(); |
michael@0 | 104 | |
michael@0 | 105 | yield BookmarkHTMLUtils.exportToFile(gBookmarksFileNew); |
michael@0 | 106 | yield promiseAsyncUpdates(); |
michael@0 | 107 | remove_all_bookmarks(); |
michael@0 | 108 | }); |
michael@0 | 109 | |
michael@0 | 110 | add_task(function test_import_new() |
michael@0 | 111 | { |
michael@0 | 112 | // Test importing a Places bookmarks.html file. |
michael@0 | 113 | // 1. import bookmarks.exported.html |
michael@0 | 114 | // 2. run the test-suite |
michael@0 | 115 | yield BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, true); |
michael@0 | 116 | yield promiseAsyncUpdates(); |
michael@0 | 117 | |
michael@0 | 118 | yield testImportedBookmarks(); |
michael@0 | 119 | yield promiseAsyncUpdates(); |
michael@0 | 120 | |
michael@0 | 121 | remove_all_bookmarks(); |
michael@0 | 122 | }); |
michael@0 | 123 | |
michael@0 | 124 | add_task(function test_emptytitle_export() |
michael@0 | 125 | { |
michael@0 | 126 | // Test exporting and importing with an empty-titled bookmark. |
michael@0 | 127 | // 1. import bookmarks |
michael@0 | 128 | // 2. create an empty-titled bookmark. |
michael@0 | 129 | // 3. export to bookmarks.exported.html |
michael@0 | 130 | // 4. empty bookmarks db |
michael@0 | 131 | // 5. import bookmarks.exported.html |
michael@0 | 132 | // 6. run the test-suite |
michael@0 | 133 | // 7. remove the empty-titled bookmark |
michael@0 | 134 | // 8. export to bookmarks.exported.html |
michael@0 | 135 | // 9. empty bookmarks db and continue |
michael@0 | 136 | |
michael@0 | 137 | yield BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, true); |
michael@0 | 138 | |
michael@0 | 139 | const NOTITLE_URL = "http://notitle.mozilla.org/"; |
michael@0 | 140 | let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, |
michael@0 | 141 | NetUtil.newURI(NOTITLE_URL), |
michael@0 | 142 | PlacesUtils.bookmarks.DEFAULT_INDEX, |
michael@0 | 143 | ""); |
michael@0 | 144 | test_bookmarks.unfiled.push({ title: "", url: NOTITLE_URL }); |
michael@0 | 145 | |
michael@0 | 146 | yield BookmarkHTMLUtils.exportToFile(gBookmarksFileNew); |
michael@0 | 147 | remove_all_bookmarks(); |
michael@0 | 148 | |
michael@0 | 149 | yield BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, true); |
michael@0 | 150 | yield promiseAsyncUpdates(); |
michael@0 | 151 | yield testImportedBookmarks(); |
michael@0 | 152 | |
michael@0 | 153 | // Cleanup. |
michael@0 | 154 | test_bookmarks.unfiled.pop(); |
michael@0 | 155 | PlacesUtils.bookmarks.removeItem(id); |
michael@0 | 156 | |
michael@0 | 157 | yield BookmarkHTMLUtils.exportToFile(gBookmarksFileNew); |
michael@0 | 158 | yield promiseAsyncUpdates(); |
michael@0 | 159 | remove_all_bookmarks(); |
michael@0 | 160 | }); |
michael@0 | 161 | |
michael@0 | 162 | add_task(function test_import_chromefavicon() |
michael@0 | 163 | { |
michael@0 | 164 | // Test exporting and importing with a bookmark pointing to a chrome favicon. |
michael@0 | 165 | // 1. import bookmarks |
michael@0 | 166 | // 2. create a bookmark pointing to a chrome favicon. |
michael@0 | 167 | // 3. export to bookmarks.exported.html |
michael@0 | 168 | // 4. empty bookmarks db |
michael@0 | 169 | // 5. import bookmarks.exported.html |
michael@0 | 170 | // 6. run the test-suite |
michael@0 | 171 | // 7. remove the bookmark pointing to a chrome favicon. |
michael@0 | 172 | // 8. export to bookmarks.exported.html |
michael@0 | 173 | // 9. empty bookmarks db and continue |
michael@0 | 174 | |
michael@0 | 175 | const PAGE_URI = NetUtil.newURI("http://example.com/chromefavicon_page"); |
michael@0 | 176 | const CHROME_FAVICON_URI = NetUtil.newURI("chrome://global/skin/icons/information-16.png"); |
michael@0 | 177 | const CHROME_FAVICON_URI_2 = NetUtil.newURI("chrome://global/skin/icons/error-16.png"); |
michael@0 | 178 | |
michael@0 | 179 | yield BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, true); |
michael@0 | 180 | let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, |
michael@0 | 181 | PAGE_URI, |
michael@0 | 182 | PlacesUtils.bookmarks.DEFAULT_INDEX, |
michael@0 | 183 | "Test"); |
michael@0 | 184 | |
michael@0 | 185 | let deferred = Promise.defer(); |
michael@0 | 186 | PlacesUtils.favicons.setAndFetchFaviconForPage( |
michael@0 | 187 | PAGE_URI, CHROME_FAVICON_URI, true, |
michael@0 | 188 | PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, |
michael@0 | 189 | deferred.resolve); |
michael@0 | 190 | yield deferred.promise; |
michael@0 | 191 | |
michael@0 | 192 | deferred = Promise.defer(); |
michael@0 | 193 | PlacesUtils.favicons.getFaviconDataForPage(PAGE_URI, |
michael@0 | 194 | function (aURI, aDataLen, aData, aMimeType) deferred.resolve(aData)); |
michael@0 | 195 | let data = yield deferred.promise; |
michael@0 | 196 | |
michael@0 | 197 | let base64Icon = "data:image/png;base64," + |
michael@0 | 198 | base64EncodeString(String.fromCharCode.apply(String, data)); |
michael@0 | 199 | |
michael@0 | 200 | test_bookmarks.unfiled.push( |
michael@0 | 201 | { title: "Test", url: PAGE_URI.spec, icon: base64Icon }); |
michael@0 | 202 | |
michael@0 | 203 | yield BookmarkHTMLUtils.exportToFile(gBookmarksFileNew); |
michael@0 | 204 | |
michael@0 | 205 | // Change the favicon to check it's really imported again later. |
michael@0 | 206 | deferred = Promise.defer(); |
michael@0 | 207 | PlacesUtils.favicons.setAndFetchFaviconForPage( |
michael@0 | 208 | PAGE_URI, CHROME_FAVICON_URI_2, true, |
michael@0 | 209 | PlacesUtils.favicons.FAVICON_LOAD_NON_PRIVATE, |
michael@0 | 210 | deferred.resolve); |
michael@0 | 211 | yield deferred.promise; |
michael@0 | 212 | |
michael@0 | 213 | remove_all_bookmarks(); |
michael@0 | 214 | |
michael@0 | 215 | yield BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, true); |
michael@0 | 216 | yield promiseAsyncUpdates(); |
michael@0 | 217 | yield testImportedBookmarks(); |
michael@0 | 218 | |
michael@0 | 219 | // Cleanup. |
michael@0 | 220 | test_bookmarks.unfiled.pop(); |
michael@0 | 221 | PlacesUtils.bookmarks.removeItem(id); |
michael@0 | 222 | |
michael@0 | 223 | yield BookmarkHTMLUtils.exportToFile(gBookmarksFileNew); |
michael@0 | 224 | yield promiseAsyncUpdates(); |
michael@0 | 225 | remove_all_bookmarks(); |
michael@0 | 226 | }); |
michael@0 | 227 | |
michael@0 | 228 | add_task(function test_import_ontop() |
michael@0 | 229 | { |
michael@0 | 230 | // Test importing the exported bookmarks.html file *on top of* the existing |
michael@0 | 231 | // bookmarks. |
michael@0 | 232 | // 1. empty bookmarks db |
michael@0 | 233 | // 2. import the exported bookmarks file |
michael@0 | 234 | // 3. export to file |
michael@0 | 235 | // 3. import the exported bookmarks file |
michael@0 | 236 | // 4. run the test-suite |
michael@0 | 237 | |
michael@0 | 238 | yield BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, true); |
michael@0 | 239 | yield BookmarkHTMLUtils.exportToFile(gBookmarksFileNew); |
michael@0 | 240 | yield BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, true); |
michael@0 | 241 | yield promiseAsyncUpdates(); |
michael@0 | 242 | yield testImportedBookmarks(); |
michael@0 | 243 | yield promiseAsyncUpdates(); |
michael@0 | 244 | remove_all_bookmarks(); |
michael@0 | 245 | }); |
michael@0 | 246 | |
michael@0 | 247 | function testImportedBookmarks() |
michael@0 | 248 | { |
michael@0 | 249 | for (let group in test_bookmarks) { |
michael@0 | 250 | do_print("[testImportedBookmarks()] Checking group '" + group + "'"); |
michael@0 | 251 | |
michael@0 | 252 | let root; |
michael@0 | 253 | switch (group) { |
michael@0 | 254 | case "menu": |
michael@0 | 255 | root = PlacesUtils.getFolderContents(PlacesUtils.bookmarksMenuFolderId).root; |
michael@0 | 256 | break; |
michael@0 | 257 | case "toolbar": |
michael@0 | 258 | root = PlacesUtils.getFolderContents(PlacesUtils.toolbarFolderId).root; |
michael@0 | 259 | break; |
michael@0 | 260 | case "unfiled": |
michael@0 | 261 | root = PlacesUtils.getFolderContents(PlacesUtils.unfiledBookmarksFolderId).root; |
michael@0 | 262 | break; |
michael@0 | 263 | } |
michael@0 | 264 | |
michael@0 | 265 | let items = test_bookmarks[group]; |
michael@0 | 266 | do_check_eq(root.childCount, items.length); |
michael@0 | 267 | |
michael@0 | 268 | for (let key in items) { |
michael@0 | 269 | yield checkItem(items[key], root.getChild(key)); |
michael@0 | 270 | } |
michael@0 | 271 | |
michael@0 | 272 | root.containerOpen = false; |
michael@0 | 273 | } |
michael@0 | 274 | } |
michael@0 | 275 | |
michael@0 | 276 | function testImportedBookmarksToFolder(aFolder) |
michael@0 | 277 | { |
michael@0 | 278 | root = PlacesUtils.getFolderContents(aFolder).root; |
michael@0 | 279 | |
michael@0 | 280 | // Menu bookmarks are put directly into the folder, while other roots are |
michael@0 | 281 | // imported into subfolders. |
michael@0 | 282 | let rootFolderCount = test_bookmarks.menu.length; |
michael@0 | 283 | |
michael@0 | 284 | for (let i = 0; i < root.childCount; i++) { |
michael@0 | 285 | let child = root.getChild(i); |
michael@0 | 286 | // This check depends on all "menu" bookmarks being listed first in the imported file :-| |
michael@0 | 287 | if (i < rootFolderCount) { |
michael@0 | 288 | checkItem(test_bookmarks.menu[i], child); |
michael@0 | 289 | } |
michael@0 | 290 | else { |
michael@0 | 291 | let container = child.QueryInterface(Ci.nsINavHistoryContainerResultNode); |
michael@0 | 292 | let group = /Toolbar/.test(container.title) ? test_bookmarks.toolbar |
michael@0 | 293 | : test_bookmarks.unfiled; |
michael@0 | 294 | container.containerOpen = true; |
michael@0 | 295 | do_print("[testImportedBookmarksToFolder()] Checking container '" + container.title + "'"); |
michael@0 | 296 | for (let t = 0; t < container.childCount; t++) { |
michael@0 | 297 | checkItem(group[t], container.getChild(t)); |
michael@0 | 298 | } |
michael@0 | 299 | container.containerOpen = false; |
michael@0 | 300 | } |
michael@0 | 301 | } |
michael@0 | 302 | |
michael@0 | 303 | root.containerOpen = false; |
michael@0 | 304 | } |
michael@0 | 305 | |
michael@0 | 306 | function checkItem(aExpected, aNode) |
michael@0 | 307 | { |
michael@0 | 308 | let id = aNode.itemId; |
michael@0 | 309 | |
michael@0 | 310 | return Task.spawn(function() { |
michael@0 | 311 | for (prop in aExpected) { |
michael@0 | 312 | switch (prop) { |
michael@0 | 313 | case "type": |
michael@0 | 314 | do_check_eq(aNode.type, aExpected.type); |
michael@0 | 315 | break; |
michael@0 | 316 | case "title": |
michael@0 | 317 | do_check_eq(aNode.title, aExpected.title); |
michael@0 | 318 | break; |
michael@0 | 319 | case "description": |
michael@0 | 320 | do_check_eq(PlacesUtils.annotations |
michael@0 | 321 | .getItemAnnotation(id, DESCRIPTION_ANNO), |
michael@0 | 322 | aExpected.description); |
michael@0 | 323 | break; |
michael@0 | 324 | case "dateAdded": |
michael@0 | 325 | do_check_eq(PlacesUtils.bookmarks.getItemDateAdded(id), |
michael@0 | 326 | aExpected.dateAdded); |
michael@0 | 327 | break; |
michael@0 | 328 | case "lastModified": |
michael@0 | 329 | do_check_eq(PlacesUtils.bookmarks.getItemLastModified(id), |
michael@0 | 330 | aExpected.lastModified); |
michael@0 | 331 | break; |
michael@0 | 332 | case "url": |
michael@0 | 333 | if (!("feedUrl" in aExpected)) |
michael@0 | 334 | do_check_eq(aNode.uri, aExpected.url) |
michael@0 | 335 | break; |
michael@0 | 336 | case "icon": |
michael@0 | 337 | let (deferred = Promise.defer(), data) { |
michael@0 | 338 | PlacesUtils.favicons.getFaviconDataForPage( |
michael@0 | 339 | NetUtil.newURI(aExpected.url), |
michael@0 | 340 | function (aURI, aDataLen, aData, aMimeType) { |
michael@0 | 341 | deferred.resolve(aData); |
michael@0 | 342 | }); |
michael@0 | 343 | data = yield deferred.promise; |
michael@0 | 344 | let base64Icon = "data:image/png;base64," + |
michael@0 | 345 | base64EncodeString(String.fromCharCode.apply(String, data)); |
michael@0 | 346 | do_check_true(base64Icon == aExpected.icon); |
michael@0 | 347 | } |
michael@0 | 348 | break; |
michael@0 | 349 | case "keyword": |
michael@0 | 350 | break; |
michael@0 | 351 | case "sidebar": |
michael@0 | 352 | do_check_eq(PlacesUtils.annotations |
michael@0 | 353 | .itemHasAnnotation(id, LOAD_IN_SIDEBAR_ANNO), |
michael@0 | 354 | aExpected.sidebar); |
michael@0 | 355 | break; |
michael@0 | 356 | case "postData": |
michael@0 | 357 | do_check_eq(PlacesUtils.annotations |
michael@0 | 358 | .getItemAnnotation(id, PlacesUtils.POST_DATA_ANNO), |
michael@0 | 359 | aExpected.postData); |
michael@0 | 360 | break; |
michael@0 | 361 | case "charset": |
michael@0 | 362 | let testURI = NetUtil.newURI(aNode.uri); |
michael@0 | 363 | do_check_eq((yield PlacesUtils.getCharsetForURI(testURI)), aExpected.charset); |
michael@0 | 364 | break; |
michael@0 | 365 | case "feedUrl": |
michael@0 | 366 | let livemark = yield PlacesUtils.livemarks.getLivemark({ id: id }); |
michael@0 | 367 | do_check_eq(livemark.siteURI.spec, aExpected.url); |
michael@0 | 368 | do_check_eq(livemark.feedURI.spec, aExpected.feedUrl); |
michael@0 | 369 | break; |
michael@0 | 370 | case "children": |
michael@0 | 371 | let folder = aNode.QueryInterface(Ci.nsINavHistoryContainerResultNode); |
michael@0 | 372 | do_check_eq(folder.hasChildren, aExpected.children.length > 0); |
michael@0 | 373 | folder.containerOpen = true; |
michael@0 | 374 | do_check_eq(folder.childCount, aExpected.children.length); |
michael@0 | 375 | |
michael@0 | 376 | aExpected.children.forEach(function (item, index) checkItem(item, folder.getChild(index))); |
michael@0 | 377 | |
michael@0 | 378 | folder.containerOpen = false; |
michael@0 | 379 | break; |
michael@0 | 380 | default: |
michael@0 | 381 | throw new Error("Unknown property"); |
michael@0 | 382 | } |
michael@0 | 383 | } |
michael@0 | 384 | }); |
michael@0 | 385 | } |