updated sHistoryListener test, uses onLoad function.

a=asa for QA checkins that are not part of the default builds
This commit is contained in:
depstein%netscape.com 2002-05-07 21:47:54 +00:00
parent 5963d80902
commit 77a8d08c16
5 changed files with 148 additions and 89 deletions

View File

@ -3,18 +3,54 @@
<script TYPE="text/javascript" SRC="nsISHistoryTestLib.js"></script>
<script TYPE="text/javascript">
function nsISHistoryTest()
{
// Test case for nsISessionHistory
// Calls the init() function of nsISHistory
// alert("In nsISHistoryTest constructor\n");
var interfaceName = "nsISHistory";
var sHistory = init();
var count = 0;
var index = 0;
var maxLength = 100;
var urlList = ["http://www.cisco.com",
"http://www.yahoo.com",
"http://www.mozilla.org"
];
var cnt = 0;
var testWin = window.open("about:blank", "testWin");
var sHistory = sHistoryInit(testWin);
var count = 0;
var index = 0;
// begins OnTestSessionHistory();
var maxLength = 100;
function loadPages()
{
var urlTotal = urlList.length;
var initTime = 10000;
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserAccess");
// Load pages sequentially in the child window
/*
for (cnt=0; cnt < urlTotal; cnt++)
{
alert ("Setting timer to load " + urlList[cnt] + " in " + (cnt + 1)*initTime + " milliseconds");
setTimeout("testWin.location.href=urlList[cnt];", (cnt + 1)*initTime);
}
setTimeout("SHistoryTests();", cnt*initTime);
*/
testWin.location = urlList[cnt++];
if (cnt == urlTotal)
setTimeout("sHistoryTests()", 5000);
else
setTimeout("loadPages()", 6000);
}
function sHistoryTests()
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserAccess");
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
// begins testing session history interface;
if (!sHistory)
{
alert("Unable to get session history");
@ -22,8 +58,6 @@ function nsISHistoryTest()
}
alert("Testing nsISHistory interfaces\n");
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
count = testHistoryCount(sHistory); // GetCount()
alert("global count: " + count);
@ -35,12 +69,12 @@ function nsISHistoryTest()
alert ("global maxLength: " + maxLength);
// Test GetEntryAtIndex()
for(i=0; i<count; i++) {
entry = testGetEntryAtIndex(sHistory, i, false);
for(cnt = 0; cnt < count; cnt++) {
entry = testGetEntryAtIndex(sHistory, cnt, false);
if (entry)
alert("GetEntryAtIndex() Valid, cnt = " + i);
alert("GetEntryAtIndex() Valid, cnt = " + cnt);
else
alert("GetEntryAtIndex() Invalid, cnt = " + i);
alert("GetEntryAtIndex() Invalid, cnt = " + cnt);
} // for
// Test the enumerator
@ -69,8 +103,7 @@ function nsISHistoryTest()
</head>
<body>
<script TYPE="text/javascript">
nsISHistoryTest();
alert("finished script execution.");
loadPages();
</script>
</body>
</html>

View File

@ -35,6 +35,7 @@
<script TYPE="text/javascript" SRC="nsISHListenerTestLib.js">
</script>
<script TYPE="text/javascript">
// *** Variables ***
@ -45,11 +46,11 @@ var testWin=null;
var updateInfo="<p>Creating New window ....<br>";
var cnt = 0;
var urlList = ["http://www.aol.com",
var urlList = ["file://D|/Embed-info/scripts/nsISHistory/loadHistoryPage.html",
"http://www.worldcom.com",
"http://www.yahoo.com",
"http://www.mozilla.org",
"http://www.mozilla.org/newsbot",
"file://D|/Embed-info/scripts/nsISHistory/loadHistoryPage.html",
"http://www.cisco.com"
];
// Variables to verify if the callbacks are invoked properly
@ -61,12 +62,13 @@ var purgeCallback = false;
var histLenInChild = 0;
function ddump(s)
{
if (debug==1)
dump(s);
else
if (debug==1) {
t = s + "\n";
dump(t);
}
else if (debug==2)
alert(s);
}
@ -78,43 +80,46 @@ function startTestcase()
function loadPages()
{
alert("In loadPages\n");
ddump("In loadPages");
alert("cnt = " + cnt);
alert("the uri = " + urlList[cnt]);
/* Load pages sequentially in the child window
* The first url will set up the listener
* The last url will test nsISHistory
*/
if (cnt == 0)
testWin = window.open(urlList[cnt], "testWin");
if (cnt == 0) {
testWin = window.open(urlList[cnt++], "testWin");
testWin.onLoad = myLoadFunction();
}
else
testWin.location = urlList[cnt];
testWin.location = urlList[cnt++];
alert("the uri = " + urlList[cnt]);
uriTotal = urlList.length;
if (cnt == (uriTotal - 1)) {
SetListenerInChild();
DoWebNavigationInChild();
DoWebNavigationInChild(); // includes loading last page
}
else if (cnt < (uriTotal - 1)) {
ddump("calling SetTimeOut again\n");
cnt++;
else {
ddump("calling SetTimeOut again");
setTimeout("loadPages()", 6000);
}
}
function myLoadFunction()
{
setTimeout("SetListenerInChild()", 6000);
}
function DoWebNavigationInChild()
{
// Trigger History operaions
// Trigger History operations
setTimeout("GoBackInChild()", 5000);
}
function GoBackInChild()
{
alert("Inside GoBackInChild");
ddump("Inside GoBackInChild");
if (testWin) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserAccess");
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
@ -125,19 +130,18 @@ function GoBackInChild()
function GoForwardInChild()
{
alert("Inside GoForwardInChild\n");
ddump("Inside GoForwardInChild");
if (testWin) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserAccess");
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
testWin.history.forward();
setTimeout("DoReloadInChild()", 6000);
}
}
function DoReloadInChild()
{
alert("Inside DoReloadInChild\n");
ddump("Inside DoReloadInChild");
if (testWin) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserAccess");
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
@ -150,35 +154,30 @@ function DoReloadInChild()
function GotoIndexInChild(index)
{
alert("Inside GotoIndexInChild; index = " + index);
ddump("Inside GotoIndexInChild; index = " + index);
if (testWin) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserAccess");
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
testWin.history.go(index);
// if (index == -1)
// setTimeout("GotoIndexInChild(1)", 6000);
// else if (index == 1)
setTimeout("LoadLastPageInChild()", 5000);
setTimeout("LoadLastPageInChild()", 5000);
}
}
function LoadLastPageInChild()
{
alert("Inside LoadLastPageInChild\n");
ddump("Inside LoadLastPageInChild");
if (testWin) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserAccess");
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
// Load the last page in the child window
//testWin.location.href = urlList[cnt];
testWin.location.href = "file://D|/Embed-info/scripts/nsISHistory/lastURL.html";
testWin.location.href = urlList[cnt];
setTimeout("PurgeHistoryInChild()", 6000);
}
}
function PurgeHistoryInChild()
{
alert("Inside PurgeHistoryInChild");
ddump("Inside PurgeHistoryInChild");
if (testWin) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserAccess");
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
@ -187,10 +186,11 @@ function PurgeHistoryInChild()
// Purge all history entries in the child window.
if (histLenInChild >0) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserAccess");
testWin.purgeTheEntries(histLenInChild);
sHistory = sHistoryInit(testWin);
purgeEntries(sHistory, histLenInChild);
}
}
alert("End of script.");
ddump("End of script.");
}
@ -201,7 +201,7 @@ function SetListenerInChild()
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
sHListener = new sessionHistoryListener();
alert("sHistoryListener object = " + sHListener);
ddump("in SHListenerTest.html: sHistoryListener object = " + sHListener);
testWin.SetListener(sHListener);
}

