Bug 435322 - Places History Visit Date doesn't show _date_ portion properly, r=dietrich

This commit is contained in:
Marco Bonardo 2009-03-05 13:08:24 +01:00
parent 210ad84906
commit ad11411e9e
4 changed files with 252 additions and 4 deletions

View File

@ -407,10 +407,15 @@ PlacesTreeView.prototype = {
// Date is calculated starting from midnight, so the modulo with a day are
// milliseconds from today's midnight.
var now = Date.now();
var midnight = now - (now % (24 * 60 * 60 * 1000));
// getTimezoneOffset corrects that based on local time.
// 86400000 = 24 * 60 * 60 * 1000 = 1 day
// 60000 = 60 * 1000 = 1 minute
var dateObj = new Date();
var now = dateObj.getTime();
var midnight = now - (now % (86400000)) +
(dateObj.getTimezoneOffset() * 60000);
var dateFormat = timeInMilliseconds > midnight ?
var dateFormat = timeInMilliseconds >= midnight ?
Ci.nsIScriptableDateFormat.dateFormatNone :
Ci.nsIScriptableDateFormat.dateFormatShort;

View File

@ -47,6 +47,6 @@ MODULE = test_browser_places
XPCSHELL_TESTS = unit
DIRS = browser perf
DIRS = browser chrome perf
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,51 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Places test code.
#
# The Initial Developer of the Original Code is Mozilla Corp.
# Portions created by the Initial Developer are Copyright (C) 2009
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Drew Willcoxon <adw@mozilla.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
relativesrcdir = browser/components/places/tests/chrome
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
_CHROME_TEST_FILES = \
test_treeview_date.xul \
$(NULL)
libs:: $(_CHROME_TEST_FILES)
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)

View File

@ -0,0 +1,192 @@
<?xml version="1.0"?>
<!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0/LGPL 2.1
-
- The contents of this file are subject to the Mozilla Public License Version
- 1.1 (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
- http://www.mozilla.org/MPL/
-
- Software distributed under the License is distributed on an "AS IS" basis,
- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- for the specific language governing rights and limitations under the
- License.
-
- The Original Code is the Places test code.
-
- The Initial Developer of the Original Code is Mozilla Corp.
- Portions created by the Initial Developer are Copyright (C) 2009
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
- Marco Bonardo <mak77@bonardo.net> (Original Author)
-
- Alternatively, the contents of this file may be used under the terms of
- either the GNU General Public License Version 2 or later (the "GPL"), or
- the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- in which case the provisions of the GPL or the LGPL are applicable instead
- of those above. If you wish to allow use of your version of this file only
- under the terms of either the GPL or the LGPL, and not to allow others to
- use your version of this file under the terms of the MPL, indicate your
- decision by deleting the provisions above and replace them with the notice
- and other provisions required by the GPL or the LGPL. If you do not delete
- the provisions above, a recipient may use your version of this file under
- the terms of any one of the MPL, the GPL or the LGPL.
-
- ***** END LICENSE BLOCK ***** -->
<?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/MochiKit/packed.js" />
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.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() {
const Cc = Components.classes;
const Ci = Components.interfaces;
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);
// Add a visit 1ms before midnight.
hs.addVisit(uri("http://before.midnight.com/"),
(midnight.getTime() - 1) * 1000,
null, hs.TRANSITION_TYPED, false, 0);
// Add a visit at midnight.
hs.addVisit(uri("http://at.midnight.com/"),
(midnight.getTime()) * 1000,
null, hs.TRANSITION_TYPED, false, 0);
// Add a visit 1ms after midnight.
hs.addVisit(uri("http://after.midnight.com/"),
(midnight.getTime() + 1) * 1000,
null, hs.TRANSITION_TYPED, false, 0);
// 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":
ok(text == node.title, "Title is correct")
break;
case "url":
ok(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;
var timeStr = ds.FormatDateTime("", dateFormat,
Ci.nsIScriptableDateFormat.timeFormatNoSeconds,
timeObj.getFullYear(), timeObj.getMonth() + 1,
timeObj.getDate(), timeObj.getHours(),
timeObj.getMinutes(), timeObj.getSeconds())
ok(text == timeStr, "Date format is correct");
break;
case "visitCount":
ok(text == 1, "Visit count is correct")
break;
}
}
}
// Cleanup.
bh.removeAllPages();
SimpleTest.finish();
}
]]>
</script>
</window>