1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/browser/browser_settitle.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,100 @@ 1.4 +/** 1.5 + * Any copyright is dedicated to the Public Domain. 1.6 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.7 + */ 1.8 + 1.9 +gBrowser.selectedTab = gBrowser.addTab(); 1.10 + 1.11 +function finishAndCleanUp() 1.12 +{ 1.13 + gBrowser.removeCurrentTab(); 1.14 + promiseClearHistory().then(finish); 1.15 +} 1.16 + 1.17 +/** 1.18 + * One-time DOMContentLoaded callback. 1.19 + */ 1.20 +function load(href, callback) 1.21 +{ 1.22 + content.location.href = href; 1.23 + gBrowser.addEventListener("load", function() { 1.24 + if (content.location.href == href) { 1.25 + gBrowser.removeEventListener("load", arguments.callee, true); 1.26 + if (callback) 1.27 + callback(); 1.28 + } 1.29 + }, true); 1.30 +} 1.31 + 1.32 +var conn = PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection; 1.33 + 1.34 +/** 1.35 + * Gets a single column value from either the places or historyvisits table. 1.36 + */ 1.37 +function getColumn(table, column, fromColumnName, fromColumnValue) 1.38 +{ 1.39 + var stmt = conn.createStatement( 1.40 + "SELECT " + column + " FROM " + table + " WHERE " + fromColumnName + "=:val " + 1.41 + "LIMIT 1"); 1.42 + try { 1.43 + stmt.params.val = fromColumnValue; 1.44 + stmt.executeStep(); 1.45 + return stmt.row[column]; 1.46 + } 1.47 + finally { 1.48 + stmt.finalize(); 1.49 + } 1.50 +} 1.51 + 1.52 +function test() 1.53 +{ 1.54 + // Make sure titles are correctly saved for a URI with the proper 1.55 + // notifications. 1.56 + 1.57 + waitForExplicitFinish(); 1.58 + 1.59 + // Create and add history observer. 1.60 + var historyObserver = { 1.61 + data: [], 1.62 + onBeginUpdateBatch: function() {}, 1.63 + onEndUpdateBatch: function() {}, 1.64 + onVisit: function(aURI, aVisitID, aTime, aSessionID, aReferringID, 1.65 + aTransitionType) { 1.66 + }, 1.67 + onTitleChanged: function(aURI, aPageTitle, aGUID) { 1.68 + this.data.push({ uri: aURI, title: aPageTitle, guid: aGUID }); 1.69 + 1.70 + // We only expect one title change. 1.71 + // 1.72 + // Although we are loading two different pages, the first page does not 1.73 + // have a title. Since the title starts out as empty and then is set 1.74 + // to empty, there is no title change notification. 1.75 + 1.76 + PlacesUtils.history.removeObserver(this); 1.77 + confirmResults(this.data); 1.78 + }, 1.79 + onDeleteURI: function() {}, 1.80 + onClearHistory: function() {}, 1.81 + onPageChanged: function() {}, 1.82 + onDeleteVisits: function() {}, 1.83 + QueryInterface: XPCOMUtils.generateQI([Ci.nsINavHistoryObserver]) 1.84 + }; 1.85 + PlacesUtils.history.addObserver(historyObserver, false); 1.86 + 1.87 + load("http://example.com/tests/toolkit/components/places/tests/browser/title1.html", function() { 1.88 + load("http://example.com/tests/toolkit/components/places/tests/browser/title2.html"); 1.89 + }); 1.90 + 1.91 + function confirmResults(data) { 1.92 + is(data[0].uri.spec, "http://example.com/tests/toolkit/components/places/tests/browser/title2.html"); 1.93 + is(data[0].title, "Some title"); 1.94 + is(data[0].guid, getColumn("moz_places", "guid", "url", data[0].uri.spec)); 1.95 + 1.96 + data.forEach(function(item) { 1.97 + var title = getColumn("moz_places", "title", "url", data[0].uri.spec); 1.98 + is(title, item.title); 1.99 + }); 1.100 + 1.101 + finishAndCleanUp(); 1.102 + } 1.103 +}