browser/components/places/tests/chrome/test_bug549192.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/places/tests/chrome/test_bug549192.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,115 @@
     1.4 +<?xml version="1.0"?>
     1.5 +
     1.6 +<!--
     1.7 +    Any copyright is dedicated to the Public Domain.
     1.8 +    http://creativecommons.org/licenses/publicdomain/
     1.9 +   -->
    1.10 +
    1.11 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
    1.12 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
    1.13 +                 type="text/css"?>
    1.14 +
    1.15 +<?xml-stylesheet href="chrome://browser/content/places/places.css"?>
    1.16 +<?xml-stylesheet href="chrome://browser/skin/places/places.css"?>
    1.17 +<?xul-overlay href="chrome://browser/content/places/placesOverlay.xul"?>
    1.18 +
    1.19 +<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    1.20 +        title="549192:  History view not updated after deleting entry"
    1.21 +        onload="runTest();">
    1.22 +
    1.23 +  <script type="application/javascript"
    1.24 +          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
    1.25 +  <script type="application/javascript" src="head.js" />
    1.26 +
    1.27 +  <body xmlns="http://www.w3.org/1999/xhtml" />
    1.28 +
    1.29 +  <tree id="tree"
    1.30 +        type="places"
    1.31 +        flatList="true"
    1.32 +        flex="1">
    1.33 +    <treecols>
    1.34 +      <treecol label="Title" id="title" anonid="title" primary="true" ordinal="1" flex="1"/>
    1.35 +    </treecols>
    1.36 +    <treechildren flex="1"/>
    1.37 +  </tree>
    1.38 +
    1.39 +  <script type="application/javascript"><![CDATA[
    1.40 +    /**
    1.41 +     * Bug 874407
    1.42 +     * Ensures that history views are updated properly after visits.
    1.43 +     * Bug 549192
    1.44 +     * Ensures that history views are updated after deleting entries.
    1.45 +     */
    1.46 +
    1.47 +    SimpleTest.waitForExplicitFinish();
    1.48 +
    1.49 +    function runTest() {
    1.50 +      // The mochitest page is added to history.
    1.51 +      waitForClearHistory(continue_test);
    1.52 +    }
    1.53 +
    1.54 +    function continue_test() {
    1.55 +      // Add some visits.
    1.56 +      let vtime = Date.now() * 1000;
    1.57 +      const ttype = PlacesUtils.history.TRANSITION_TYPED;
    1.58 +      let places =
    1.59 +        [{ uri: Services.io.newURI("http://example.tld/", null, null),
    1.60 +           visitDate: ++vtime, transition: ttype },
    1.61 +         { uri: Services.io.newURI("http://example2.tld/", null, null),
    1.62 +           visitDate: ++vtime, transition: ttype },
    1.63 +         { uri: Services.io.newURI("http://example3.tld/", null, null),
    1.64 +           visitDate: ++vtime, transition: ttype }];
    1.65 +
    1.66 +      addVisits(places, function() {
    1.67 +        // Make a history query.
    1.68 +        let query = PlacesUtils.history.getNewQuery();
    1.69 +        let opts = PlacesUtils.history.getNewQueryOptions();
    1.70 +        opts.sortingMode = opts.SORT_BY_DATE_DESCENDING;
    1.71 +        let queryURI = PlacesUtils.history.queriesToQueryString([query], 1, opts);
    1.72 +
    1.73 +        // Setup the places tree contents.
    1.74 +        var tree = document.getElementById("tree");
    1.75 +        tree.place = queryURI;
    1.76 +
    1.77 +        // loop through the rows and check them.
    1.78 +        let treeView = tree.view;
    1.79 +        let selection = treeView.selection;
    1.80 +        let rc = treeView.rowCount;
    1.81 +
    1.82 +        for (let i = 0; i < rc; i++) {
    1.83 +          selection.select(i);
    1.84 +          let node = tree.selectedNode;
    1.85 +          is(node.uri, places[rc - i - 1].uri.spec,
    1.86 +             "Found expected node at position " + i + ".");
    1.87 +        }
    1.88 +
    1.89 +        is(rc, 3, "Found expected number of rows.");
    1.90 +
    1.91 +        // First check live-update of the view when adding visits.
    1.92 +        places.forEach(place => place.visitDate = ++vtime);
    1.93 +        addVisits(places, function() {
    1.94 +          for (let i = 0; i < rc; i++) {
    1.95 +            selection.select(i);
    1.96 +            let node = tree.selectedNode;
    1.97 +            is(node.uri, places[rc - i - 1].uri.spec,
    1.98 +               "Found expected node at position " + i + ".");
    1.99 +          }
   1.100 +
   1.101 +          // Now remove the pages and verify live-update again.
   1.102 +          for (let i = 0; i < rc; i++) {
   1.103 +            selection.select(0);
   1.104 +            let node = tree.selectedNode;
   1.105 +            tree.controller.remove("Removing page");
   1.106 +            ok(treeView.treeIndexForNode(node) == Ci.nsINavHistoryResultTreeViewer.INDEX_INVISIBLE,
   1.107 +              node.uri + " removed.");
   1.108 +            ok(treeView.rowCount == rc - i - 1, "Rows count decreased");
   1.109 +          }
   1.110 +
   1.111 +          // Cleanup.
   1.112 +          waitForClearHistory(SimpleTest.finish);
   1.113 +        });
   1.114 +      });
   1.115 +    }
   1.116 +
   1.117 +  ]]></script>
   1.118 +</window>

mercurial