gecko/toolkit/components/places/tests/chrome/test_329534.xul

174 lines
5.4 KiB
Plaintext
Raw Normal View History

2008-08-06 10:20:30 -07:00
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet
href="file:///c:/mozbuild/fx3.1/mozilla-central/testing/mochitest/tests/SimpleTest/test.css" type="text/css"?>
<window title="Distribute to loading Livemark"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<body xmlns="http://www.w3.org/1999/xhtml" />
<script type="application/javascript">
<![CDATA[
/*
Test distribute the load of livemark update
*/
SimpleTest.waitForExplicitFinish();
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
var iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
function uri(spec) {
return iosvc.newURI(spec, null, null);
}
var lmsvc = Cc["@mozilla.org/browser/livemark-service;2"].
getService(Ci.nsILivemarkService);
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);
var toolbarFolderId = bmsvc.toolbarFolder;
var status = 0;
var secondFolderId = 0;
var firstLoadTime = 0;
var firstURL = "";
var secondURL = "";
// stop updating livemarks
lmsvc.stopUpdateLivemarks();
2008-08-06 10:20:30 -07:00
// add 2 feeds
const FEED1 = "http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/rss_as_html.rss";
2008-08-06 10:20:30 -07:00
gLivemarkId1 = lmsvc.createLivemarkFolderOnly( toolbarFolderId, "foo",
uri("http:/mochi.test:8888/"),
2008-08-06 10:20:30 -07:00
uri(FEED1), -1);
const FEED2 = "http://mochi.test:8888/tests/toolkit/components/places/tests/chrome/sample_feed.atom";
2008-08-06 10:20:30 -07:00
gLivemarkId2 = lmsvc.createLivemarkFolderOnly( toolbarFolderId, "bar",
uri("http:/mochi.test:8888/"),
2008-08-06 10:20:30 -07:00
uri(FEED2), -1);
var observer =
{
QueryInterface: function(iid) {
if (iid.equals(Ci.nsINavBookmarkObserver) ||
iid.equals(Ci.nsISupports))
return this;
throw Cr.NS_ERROR_NO_INTERFACE;
},
// nsINavBookmarkObserver
onBeginUpdateBatch: function(){},
onEndUpdateBatch: function(){},
onItemAdded: function(bookmarkId, folderId, index, itemType) {
2008-08-06 10:20:30 -07:00
if ( status == 0 ) {
runTest1( folderId );
} else {
runTest2( folderId );
if ( status == 2 ) {
bmsvc.removeObserver(this);
bmsvc.removeItem(gLivemarkId1);
bmsvc.removeItem(gLivemarkId2);
2008-08-06 10:20:30 -07:00
SimpleTest.finish();
}
}
},
onBeforeItemRemoved: function(){},
onItemRemoved: function() {},
onItemChanged: function() {},
onItemVisited: function() {},
onItemMoved: function() {}
2008-08-06 10:20:30 -07:00
};
bmsvc.addObserver(observer, false);
// start updating livemarks
firstLoadTime = Date.now();
2008-08-06 10:20:30 -07:00
lmsvc.start();
// First
function runTest1( folderId ) {
if ( folderId == gLivemarkId1 ) {
secondFolderId = gLivemarkId2;
firstURL = "http://www.example.com/index.html";
secondURL = "http://example.org/2003/12/13/atom03";
} else if ( folderId == gLivemarkId2 ) {
2008-08-06 10:20:30 -07:00
secondFolderId = gLivemarkId1;
firstURL = "http://example.org/2003/12/13/atom03";
secondURL = "http://www.example.com/index.html";
}
2008-08-06 10:20:30 -07:00
if ( secondFolderId != 0 ) {
status++;
/* first folder is loading now */
var options = histsvc.getNewQueryOptions();
var query = histsvc.getNewQuery();
query.setFolders([folderId], 1);
var result = histsvc.executeQuery(query, options);
var rootNode = result.root;
rootNode.containerOpen = true;
var cc = rootNode.childCount;
ok( cc == 1, "first livemark is empty" );
var node = rootNode.getChild( 0 );
ok( node.uri == firstURL,
2008-08-06 10:20:30 -07:00
"first livemark item is invalid value "+node.uri);
/* second folder has no item */
options = histsvc.getNewQueryOptions();
query = histsvc.getNewQuery();
query.setFolders([secondFolderId], 1);
result = histsvc.executeQuery(query, options);
rootNode = result.root;
rootNode.containerOpen = true;
cc = rootNode.childCount;
ok( cc == 0, "second livemark is not empty" );
}
}
// Second
function runTest2( folderId ) {
if ( folderId == secondFolderId ) {
status++;
var secondLoadTime = Date.now();
2008-08-06 10:20:30 -07:00
/* second folder is loading now */
var options = histsvc.getNewQueryOptions();
var query = histsvc.getNewQuery();
query.setFolders([folderId], 1);
var result = histsvc.executeQuery(query, options);
var rootNode = result.root;
rootNode.containerOpen = true;
var cc = rootNode.childCount;
ok( cc == 1, "second livemark is empty" );
var node = rootNode.getChild( 0 );
ok( node.uri == secondURL,
2008-08-06 10:20:30 -07:00
"second livemark item is invalid value "+node.uri);
/* Check passed 2sec.
We should check for 3s but are relaxing request to accomplish possible
VM timing bugs.
For the same reason if time elapsed is 0 we have catched an interval
where VM has not updated timers, we will still consider the test valid
to avoid random test failures.
*/
2008-08-06 10:20:30 -07:00
t = parseInt( (secondLoadTime - firstLoadTime) / 1000 );
if (t > 0)
ok( t >= 2, "not passed 2sec when second livemark loading" );
2008-08-06 10:20:30 -07:00
}
}
]]>
</script>
</window>