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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /**
     2  * Any copyright is dedicated to the Public Domain.
     3  * http://creativecommons.org/publicdomain/zero/1.0/
     4  */
     6 gBrowser.selectedTab = gBrowser.addTab();
     8 function finishAndCleanUp()
     9 {
    10   gBrowser.removeCurrentTab();
    11   promiseClearHistory().then(finish);
    12 }
    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 }
    29 var conn = PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection;
    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 }
    49 function test()
    50 {
    51   // Make sure titles are correctly saved for a URI with the proper
    52   // notifications.
    54   waitForExplicitFinish();
    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 });
    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.
    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);
    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   });
    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));
    93     data.forEach(function(item) {
    94       var title = getColumn("moz_places", "title", "url", data[0].uri.spec);
    95       is(title, item.title);
    96     });
    98     finishAndCleanUp();
    99   }
   100 }

mercurial