diff --git a/toolkit/components/places/tests/browser/browser_bug248970.js b/toolkit/components/places/tests/browser/browser_bug248970.js index 3c93408601bb..06711afd448e 100644 --- a/toolkit/components/places/tests/browser/browser_bug248970.js +++ b/toolkit/components/places/tests/browser/browser_bug248970.js @@ -38,27 +38,27 @@ function test() { } function checkPlaces(aWindow, aIsPrivate, aCallback) { - // Updates the place items count - placeItemsCount = getPlacesItemsCount(aWindow); // History items should be retrievable by query - checkHistoryItems(aWindow); + 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"); - // 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(aWindow.PlacesUtils.bookmarks.isBookmarked(bookmarkUri), - "Bookmark should be bookmarked, data should be retrievable"); - is(bookmarkKeyword, aWindow.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(); + aCallback(); + }); } clearHistory(function() { @@ -141,15 +141,16 @@ function fillHistoryVisitedURI(aWin, aCallback) { aWin, aCallback); } -function checkHistoryItems(aWin) { - visitedURIs.forEach(function (visitedUri) { - ok(aWin.PlacesUtils.bhistory.isVisited(NetUtil.newURI(visitedUri)), ""); +function checkHistoryItems() { + for (let i = 0; i < visitedURIs.length; i++) { + let visitedUri = visitedURIs[i]; + ok((yield promiseIsURIVisited(NetUtil.newURI(visitedUri))), ""); if (/embed/.test(visitedUri)) { is(!!pageInDatabase(visitedUri), false, "Check if URI is in database"); } else { ok(!!pageInDatabase(visitedUri), "Check if URI is in database"); } - }); + } } /** diff --git a/toolkit/components/places/tests/browser/head.js b/toolkit/components/places/tests/browser/head.js index 42c7cadbf98d..f6860ca341fd 100644 --- a/toolkit/components/places/tests/browser/head.js +++ b/toolkit/components/places/tests/browser/head.js @@ -7,6 +7,8 @@ Components.utils.import("resource://gre/modules/NetUtil.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "Promise", "resource://gre/modules/commonjs/sdk/core/promise.js"); +XPCOMUtils.defineLazyModuleGetter(this, "Task", + "resource://gre/modules/Task.jsm"); /** * Allows waiting for an observer notification once. @@ -346,3 +348,22 @@ function whenNewWindowLoaded(aOptions, aCallback) { aCallback(win); }, false); } + +/** + * Asynchronously check a url is visited. + * + * @param aURI The URI. + * @param aExpectedValue The expected value. + * @return {Promise} + * @resolves When the check has been added successfully. + * @rejects JavaScript exception. + */ +function promiseIsURIVisited(aURI, aExpectedValue) { + let deferred = Promise.defer(); + + PlacesUtils.asyncHistory.isURIVisited(aURI, function(aURI, aIsVisited) { + deferred.resolve(aIsVisited); + }); + + return deferred.promise; +} diff --git a/toolkit/components/places/tests/head_common.js b/toolkit/components/places/tests/head_common.js index ba804c05ba51..9221396c804d 100644 --- a/toolkit/components/places/tests/head_common.js +++ b/toolkit/components/places/tests/head_common.js @@ -915,19 +915,15 @@ function promiseAddVisits(aPlaceInfo) /** * Asynchronously check a url is visited. * - * @param aURI - * The URI. - * + * @param aURI The URI. * @return {Promise} * @resolves When the check has been added successfully. * @rejects JavaScript exception. */ -function promiseIsURIVisited(aURI) -{ +function promiseIsURIVisited(aURI) { let deferred = Promise.defer(); - let history = Cc["@mozilla.org/browser/history;1"] - .getService(Ci.mozIAsyncHistory); - history.isURIVisited(aURI, function(aURI, aIsVisited) { + + PlacesUtils.asyncHistory.isURIVisited(aURI, function(aURI, aIsVisited) { deferred.resolve(aIsVisited); }); diff --git a/toolkit/components/places/tests/unit/test_425563.js b/toolkit/components/places/tests/unit/test_425563.js index 6a5df9a745d9..261d09758308 100644 --- a/toolkit/components/places/tests/unit/test_425563.js +++ b/toolkit/components/places/tests/unit/test_425563.js @@ -43,10 +43,10 @@ add_task(function test_execute() // check that all links are marked as visited count_visited_URIs.forEach(function (visited_uri) { - do_check_eq(PlacesUtils.bhistory.isVisited(uri(visited_uri)), true); + do_check_true(yield promiseIsURIVisited(uri(visited_uri))); }); notcount_visited_URIs.forEach(function (visited_uri) { - do_check_eq(PlacesUtils.bhistory.isVisited(uri(visited_uri)), true); + do_check_true(yield promiseIsURIVisited(uri(visited_uri))); }); // check that visit_count does not take in count embed and downloads diff --git a/toolkit/components/places/tests/unit/test_async_history_api.js b/toolkit/components/places/tests/unit/test_async_history_api.js index 1f9cfc491ea8..354c781d93ef 100644 --- a/toolkit/components/places/tests/unit/test_async_history_api.js +++ b/toolkit/components/places/tests/unit/test_async_history_api.js @@ -8,21 +8,12 @@ //////////////////////////////////////////////////////////////////////////////// //// Globals -XPCOMUtils.defineLazyServiceGetter(this, "gHistory", - "@mozilla.org/browser/history;1", - "mozIAsyncHistory"); - -XPCOMUtils.defineLazyServiceGetter(this, "gGlobalHistory", - "@mozilla.org/browser/nav-history-service;1", - "nsIGlobalHistory2"); - const TEST_DOMAIN = "http://mozilla.org/"; const URI_VISIT_SAVED = "uri-visit-saved"; const RECENT_EVENT_THRESHOLD = 15 * 60 * 1000000; //////////////////////////////////////////////////////////////////////////////// //// Helpers - /** * Object that represents a mozIVisitInfo object. * @@ -40,6 +31,25 @@ function VisitInfo(aTransitionType, this.visitDate = aVisitTime || Date.now() * 1000; } +function promiseUpdatePlaces(aPlaces) { + let deferred = Promise.defer(); + PlacesUtils.asyncHistory.updatePlaces(aPlaces, { + _errors: [], + _results: [], + handleError: function handleError(aResultCode, aPlace) { + this._errors.push({ resultCode: aResultCode, info: aPlace}); + }, + handleResult: function handleResult(aPlace) { + this._results.push(aPlace); + }, + handleCompletion: function handleCompletion() { + deferred.resolve({ errors: this._errors, results: this._results }); + } + }); + + return deferred.promise; +} + /** * Listens for a title change notification, and calls aCallback when it gets it. * @@ -135,38 +145,6 @@ function do_check_title_for_uri(aURI, stmt.finalize(); } -/** - * Default callback handler throws when success is unexpected. - * - * @param handleErrorFunc - * The error handling function - */ -function expectHandleError(handleErrorFunc) -{ - return { - handleError: handleErrorFunc, - handleResult: function handleResult(aPlaceInfo) { - do_throw("Unexpected success."); - } - }; -} -/** - * Default callback handler throws when failure is unexpected. - * - * @param handleResultFunc - * The success handling function - */ - -function expectHandleResult(handleResultFunc) -{ - return { - handleError: function handleError(aResultCode, aPlacesInfo) { - do_throw("Unexpected error: " + aResultCode); - }, - handleResult: handleResultFunc - }; -} - //////////////////////////////////////////////////////////////////////////////// //// Test Functions @@ -174,7 +152,6 @@ function test_interface_exists() { let history = Cc["@mozilla.org/browser/history;1"].getService(Ci.nsISupports); do_check_true(history instanceof Ci.mozIAsyncHistory); - run_next_test(); } function test_invalid_uri_throws() @@ -186,7 +163,7 @@ function test_invalid_uri_throws() ], }; try { - gHistory.updatePlaces(place); + yield promiseUpdatePlaces(place); do_throw("Should have thrown!"); } catch (e) { @@ -204,21 +181,20 @@ function test_invalid_uri_throws() for (let i = 0; i < TEST_VALUES.length; i++) { place.uri = TEST_VALUES[i]; try { - gHistory.updatePlaces(place); + yield promiseUpdatePlaces(place); do_throw("Should have thrown!"); } catch (e) { do_check_eq(e.result, Cr.NS_ERROR_INVALID_ARG); } } - run_next_test(); } function test_invalid_places_throws() { // First, test passing in nothing. try { - gHistory.updatePlaces(); + PlacesUtils.asyncHistory.updatePlaces(); do_throw("Should have thrown!"); } catch (e) { @@ -236,15 +212,13 @@ function test_invalid_places_throws() for (let i = 0; i < TEST_VALUES.length; i++) { let value = TEST_VALUES[i]; try { - gHistory.updatePlaces(value); + yield promiseUpdatePlaces(value); do_throw("Should have thrown!"); } catch (e) { do_check_eq(e.result, Cr.NS_ERROR_INVALID_ARG); } } - - run_next_test(); } function test_invalid_guid_throws() @@ -258,7 +232,7 @@ function test_invalid_guid_throws() ], }; try { - gHistory.updatePlaces(place); + yield promiseUpdatePlaces(place); do_throw("Should have thrown!"); } catch (e) { @@ -269,14 +243,12 @@ function test_invalid_guid_throws() place.guid = "__BADGUID+__"; do_check_eq(place.guid.length, 12); try { - gHistory.updatePlaces(place); + yield promiseUpdatePlaces(place); do_throw("Should have thrown!"); } catch (e) { do_check_eq(e.result, Cr.NS_ERROR_INVALID_ARG); } - - run_next_test(); } function test_no_visits_throws() @@ -309,7 +281,7 @@ function test_no_visits_throws() log_test_conditions(place); try { - gHistory.updatePlaces(place); + yield promiseUpdatePlaces(place); do_throw("Should have thrown!"); } catch (e) { @@ -318,8 +290,6 @@ function test_no_visits_throws() } } } - - run_next_test(); } function test_add_visit_no_date_throws() @@ -332,14 +302,12 @@ function test_add_visit_no_date_throws() }; delete place.visits[0].visitDate; try { - gHistory.updatePlaces(place); + yield promiseUpdatePlaces(place); do_throw("Should have thrown!"); } catch (e) { do_check_eq(e.result, Cr.NS_ERROR_INVALID_ARG); } - - run_next_test(); } function test_add_visit_no_transitionType_throws() @@ -352,14 +320,12 @@ function test_add_visit_no_transitionType_throws() }; delete place.visits[0].transitionType; try { - gHistory.updatePlaces(place); + yield promiseUpdatePlaces(place); do_throw("Should have thrown!"); } catch (e) { do_check_eq(e.result, Cr.NS_ERROR_INVALID_ARG); } - - run_next_test(); } function test_add_visit_invalid_transitionType_throws() @@ -373,7 +339,7 @@ function test_add_visit_invalid_transitionType_throws() ], }; try { - gHistory.updatePlaces(place); + yield promiseUpdatePlaces(place); do_throw("Should have thrown!"); } catch (e) { @@ -383,14 +349,12 @@ function test_add_visit_invalid_transitionType_throws() // Now, test something that has a transition type greater than the last one. place.visits[0] = new VisitInfo(TRANSITION_FRAMED_LINK + 1); try { - gHistory.updatePlaces(place); + yield promiseUpdatePlaces(place); do_throw("Should have thrown!"); } catch (e) { do_check_eq(e.result, Cr.NS_ERROR_INVALID_ARG); } - - run_next_test(); } function test_non_addable_uri_errors() @@ -430,17 +394,16 @@ function test_non_addable_uri_errors() } }); - let callbackCount = 0; - gHistory.updatePlaces(places, expectHandleError(function(aResultCode, aPlaceInfo) { - do_log_info("Checking '" + aPlaceInfo.uri.spec + "'"); - do_check_eq(aResultCode, Cr.NS_ERROR_INVALID_ARG); - do_check_false(gGlobalHistory.isVisited(aPlaceInfo.uri)); - - // If we have had all of our callbacks, continue running tests. - if (++callbackCount == places.length) { - promiseAsyncUpdates().then(run_next_test); - } - })); + let placesResult = yield promiseUpdatePlaces(places); + if (placesResult.results.length > 0) { + do_throw("Unexpected success."); + } + for (let place of placesResult.errors) { + do_log_info("Checking '" + place.info.uri.spec + "'"); + do_check_eq(place.resultCode, Cr.NS_ERROR_INVALID_ARG); + do_check_false(yield promiseIsURIVisited(place.info.uri)); + } + yield promiseAsyncUpdates(); } function test_duplicate_guid_errors() @@ -454,26 +417,32 @@ function test_duplicate_guid_errors() ], }; - do_check_false(gGlobalHistory.isVisited(place.uri)); - gHistory.updatePlaces(place, expectHandleResult(function(aPlaceInfo) { - do_check_true(gGlobalHistory.isVisited(place.uri)); + do_check_false(yield promiseIsURIVisited(place.uri)); + let placesResult = yield promiseUpdatePlaces(place); + if (placesResult.errors.length > 0) { + do_throw("Unexpected error."); + } + let placeInfo = placesResult.results[0]; + do_check_true(yield promiseIsURIVisited(placeInfo.uri)); - let badPlace = { - uri: NetUtil.newURI(TEST_DOMAIN + "test_duplicate_guid_fails_second"), - visits: [ - new VisitInfo(), - ], - guid: aPlaceInfo.guid, - }; + let badPlace = { + uri: NetUtil.newURI(TEST_DOMAIN + "test_duplicate_guid_fails_second"), + visits: [ + new VisitInfo(), + ], + guid: placeInfo.guid, + }; - do_check_false(gGlobalHistory.isVisited(badPlace.uri)); - gHistory.updatePlaces(badPlace, expectHandleError(function(aResultCode, aPlaceInfo) { - do_check_eq(aResultCode, Cr.NS_ERROR_STORAGE_CONSTRAINT); - do_check_false(gGlobalHistory.isVisited(badPlace.uri)); + do_check_false(yield promiseIsURIVisited(badPlace.uri)); + placesResult = yield promiseUpdatePlaces(badPlace); + if (placesResult.results.length > 0) { + do_throw("Unexpected success."); + } + let badPlaceInfo = placesResult.errors[0]; + do_check_eq(badPlaceInfo.resultCode, Cr.NS_ERROR_STORAGE_CONSTRAINT); + do_check_false(yield promiseIsURIVisited(badPlaceInfo.info.uri)); - promiseAsyncUpdates().then(run_next_test); - })); - })); + yield promiseAsyncUpdates(); } function test_invalid_referrerURI_ignored() @@ -486,29 +455,31 @@ function test_invalid_referrerURI_ignored() ], }; place.visits[0].referrerURI = NetUtil.newURI(place.uri.spec + "_unvisistedURI"); - do_check_false(gGlobalHistory.isVisited(place.uri)); - do_check_false(gGlobalHistory.isVisited(place.visits[0].referrerURI)); + do_check_false(yield promiseIsURIVisited(place.uri)); + do_check_false(yield promiseIsURIVisited(place.visits[0].referrerURI)); - gHistory.updatePlaces(place, expectHandleResult(function(aPlaceInfo) { - let uri = aPlaceInfo.uri; - do_check_true(gGlobalHistory.isVisited(uri)); + let placesResult = yield promiseUpdatePlaces(place); + if (placesResult.errors.length > 0) { + do_throw("Unexpected error."); + } + let placeInfo = placesResult.results[0]; + do_check_true(yield promiseIsURIVisited(placeInfo.uri)); - // Check to make sure we do not visit the invalid referrer. - do_check_false(gGlobalHistory.isVisited(place.visits[0].referrerURI)); + // Check to make sure we do not visit the invalid referrer. + do_check_false(yield promiseIsURIVisited(place.visits[0].referrerURI)); - // Check to make sure from_visit is zero in database. - let stmt = DBConn().createStatement( - "SELECT from_visit " + - "FROM moz_historyvisits " + - "WHERE id = :visit_id" - ); - stmt.params.visit_id = aPlaceInfo.visits[0].visitId; - do_check_true(stmt.executeStep()); - do_check_eq(stmt.row.from_visit, 0); - stmt.finalize(); + // Check to make sure from_visit is zero in database. + let stmt = DBConn().createStatement( + "SELECT from_visit " + + "FROM moz_historyvisits " + + "WHERE id = :visit_id" + ); + stmt.params.visit_id = placeInfo.visits[0].visitId; + do_check_true(stmt.executeStep()); + do_check_eq(stmt.row.from_visit, 0); + stmt.finalize(); - promiseAsyncUpdates().then(run_next_test); - })); + yield promiseAsyncUpdates(); } function test_nonnsIURI_referrerURI_ignored() @@ -521,25 +492,27 @@ function test_nonnsIURI_referrerURI_ignored() ], }; place.visits[0].referrerURI = place.uri.spec + "_nonnsIURI"; - do_check_false(gGlobalHistory.isVisited(place.uri)); + do_check_false(yield promiseIsURIVisited(place.uri)); - gHistory.updatePlaces(place, expectHandleResult(function(aPlaceInfo) { - let uri = aPlaceInfo.uri; - do_check_true(gGlobalHistory.isVisited(uri)); + let placesResult = yield promiseUpdatePlaces(place); + if (placesResult.errors.length > 0) { + do_throw("Unexpected error."); + } + let placeInfo = placesResult.results[0]; + do_check_true(yield promiseIsURIVisited(placeInfo.uri)); - // Check to make sure from_visit is zero in database. - let stmt = DBConn().createStatement( - "SELECT from_visit " + - "FROM moz_historyvisits " + - "WHERE id = :visit_id" - ); - stmt.params.visit_id = aPlaceInfo.visits[0].visitId; - do_check_true(stmt.executeStep()); - do_check_eq(stmt.row.from_visit, 0); - stmt.finalize(); + // Check to make sure from_visit is zero in database. + let stmt = DBConn().createStatement( + "SELECT from_visit " + + "FROM moz_historyvisits " + + "WHERE id = :visit_id" + ); + stmt.params.visit_id = placeInfo.visits[0].visitId; + do_check_true(stmt.executeStep()); + do_check_eq(stmt.row.from_visit, 0); + stmt.finalize(); - promiseAsyncUpdates().then(run_next_test); - })); + yield promiseAsyncUpdates(); } function test_invalid_sessionId_ignored() @@ -552,29 +525,31 @@ function test_invalid_sessionId_ignored() ], }; place.visits[0].sessionId = 0; - do_check_false(gGlobalHistory.isVisited(place.uri)); + do_check_false(yield promiseIsURIVisited(place.uri)); - gHistory.updatePlaces(place, expectHandleResult(function(aPlaceInfo) { - let uri = aPlaceInfo.uri; - do_check_true(gGlobalHistory.isVisited(uri)); + let placesResult = yield promiseUpdatePlaces(place); + if (placesResult.errors.length > 0) { + do_throw("Unexpected error."); + } + let placeInfo = placesResult.results[0]; + do_check_true(yield promiseIsURIVisited(placeInfo.uri)); - // Check to make sure we do not persist bogus sessionId with the visit. - let visit = aPlaceInfo.visits[0]; - do_check_neq(visit.sessionId, place.visits[0].sessionId); + // Check to make sure we do not persist bogus sessionId with the visit. + let visit = placeInfo.visits[0]; + do_check_neq(visit.sessionId, place.visits[0].sessionId); - // Check to make sure we do not persist bogus sessionId in database. - let stmt = DBConn().createStatement( - "SELECT session " + - "FROM moz_historyvisits " + - "WHERE id = :visit_id" - ); - stmt.params.visit_id = visit.visitId; - do_check_true(stmt.executeStep()); - do_check_neq(stmt.row.session, place.visits[0].sessionId); - stmt.finalize(); + // Check to make sure we do not persist bogus sessionId in database. + let stmt = DBConn().createStatement( + "SELECT session " + + "FROM moz_historyvisits " + + "WHERE id = :visit_id" + ); + stmt.params.visit_id = visit.visitId; + do_check_true(stmt.executeStep()); + do_check_neq(stmt.row.session, place.visits[0].sessionId); + stmt.finalize(); - promiseAsyncUpdates().then(run_next_test); - })); + yield promiseAsyncUpdates(); } function test_unstored_sessionId_ignored() @@ -598,34 +573,35 @@ function test_unstored_sessionId_ignored() // Create bogus sessionId that is not in database. place.visits[0].sessionId = maxSessionId + 10; - do_check_false(gGlobalHistory.isVisited(place.uri)); + do_check_false(yield promiseIsURIVisited(place.uri)); - gHistory.updatePlaces(place, expectHandleResult(function(aPlaceInfo) { - let uri = aPlaceInfo.uri; - do_check_true(gGlobalHistory.isVisited(uri)); + let placesResult = yield promiseUpdatePlaces(place); + if (placesResult.errors.length > 0) { + do_throw("Unexpected error."); + } + let placeInfo = placesResult.results[0]; + do_check_true(yield promiseIsURIVisited(placeInfo.uri)); - // Check to make sure we do not persist bogus sessionId with the visit. - let visit = aPlaceInfo.visits[0]; - do_check_neq(visit.sessionId, place.visits[0].sessionId); + // Check to make sure we do not persist bogus sessionId with the visit. + let visit = placeInfo.visits[0]; + do_check_neq(visit.sessionId, place.visits[0].sessionId); - // Check to make sure we do not persist bogus sessionId in the database. - let stmt = DBConn().createStatement( - "SELECT MAX(session) as max_session " + - "FROM moz_historyvisits" - ); - do_check_true(stmt.executeStep()); + // Check to make sure we do not persist bogus sessionId in the database. + let stmt = DBConn().createStatement( + "SELECT MAX(session) as max_session " + + "FROM moz_historyvisits" + ); + do_check_true(stmt.executeStep()); - // Max sessionId should increase by 1 because we will generate a new - // non-bogus sessionId. - let newMaxSessionId = stmt.row.max_session; - do_check_eq(maxSessionId + 1, newMaxSessionId); - stmt.finalize(); + // Max sessionId should increase by 1 because we will generate a new + // non-bogus sessionId. + let newMaxSessionId = stmt.row.max_session; + do_check_eq(maxSessionId + 1, newMaxSessionId); + stmt.finalize(); - promiseAsyncUpdates().then(run_next_test); - })); + yield promiseAsyncUpdates(); } - function test_old_referrer_ignored() { // This tests that a referrer for a visit which is not recent (specifically, @@ -641,43 +617,49 @@ function test_old_referrer_ignored() // First we must add our referrer to the history so that it is not ignored // as being invalid. - do_check_false(gGlobalHistory.isVisited(referrerPlace.uri)); - gHistory.updatePlaces(referrerPlace, expectHandleResult(function(aPlaceInfo) { - // Now that the referrer is added, we can add a page with a valid - // referrer to determine if the recency of the referrer is taken into - // account. - do_check_true(gGlobalHistory.isVisited(referrerPlace.uri)); + do_check_false(yield promiseIsURIVisited(referrerPlace.uri)); + let placesResult = yield promiseUpdatePlaces(referrerPlace); + if (placesResult.errors.length > 0) { + do_throw("Unexpected error."); + } - let visitInfo = new VisitInfo(); - visitInfo.referrerURI = referrerPlace.uri; - let place = { - uri: NetUtil.newURI(TEST_DOMAIN + "test_old_referrer_ignored_page"), - visits: [ - visitInfo, - ], - }; + // Now that the referrer is added, we can add a page with a valid + // referrer to determine if the recency of the referrer is taken into + // account. + do_check_true(yield promiseIsURIVisited(referrerPlace.uri)); - do_check_false(gGlobalHistory.isVisited(place.uri)); - gHistory.updatePlaces(place, expectHandleResult (function(aPlaceInfo) { - do_check_true(gGlobalHistory.isVisited(place.uri)); + let visitInfo = new VisitInfo(); + visitInfo.referrerURI = referrerPlace.uri; + let place = { + uri: NetUtil.newURI(TEST_DOMAIN + "test_old_referrer_ignored_page"), + visits: [ + visitInfo, + ], + }; - // Though the visit will not contain the referrer, we must examine the - // database to be sure. - do_check_eq(aPlaceInfo.visits[0].referrerURI, null); - let stmt = DBConn().createStatement( - "SELECT COUNT(1) AS count " + - "FROM moz_historyvisits " + - "WHERE place_id = (SELECT id FROM moz_places WHERE url = :page_url) " + - "AND from_visit = 0 " - ); - stmt.params.page_url = place.uri.spec; - do_check_true(stmt.executeStep()); - do_check_eq(stmt.row.count, 1); - stmt.finalize(); + do_check_false(yield promiseIsURIVisited(place.uri)); + placesResult = yield promiseUpdatePlaces(place); + if (placesResult.errors.length > 0) { + do_throw("Unexpected error."); + } + let placeInfo = placesResult.results[0]; + do_check_true(yield promiseIsURIVisited(place.uri)); - promiseAsyncUpdates().then(run_next_test); - })); - })); + // Though the visit will not contain the referrer, we must examine the + // database to be sure. + do_check_eq(placeInfo.visits[0].referrerURI, null); + let stmt = DBConn().createStatement( + "SELECT COUNT(1) AS count " + + "FROM moz_historyvisits " + + "WHERE place_id = (SELECT id FROM moz_places WHERE url = :page_url) " + + "AND from_visit = 0 " + ); + stmt.params.page_url = place.uri.spec; + do_check_true(stmt.executeStep()); + do_check_eq(stmt.row.count, 1); + stmt.finalize(); + + yield promiseAsyncUpdates(); } function test_place_id_ignored() @@ -689,34 +671,36 @@ function test_place_id_ignored() ], }; - do_check_false(gGlobalHistory.isVisited(place.uri)); - gHistory.updatePlaces(place, expectHandleResult(function(aPlaceInfo) { - do_check_true(gGlobalHistory.isVisited(place.uri)); + do_check_false(yield promiseIsURIVisited(place.uri)); + let placesResult = yield promiseUpdatePlaces(place); + if (placesResult.errors.length > 0) { + do_throw("Unexpected error."); + } + let placeInfo = placesResult.results[0]; + do_check_true(yield promiseIsURIVisited(place.uri)); - let placeId = aPlaceInfo.placeId; - do_check_neq(placeId, 0); + let placeId = placeInfo.placeId; + do_check_neq(placeId, 0); - let badPlace = { - uri: NetUtil.newURI(TEST_DOMAIN + "test_place_id_ignored_second"), - visits: [ - new VisitInfo(), - ], - placeId: placeId, - }; + let badPlace = { + uri: NetUtil.newURI(TEST_DOMAIN + "test_place_id_ignored_second"), + visits: [ + new VisitInfo(), + ], + placeId: placeId, + }; - do_check_false(gGlobalHistory.isVisited(badPlace.uri)); - gHistory.updatePlaces(badPlace, { - handleResult: function handleResult(aPlaceInfo) { - do_check_neq(aPlaceInfo.placeId, placeId); - do_check_true(gGlobalHistory.isVisited(badPlace.uri)); + do_check_false(yield promiseIsURIVisited(badPlace.uri)); + placesResult = yield promiseUpdatePlaces(badPlace); + if (placesResult.errors.length > 0) { + do_throw("Unexpected error."); + } + placeInfo = placesResult.results[0]; - promiseAsyncUpdates().then(run_next_test); - }, - handleError: function handleError(aResultCode) { - do_throw("Unexpected error: " + aResultCode); - } - }); - })); + do_check_neq(placeInfo.placeId, placeId); + do_check_true(yield promiseIsURIVisited(badPlace.uri)); + + yield promiseAsyncUpdates(); } function test_handleCompletion_called_when_complete() @@ -738,29 +722,27 @@ function test_handleCompletion_called_when_complete() ], }, ]; - do_check_false(gGlobalHistory.isVisited(places[0].uri)); - do_check_false(gGlobalHistory.isVisited(places[1].uri)); + do_check_false(yield promiseIsURIVisited(places[0].uri)); + do_check_false(yield promiseIsURIVisited(places[1].uri)); const EXPECTED_COUNT_SUCCESS = 2; const EXPECTED_COUNT_FAILURE = 1; let callbackCountSuccess = 0; let callbackCountFailure = 0; - gHistory.updatePlaces(places, { - handleResult: function handleResult(aPlaceInfo) { - let checker = PlacesUtils.history.canAddURI(aPlaceInfo.uri) ? - do_check_true : do_check_false; - callbackCountSuccess++; - }, - handleError: function handleError(aResultCode, aPlaceInfo) { - callbackCountFailure++; - }, - handleCompletion: function handleCompletion() { - do_check_eq(callbackCountSuccess, EXPECTED_COUNT_SUCCESS); - do_check_eq(callbackCountFailure, EXPECTED_COUNT_FAILURE); - promiseAsyncUpdates().then(run_next_test); - }, - }); + let placesResult = yield promiseUpdatePlaces(places); + for (let place of placesResult.results) { + let checker = PlacesUtils.history.canAddURI(place.uri) ? + do_check_true : do_check_false; + callbackCountSuccess++; + } + for (let error of placesResult.errors) { + callbackCountFailure++; + } + + do_check_eq(callbackCountSuccess, EXPECTED_COUNT_SUCCESS); + do_check_eq(callbackCountFailure, EXPECTED_COUNT_FAILURE); + yield promiseAsyncUpdates(); } function test_add_visit() @@ -776,19 +758,23 @@ function test_add_visit() transitionType++) { place.visits.push(new VisitInfo(transitionType, VISIT_TIME)); } - do_check_false(gGlobalHistory.isVisited(place.uri)); + do_check_false(yield promiseIsURIVisited(place.uri)); let callbackCount = 0; - gHistory.updatePlaces(place, expectHandleResult(function(aPlaceInfo) { - do_check_true(gGlobalHistory.isVisited(place.uri)); + let placesResult = yield promiseUpdatePlaces(place); + if (placesResult.errors.length > 0) { + do_throw("Unexpected error."); + } + for (let placeInfo of placesResult.results) { + do_check_true(yield promiseIsURIVisited(place.uri)); // Check mozIPlaceInfo properties. - do_check_true(place.uri.equals(aPlaceInfo.uri)); - do_check_eq(aPlaceInfo.frecency, -1); // We don't pass frecency here! - do_check_eq(aPlaceInfo.title, place.title); + do_check_true(place.uri.equals(placeInfo.uri)); + do_check_eq(placeInfo.frecency, -1); // We don't pass frecency here! + do_check_eq(placeInfo.title, place.title); // Check mozIVisitInfo properties. - let visits = aPlaceInfo.visits; + let visits = placeInfo.visits; do_check_eq(visits.length, 1); let visit = visits[0]; do_check_eq(visit.visitDate, VISIT_TIME); @@ -800,8 +786,8 @@ function test_add_visit() // undefined. if (visit.transitionType == TRANSITION_EMBED) { // Check mozIPlaceInfo properties. - do_check_eq(aPlaceInfo.placeId, 0, '//'); - do_check_eq(aPlaceInfo.guid, null); + do_check_eq(placeInfo.placeId, 0, '//'); + do_check_eq(placeInfo.guid, null); // Check mozIVisitInfo properties. do_check_eq(visit.visitId, 0); @@ -810,8 +796,8 @@ function test_add_visit() // But they should be valid for non-embed visits. else { // Check mozIPlaceInfo properties. - do_check_true(aPlaceInfo.placeId > 0); - do_check_valid_places_guid(aPlaceInfo.guid); + do_check_true(placeInfo.placeId > 0); + do_check_valid_places_guid(placeInfo.guid); // Check mozIVisitInfo properties. do_check_true(visit.visitId > 0); @@ -820,9 +806,9 @@ function test_add_visit() // If we have had all of our callbacks, continue running tests. if (++callbackCount == place.visits.length) { - promiseAsyncUpdates().then(run_next_test); + yield promiseAsyncUpdates(); } - })); + } } function test_properties_saved() @@ -840,15 +826,19 @@ function test_properties_saved() new VisitInfo(transitionType), ], }; - do_check_false(gGlobalHistory.isVisited(place.uri)); + do_check_false(yield promiseIsURIVisited(place.uri)); places.push(place); } let callbackCount = 0; - gHistory.updatePlaces(places, expectHandleResult(function(aPlaceInfo) { - let uri = aPlaceInfo.uri; - do_check_true(gGlobalHistory.isVisited(uri)); - let visit = aPlaceInfo.visits[0]; + let placesResult = yield promiseUpdatePlaces(places); + if (placesResult.errors.length > 0) { + do_throw("Unexpected error."); + } + for (let placeInfo of placesResult.results) { + let uri = placeInfo.uri; + do_check_true(yield promiseIsURIVisited(uri)); + let visit = placeInfo.visits[0]; print("TEST-INFO | test_properties_saved | updatePlaces callback for " + "transition type " + visit.transitionType); @@ -908,16 +898,16 @@ function test_properties_saved() "AND h.title = :title " ); stmt.params.page_url = uri.spec; - stmt.params.title = aPlaceInfo.title; + stmt.params.title = placeInfo.title; do_check_true(stmt.executeStep()); do_check_eq(stmt.row.count, EXPECTED_COUNT); stmt.finalize(); // If we have had all of our callbacks, continue running tests. if (++callbackCount == places.length) { - promiseAsyncUpdates().then(run_next_test); + yield promiseAsyncUpdates(); } - })); + } } function test_guid_saved() @@ -930,15 +920,18 @@ function test_guid_saved() ], }; do_check_valid_places_guid(place.guid); - do_check_false(gGlobalHistory.isVisited(place.uri)); + do_check_false(yield promiseIsURIVisited(place.uri)); - gHistory.updatePlaces(place, expectHandleResult(function(aPlaceInfo) { - let uri = aPlaceInfo.uri; - do_check_true(gGlobalHistory.isVisited(uri)); - do_check_eq(aPlaceInfo.guid, place.guid); - do_check_guid_for_uri(uri, place.guid); - promiseAsyncUpdates().then(run_next_test); - })); + let placesResult = yield promiseUpdatePlaces(place); + if (placesResult.errors.length > 0) { + do_throw("Unexpected error."); + } + let placeInfo = placesResult.results[0]; + let uri = placeInfo.uri; + do_check_true(yield promiseIsURIVisited(uri)); + do_check_eq(placeInfo.guid, place.guid); + do_check_guid_for_uri(uri, place.guid); + yield promiseAsyncUpdates(); } function test_referrer_saved() @@ -956,43 +949,46 @@ function test_referrer_saved() }, ]; places[1].visits[0].referrerURI = places[0].uri; - do_check_false(gGlobalHistory.isVisited(places[0].uri)); - do_check_false(gGlobalHistory.isVisited(places[1].uri)); + do_check_false(yield promiseIsURIVisited(places[0].uri)); + do_check_false(yield promiseIsURIVisited(places[1].uri)); - let callbackCount = 0; + let resultCount = 0; let referrerSessionId; - gHistory.updatePlaces(places, expectHandleResult(function(aPlaceInfo) { - let uri = aPlaceInfo.uri; - do_check_true(gGlobalHistory.isVisited(uri)); - let visit = aPlaceInfo.visits[0]; + let placesResult = yield promiseUpdatePlaces(places); + if (placesResult.errors.length > 0) { + do_throw("Unexpected error."); + } + for (let placeInfo of placesResult.results) { + let uri = placeInfo.uri; + do_check_true(yield promiseIsURIVisited(uri)); + let visit = placeInfo.visits[0]; // We need to insert all of our visits before we can test conditions. - if (++callbackCount != places.length) { + if (++resultCount != places.length) { referrerSessionId = visit.sessionId; - return; - } + } else { + do_check_true(places[0].uri.equals(visit.referrerURI)); + do_check_eq(visit.sessionId, referrerSessionId); - do_check_true(places[0].uri.equals(visit.referrerURI)); - do_check_eq(visit.sessionId, referrerSessionId); - - let stmt = DBConn().createStatement( - "SELECT COUNT(1) AS count " + - "FROM moz_historyvisits " + - "WHERE place_id = (SELECT id FROM moz_places WHERE url = :page_url) " + - "AND from_visit = ( " + - "SELECT id " + + let stmt = DBConn().createStatement( + "SELECT COUNT(1) AS count " + "FROM moz_historyvisits " + - "WHERE place_id = (SELECT id FROM moz_places WHERE url = :referrer) " + - ") " - ); - stmt.params.page_url = uri.spec; - stmt.params.referrer = visit.referrerURI.spec; - do_check_true(stmt.executeStep()); - do_check_eq(stmt.row.count, 1); - stmt.finalize(); + "WHERE place_id = (SELECT id FROM moz_places WHERE url = :page_url) " + + "AND from_visit = ( " + + "SELECT id " + + "FROM moz_historyvisits " + + "WHERE place_id = (SELECT id FROM moz_places WHERE url = :referrer) " + + ") " + ); + stmt.params.page_url = uri.spec; + stmt.params.referrer = visit.referrerURI.spec; + do_check_true(stmt.executeStep()); + do_check_eq(stmt.row.count, 1); + stmt.finalize(); - promiseAsyncUpdates().then(run_next_test); - })); + yield promiseAsyncUpdates(); + } + } } function test_sessionId_saved() @@ -1004,29 +1000,32 @@ function test_sessionId_saved() ], }; place.visits[0].sessionId = 3; - do_check_false(gGlobalHistory.isVisited(place.uri)); + do_check_false(yield promiseIsURIVisited(place.uri)); - gHistory.updatePlaces(place, expectHandleResult(function(aPlaceInfo) { - let uri = aPlaceInfo.uri; - do_check_true(gGlobalHistory.isVisited(uri)); + let placesResult = yield promiseUpdatePlaces(place); + if (placesResult.errors.length > 0) { + do_throw("Unexpected error."); + } + let placeInfo = placesResult.results[0]; + let uri = placeInfo.uri; + do_check_true(yield promiseIsURIVisited(uri)); - let visit = aPlaceInfo.visits[0]; - do_check_eq(visit.sessionId, place.visits[0].sessionId); + let visit = placeInfo.visits[0]; + do_check_eq(visit.sessionId, place.visits[0].sessionId); - let stmt = DBConn().createStatement( - "SELECT COUNT(1) AS count " + - "FROM moz_historyvisits " + - "WHERE place_id = (SELECT id FROM moz_places WHERE url = :page_url) " + - "AND session = :session_id " - ); - stmt.params.page_url = uri.spec; - stmt.params.session_id = visit.sessionId; - do_check_true(stmt.executeStep()); - do_check_eq(stmt.row.count, 1); - stmt.finalize(); + let stmt = DBConn().createStatement( + "SELECT COUNT(1) AS count " + + "FROM moz_historyvisits " + + "WHERE place_id = (SELECT id FROM moz_places WHERE url = :page_url) " + + "AND session = :session_id " + ); + stmt.params.page_url = uri.spec; + stmt.params.session_id = visit.sessionId; + do_check_true(stmt.executeStep()); + do_check_eq(stmt.row.count, 1); + stmt.finalize(); - promiseAsyncUpdates().then(run_next_test); - })); + yield promiseAsyncUpdates(); } function test_guid_change_saved() @@ -1038,19 +1037,22 @@ function test_guid_change_saved() new VisitInfo(), ], }; - do_check_false(gGlobalHistory.isVisited(place.uri)); + do_check_false(yield promiseIsURIVisited(place.uri)); - gHistory.updatePlaces(place, expectHandleResult(function(aPlaceInfo) { + let placesResult = yield promiseUpdatePlaces(place); + if (placesResult.errors.length > 0) { + do_throw("Unexpected error."); + } + // Then, change the guid with visits. + place.guid = "_GUIDCHANGE_"; + place.visits = [new VisitInfo()]; + placesResult = yield promiseUpdatePlaces(place); + if (placesResult.errors.length > 0) { + do_throw("Unexpected error."); + } + do_check_guid_for_uri(place.uri, place.guid); - // Then, change the guid with visits. - place.guid = "_GUIDCHANGE_"; - place.visits = [new VisitInfo()]; - gHistory.updatePlaces(place, expectHandleResult(function(aPlaceInfo) { - do_check_guid_for_uri(place.uri, place.guid); - - promiseAsyncUpdates().then(run_next_test); - })); - })); + yield promiseAsyncUpdates(); } function test_title_change_saved() @@ -1063,33 +1065,41 @@ function test_title_change_saved() new VisitInfo(), ], }; - do_check_false(gGlobalHistory.isVisited(place.uri)); + do_check_false(yield promiseIsURIVisited(place.uri)); - gHistory.updatePlaces(place, expectHandleResult(function(aPlaceInfo) { + let placesResult = yield promiseUpdatePlaces(place); + if (placesResult.errors.length > 0) { + do_throw("Unexpected error."); + } - // Now, make sure the empty string clears the title. - place.title = ""; - place.visits = [new VisitInfo()]; - gHistory.updatePlaces(place, expectHandleResult(function(aPlaceInfo) { - do_check_title_for_uri(place.uri, null); + // Now, make sure the empty string clears the title. + place.title = ""; + place.visits = [new VisitInfo()]; + placesResult = yield promiseUpdatePlaces(place); + if (placesResult.errors.length > 0) { + do_throw("Unexpected error."); + } + do_check_title_for_uri(place.uri, null); - // Then, change the title with visits. - place.title = "title change"; - place.visits = [new VisitInfo()]; - gHistory.updatePlaces(place, expectHandleResult(function(aPlaceInfo) { - do_check_title_for_uri(place.uri, place.title); + // Then, change the title with visits. + place.title = "title change"; + place.visits = [new VisitInfo()]; + placesResult = yield promiseUpdatePlaces(place); + if (placesResult.errors.length > 0) { + do_throw("Unexpected error."); + } + do_check_title_for_uri(place.uri, place.title); - // Lastly, check that the title is cleared if we set it to null. - place.title = null; - place.visits = [new VisitInfo()]; - gHistory.updatePlaces(place, expectHandleResult(function(aPlaceInfo) { - do_check_title_for_uri(place.uri, place.title); + // Lastly, check that the title is cleared if we set it to null. + place.title = null; + place.visits = [new VisitInfo()]; + placesResult = yield promiseUpdatePlaces(place); + if (placesResult.errors.length > 0) { + do_throw("Unexpected error."); + } + do_check_title_for_uri(place.uri, place.title); - promiseAsyncUpdates().then(run_next_test); - })); - })); - })); - })); + yield promiseAsyncUpdates(); } function test_no_title_does_not_clear_title() @@ -1103,18 +1113,22 @@ function test_no_title_does_not_clear_title() new VisitInfo(), ], }; - do_check_false(gGlobalHistory.isVisited(place.uri)); + do_check_false(yield promiseIsURIVisited(place.uri)); - gHistory.updatePlaces(place, expectHandleResult(function(aPlaceInfo) { - // Now, make sure that not specifying a title does not clear it. - delete place.title; - place.visits = [new VisitInfo()]; - gHistory.updatePlaces(place, expectHandleResult(function(aPlaceInfo) { - do_check_title_for_uri(place.uri, TITLE); + let placesResult = yield promiseUpdatePlaces(place); + if (placesResult.errors.length > 0) { + do_throw("Unexpected error."); + } + // Now, make sure that not specifying a title does not clear it. + delete place.title; + place.visits = [new VisitInfo()]; + placesResult = yield promiseUpdatePlaces(place); + if (placesResult.errors.length > 0) { + do_throw("Unexpected error."); + } + do_check_title_for_uri(place.uri, TITLE); - promiseAsyncUpdates().then(run_next_test); - })); - })); + yield promiseAsyncUpdates(); } function test_title_change_notifies() @@ -1127,7 +1141,7 @@ function test_title_change_notifies() new VisitInfo(), ], }; - do_check_false(gGlobalHistory.isVisited(place.uri)); + do_check_false(yield promiseIsURIVisited(place.uri)); let silentObserver = new TitleChangedObserver(place.uri, "DO NOT WANT", function() { @@ -1135,31 +1149,43 @@ function test_title_change_notifies() }); PlacesUtils.history.addObserver(silentObserver, false); - gHistory.updatePlaces(place); + let placesResult = yield promiseUpdatePlaces(place); + if (placesResult.errors.length > 0) { + do_throw("Unexpected error."); + } // The second case to test is that we get the notification when we add // it for the first time. The first case will fail before our callback if it // is busted, so we can do this now. place.uri = NetUtil.newURI(place.uri.spec + "/new-visit-with-title"); place.title = "title 1"; - let callbackCount = 0; - let observer = new TitleChangedObserver(place.uri, place.title, function() { - switch (++callbackCount) { - case 1: - // The third case to test is to make sure we get a notification when we - // change an existing place. - observer.expectedTitle = place.title = "title 2"; - place.visits = [new VisitInfo()]; - gHistory.updatePlaces(place); - break; - case 2: - PlacesUtils.history.removeObserver(silentObserver); - PlacesUtils.history.removeObserver(observer); - promiseAsyncUpdates().then(run_next_test); - }; - }); - PlacesUtils.history.addObserver(observer, false); - gHistory.updatePlaces(place); + function promiseTitleChangedObserver(aPlace) { + let deferred = Promise.defer(); + let callbackCount = 0; + let observer = new TitleChangedObserver(aPlace.uri, aPlace.title, function() { + switch (++callbackCount) { + case 1: + // The third case to test is to make sure we get a notification when + // we change an existing place. + observer.expectedTitle = place.title = "title 2"; + place.visits = [new VisitInfo()]; + PlacesUtils.asyncHistory.updatePlaces(place); + break; + case 2: + PlacesUtils.history.removeObserver(silentObserver); + PlacesUtils.history.removeObserver(observer); + deferred.resolve(); + break; + }; + }); + + PlacesUtils.history.addObserver(observer, false); + PlacesUtils.asyncHistory.updatePlaces(aPlace); + return deferred.promise; + } + + yield promiseTitleChangedObserver(place); + yield promiseAsyncUpdates(); } function test_visit_notifies() @@ -1173,35 +1199,42 @@ function test_visit_notifies() new VisitInfo(), ], }; - do_check_false(gGlobalHistory.isVisited(place.uri)); + do_check_false(yield promiseIsURIVisited(place.uri)); - let callbackCount = 0; - let finisher = function() { - if (++callbackCount == 2) { - promiseAsyncUpdates().then(run_next_test); + function promiseVisitObserver(aPlace) { + let deferred = Promise.defer(); + let callbackCount = 0; + let finisher = function() { + if (++callbackCount == 2) { + deferred.resolve(); + } } + let visitObserver = new VisitObserver(place.uri, place.guid, + function(aVisitDate, + aTransitionType) { + let visit = place.visits[0]; + do_check_eq(visit.visitDate, aVisitDate); + do_check_eq(visit.transitionType, aTransitionType); + + PlacesUtils.history.removeObserver(visitObserver); + finisher(); + }); + PlacesUtils.history.addObserver(visitObserver, false); + let observer = function(aSubject, aTopic, aData) { + do_log_info("observe(" + aSubject + ", " + aTopic + ", " + aData + ")"); + do_check_true(aSubject instanceof Ci.nsIURI); + do_check_true(aSubject.equals(place.uri)); + + Services.obs.removeObserver(observer, URI_VISIT_SAVED); + finisher(); + }; + Services.obs.addObserver(observer, URI_VISIT_SAVED, false); + PlacesUtils.asyncHistory.updatePlaces(place); + return deferred.promise; } - let visitObserver = new VisitObserver(place.uri, place.guid, - function(aVisitDate, - aTransitionType) { - let visit = place.visits[0]; - do_check_eq(visit.visitDate, aVisitDate); - do_check_eq(visit.transitionType, aTransitionType); - PlacesUtils.history.removeObserver(visitObserver); - finisher(); - }); - PlacesUtils.history.addObserver(visitObserver, false); - let observer = function(aSubject, aTopic, aData) { - do_log_info("observe(" + aSubject + ", " + aTopic + ", " + aData + ")"); - do_check_true(aSubject instanceof Ci.nsIURI); - do_check_true(aSubject.equals(place.uri)); - - Services.obs.removeObserver(observer, URI_VISIT_SAVED); - finisher(); - }; - Services.obs.addObserver(observer, URI_VISIT_SAVED, false); - gHistory.updatePlaces(place); + yield promiseVisitObserver(place); + yield promiseAsyncUpdates(); } function test_referrer_sessionId_persists() @@ -1217,30 +1250,36 @@ function test_referrer_sessionId_persists() // First we add the referrer visit, and then the main visit with referrer // attached. We ensure that the sessionId is maintained across the updates. - do_check_false(gGlobalHistory.isVisited(referrerPlace.uri)); - gHistory.updatePlaces(referrerPlace, expectHandleResult(function(aPlaceInfo) { - do_check_true(gGlobalHistory.isVisited(referrerPlace.uri)); + do_check_false(yield promiseIsURIVisited(referrerPlace.uri)); + let placesResult = yield promiseUpdatePlaces(referrerPlace); + if (placesResult.errors.length > 0) { + do_throw("Unexpected error."); + } + let placeInfo = placesResult.results[0]; + do_check_true(yield promiseIsURIVisited(referrerPlace.uri)); - let sessionId = aPlaceInfo.visits[0].sessionId; - do_check_neq(sessionId, null); + let sessionId = placeInfo.visits[0].sessionId; + do_check_neq(sessionId, null); - let place = { - uri: NetUtil.newURI(TEST_DOMAIN + "test_referrer_sessionId_persists"), - visits: [ - new VisitInfo(), - ], - }; - place.visits[0].referrerURI = referrerPlace.uri; + let place = { + uri: NetUtil.newURI(TEST_DOMAIN + "test_referrer_sessionId_persists"), + visits: [ + new VisitInfo(), + ], + }; + place.visits[0].referrerURI = referrerPlace.uri; - do_check_false(gGlobalHistory.isVisited(place.uri)); - gHistory.updatePlaces(place, expectHandleResult(function(aPlaceInfo) { - do_check_true(gGlobalHistory.isVisited(place.uri)); + do_check_false(yield promiseIsURIVisited(place.uri)); + placesResult = yield promiseUpdatePlaces(place); + if (placesResult.errors.length > 0) { + do_throw("Unexpected error."); + } + placeInfo = placesResult.results[0]; + do_check_true(yield promiseIsURIVisited(place.uri)); - do_check_eq(aPlaceInfo.visits[0].sessionId, sessionId); + do_check_eq(placeInfo.visits[0].sessionId, sessionId); - promiseAsyncUpdates().then(run_next_test); - })); - })); + yield promiseAsyncUpdates(); } // test with empty mozIVisitInfoCallback object @@ -1269,9 +1308,9 @@ function test_callbacks_not_supplied() do_log_info("Could not construct URI for '" + url + "'; ignoring"); } }); - - gHistory.updatePlaces(places, {}); - promiseAsyncUpdates().then(run_next_test); + + PlacesUtils.asyncHistory.updatePlaces(places, {}); + yield promiseAsyncUpdates(); } //////////////////////////////////////////////////////////////////////////////// @@ -1309,7 +1348,7 @@ function test_callbacks_not_supplied() test_visit_notifies, test_referrer_sessionId_persists, test_callbacks_not_supplied, -].forEach(add_test); +].forEach(add_task); function run_test() { diff --git a/toolkit/components/places/tests/unit/test_preventive_maintenance.js b/toolkit/components/places/tests/unit/test_preventive_maintenance.js index 721cdd7025b9..0b0ecedd8907 100644 --- a/toolkit/components/places/tests/unit/test_preventive_maintenance.js +++ b/toolkit/components/places/tests/unit/test_preventive_maintenance.js @@ -17,7 +17,6 @@ const FINISHED_MAINTENANCE_NOTIFICATION_TOPIC = "places-maintenance-finished"; // Get services and database connection let hs = PlacesUtils.history; -let bh = PlacesUtils.bhistory; let bs = PlacesUtils.bookmarks; let ts = PlacesUtils.tagging; let as = PlacesUtils.annotations; @@ -1289,24 +1288,28 @@ tests.push({ asyncCheck: function (aCallback) { // Check that all items are correct - do_check_true(bh.isVisited(this._uri1)); - do_check_true(bh.isVisited(this._uri2)); + PlacesUtils.asyncHistory.isURIVisited(this._uri1, function(aURI, aIsVisited) { + do_check_true(aIsVisited); + PlacesUtils.asyncHistory.isURIVisited(this._uri2, function(aURI, aIsVisited) { + do_check_true(aIsVisited); - do_check_eq(bs.getBookmarkURI(this._bookmarkId).spec, this._uri1.spec); - do_check_eq(bs.getItemIndex(this._folderId), 0); + do_check_eq(bs.getBookmarkURI(this._bookmarkId).spec, this._uri1.spec); + do_check_eq(bs.getItemIndex(this._folderId), 0); - do_check_eq(bs.getItemType(this._folderId), bs.TYPE_FOLDER); - do_check_eq(bs.getItemType(this._separatorId), bs.TYPE_SEPARATOR); + do_check_eq(bs.getItemType(this._folderId), bs.TYPE_FOLDER); + do_check_eq(bs.getItemType(this._separatorId), bs.TYPE_SEPARATOR); - do_check_eq(ts.getTagsForURI(this._uri1).length, 1); - do_check_eq(bs.getKeywordForBookmark(this._bookmarkId), "testkeyword"); - do_check_eq(as.getPageAnnotation(this._uri2, "anno"), "anno"); - do_check_eq(as.getItemAnnotation(this._bookmarkId, "anno"), "anno"); + do_check_eq(ts.getTagsForURI(this._uri1).length, 1); + do_check_eq(bs.getKeywordForBookmark(this._bookmarkId), "testkeyword"); + do_check_eq(as.getPageAnnotation(this._uri2, "anno"), "anno"); + do_check_eq(as.getItemAnnotation(this._bookmarkId, "anno"), "anno"); - fs.getFaviconURLForPage(this._uri2, function (aFaviconURI) { - do_check_true(aFaviconURI.equals(SMALLPNG_DATA_URI)); - aCallback(); - }); + fs.getFaviconURLForPage(this._uri2, function (aFaviconURI) { + do_check_true(aFaviconURI.equals(SMALLPNG_DATA_URI)); + aCallback(); + }); + }.bind(this)); + }.bind(this)); } }); diff --git a/toolkit/components/places/tests/unit/test_removeVisitsByTimeframe.js b/toolkit/components/places/tests/unit/test_removeVisitsByTimeframe.js index f287476c4afa..2005aa1d9476 100644 --- a/toolkit/components/places/tests/unit/test_removeVisitsByTimeframe.js +++ b/toolkit/components/places/tests/unit/test_removeVisitsByTimeframe.js @@ -46,14 +46,15 @@ var tests = [ } resultRoot.containerOpen = false; - print("nsIGlobalHistory2.isVisited should return true."); - do_check_true(histsvc.QueryInterface(Ci.nsIGlobalHistory2). - isVisited(TEST_URI)); + print("asyncHistory.isURIVisited should return true."); + PlacesUtils.asyncHistory.isURIVisited(TEST_URI, function(aURI, aIsVisited) { + do_check_true(aIsVisited); - promiseAsyncUpdates().then(function () { - print("Frecency should be positive.") - do_check_true(frecencyForUrl(TEST_URI) > 0); - run_next_test(); + promiseAsyncUpdates().then(function () { + print("Frecency should be positive.") + do_check_true(frecencyForUrl(TEST_URI) > 0); + run_next_test(); + }); }); } }, @@ -98,14 +99,15 @@ var tests = [ } resultRoot.containerOpen = false; - print("nsIGlobalHistory2.isVisited should return true."); - do_check_true(histsvc.QueryInterface(Ci.nsIGlobalHistory2). - isVisited(TEST_URI)); + print("asyncHistory.isURIVisited should return true."); + PlacesUtils.asyncHistory.isURIVisited(TEST_URI, function(aURI, aIsVisited) { + do_check_true(aIsVisited); - promiseAsyncUpdates().then(function () { - print("Frecency should be positive.") - do_check_true(frecencyForUrl(TEST_URI) > 0); - run_next_test(); + promiseAsyncUpdates().then(function () { + print("Frecency should be positive.") + do_check_true(frecencyForUrl(TEST_URI) > 0); + run_next_test(); + }); }); } }, @@ -143,14 +145,15 @@ var tests = [ } resultRoot.containerOpen = false; - print("nsIGlobalHistory2.isVisited should return true."); - do_check_true(histsvc.QueryInterface(Ci.nsIGlobalHistory2). - isVisited(TEST_URI)); + print("asyncHistory.isURIVisited should return true."); + PlacesUtils.asyncHistory.isURIVisited(TEST_URI, function(aURI, aIsVisited) { + do_check_true(aIsVisited); - promiseAsyncUpdates().then(function () { - print("Frecency should be positive.") - do_check_true(frecencyForUrl(TEST_URI) > 0); - run_next_test(); + promiseAsyncUpdates().then(function () { + print("Frecency should be positive.") + do_check_true(frecencyForUrl(TEST_URI) > 0); + run_next_test(); + }); }); } }, @@ -195,14 +198,15 @@ var tests = [ } resultRoot.containerOpen = false; - print("nsIGlobalHistory2.isVisited should return true."); - do_check_true(histsvc.QueryInterface(Ci.nsIGlobalHistory2). - isVisited(TEST_URI)); + print("asyncHistory.isURIVisited should return true."); + PlacesUtils.asyncHistory.isURIVisited(TEST_URI, function(aURI, aIsVisited) { + do_check_true(aIsVisited); - promiseAsyncUpdates().then(function () { - print("Frecency should be positive.") - do_check_true(frecencyForUrl(TEST_URI) > 0); - run_next_test(); + promiseAsyncUpdates().then(function () { + print("Frecency should be positive.") + do_check_true(frecencyForUrl(TEST_URI) > 0); + run_next_test(); + }); }); } }, @@ -235,10 +239,11 @@ var tests = [ do_check_eq(resultRoot.childCount, 0); resultRoot.containerOpen = false; - print("nsIGlobalHistory2.isVisited should return false."); - do_check_false(histsvc.QueryInterface(Ci.nsIGlobalHistory2). - isVisited(TEST_URI)); - run_next_test(); + print("asyncHistory.isURIVisited should return false."); + PlacesUtils.asyncHistory.isURIVisited(TEST_URI, function(aURI, aIsVisited) { + do_check_false(aIsVisited); + run_next_test(); + }); } }, @@ -270,14 +275,15 @@ var tests = [ do_check_eq(resultRoot.childCount, 0); resultRoot.containerOpen = false; - print("nsIGlobalHistory2.isVisited should return false."); - do_check_false(histsvc.QueryInterface(Ci.nsIGlobalHistory2). - isVisited(PLACE_URI)); + print("asyncHistory.isURIVisited should return false."); + PlacesUtils.asyncHistory.isURIVisited(PLACE_URI, function(aURI, aIsVisited) { + do_check_false(aIsVisited); - promiseAsyncUpdates().then(function () { - print("Frecency should be zero.") - do_check_eq(frecencyForUrl(PLACE_URL), 0); - run_next_test(); + promiseAsyncUpdates().then(function () { + print("Frecency should be zero.") + do_check_eq(frecencyForUrl(PLACE_URL), 0); + run_next_test(); + }); }); } }, @@ -317,17 +323,18 @@ var tests = [ do_check_eq(resultRoot.childCount, 0); resultRoot.containerOpen = false; - print("nsIGlobalHistory2.isVisited should return false."); - do_check_false(histsvc.QueryInterface(Ci.nsIGlobalHistory2). - isVisited(TEST_URI)); + print("asyncHistory.isURIVisited should return false."); + PlacesUtils.asyncHistory.isURIVisited(TEST_URI, function(aURI, aIsVisited) { + do_check_false(aIsVisited); - print("nsINavBookmarksService.isBookmarked should return true."); - do_check_true(bmsvc.isBookmarked(TEST_URI)); + print("nsINavBookmarksService.isBookmarked should return true."); + do_check_true(bmsvc.isBookmarked(TEST_URI)); - promiseAsyncUpdates().then(function () { - print("Frecency should be negative.") - do_check_true(frecencyForUrl(TEST_URI) < 0); - run_next_test(); + promiseAsyncUpdates().then(function () { + print("Frecency should be negative.") + do_check_true(frecencyForUrl(TEST_URI) < 0); + run_next_test(); + }); }); } },