DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
<?xml version="1.0"?>

<!-- This Source Code Form is subject to the terms of the Mozilla Public
   - License, v. 2.0. If a copy of the MPL was not distributed with this
   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
                 type="text/css"?>

<?xml-stylesheet href="chrome://browser/content/places/places.css"?>
<?xml-stylesheet href="chrome://browser/skin/places/places.css"?>
<?xul-overlay href="chrome://browser/content/places/placesOverlay.xul"?>

<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        title="435322: Places tree view's formatting"
        onload="runTest();">

  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
  <script type="application/javascript" src="head.js" />

  <body xmlns="http://www.w3.org/1999/xhtml" />

  <tree id="tree"
        type="places"
        flatList="true"
        flex="1">
    <treecols>
      <treecol label="Title" id="title" anonid="title" primary="true" ordinal="1" flex="1"/>
      <splitter class="tree-splitter"/>
      <treecol label="Tags" id="tags" anonid="tags" flex="1"/>
      <splitter class="tree-splitter"/>
      <treecol label="Url" id="url" anonid="url" flex="1"/>
      <splitter class="tree-splitter"/>
      <treecol label="Visit Date" id="date" anonid="date" flex="1"/>
      <splitter class="tree-splitter"/>
      <treecol label="Visit Count" id="visitCount" anonid="visitCount" flex="1"/>
    </treecols>
    <treechildren flex="1"/>
  </tree>

  <script type="application/javascript">
  <![CDATA[

    /**
     * Bug 435322
     * https://bugzilla.mozilla.org/show_bug.cgi?id=435322
     *
     * Ensures that date in places treeviews is correctly formatted.
     */

    SimpleTest.waitForExplicitFinish();

    function runTest() {
      // The mochitest page is added to history.
      waitForClearHistory(continue_test);
    }

    function continue_test() {
      var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
               getService(Ci.nsINavHistoryService);
      var bh = hs.QueryInterface(Ci.nsIBrowserHistory);
      var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
               getService(Ci.nsINavBookmarksService);
      var ds = Cc["@mozilla.org/intl/scriptabledateformat;1"].
               getService(Ci.nsIScriptableDateFormat);

      var iosvc = Cc["@mozilla.org/network/io-service;1"].
                  getService(Ci.nsIIOService);
      function uri(spec) {
        return iosvc.newURI(spec, null, null);
      }

      var midnight = new Date();
      midnight.setHours(0);
      midnight.setMinutes(0);
      midnight.setSeconds(0);
      midnight.setMilliseconds(0);

      function addVisitsCallback() {
        // add a bookmark to the midnight visit
        var itemId = bs.insertBookmark(bs.toolbarFolder,
                                       uri("http://at.midnight.com/"),
                                       bs.DEFAULT_INDEX,
                                       "A bookmark at midnight");

        // Make a history query.
        var query = hs.getNewQuery();
        var opts = hs.getNewQueryOptions();
        var queryURI = hs.queriesToQueryString([query], 1, opts);

        // Setup the places tree contents.
        var tree = document.getElementById("tree");
        tree.place = queryURI;

        // loop through the rows and check formatting
        var treeView = tree.view;
        var rc = treeView.rowCount;
        ok(rc >= 3, "Rows found");
        var columns = tree.columns;
        ok(columns.count > 0, "Columns found");
        for (var r = 0; r < rc; r++) {
          var node = treeView.nodeForTreeIndex(r);
          ok(node, "Places node found");
          for (var ci = 0; ci < columns.count; ci++) {
            var c = columns.getColumnAt(ci);
            var text = treeView.getCellText(r, c);
            switch (c.element.getAttribute("anonid")) {
              case "title":
                // The title can differ, we did not set any title so we would
                // expect null, but in such a case the view will generate a title
                // through PlacesUIUtils.getBestTitle.
                if (node.title)
                  is(text, node.title, "Title is correct");
                break;
              case "url":
                is(text, node.uri, "Uri is correct");
                break;
              case "date":
                var timeObj = new Date(node.time / 1000);
                // Default is short date format.
                var dateFormat = Ci.nsIScriptableDateFormat.dateFormatShort;
                // For today's visits we don't show date portion.
                if (node.uri == "http://at.midnight.com/" ||
                    node.uri == "http://after.midnight.com/")
                  dateFormat = Ci.nsIScriptableDateFormat.dateFormatNone;
                else if (node.uri == "http://before.midnight.com/")
                  dateFormat = Ci.nsIScriptableDateFormat.dateFormatShort;
                else {
                  // Avoid to test spurious uris, due to how the test works
                  // a redirecting uri could be put in the tree while we test.
                  break;
                }
                var timeStr = ds.FormatDateTime("", dateFormat,
                      Ci.nsIScriptableDateFormat.timeFormatNoSeconds,
                      timeObj.getFullYear(), timeObj.getMonth() + 1,
                      timeObj.getDate(), timeObj.getHours(),
                      timeObj.getMinutes(), timeObj.getSeconds())

                is(text, timeStr, "Date format is correct");
                break;
              case "visitCount":
                is(text, 1, "Visit count is correct");
                break;
            }
          }
        }
        // Cleanup.
        bs.removeItem(itemId);
        waitForClearHistory(SimpleTest.finish);
      }

      // Add a visit 1ms before midnight, a visit at midnight, and
      // a visit 1ms after midnight.
      addVisits(
        [{uri: uri("http://before.midnight.com/"),
           visitDate: (midnight.getTime() - 1) * 1000,
           transition: hs.TRANSITION_TYPED},
         {uri: uri("http://at.midnight.com/"),
           visitDate: (midnight.getTime()) * 1000,
           transition: hs.TRANSITION_TYPED},
         {uri: uri("http://after.midnight.com/"),
           visitDate: (midnight.getTime() + 1) * 1000,
           transition: hs.TRANSITION_TYPED}],
        addVisitsCallback);
    }

    /**
     * Clears history invoking callback when done.
     */
    function waitForClearHistory(aCallback) {
      const TOPIC_EXPIRATION_FINISHED = "places-expiration-finished";
      let observer = {
        observe: function(aSubject, aTopic, aData) {
          Services.obs.removeObserver(this, TOPIC_EXPIRATION_FINISHED);
          aCallback();
        }
      };
      Services.obs.addObserver(observer, TOPIC_EXPIRATION_FINISHED, false);
      let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
               getService(Ci.nsINavHistoryService);
      hs.QueryInterface(Ci.nsIBrowserHistory).removeAllPages();
   }

  ]]>
  </script>
</window>