1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/expiration/test_analyze_runs.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,125 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +//////////////////////////////////////////////////////////////////////////////// 1.8 +//// Constants 1.9 + 1.10 +const TOPIC_AUTOCOMPLETE_FEEDBACK_INCOMING = "autocomplete-will-enter-text"; 1.11 + 1.12 +//////////////////////////////////////////////////////////////////////////////// 1.13 +//// Helpers 1.14 + 1.15 +/** 1.16 + * Ensures that we have no data in the tables created by ANALYZE. 1.17 + */ 1.18 +function clearAnalyzeData() 1.19 +{ 1.20 + let db = DBConn(); 1.21 + if (!db.tableExists("sqlite_stat1")) { 1.22 + return; 1.23 + } 1.24 + db.executeSimpleSQL("DELETE FROM sqlite_stat1"); 1.25 +} 1.26 + 1.27 +/** 1.28 + * Checks that we ran ANALYZE on the specified table. 1.29 + * 1.30 + * @param aTableName 1.31 + * The table to check if ANALYZE was ran. 1.32 + * @param aRan 1.33 + * True if it was expected to run, false otherwise 1.34 + */ 1.35 +function do_check_analyze_ran(aTableName, aRan) 1.36 +{ 1.37 + let db = DBConn(); 1.38 + do_check_true(db.tableExists("sqlite_stat1")); 1.39 + let stmt = db.createStatement("SELECT idx FROM sqlite_stat1 WHERE tbl = :table"); 1.40 + stmt.params.table = aTableName; 1.41 + try { 1.42 + if (aRan) { 1.43 + do_check_true(stmt.executeStep()); 1.44 + do_check_neq(stmt.row.idx, null); 1.45 + } 1.46 + else { 1.47 + do_check_false(stmt.executeStep()); 1.48 + } 1.49 + } 1.50 + finally { 1.51 + stmt.finalize(); 1.52 + } 1.53 +} 1.54 + 1.55 +//////////////////////////////////////////////////////////////////////////////// 1.56 +//// Tests 1.57 + 1.58 +function run_test() 1.59 +{ 1.60 + run_next_test(); 1.61 +} 1.62 + 1.63 +add_task(function init_tests() 1.64 +{ 1.65 + const TEST_URI = NetUtil.newURI("http://mozilla.org/"); 1.66 + const TEST_TITLE = "This is a test"; 1.67 + let bs = PlacesUtils.bookmarks; 1.68 + bs.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, TEST_URI, 1.69 + bs.DEFAULT_INDEX, TEST_TITLE); 1.70 + yield promiseAddVisits(TEST_URI); 1.71 + let thing = { 1.72 + QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompleteInput, 1.73 + Ci.nsIAutoCompletePopup, 1.74 + Ci.nsIAutoCompleteController]), 1.75 + get popup() { return thing; }, 1.76 + get controller() { return thing; }, 1.77 + popupOpen: true, 1.78 + selectedIndex: 0, 1.79 + getValueAt: function() { return TEST_URI.spec; }, 1.80 + searchString: TEST_TITLE, 1.81 + }; 1.82 + Services.obs.notifyObservers(thing, TOPIC_AUTOCOMPLETE_FEEDBACK_INCOMING, 1.83 + null); 1.84 +}); 1.85 + 1.86 +add_task(function test_timed() 1.87 +{ 1.88 + clearAnalyzeData(); 1.89 + 1.90 + // Set a low interval and wait for the timed expiration to start. 1.91 + let promise = promiseTopicObserved(PlacesUtils.TOPIC_EXPIRATION_FINISHED); 1.92 + setInterval(3); 1.93 + yield promise; 1.94 + setInterval(3600); 1.95 + 1.96 + do_check_analyze_ran("moz_places", false); 1.97 + do_check_analyze_ran("moz_bookmarks", false); 1.98 + do_check_analyze_ran("moz_historyvisits", false); 1.99 + do_check_analyze_ran("moz_inputhistory", true); 1.100 +}); 1.101 + 1.102 +add_task(function test_debug() 1.103 +{ 1.104 + clearAnalyzeData(); 1.105 + 1.106 + yield promiseForceExpirationStep(1); 1.107 + 1.108 + do_check_analyze_ran("moz_places", true); 1.109 + do_check_analyze_ran("moz_bookmarks", true); 1.110 + do_check_analyze_ran("moz_historyvisits", true); 1.111 + do_check_analyze_ran("moz_inputhistory", true); 1.112 +}); 1.113 + 1.114 +add_task(function test_clear_history() 1.115 +{ 1.116 + clearAnalyzeData(); 1.117 + 1.118 + let promise = promiseTopicObserved(PlacesUtils.TOPIC_EXPIRATION_FINISHED); 1.119 + let listener = Cc["@mozilla.org/places/expiration;1"] 1.120 + .getService(Ci.nsINavHistoryObserver); 1.121 + listener.onClearHistory(); 1.122 + yield promise; 1.123 + 1.124 + do_check_analyze_ran("moz_places", true); 1.125 + do_check_analyze_ran("moz_bookmarks", false); 1.126 + do_check_analyze_ran("moz_historyvisits", true); 1.127 + do_check_analyze_ran("moz_inputhistory", true); 1.128 +});