Bug 858377 - Increase time skew to avoid intermittent failure in test_393498.js

Includes some test cleanups
This commit is contained in:
Marco Bonardo 2013-05-31 00:19:33 +02:00
Родитель e126885445
Коммит cc6dfc34db
1 изменённых файлов: 66 добавлений и 81 удалений

Просмотреть файл

@ -4,114 +4,99 @@
* 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/. */
try {
var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].getService(Ci.nsINavBookmarksService);
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService);
} catch(ex) {
do_throw("Could not get services\n");
}
let observer = {
__proto__: NavBookmarkObserver.prototype,
// create and add bookmarks observer
var observer = {
onBeginUpdateBatch: function() {},
onEndUpdateBatch: function() {},
onItemAdded: function(id, folder, index, itemType, uri) {
onItemAdded: function (id, folder, index) {
this._itemAddedId = id;
this._itemAddedParent = folder;
this._itemAddedIndex = index;
},
onItemRemoved: function() {},
_itemChangedProperty: null,
onItemChanged: function(id, property, isAnnotationProperty, value,
lastModified, itemType) {
onItemChanged: function (id, property, isAnnotationProperty, value) {
this._itemChangedId = id;
this._itemChangedProperty = property;
this._itemChanged_isAnnotationProperty = isAnnotationProperty;
this._itemChangedValue = value;
},
onItemVisited: function() {},
onItemMoved: function() {},
QueryInterface: function(iid) {
if (iid.equals(Ci.nsINavBookmarkObserver) ||
iid.equals(Ci.nsISupports)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
}
};
bmsvc.addObserver(observer, false);
PlacesUtils.bookmarks.addObserver(observer, false);
do_register_cleanup(function () {
PlacesUtils.bookmarks.removeObserver(observer);
});
// main
function run_test() {
var testFolder = bmsvc.createFolder(bmsvc.placesRoot, "test Folder",
bmsvc.DEFAULT_INDEX);
var bookmarkId = bmsvc.insertBookmark(testFolder, uri("http://google.com/"),
bmsvc.DEFAULT_INDEX, "");
do_check_true(observer.itemChangedProperty == null);
// We set times in the past to workaround a timing bug due to virtual
// machines and the skew between PR_Now() and Date.now(), see bug 427142 and
// bug 858377 for details.
const PAST_PRTIME = (Date.now() - 86400000) * 1000;
// We set lastModified in the past to workaround a timing bug on
// virtual machines, see bug 427142 for details.
var newDate = (Date.now() - 10) * 1000;
bmsvc.setItemDateAdded(bookmarkId, newDate);
// test notification
// Insert a new bookmark.
let testFolder = PlacesUtils.bookmarks.createFolder(
PlacesUtils.placesRootId, "test Folder",
PlacesUtils.bookmarks.DEFAULT_INDEX);
let bookmarkId = PlacesUtils.bookmarks.insertBookmark(
testFolder, uri("http://google.com/"),
PlacesUtils.bookmarks.DEFAULT_INDEX, "");
// Sanity check.
do_check_true(observer.itemChangedProperty === undefined);
// Set dateAdded in the past and verify the bookmarks cache.
PlacesUtils.bookmarks.setItemDateAdded(bookmarkId, PAST_PRTIME);
do_check_eq(observer._itemChangedProperty, "dateAdded");
do_check_eq(observer._itemChangedValue, newDate);
// test saved value
var dateAdded = bmsvc.getItemDateAdded(bookmarkId);
do_check_eq(dateAdded, newDate);
do_check_eq(observer._itemChangedValue, PAST_PRTIME);
let dateAdded = PlacesUtils.bookmarks.getItemDateAdded(bookmarkId);
do_check_eq(dateAdded, PAST_PRTIME);
// after just inserting, modified should not be set
var lastModified = bmsvc.getItemLastModified(bookmarkId);
do_check_eq(lastModified, dateAdded);
// After just inserting, modified should be the same as dateAdded.
do_check_eq(PlacesUtils.bookmarks.getItemLastModified(bookmarkId), dateAdded);
bmsvc.setItemLastModified(bookmarkId, newDate);
// test notification
// Set lastModified in the past and verify the bookmarks cache.
PlacesUtils.bookmarks.setItemLastModified(bookmarkId, PAST_PRTIME);
do_check_eq(observer._itemChangedProperty, "lastModified");
do_check_eq(observer._itemChangedValue, newDate);
// test saved value
do_check_eq(bmsvc.getItemLastModified(bookmarkId), newDate);
do_check_eq(observer._itemChangedValue, PAST_PRTIME);
do_check_eq(PlacesUtils.bookmarks.getItemLastModified(bookmarkId),
PAST_PRTIME);
// set bookmark title
bmsvc.setItemTitle(bookmarkId, "Google");
// Set bookmark title
PlacesUtils.bookmarks.setItemTitle(bookmarkId, "Google");
// Test notifications.
do_check_eq(observer._itemChangedId, bookmarkId);
do_check_eq(observer._itemChangedProperty, "title");
do_check_eq(observer._itemChangedValue, "Google");
// check lastModified has been updated
do_check_true(bmsvc.getItemLastModified(bookmarkId) > newDate);
// Check lastModified has been updated.
is_time_ordered(PAST_PRTIME,
PlacesUtils.bookmarks.getItemLastModified(bookmarkId));
// check that node properties are updated
var query = histsvc.getNewQuery();
query.setFolders([testFolder], 1);
var result = histsvc.executeQuery(query, histsvc.getNewQueryOptions());
var rootNode = result.root;
rootNode.containerOpen = true;
do_check_eq(rootNode.childCount, 1);
var childNode = rootNode.getChild(0);
// Check that node properties are updated.
let root = PlacesUtils.getFolderContents(testFolder).root;
do_check_eq(root.childCount, 1);
let childNode = root.getChild(0);
// confirm current dates match node properties
do_check_eq(bmsvc.getItemDateAdded(bookmarkId), childNode.dateAdded);
do_check_eq(bmsvc.getItemLastModified(bookmarkId), childNode.lastModified);
do_check_eq(PlacesUtils.bookmarks.getItemDateAdded(bookmarkId),
childNode.dateAdded);
do_check_eq(PlacesUtils.bookmarks.getItemLastModified(bookmarkId),
childNode.lastModified);
// test live update of lastModified caused by other changes:
// We set lastModified in the past to workaround timers resolution,
// see bug 427142 for details.
var pastDate = (Date.now() - 10) * 1000;
bmsvc.setItemLastModified(bookmarkId, pastDate);
// set title (causing update of last modified)
var oldLastModified = bmsvc.getItemLastModified(bookmarkId);
bmsvc.setItemTitle(bookmarkId, "Google");
// test that lastModified is updated
is_time_ordered(oldLastModified, childNode.lastModified);
// test that node value matches db value
do_check_eq(bmsvc.getItemLastModified(bookmarkId), childNode.lastModified);
// Test live update of lastModified when setting title.
PlacesUtils.bookmarks.setItemLastModified(bookmarkId, PAST_PRTIME);
PlacesUtils.bookmarks.setItemTitle(bookmarkId, "Google");
// test live update of the exposed date apis
newDate = Date.now() * 1000;
bmsvc.setItemDateAdded(bookmarkId, newDate);
do_check_eq(childNode.dateAdded, newDate);
bmsvc.setItemLastModified(bookmarkId, newDate);
do_check_eq(childNode.lastModified, newDate);
// Check lastModified has been updated.
is_time_ordered(PAST_PRTIME, childNode.lastModified);
// Test that node value matches db value.
do_check_eq(PlacesUtils.bookmarks.getItemLastModified(bookmarkId),
childNode.lastModified);
rootNode.containerOpen = false;
// Test live update of the exposed date apis.
PlacesUtils.bookmarks.setItemDateAdded(bookmarkId, PAST_PRTIME);
do_check_eq(childNode.dateAdded, PAST_PRTIME);
PlacesUtils.bookmarks.setItemLastModified(bookmarkId, PAST_PRTIME);
do_check_eq(childNode.lastModified, PAST_PRTIME);
root.containerOpen = false;
}