View File

@ -4,7 +4,9 @@
<head>
<title>loadHistoryPage</title>
// called from SHListenerTest.html. Sets the sHistory listener, and purges sHistory.
<! -- called from SHListenerTest.html.
-- Sets the sHistory listener, and purges sHistory.
-->
<script TYPE="text/javascript" src="nsISHistoryTestLib.js">
@ -15,26 +17,27 @@
<script TYPE="text/javascript">
var tc ;
var debug=0;
var debug=1;
function SetListener(listener)
{
sHistory = sHistoryInit();
alert("session history object = " + sHistory + "\n About to set listener");
setSHistoryListener(sHistory, listener);
sHistory = sHistoryInit(window); // js window
ddump("loadHistoryPage.html: session history object = " + sHistory + "\n About to set listener\n");
setSHistoryListener(sHistory, listener);
}
function ddump(s)
{
if (debug==1)
dump(s);
else if (debug==2)
alert(s);
}
function purgeTheEntries(entries)
{
sHistory = sHistoryInit();
alert("session history object = " + sHistory + "\n About to purge history.");
sHistory = sHistoryInit(window); // js window
ddump("session history object = " + sHistory + "\n About to purge history.\n");
purgeEntries(sHistory, entries);
}

View File

@ -29,7 +29,7 @@ nsISHistoryListener object
function sessionHistoryListener()
{
alert("In sessionHistoryListener constructor");
ddump("In sessionHistoryListener constructor\n");
this.interfaceName = "nsISHistoryListener";
}
@ -56,14 +56,14 @@ sessionHistoryListener.prototype =
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
uriSpec = newUrl.spec;
alert("In OnHistoryNewEntry(). uriSpec = " + uriSpec);
ddump("In OnHistoryNewEntry(). uriSpec = " + uriSpec + "\n");
},
OnHistoryGoBack: function(uri)
{
uriSpec = uri.spec;
alert("In OnHistoryGoBack(). uriSpec = " + uriSpec);
ddump("In OnHistoryGoBack(). uriSpec = " + uriSpec + "\n");
backCallback = true;
return true;
},
@ -72,7 +72,7 @@ sessionHistoryListener.prototype =
{
uriSpec = uri.spec;
alert("In OnHistoryGoForward(). uriSpec = " + uriSpec);
ddump("In OnHistoryGoForward(). uriSpec = " + uriSpec + "\n");
forwardCallback = true;
return true;
},
@ -81,8 +81,8 @@ sessionHistoryListener.prototype =
{
uriSpec = uri.spec;
alert("In OnHistoryReload(). uriSpec = " + uriSpec);
alert("In OnHistoryReload(). reloadFlags = " + reloadFlags);
ddump("In OnHistoryReload(). uriSpec = " + uriSpec + "\n");
ddump("In OnHistoryReload(). reloadFlags = " + reloadFlags + "\n");
reloadCallback = true;
return true;
},
@ -91,15 +91,15 @@ sessionHistoryListener.prototype =
{
uriSpec = uri.spec;
alert("In OnHistoryGotoIndex(). uriSpec = " + uriSpec);
alert("In OnHistoryGotoIndex(). index = " + index);
ddump("In OnHistoryGotoIndex(). uriSpec = " + uriSpec + "\n");
ddump("In OnHistoryGotoIndex(). index = " + index + "\n");
gotoCallback = true;
return true;
},
OnHistoryPurge: function(numEntries)
{
alert("In OnHistoryPurge(). numEntries = " + numEntries);
ddump("In OnHistoryPurge(). numEntries = " + numEntries + "\n");
purgeCallback = true;
return true;
},
@ -108,7 +108,7 @@ sessionHistoryListener.prototype =
{
if (debug ==1)
dump(s);
else
else if (debug==2)
alert(s);
}
}

