tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_bug549192.xhtml (4458B)


      1 <?xml version="1.0"?>
      2 
      3 <!--
      4    Any copyright is dedicated to the Public Domain.
      5    http://creativecommons.org/licenses/publicdomain/
      6   -->
      7 
      8 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
      9 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
     10                 type="text/css"?>
     11 
     12 <?xml-stylesheet href="chrome://browser/content/places/places.css"?>
     13 <?xml-stylesheet href="chrome://browser/skin/places/tree-icons.css"?>
     14 
     15 <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     16        title="549192:  History view not updated after deleting entry"
     17        onload="runTest();">
     18 
     19  <script type="application/javascript"
     20          src="chrome://browser/content/places/places-tree.js"/>
     21  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
     22  <script type="application/javascript" src="head.js" />
     23 
     24  <body xmlns="http://www.w3.org/1999/xhtml" />
     25 
     26  <tree id="tree"
     27        is="places-tree"
     28        flatList="true"
     29        flex="1">
     30    <treecols>
     31      <treecol label="Title" id="title" anonid="title" primary="true" style="order: 1;" flex="1"/>
     32    </treecols>
     33    <treechildren flex="1"/>
     34  </tree>
     35 
     36  <script type="application/javascript"><![CDATA[
     37    /**
     38     * Bug 874407
     39     * Ensures that history views are updated properly after visits.
     40     * Bug 549192
     41     * Ensures that history views are updated after deleting entries.
     42     */
     43 
     44    function runTest() {
     45      SimpleTest.waitForExplicitFinish();
     46 
     47      (async function() {
     48        await PlacesUtils.history.clear();
     49 
     50        // Add some visits.
     51        let timeInMicroseconds = PlacesUtils.toPRTime(Date.now() - 10000);
     52 
     53        function newTimeInMicroseconds() {
     54          timeInMicroseconds = timeInMicroseconds + 1000;
     55          return timeInMicroseconds;
     56        }
     57 
     58        const transition = PlacesUtils.history.TRANSITIONS.TYPED;
     59        let places =
     60          [{ uri: Services.io.newURI("https://example.tld/"),
     61             visitDate: newTimeInMicroseconds(), transition },
     62           { uri: Services.io.newURI("https://example2.tld/"),
     63             visitDate: newTimeInMicroseconds(), transition },
     64           { uri: Services.io.newURI("https://example3.tld/"),
     65             visitDate: newTimeInMicroseconds(), transition }];
     66 
     67        await PlacesTestUtils.addVisits(places);
     68 
     69        // Make a history query.
     70        let query = PlacesUtils.history.getNewQuery();
     71        let opts = PlacesUtils.history.getNewQueryOptions();
     72        opts.sortingMode = opts.SORT_BY_DATE_DESCENDING;
     73        let queryURI = PlacesUtils.history.queryToQueryString(query, opts);
     74 
     75        // Setup the places tree contents.
     76        var tree = document.getElementById("tree");
     77        tree.place = queryURI;
     78 
     79        // loop through the rows and check them.
     80        let treeView = tree.view;
     81        let selection = treeView.selection;
     82        let rc = treeView.rowCount;
     83 
     84        for (let i = 0; i < rc; i++) {
     85          selection.select(i);
     86          let node = tree.selectedNode;
     87          is(node.uri, places[rc - i - 1].uri.spec,
     88             "Found expected node at position " + i + ".");
     89        }
     90 
     91        is(rc, 3, "Found expected number of rows.");
     92 
     93        // First check live-update of the view when adding visits.
     94        places.forEach(place => place.visitDate = newTimeInMicroseconds());
     95        await PlacesTestUtils.addVisits(places);
     96 
     97        for (let i = 0; i < rc; i++) {
     98          selection.select(i);
     99          let node = tree.selectedNode;
    100          is(node.uri, places[rc - i - 1].uri.spec,
    101             "Found expected node at position " + i + ".");
    102        }
    103 
    104        // Now remove the pages and verify live-update again.
    105        for (let i = 0; i < rc; i++) {
    106          selection.select(0);
    107          let node = tree.selectedNode;
    108 
    109          const promiseRemoved = PlacesTestUtils.waitForNotification(
    110            "page-removed",
    111            events => events[0].url === node.uri
    112          );
    113 
    114          tree.controller.remove();
    115 
    116          const removeEvents = await promiseRemoved;
    117          ok(
    118            removeEvents[0].isRemovedFromStore,
    119            "isRemovedFromStore should be true"
    120          );
    121          ok(treeView.treeIndexForNode(node) == -1, node.uri + " removed.");
    122          is(treeView.rowCount, rc - i - 1, "Rows count decreased");
    123        }
    124 
    125        // Cleanup.
    126        await PlacesUtils.history.clear();
    127      })().then(() => SimpleTest.finish());
    128    }
    129  ]]></script>
    130 </window>