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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/places/tests/browser/browser_bug646422.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,49 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +/**
     1.9 + * Test for Bug 646224.  Make sure that after changing the URI via
    1.10 + * history.pushState, the history service has a title stored for the new URI.
    1.11 + **/
    1.12 +
    1.13 +function test() {
    1.14 +  waitForExplicitFinish();
    1.15 +
    1.16 +  let tab = gBrowser.addTab('http://example.com');
    1.17 +  let tabBrowser = tab.linkedBrowser;
    1.18 +
    1.19 +  tabBrowser.addEventListener('load', function(aEvent) {
    1.20 +    tabBrowser.removeEventListener('load', arguments.callee, true);
    1.21 +
    1.22 +    // Control should now flow down to observer.onTitleChanged().
    1.23 +    let cw = tabBrowser.contentWindow;
    1.24 +    ok(cw.document.title, 'Content window should initially have a title.');
    1.25 +    cw.history.pushState('', '', 'new_page');
    1.26 +  }, true);
    1.27 +
    1.28 +  let observer = {
    1.29 +    onTitleChanged: function(uri, title) {
    1.30 +      // If the uri of the page whose title is changing ends with 'new_page',
    1.31 +      // then it's the result of our pushState.
    1.32 +      if (/new_page$/.test(uri.spec)) {
    1.33 +        is(title, tabBrowser.contentWindow.document.title,
    1.34 +           'Title after pushstate.');
    1.35 +        PlacesUtils.history.removeObserver(this);
    1.36 +        gBrowser.removeTab(tab);
    1.37 +        finish();
    1.38 +      }
    1.39 +    },
    1.40 +
    1.41 +    onBeginUpdateBatch: function() { },
    1.42 +    onEndUpdateBatch: function() { },
    1.43 +    onVisit: function() { },
    1.44 +    onDeleteURI: function() { },
    1.45 +    onClearHistory: function() { },
    1.46 +    onPageChanged: function() { },
    1.47 +    onDeleteVisits: function() { },
    1.48 +    QueryInterface: XPCOMUtils.generateQI([Ci.nsINavHistoryObserver])
    1.49 +  };
    1.50 +
    1.51 +  PlacesUtils.history.addObserver(observer, false);
    1.52 +}

mercurial