$OpenBSD$ index f2cf018..75662ee 100644 --- toolkit/components/places/tests/browser/browser_bug248970.js.orig Fri Feb 20 15:40:39 2015 +++ toolkit/components/places/tests/browser/browser_bug248970.js Fri Feb 20 15:40:39 2015 @@ -15,13 +15,10 @@ let visitedURIs = [ "http://www.test-embed.com/", "http://www.test-framed.com/", "http://www.test-download.com/" -]; - -function test() { - waitForExplicitFinish(); +].map(NetUtil.newURI.bind(NetUtil)); +add_task(function () { let windowsToClose = []; - let windowCount = 0; let placeItemsCount = 0; registerCleanupFunction(function() { @@ -30,97 +27,99 @@ function test() { }); }); - function testOnWindow(aIsPrivate, aCallback) { - whenNewWindowLoaded(aIsPrivate, function(win) { - windowsToClose.push(win); - checkPlaces(win, aIsPrivate, aCallback); - }); - } + yield promiseClearHistory(); + + // History database should be empty + is(PlacesUtils.history.hasHistoryEntries, false, + "History database should be empty"); + + // Ensure we wait for the default bookmarks import. + let bookmarksDeferred = Promise.defer(); + waitForCondition(() => { + placeItemsCount = getPlacesItemsCount(); + return placeItemsCount > 0 + }, bookmarksDeferred.resolve, "Should have default bookmarks"); + yield bookmarksDeferred.promise; + + // Create a handful of history items with various visit types + yield promiseAddVisits([ + { uri: visitedURIs[0], transition: TRANSITION_LINK }, + { uri: visitedURIs[1], transition: TRANSITION_TYPED }, + { uri: visitedURIs[2], transition: TRANSITION_BOOKMARK }, + { uri: visitedURIs[3], transition: TRANSITION_REDIRECT_PERMANENT }, + { uri: visitedURIs[4], transition: TRANSITION_REDIRECT_TEMPORARY }, + { uri: visitedURIs[5], transition: TRANSITION_EMBED }, + { uri: visitedURIs[6], transition: TRANSITION_FRAMED_LINK }, + { uri: visitedURIs[7], transition: TRANSITION_DOWNLOAD } + ]); + + // History database should have entries + is(PlacesUtils.history.hasHistoryEntries, true, + "History database should have entries"); + + placeItemsCount += 7; + // We added 7 new items to history. + is(getPlacesItemsCount(), placeItemsCount, + "Check the total items count"); + + function* testOnWindow(aIsPrivate, aCount) { + let deferred = Promise.defer(); + whenNewWindowLoaded({ private: aIsPrivate }, deferred.resolve); + let win = yield deferred.promise; + windowsToClose.push(win); - function checkPlaces(aWindow, aIsPrivate, aCallback) { // History items should be retrievable by query - Task.spawn(checkHistoryItems).then(function() { - // Updates the place items count - placeItemsCount = getPlacesItemsCount(aWindow); - // Create Bookmark - let bookmarkTitle = "title " + windowCount; - let bookmarkKeyword = "keyword " + windowCount; - let bookmarkUri = NetUtil.newURI("http://test-a-" + windowCount + ".com/"); - createBookmark(aWindow, bookmarkUri, bookmarkTitle, bookmarkKeyword); - placeItemsCount++; - windowCount++; - ok(PlacesUtils.bookmarks.isBookmarked(bookmarkUri), - "Bookmark should be bookmarked, data should be retrievable"); - is(bookmarkKeyword, PlacesUtils.bookmarks.getKeywordForURI(bookmarkUri), - "Check bookmark uri keyword"); - is(getPlacesItemsCount(aWindow), placeItemsCount, - "Check the new bookmark items count"); - is(isBookmarkAltered(aWindow), false, "Check if bookmark has been visited"); - - aCallback(); - }); - } + yield checkHistoryItems(); - clearHistory(function() { // Updates the place items count - placeItemsCount = getPlacesItemsCount(window); - // History database should be empty - is(PlacesUtils.history.hasHistoryEntries, false, - "History database should be empty"); - // Create a handful of history items with various visit types - fillHistoryVisitedURI(window, function() { - placeItemsCount += 7; - // History database should have entries - is(PlacesUtils.history.hasHistoryEntries, true, - "History database should have entries"); - // We added 7 new items to history. - is(getPlacesItemsCount(window), placeItemsCount, - "Check the total items count"); - // Test on windows. - testOnWindow(false, function() { - testOnWindow(true, function() { - testOnWindow(false, finish); - }); - }); - }); - }); -} + let count = getPlacesItemsCount(); + + // Create Bookmark + let bookmarkTitle = "title " + windowsToClose.length; + let bookmarkKeyword = "keyword " + windowsToClose.length; + let bookmarkUri = NetUtil.newURI("http://test-a-" + windowsToClose.length + ".com/"); + + let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.bookmarksMenuFolderId, + bookmarkUri, + PlacesUtils.bookmarks.DEFAULT_INDEX, + bookmarkTitle); + PlacesUtils.bookmarks.setKeywordForBookmark(id, bookmarkKeyword); + count++; + + ok(PlacesUtils.bookmarks.isBookmarked(bookmarkUri), + "Bookmark should be bookmarked, data should be retrievable"); + is(bookmarkKeyword, PlacesUtils.bookmarks.getKeywordForURI(bookmarkUri), + "Check bookmark uri keyword"); + is(getPlacesItemsCount(), count, + "Check the new bookmark items count"); + is(isBookmarkAltered(), false, "Check if bookmark has been visited"); + } -function whenNewWindowLoaded(aIsPrivate, aCallback) { - let win = OpenBrowserWindow({private: aIsPrivate}); - win.addEventListener("load", function onLoad() { - win.removeEventListener("load", onLoad, false); - aCallback(win); - }, false); -} - -function clearHistory(aCallback) { - Services.obs.addObserver(function observer(aSubject, aTopic, aData) { - Services.obs.removeObserver(observer, PlacesUtils.TOPIC_EXPIRATION_FINISHED); - aCallback(); - }, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false); - PlacesUtils.bhistory.removeAllPages(); -} + // Test on windows. + yield testOnWindow(false); + yield testOnWindow(true); + yield testOnWindow(false); +}); /** * Function performs a really simple query on our places entries, * and makes sure that the number of entries equal num_places_entries. */ -function getPlacesItemsCount(aWin){ +function getPlacesItemsCount() { // Get bookmarks count - let options = aWin.PlacesUtils.history.getNewQueryOptions(); + let options = PlacesUtils.history.getNewQueryOptions(); options.includeHidden = true; options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS; - let root = aWin.PlacesUtils.history.executeQuery( - aWin.PlacesUtils.history.getNewQuery(), options).root; + let root = PlacesUtils.history.executeQuery( + PlacesUtils.history.getNewQuery(), options).root; root.containerOpen = true; let cc = root.childCount; root.containerOpen = false; // Get history item count options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_HISTORY; - let root = aWin.PlacesUtils.history.executeQuery( - aWin.PlacesUtils.history.getNewQuery(), options).root; + let root = PlacesUtils.history.executeQuery( + PlacesUtils.history.getNewQuery(), options).root; root.containerOpen = true; cc += root.childCount; root.containerOpen = false; @@ -128,24 +127,11 @@ function getPlacesItemsCount(aWin){ return cc; } -function fillHistoryVisitedURI(aWin, aCallback) { - addVisits([ - {uri: NetUtil.newURI(visitedURIs[0]), transition: PlacesUtils.history.TRANSITION_LINK}, - {uri: NetUtil.newURI(visitedURIs[1]), transition: PlacesUtils.history.TRANSITION_TYPED}, - {uri: NetUtil.newURI(visitedURIs[2]), transition: PlacesUtils.history.TRANSITION_BOOKMARK}, - {uri: NetUtil.newURI(visitedURIs[3]), transition: PlacesUtils.history.TRANSITION_REDIRECT_PERMANENT}, - {uri: NetUtil.newURI(visitedURIs[4]), transition: PlacesUtils.history.TRANSITION_REDIRECT_TEMPORARY}, - {uri: NetUtil.newURI(visitedURIs[5]), transition: PlacesUtils.history.TRANSITION_EMBED}, - {uri: NetUtil.newURI(visitedURIs[6]), transition: PlacesUtils.history.TRANSITION_FRAMED_LINK}, - {uri: NetUtil.newURI(visitedURIs[7]), transition: PlacesUtils.history.TRANSITION_DOWNLOAD}], - aWin, aCallback); -} - -function checkHistoryItems() { +function* checkHistoryItems() { for (let i = 0; i < visitedURIs.length; i++) { let visitedUri = visitedURIs[i]; - ok((yield promiseIsURIVisited(NetUtil.newURI(visitedUri))), ""); - if (/embed/.test(visitedUri)) { + ok((yield promiseIsURIVisited(visitedUri)), ""); + if (/embed/.test(visitedUri.spec)) { is(!!pageInDatabase(visitedUri), false, "Check if URI is in database"); } else { ok(!!pageInDatabase(visitedUri), "Check if URI is in database"); @@ -175,75 +161,21 @@ function pageInDatabase(aURI) { } /** - * Gets the database connection. If the Places connection is invalid it will - * try to create a new connection. - * - * @param [optional] aForceNewConnection - * Forces creation of a new connection to the database. When a - * connection is asyncClosed it cannot anymore schedule async statements, - * though connectionReady will keep returning true (Bug 726990). - * - * @return The database connection or null if unable to get one. - */ -let gDBConn; -function DBConn(aForceNewConnection) { - if (!aForceNewConnection) { - let db = - PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection; - if (db.connectionReady) - return db; - } - - // If the Places database connection has been closed, create a new connection. - if (!gDBConn || aForceNewConnection) { - let file = Services.dirsvc.get('ProfD', Ci.nsIFile); - file.append("places.sqlite"); - let dbConn = gDBConn = Services.storage.openDatabase(file); - - // Be sure to cleanly close this connection. - Services.obs.addObserver(function DBCloseCallback(aSubject, aTopic, aData) { - Services.obs.removeObserver(DBCloseCallback, aTopic); - dbConn.asyncClose(); - }, "profile-before-change", false); - } - - return gDBConn.connectionReady ? gDBConn : null; -}; - -/** - * Function creates a bookmark - * @param aURI - * The URI for the bookmark - * @param aTitle - * The title for the bookmark - * @param aKeyword - * The keyword for the bookmark - * @returns the bookmark - */ -function createBookmark(aWin, aURI, aTitle, aKeyword) { - let bookmarkID = aWin.PlacesUtils.bookmarks.insertBookmark( - aWin.PlacesUtils.bookmarksMenuFolderId, aURI, - aWin.PlacesUtils.bookmarks.DEFAULT_INDEX, aTitle); - aWin.PlacesUtils.bookmarks.setKeywordForBookmark(bookmarkID, aKeyword); - return bookmarkID; -} - -/** * Function attempts to check if Bookmark-A has been visited * during private browsing mode, function should return false * * @returns false if the accessCount has not changed * true if the accessCount has changed */ -function isBookmarkAltered(aWin){ - let options = aWin.PlacesUtils.history.getNewQueryOptions(); +function isBookmarkAltered(){ + let options = PlacesUtils.history.getNewQueryOptions(); options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS; options.maxResults = 1; // should only expect a new bookmark - let query = aWin.PlacesUtils.history.getNewQuery(); - query.setFolders([aWin.PlacesUtils.bookmarks.bookmarksMenuFolder], 1); + let query = PlacesUtils.history.getNewQuery(); + query.setFolders([PlacesUtils.bookmarks.bookmarksMenuFolder], 1); - let root = aWin.PlacesUtils.history.executeQuery(query, options).root; + let root = PlacesUtils.history.executeQuery(query, options).root; root.containerOpen = true; is(root.childCount, options.maxResults, "Check new bookmarks results"); let node = root.getChild(0);