Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 5 | //// Constants |
michael@0 | 6 | |
michael@0 | 7 | const TOPIC_AUTOCOMPLETE_FEEDBACK_INCOMING = "autocomplete-will-enter-text"; |
michael@0 | 8 | |
michael@0 | 9 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 10 | //// Helpers |
michael@0 | 11 | |
michael@0 | 12 | /** |
michael@0 | 13 | * Ensures that we have no data in the tables created by ANALYZE. |
michael@0 | 14 | */ |
michael@0 | 15 | function clearAnalyzeData() |
michael@0 | 16 | { |
michael@0 | 17 | let db = DBConn(); |
michael@0 | 18 | if (!db.tableExists("sqlite_stat1")) { |
michael@0 | 19 | return; |
michael@0 | 20 | } |
michael@0 | 21 | db.executeSimpleSQL("DELETE FROM sqlite_stat1"); |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | /** |
michael@0 | 25 | * Checks that we ran ANALYZE on the specified table. |
michael@0 | 26 | * |
michael@0 | 27 | * @param aTableName |
michael@0 | 28 | * The table to check if ANALYZE was ran. |
michael@0 | 29 | * @param aRan |
michael@0 | 30 | * True if it was expected to run, false otherwise |
michael@0 | 31 | */ |
michael@0 | 32 | function do_check_analyze_ran(aTableName, aRan) |
michael@0 | 33 | { |
michael@0 | 34 | let db = DBConn(); |
michael@0 | 35 | do_check_true(db.tableExists("sqlite_stat1")); |
michael@0 | 36 | let stmt = db.createStatement("SELECT idx FROM sqlite_stat1 WHERE tbl = :table"); |
michael@0 | 37 | stmt.params.table = aTableName; |
michael@0 | 38 | try { |
michael@0 | 39 | if (aRan) { |
michael@0 | 40 | do_check_true(stmt.executeStep()); |
michael@0 | 41 | do_check_neq(stmt.row.idx, null); |
michael@0 | 42 | } |
michael@0 | 43 | else { |
michael@0 | 44 | do_check_false(stmt.executeStep()); |
michael@0 | 45 | } |
michael@0 | 46 | } |
michael@0 | 47 | finally { |
michael@0 | 48 | stmt.finalize(); |
michael@0 | 49 | } |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 53 | //// Tests |
michael@0 | 54 | |
michael@0 | 55 | function run_test() |
michael@0 | 56 | { |
michael@0 | 57 | run_next_test(); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | add_task(function init_tests() |
michael@0 | 61 | { |
michael@0 | 62 | const TEST_URI = NetUtil.newURI("http://mozilla.org/"); |
michael@0 | 63 | const TEST_TITLE = "This is a test"; |
michael@0 | 64 | let bs = PlacesUtils.bookmarks; |
michael@0 | 65 | bs.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, TEST_URI, |
michael@0 | 66 | bs.DEFAULT_INDEX, TEST_TITLE); |
michael@0 | 67 | yield promiseAddVisits(TEST_URI); |
michael@0 | 68 | let thing = { |
michael@0 | 69 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompleteInput, |
michael@0 | 70 | Ci.nsIAutoCompletePopup, |
michael@0 | 71 | Ci.nsIAutoCompleteController]), |
michael@0 | 72 | get popup() { return thing; }, |
michael@0 | 73 | get controller() { return thing; }, |
michael@0 | 74 | popupOpen: true, |
michael@0 | 75 | selectedIndex: 0, |
michael@0 | 76 | getValueAt: function() { return TEST_URI.spec; }, |
michael@0 | 77 | searchString: TEST_TITLE, |
michael@0 | 78 | }; |
michael@0 | 79 | Services.obs.notifyObservers(thing, TOPIC_AUTOCOMPLETE_FEEDBACK_INCOMING, |
michael@0 | 80 | null); |
michael@0 | 81 | }); |
michael@0 | 82 | |
michael@0 | 83 | add_task(function test_timed() |
michael@0 | 84 | { |
michael@0 | 85 | clearAnalyzeData(); |
michael@0 | 86 | |
michael@0 | 87 | // Set a low interval and wait for the timed expiration to start. |
michael@0 | 88 | let promise = promiseTopicObserved(PlacesUtils.TOPIC_EXPIRATION_FINISHED); |
michael@0 | 89 | setInterval(3); |
michael@0 | 90 | yield promise; |
michael@0 | 91 | setInterval(3600); |
michael@0 | 92 | |
michael@0 | 93 | do_check_analyze_ran("moz_places", false); |
michael@0 | 94 | do_check_analyze_ran("moz_bookmarks", false); |
michael@0 | 95 | do_check_analyze_ran("moz_historyvisits", false); |
michael@0 | 96 | do_check_analyze_ran("moz_inputhistory", true); |
michael@0 | 97 | }); |
michael@0 | 98 | |
michael@0 | 99 | add_task(function test_debug() |
michael@0 | 100 | { |
michael@0 | 101 | clearAnalyzeData(); |
michael@0 | 102 | |
michael@0 | 103 | yield promiseForceExpirationStep(1); |
michael@0 | 104 | |
michael@0 | 105 | do_check_analyze_ran("moz_places", true); |
michael@0 | 106 | do_check_analyze_ran("moz_bookmarks", true); |
michael@0 | 107 | do_check_analyze_ran("moz_historyvisits", true); |
michael@0 | 108 | do_check_analyze_ran("moz_inputhistory", true); |
michael@0 | 109 | }); |
michael@0 | 110 | |
michael@0 | 111 | add_task(function test_clear_history() |
michael@0 | 112 | { |
michael@0 | 113 | clearAnalyzeData(); |
michael@0 | 114 | |
michael@0 | 115 | let promise = promiseTopicObserved(PlacesUtils.TOPIC_EXPIRATION_FINISHED); |
michael@0 | 116 | let listener = Cc["@mozilla.org/places/expiration;1"] |
michael@0 | 117 | .getService(Ci.nsINavHistoryObserver); |
michael@0 | 118 | listener.onClearHistory(); |
michael@0 | 119 | yield promise; |
michael@0 | 120 | |
michael@0 | 121 | do_check_analyze_ran("moz_places", true); |
michael@0 | 122 | do_check_analyze_ran("moz_bookmarks", false); |
michael@0 | 123 | do_check_analyze_ran("moz_historyvisits", true); |
michael@0 | 124 | do_check_analyze_ran("moz_inputhistory", true); |
michael@0 | 125 | }); |