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 | /** |
michael@0 | 2 | * Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 4 | */ |
michael@0 | 5 | |
michael@0 | 6 | gBrowser.selectedTab = gBrowser.addTab(); |
michael@0 | 7 | |
michael@0 | 8 | function finishAndCleanUp() |
michael@0 | 9 | { |
michael@0 | 10 | gBrowser.removeCurrentTab(); |
michael@0 | 11 | promiseClearHistory().then(finish); |
michael@0 | 12 | } |
michael@0 | 13 | |
michael@0 | 14 | /** |
michael@0 | 15 | * One-time DOMContentLoaded callback. |
michael@0 | 16 | */ |
michael@0 | 17 | function load(href, callback) |
michael@0 | 18 | { |
michael@0 | 19 | content.location.href = href; |
michael@0 | 20 | gBrowser.addEventListener("load", function() { |
michael@0 | 21 | if (content.location.href == href) { |
michael@0 | 22 | gBrowser.removeEventListener("load", arguments.callee, true); |
michael@0 | 23 | if (callback) |
michael@0 | 24 | callback(); |
michael@0 | 25 | } |
michael@0 | 26 | }, true); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | var conn = PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection; |
michael@0 | 30 | |
michael@0 | 31 | /** |
michael@0 | 32 | * Gets a single column value from either the places or historyvisits table. |
michael@0 | 33 | */ |
michael@0 | 34 | function getColumn(table, column, fromColumnName, fromColumnValue) |
michael@0 | 35 | { |
michael@0 | 36 | var stmt = conn.createStatement( |
michael@0 | 37 | "SELECT " + column + " FROM " + table + " WHERE " + fromColumnName + "=:val " + |
michael@0 | 38 | "LIMIT 1"); |
michael@0 | 39 | try { |
michael@0 | 40 | stmt.params.val = fromColumnValue; |
michael@0 | 41 | stmt.executeStep(); |
michael@0 | 42 | return stmt.row[column]; |
michael@0 | 43 | } |
michael@0 | 44 | finally { |
michael@0 | 45 | stmt.finalize(); |
michael@0 | 46 | } |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | function test() |
michael@0 | 50 | { |
michael@0 | 51 | // Make sure titles are correctly saved for a URI with the proper |
michael@0 | 52 | // notifications. |
michael@0 | 53 | |
michael@0 | 54 | waitForExplicitFinish(); |
michael@0 | 55 | |
michael@0 | 56 | // Create and add history observer. |
michael@0 | 57 | var historyObserver = { |
michael@0 | 58 | data: [], |
michael@0 | 59 | onBeginUpdateBatch: function() {}, |
michael@0 | 60 | onEndUpdateBatch: function() {}, |
michael@0 | 61 | onVisit: function(aURI, aVisitID, aTime, aSessionID, aReferringID, |
michael@0 | 62 | aTransitionType) { |
michael@0 | 63 | }, |
michael@0 | 64 | onTitleChanged: function(aURI, aPageTitle, aGUID) { |
michael@0 | 65 | this.data.push({ uri: aURI, title: aPageTitle, guid: aGUID }); |
michael@0 | 66 | |
michael@0 | 67 | // We only expect one title change. |
michael@0 | 68 | // |
michael@0 | 69 | // Although we are loading two different pages, the first page does not |
michael@0 | 70 | // have a title. Since the title starts out as empty and then is set |
michael@0 | 71 | // to empty, there is no title change notification. |
michael@0 | 72 | |
michael@0 | 73 | PlacesUtils.history.removeObserver(this); |
michael@0 | 74 | confirmResults(this.data); |
michael@0 | 75 | }, |
michael@0 | 76 | onDeleteURI: function() {}, |
michael@0 | 77 | onClearHistory: function() {}, |
michael@0 | 78 | onPageChanged: function() {}, |
michael@0 | 79 | onDeleteVisits: function() {}, |
michael@0 | 80 | QueryInterface: XPCOMUtils.generateQI([Ci.nsINavHistoryObserver]) |
michael@0 | 81 | }; |
michael@0 | 82 | PlacesUtils.history.addObserver(historyObserver, false); |
michael@0 | 83 | |
michael@0 | 84 | load("http://example.com/tests/toolkit/components/places/tests/browser/title1.html", function() { |
michael@0 | 85 | load("http://example.com/tests/toolkit/components/places/tests/browser/title2.html"); |
michael@0 | 86 | }); |
michael@0 | 87 | |
michael@0 | 88 | function confirmResults(data) { |
michael@0 | 89 | is(data[0].uri.spec, "http://example.com/tests/toolkit/components/places/tests/browser/title2.html"); |
michael@0 | 90 | is(data[0].title, "Some title"); |
michael@0 | 91 | is(data[0].guid, getColumn("moz_places", "guid", "url", data[0].uri.spec)); |
michael@0 | 92 | |
michael@0 | 93 | data.forEach(function(item) { |
michael@0 | 94 | var title = getColumn("moz_places", "title", "url", data[0].uri.spec); |
michael@0 | 95 | is(title, item.title); |
michael@0 | 96 | }); |
michael@0 | 97 | |
michael@0 | 98 | finishAndCleanUp(); |
michael@0 | 99 | } |
michael@0 | 100 | } |