michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: //// Constants michael@0: michael@0: const TOPIC_AUTOCOMPLETE_FEEDBACK_INCOMING = "autocomplete-will-enter-text"; michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: //// Helpers michael@0: michael@0: /** michael@0: * Ensures that we have no data in the tables created by ANALYZE. michael@0: */ michael@0: function clearAnalyzeData() michael@0: { michael@0: let db = DBConn(); michael@0: if (!db.tableExists("sqlite_stat1")) { michael@0: return; michael@0: } michael@0: db.executeSimpleSQL("DELETE FROM sqlite_stat1"); michael@0: } michael@0: michael@0: /** michael@0: * Checks that we ran ANALYZE on the specified table. michael@0: * michael@0: * @param aTableName michael@0: * The table to check if ANALYZE was ran. michael@0: * @param aRan michael@0: * True if it was expected to run, false otherwise michael@0: */ michael@0: function do_check_analyze_ran(aTableName, aRan) michael@0: { michael@0: let db = DBConn(); michael@0: do_check_true(db.tableExists("sqlite_stat1")); michael@0: let stmt = db.createStatement("SELECT idx FROM sqlite_stat1 WHERE tbl = :table"); michael@0: stmt.params.table = aTableName; michael@0: try { michael@0: if (aRan) { michael@0: do_check_true(stmt.executeStep()); michael@0: do_check_neq(stmt.row.idx, null); michael@0: } michael@0: else { michael@0: do_check_false(stmt.executeStep()); michael@0: } michael@0: } michael@0: finally { michael@0: stmt.finalize(); michael@0: } michael@0: } michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: //// Tests michael@0: michael@0: function run_test() michael@0: { michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_task(function init_tests() michael@0: { michael@0: const TEST_URI = NetUtil.newURI("http://mozilla.org/"); michael@0: const TEST_TITLE = "This is a test"; michael@0: let bs = PlacesUtils.bookmarks; michael@0: bs.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, TEST_URI, michael@0: bs.DEFAULT_INDEX, TEST_TITLE); michael@0: yield promiseAddVisits(TEST_URI); michael@0: let thing = { michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompleteInput, michael@0: Ci.nsIAutoCompletePopup, michael@0: Ci.nsIAutoCompleteController]), michael@0: get popup() { return thing; }, michael@0: get controller() { return thing; }, michael@0: popupOpen: true, michael@0: selectedIndex: 0, michael@0: getValueAt: function() { return TEST_URI.spec; }, michael@0: searchString: TEST_TITLE, michael@0: }; michael@0: Services.obs.notifyObservers(thing, TOPIC_AUTOCOMPLETE_FEEDBACK_INCOMING, michael@0: null); michael@0: }); michael@0: michael@0: add_task(function test_timed() michael@0: { michael@0: clearAnalyzeData(); michael@0: michael@0: // Set a low interval and wait for the timed expiration to start. michael@0: let promise = promiseTopicObserved(PlacesUtils.TOPIC_EXPIRATION_FINISHED); michael@0: setInterval(3); michael@0: yield promise; michael@0: setInterval(3600); michael@0: michael@0: do_check_analyze_ran("moz_places", false); michael@0: do_check_analyze_ran("moz_bookmarks", false); michael@0: do_check_analyze_ran("moz_historyvisits", false); michael@0: do_check_analyze_ran("moz_inputhistory", true); michael@0: }); michael@0: michael@0: add_task(function test_debug() michael@0: { michael@0: clearAnalyzeData(); michael@0: michael@0: yield promiseForceExpirationStep(1); michael@0: michael@0: do_check_analyze_ran("moz_places", true); michael@0: do_check_analyze_ran("moz_bookmarks", true); michael@0: do_check_analyze_ran("moz_historyvisits", true); michael@0: do_check_analyze_ran("moz_inputhistory", true); michael@0: }); michael@0: michael@0: add_task(function test_clear_history() michael@0: { michael@0: clearAnalyzeData(); michael@0: michael@0: let promise = promiseTopicObserved(PlacesUtils.TOPIC_EXPIRATION_FINISHED); michael@0: let listener = Cc["@mozilla.org/places/expiration;1"] michael@0: .getService(Ci.nsINavHistoryObserver); michael@0: listener.onClearHistory(); michael@0: yield promise; michael@0: michael@0: do_check_analyze_ran("moz_places", true); michael@0: do_check_analyze_ran("moz_bookmarks", false); michael@0: do_check_analyze_ran("moz_historyvisits", true); michael@0: do_check_analyze_ran("moz_inputhistory", true); michael@0: });