View File

@ -28,36 +28,44 @@
// of how to use these methods.
// ***************************************************************************
// init() creates and returns the session history object.
function init()
// sHistoryInit() creates and returns the session history object.
function sHistoryInit(theWindow)
{
//alert("In nsISHistoryTest::Init method");
var sHistory = null;
var ifaceReq;
var webNav;
try
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserAccess");
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var ifaceReq = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
if (!ifaceReq) {
alert("Unable to get interface requestor object");
try {
ifaceReq = theWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
}
catch(e){
alert("Unable to get interface requestor object: " + e);
return false;
}
var webNav = ifaceReq.getInterface(Components.interfaces.nsIWebNavigation);
if(!webNav) {
alert("Unable to get WebNavigation");
try {
webNav = ifaceReq.getInterface(Components.interfaces.nsIWebNavigation);
}
catch(e) {
alert("Unable to get WebNavigation: " + e);
return false;
}
sHistory = webNav.sessionHistory;
if (!sHistory) {
alert("Didn't get SessionHistory object");
try {
sHistory = webNav.sessionHistory;
}
catch(e) {
alert("Didn't get SessionHistory object: " + e);
return false;
}
return sHistory;
}
catch(e)
{
alert("Could not find Session History component" + e);
alert("Could not find Session History component: " + e);
return false;
}
}
@ -146,15 +154,15 @@ function testHistoryEntry(entry, index)
// Get URI for the next Entry
Uri = entry.URI;
uriSpec = Uri.spec;
alert("The URI = " + uriSpec);
dump("The URI = " + uriSpec);
// Get Title for the nextEntry
title = entry.title;
alert("The page title = " + title);
dump("The page title = " + title);
// Get SubFrame Status for the nextEntry
frameStatus = entry.isSubFrame;
alert("The subframe value = " + frameStatus);
dump("The subframe value = " + frameStatus);
}
// *************************************************************************
@ -216,4 +224,19 @@ function purgeEntries(sHistory, numEntries)
alert("Didn't get SessionHistory object");
}
sHistory.PurgeHistory(numEntries);
}
}
// *************************************************************************
// setSHistoryListener() adds a session history listener. This enables session
// history events to be tracked (i.e. url load, forward, back, ...). A listener
// and the session history object are the input parameters.
function setSHistoryListener(sHistory, listener)
{
dump("Inside nsISHistoryTestLib.js: setSHistoryListener()");
if (!sHistory) {
alert("Didn't get SessionHistory object");
}
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserAccess");
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
sHistory.addSHistoryListener(listener);
}