2007-05-03 01:56:41 -07:00
|
|
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et: */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.com code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla Corp.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2007
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Dietrich Ayala <dietrich@mozilla.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
// get history service
|
|
|
|
try {
|
|
|
|
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService);
|
|
|
|
} catch(ex) {
|
|
|
|
do_throw("Could not get nav-history-service\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get bookmark service
|
|
|
|
try {
|
|
|
|
var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Ci.nsINavBookmarksService);
|
|
|
|
} catch(ex) {
|
|
|
|
do_throw("Could not get nav-bookmarks-service\n");
|
|
|
|
}
|
|
|
|
|
2007-05-11 12:26:14 -07:00
|
|
|
// Get annotation service
|
|
|
|
try {
|
|
|
|
var annosvc = Cc["@mozilla.org/browser/annotation-service;1"].getService(Ci.nsIAnnotationService);
|
|
|
|
} catch(ex) {
|
|
|
|
do_throw("Could not get annotation service\n");
|
|
|
|
}
|
|
|
|
|
2007-05-16 23:06:48 -07:00
|
|
|
// Get livemark service
|
|
|
|
try {
|
|
|
|
var livemarksvc = Cc["@mozilla.org/browser/livemark-service;2"].getService(Ci.nsILivemarkService);
|
|
|
|
} catch(ex) {
|
|
|
|
do_throw("Could not get livemark service\n");
|
|
|
|
}
|
|
|
|
|
2008-07-03 11:07:56 -07:00
|
|
|
// Get favicon service
|
|
|
|
try {
|
|
|
|
var iconsvc = Cc["@mozilla.org/browser/favicon-service;1"].getService(Ci.nsIFaviconService);
|
|
|
|
} catch(ex) {
|
|
|
|
do_throw("Could not get favicon service\n");
|
|
|
|
}
|
|
|
|
|
2007-05-15 16:23:51 -07:00
|
|
|
// Get microsummary service
|
|
|
|
try {
|
|
|
|
var mssvc = Cc["@mozilla.org/microsummary/service;1"].getService(Ci.nsIMicrosummaryService);
|
|
|
|
} catch(ex) {
|
|
|
|
do_throw("Could not get microsummary service\n");
|
|
|
|
}
|
|
|
|
|
2007-05-16 23:06:48 -07:00
|
|
|
// Get io service
|
|
|
|
try {
|
|
|
|
var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
|
|
|
} catch (ex) {
|
|
|
|
do_throw("Could not get io service\n");
|
|
|
|
}
|
|
|
|
|
2007-05-11 12:26:14 -07:00
|
|
|
const DESCRIPTION_ANNO = "bookmarkProperties/description";
|
2007-05-16 23:06:48 -07:00
|
|
|
const LOAD_IN_SIDEBAR_ANNO = "bookmarkProperties/loadInSidebar";
|
2007-12-04 17:56:55 -08:00
|
|
|
const POST_DATA_ANNO = "bookmarkProperties/POSTData";
|
2007-05-11 12:26:14 -07:00
|
|
|
|
2008-07-03 11:07:56 -07:00
|
|
|
const TEST_FAVICON_PAGE_URL = "http://en-US.www.mozilla.com/en-US/firefox/central/";
|
|
|
|
const TEST_FAVICON_DATA_URL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAHWSURBVHjaYvz//z8DJQAggJiQOe/fv2fv7Oz8rays/N+VkfG/iYnJfyD/1+rVq7ffu3dPFpsBAAHEAHIBCJ85c8bN2Nj4vwsDw/8zQLwKiO8CcRoQu0DxqlWrdsHUwzBAAIGJmTNnPgYa9j8UqhFElwPxf2MIDeIrKSn9FwSJoRkAEEAM0DD4DzMAyPi/G+QKY4hh5WAXGf8PDQ0FGwJ22d27CjADAAIIrLmjo+MXA9R2kAHvGBA2wwx6B8W7od6CeQcggKCmCEL8bgwxYCbUIGTDVkHDBia+CuotgACCueD3TDQN75D4xmAvCoK9ARMHBzAw0AECiBHkAlC0Mdy7x9ABNA3obAZXIAa6iKEcGlMVQHwWyjYuL2d4v2cPg8vZswx7gHyAAAK7AOif7SAbOqCmn4Ha3AHFsIDtgPq/vLz8P4MSkJ2W9h8ggBjevXvHDo4FQUQg/kdypqCg4H8lUIACnQ/SOBMYI8bAsAJFPcj1AAEEjwVQqLpAbXmH5BJjqI0gi9DTAAgDBBCcAVLkgmQ7yKCZxpCQxqUZhAECCJ4XgMl493ug21ZD+aDAXH0WLM4A9MZPXJkJIIAwTAR5pQMalaCABQUULttBGCCAGCnNzgABBgAMJ5THwGvJLAAAAABJRU5ErkJggg==";
|
|
|
|
|
2007-05-03 01:56:41 -07:00
|
|
|
// main
|
|
|
|
function run_test() {
|
|
|
|
// get places import/export service
|
|
|
|
var importer = Cc["@mozilla.org/browser/places/import-export-service;1"].getService(Ci.nsIPlacesImportExportService);
|
|
|
|
|
2007-11-26 16:08:50 -08:00
|
|
|
// avoid creating the places smart folder during tests
|
|
|
|
Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch).
|
2008-04-08 11:42:53 -07:00
|
|
|
setIntPref("browser.places.smartBookmarksVersion", -1);
|
2007-11-26 16:08:50 -08:00
|
|
|
|
2007-05-16 23:06:48 -07:00
|
|
|
// file pointer to legacy bookmarks file
|
2007-05-03 01:56:41 -07:00
|
|
|
var bookmarksFileOld = do_get_file("browser/components/places/tests/unit/bookmarks.preplaces.html");
|
2007-05-16 23:06:48 -07:00
|
|
|
// file pointer to a new places-exported bookmarks file
|
2007-05-03 01:56:41 -07:00
|
|
|
var bookmarksFileNew = dirSvc.get("ProfD", Ci.nsILocalFile);
|
|
|
|
bookmarksFileNew.append("bookmarks.exported.html");
|
|
|
|
|
2007-05-16 23:06:48 -07:00
|
|
|
// create bookmarks.exported.html
|
|
|
|
if (bookmarksFileNew.exists())
|
|
|
|
bookmarksFileNew.remove(false);
|
|
|
|
bookmarksFileNew.create(Ci.nsILocalFile.NORMAL_FILE_TYPE, 0600);
|
2007-05-11 12:26:14 -07:00
|
|
|
if (!bookmarksFileNew.exists())
|
2007-05-03 01:56:41 -07:00
|
|
|
do_throw("couldn't create file: bookmarks.exported.html");
|
|
|
|
|
2007-05-16 23:06:48 -07:00
|
|
|
// Test importing a pre-Places canonical bookmarks file.
|
2007-05-18 00:00:00 -07:00
|
|
|
// 1. import bookmarks.preplaces.html
|
|
|
|
// 2. run the test-suite
|
|
|
|
// Note: we do not empty the db before this import to catch bugs like 380999
|
2007-05-16 23:06:48 -07:00
|
|
|
try {
|
|
|
|
importer.importHTMLFromFile(bookmarksFileOld, true);
|
|
|
|
} catch(ex) { do_throw("couldn't import legacy bookmarks file: " + ex); }
|
2007-11-19 19:33:19 -08:00
|
|
|
testCanonicalBookmarks(bmsvc.bookmarksMenuFolder);
|
2007-05-03 01:56:41 -07:00
|
|
|
|
|
|
|
// Test exporting a Places canonical bookmarks file.
|
|
|
|
// 1. export to bookmarks.exported.html
|
2007-05-16 23:06:48 -07:00
|
|
|
// 2. empty bookmarks db
|
|
|
|
// 3. import bookmarks.exported.html
|
|
|
|
// 4. run the test-suite
|
|
|
|
try {
|
|
|
|
importer.exportHTMLToFile(bookmarksFileNew);
|
|
|
|
} catch(ex) { do_throw("couldn't export to file: " + ex); }
|
2007-11-19 18:01:53 -08:00
|
|
|
bmsvc.removeFolderChildren(bmsvc.bookmarksMenuFolder);
|
2007-11-19 19:33:19 -08:00
|
|
|
bmsvc.removeFolderChildren(bmsvc.toolbarFolder);
|
2007-05-16 23:06:48 -07:00
|
|
|
try {
|
|
|
|
importer.importHTMLFromFile(bookmarksFileNew, true);
|
|
|
|
} catch(ex) { do_throw("couldn't import the exported file: " + ex); }
|
2008-04-01 11:26:09 -07:00
|
|
|
testCanonicalBookmarks(bmsvc.bookmarksMenuFolder);
|
|
|
|
|
2007-05-18 00:00:00 -07:00
|
|
|
/*
|
|
|
|
// XXX import-to-folder tests disabled due to bug 363634
|
2007-05-16 23:06:48 -07:00
|
|
|
// Test importing a pre-Places canonical bookmarks file to a specific folder.
|
|
|
|
// 1. create a new folder
|
|
|
|
// 2. import bookmarks.preplaces.html to that folder
|
|
|
|
// 3. run the test-suite
|
2007-11-19 18:01:53 -08:00
|
|
|
var testFolder = bmsvc.createFolder(bmsvc.bookmarksMenuFolder, "test-import", bmsvc.DEFAULT_INDEX);
|
2007-05-16 23:06:48 -07:00
|
|
|
try {
|
2007-05-18 00:00:00 -07:00
|
|
|
importer.importHTMLFromFileToFolder(bookmarksFileOld, testFolder, false);
|
2007-05-16 23:06:48 -07:00
|
|
|
} catch(ex) { do_throw("couldn't import the exported file to folder: " + ex); }
|
|
|
|
testCanonicalBookmarks(testFolder);
|
|
|
|
bmsvc.removeFolder(testFolder);
|
2007-05-03 01:56:41 -07:00
|
|
|
|
|
|
|
// Test importing a Places canonical bookmarks file to a specific folder.
|
|
|
|
// 1. create a new folder
|
|
|
|
// 2. import bookmarks.exported.html to that folder
|
|
|
|
// 3. run the test-suite
|
2007-11-19 18:01:53 -08:00
|
|
|
var testFolder = bmsvc.createFolder(bmsvc.bookmarksMenuFolder, "test-import", bmsvc.DEFAULT_INDEX);
|
2007-05-16 23:06:48 -07:00
|
|
|
try {
|
2007-05-18 00:00:00 -07:00
|
|
|
importer.importHTMLFromFileToFolder(bookmarksFileNew, testFolder, false);
|
2007-05-16 23:06:48 -07:00
|
|
|
} catch(ex) { do_throw("couldn't import the exported file to folder: " + ex); }
|
2007-05-03 01:56:41 -07:00
|
|
|
testCanonicalBookmarks(testFolder);
|
2007-05-16 23:06:48 -07:00
|
|
|
bmsvc.removeFolder(testFolder);
|
2007-05-18 00:48:00 -07:00
|
|
|
|
|
|
|
// XXX Disabled due to bug 381129 - separators will be duplicated on re-import
|
2007-05-16 23:06:48 -07:00
|
|
|
// Test importing the exported bookmarks.html file *on top of* the existing
|
|
|
|
// bookmarks. This tests import of IDs. If we support IDs correctly, there
|
|
|
|
// should be no difference after the import.
|
|
|
|
// 1. empty bookmarks db
|
|
|
|
// 2. import the exported bookmarks file
|
|
|
|
// 3. export to file
|
|
|
|
// 3. import the exported bookmarks file
|
|
|
|
// 4. run the test-suite
|
2007-11-19 18:01:53 -08:00
|
|
|
bmsvc.removeFolderChildren(bmsvc.bookmarksMenuFolder);
|
2007-05-16 23:06:48 -07:00
|
|
|
try {
|
|
|
|
importer.importHTMLFromFile(bookmarksFileNew, true);
|
|
|
|
} catch(ex) { do_throw("couldn't import the exported file: " + ex); }
|
|
|
|
try {
|
|
|
|
importer.exportHTMLToFile(bookmarksFileNew);
|
|
|
|
} catch(ex) { do_throw("couldn't export to file: " + ex); }
|
|
|
|
try {
|
|
|
|
importer.importHTMLFromFile(bookmarksFileNew, true);
|
|
|
|
} catch(ex) { do_throw("couldn't import the exported file: " + ex); }
|
2007-11-19 18:01:53 -08:00
|
|
|
testCanonicalBookmarks(bmsvc.bookmarksMenuFolder);
|
2007-05-18 00:48:00 -07:00
|
|
|
*/
|
2007-05-03 01:56:41 -07:00
|
|
|
/*
|
|
|
|
XXX if there are new fields we add to the bookmarks HTML format
|
|
|
|
then test them here
|
|
|
|
Test importing a Places canonical bookmarks file
|
|
|
|
1. empty the bookmarks datastore
|
|
|
|
2. import bookmarks.places.html
|
|
|
|
3. run the test-suite
|
|
|
|
4. run the additional-test-suite
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests a bookmarks datastore that has a set of bookmarks, etc
|
|
|
|
// that flex each supported field and feature.
|
|
|
|
function testCanonicalBookmarks(aFolder) {
|
|
|
|
// query to see if the deleted folder and items have been imported
|
2007-05-16 23:06:48 -07:00
|
|
|
var query = histsvc.getNewQuery();
|
|
|
|
query.setFolders([aFolder], 1);
|
|
|
|
var result = histsvc.executeQuery(query, histsvc.getNewQueryOptions());
|
|
|
|
var rootNode = result.root;
|
|
|
|
rootNode.containerOpen = true;
|
|
|
|
|
2008-04-01 11:26:09 -07:00
|
|
|
// 6-2: the toolbar folder and unfiled bookmarks folder imported to the
|
|
|
|
// corresponding places folders
|
2007-11-19 18:01:53 -08:00
|
|
|
do_check_eq(rootNode.childCount, 4);
|
2007-05-16 23:06:48 -07:00
|
|
|
|
|
|
|
// get test folder
|
2007-11-19 18:01:53 -08:00
|
|
|
var testFolder = rootNode.getChild(3);
|
2007-05-16 23:06:48 -07:00
|
|
|
do_check_eq(testFolder.type, testFolder.RESULT_TYPE_FOLDER);
|
|
|
|
do_check_eq(testFolder.title, "test");
|
2007-05-18 17:40:55 -07:00
|
|
|
|
|
|
|
// add date
|
|
|
|
do_check_eq(bmsvc.getItemDateAdded(testFolder.itemId)/1000000, 1177541020);
|
|
|
|
// last modified
|
|
|
|
do_check_eq(bmsvc.getItemLastModified(testFolder.itemId)/1000000, 1177541050);
|
|
|
|
|
2007-05-16 23:06:48 -07:00
|
|
|
testFolder = testFolder.QueryInterface(Ci.nsINavHistoryQueryResultNode);
|
|
|
|
do_check_eq(testFolder.hasChildren, true);
|
|
|
|
// folder description
|
|
|
|
do_check_true(annosvc.itemHasAnnotation(testFolder.itemId,
|
|
|
|
DESCRIPTION_ANNO));
|
|
|
|
do_check_eq("folder test comment",
|
2007-07-11 02:57:59 -07:00
|
|
|
annosvc.getItemAnnotation(testFolder.itemId, DESCRIPTION_ANNO));
|
2007-05-16 23:06:48 -07:00
|
|
|
// open test folder, and test the children
|
|
|
|
testFolder.containerOpen = true;
|
|
|
|
var cc = testFolder.childCount;
|
|
|
|
// XXX Bug 380468
|
|
|
|
// do_check_eq(cc, 2);
|
|
|
|
do_check_eq(cc, 1);
|
|
|
|
|
|
|
|
// test bookmark 1
|
|
|
|
var testBookmark1 = testFolder.getChild(0);
|
|
|
|
// url
|
|
|
|
do_check_eq("http://test/post", testBookmark1.uri);
|
|
|
|
// title
|
|
|
|
do_check_eq("test post keyword", testBookmark1.title);
|
|
|
|
// keyword
|
|
|
|
do_check_eq("test", bmsvc.getKeywordForBookmark(testBookmark1.itemId));
|
|
|
|
// sidebar
|
|
|
|
do_check_true(annosvc.itemHasAnnotation(testBookmark1.itemId,
|
|
|
|
LOAD_IN_SIDEBAR_ANNO));
|
|
|
|
// add date
|
2007-05-18 17:40:55 -07:00
|
|
|
do_check_eq(testBookmark1.dateAdded/1000000, 1177375336);
|
|
|
|
|
2007-05-16 23:06:48 -07:00
|
|
|
// last modified
|
2007-05-18 17:40:55 -07:00
|
|
|
do_check_eq(testBookmark1.lastModified/1000000, 1177375423);
|
|
|
|
|
2007-05-16 23:06:48 -07:00
|
|
|
// post data
|
2008-02-15 08:45:29 -08:00
|
|
|
do_check_true(annosvc.itemHasAnnotation(testBookmark1.itemId,
|
|
|
|
POST_DATA_ANNO));
|
2007-05-16 23:06:48 -07:00
|
|
|
do_check_eq("hidden1%3Dbar&text1%3D%25s",
|
2007-12-04 17:56:55 -08:00
|
|
|
annosvc.getItemAnnotation(testBookmark1.itemId, POST_DATA_ANNO));
|
|
|
|
|
2008-02-15 08:45:29 -08:00
|
|
|
// last charset
|
2008-04-08 11:41:04 -07:00
|
|
|
var testURI = uri(testBookmark1.uri);
|
|
|
|
do_check_eq("ISO-8859-1", histsvc.getCharsetForURI(testURI));
|
|
|
|
|
2008-02-15 08:45:29 -08:00
|
|
|
// description
|
2007-05-16 23:06:48 -07:00
|
|
|
do_check_true(annosvc.itemHasAnnotation(testBookmark1.itemId,
|
|
|
|
DESCRIPTION_ANNO));
|
|
|
|
do_check_eq("item description",
|
2007-07-11 02:57:59 -07:00
|
|
|
annosvc.getItemAnnotation(testBookmark1.itemId,
|
|
|
|
DESCRIPTION_ANNO));
|
2007-05-16 23:06:48 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
// XXX Bug 380468
|
|
|
|
// test bookmark 2
|
|
|
|
var testBookmark2 = testFolder.getChild(1);
|
|
|
|
// url
|
|
|
|
do_check_eq("http://test/micsum", testBookmark2.uri);
|
|
|
|
// title
|
|
|
|
do_check_eq("test microsummary", testBookmark2.title);
|
|
|
|
// check that it's a microsummary
|
|
|
|
var micsum = mssvc.getMicrosummary(testBookmark2.itemId);
|
|
|
|
if (!micsum)
|
|
|
|
do_throw("Could not import microsummary");
|
|
|
|
// check generator uri
|
|
|
|
var generator = micsum.generator;
|
|
|
|
do_check_eq("urn:source:http://dietrich.ganx4.com/mozilla/test-microsummary.xml", generator.uri.spec);
|
|
|
|
// expiration and generated title can change, so don't test them
|
|
|
|
*/
|
|
|
|
// clean up
|
|
|
|
testFolder.containerOpen = false;
|
|
|
|
rootNode.containerOpen = false;
|
2007-11-19 18:01:53 -08:00
|
|
|
|
|
|
|
query.setFolders([bmsvc.toolbarFolder], 1);
|
|
|
|
result = histsvc.executeQuery(query, histsvc.getNewQueryOptions());
|
|
|
|
// bookmarks toolbar
|
|
|
|
var toolbar = result.root;
|
|
|
|
toolbar.containerOpen = true;
|
|
|
|
do_check_eq(toolbar.childCount, 2);
|
|
|
|
|
|
|
|
// livemark
|
|
|
|
var livemark = toolbar.getChild(1);
|
|
|
|
// title
|
|
|
|
do_check_eq("Latest Headlines", livemark.title);
|
|
|
|
// livemark check
|
|
|
|
do_check_true(livemarksvc.isLivemark(livemark.itemId));
|
|
|
|
// site url
|
|
|
|
do_check_eq("http://en-us.fxfeeds.mozilla.com/en-US/firefox/livebookmarks/",
|
|
|
|
livemarksvc.getSiteURI(livemark.itemId).spec);
|
|
|
|
// feed url
|
|
|
|
do_check_eq("http://en-us.fxfeeds.mozilla.com/en-US/firefox/headlines.xml",
|
|
|
|
livemarksvc.getFeedURI(livemark.itemId).spec);
|
|
|
|
|
|
|
|
toolbar.containerOpen = false;
|
2008-04-01 11:26:09 -07:00
|
|
|
|
|
|
|
// unfiled bookmarks
|
|
|
|
query.setFolders([bmsvc.unfiledBookmarksFolder], 1);
|
|
|
|
result = histsvc.executeQuery(query, histsvc.getNewQueryOptions());
|
|
|
|
var unfiledBookmarks = result.root;
|
|
|
|
unfiledBookmarks.containerOpen = true;
|
|
|
|
do_check_eq(unfiledBookmarks.childCount, 1);
|
|
|
|
unfiledBookmarks.containerOpen = false;
|
2008-07-03 11:07:56 -07:00
|
|
|
|
|
|
|
// favicons
|
|
|
|
var faviconURI = iconsvc.getFaviconForPage(uri(TEST_FAVICON_PAGE_URL));
|
|
|
|
var dataURL = iconsvc.getFaviconDataAsDataURL(faviconURI);
|
|
|
|
do_check_eq(TEST_FAVICON_DATA_URL, dataURL);
|
2007-05-03 01:56:41 -07:00
|
|
|
}
|