toolkit/components/places/tests/browser/browser_settitle.js

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

mercurial