Bug 416066 - Tests for bug 399606 are commented out and unreliable, so fix them, r=sdwilsh

This commit is contained in:
Marco Bonardo 2009-08-21 22:36:47 +02:00
parent 89c31657a5
commit 6f4aab9823
14 changed files with 74 additions and 663 deletions

View File

@ -47,28 +47,29 @@ include $(DEPTH)/config/autoconf.mk
MODULE = test_places
XPCSHELL_TESTS = \
autocomplete \
sync \
bookmarks \
queries \
unit \
$(NULL)
autocomplete \
sync \
bookmarks \
queries \
unit \
$(NULL)
# Simple MochiTests
MOCHI_TESTS = mochitest/test_bug_405924.html \
mochitest/test_bug_411966.html \
mochitest/test_bug_461710.html \
$(NULL)
MOCHI_TESTS = \
mochitest/test_bug_405924.html \
mochitest/test_bug_411966.html \
mochitest/test_bug_461710.html \
$(NULL)
MOCHI_CONTENT = mochitest/prompt_common.js \
$(NULL)
MOCHI_CONTENT = \
mochitest/prompt_common.js \
$(NULL)
DIRS = \
chrome \
mochitest/bug_411966 \
mochitest/bug_461710 \
# These tests are disabled for the time being, see bug 416066
# browser \
browser \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -46,24 +46,19 @@ include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
_BROWSER_FILES = \
browser_bug413985-httprefresh.js \
# browser_bug413985-location.reload.js \
# browser_bug413985-location.replace.js \
browser_bug413985-window.location.href.js \
browser_bug413985-window.location.js \
browser_bug413985-history.go-0.js \
$(NULL)
browser_bug399606.js \
$(NULL)
# These are files that need to be loaded via the HTTP proxy server
# Access them through http://example.com/
_HTTP_FILES = \
399606-httprefresh.html \
399606-location.reload.html \
399606-location.replace.html \
399606-window.location.href.html \
399606-window.location.html \
399606-history.go-0.html \
$(NULL)
bug_399606/399606-httprefresh.html \
bug_399606/399606-location.reload.html \
bug_399606/399606-location.replace.html \
bug_399606/399606-window.location.href.html \
bug_399606/399606-window.location.html \
bug_399606/399606-history.go-0.html \
$(NULL)
libs:: $(_BROWSER_FILES)
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)

View File

@ -20,6 +20,7 @@
*
* Contributor(s):
* Shawn Wilsher <me@shawnwilsher.com> (Original Author)
* Marco Bonardo <mak77@bonardo.net>
*
* 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
@ -35,25 +36,34 @@
*
* ***** END LICENSE BLOCK ***** */
function test()
{
const TEST_URI = "http://example.com/tests/toolkit/components/places/tests/browser/399606-window.location.href.html";
function test() {
// Due to LAZY_ADD this is an async test.
waitForExplicitFinish();
const LAZY_ADD_TIMER = 3000;
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
var URIs = [
"http://example.com/tests/toolkit/components/places/tests/browser/399606-window.location.href.html",
"http://example.com/tests/toolkit/components/places/tests/browser/399606-history.go-0.html",
"http://example.com/tests/toolkit/components/places/tests/browser/399606-location.replace.html",
"http://example.com/tests/toolkit/components/places/tests/browser/399606-location.reload.html",
"http://example.com/tests/toolkit/components/places/tests/browser/399606-httprefresh.html",
"http://example.com/tests/toolkit/components/places/tests/browser/399606-window.location.html",
];
var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
// create and add history observer
var observer = {
// Create and add history observer.
var historyObserver = {
visitCount: Array(),
onBeginUpdateBatch: function() {},
onEndUpdateBatch: function() {},
onVisit: function(aURI, aVisitID, aTime, aSessionID, aReferringID,
aTransitionType) {
info("onVisit: " + aURI.spec);
confirm_results();
histsvc.removeObserver(observer, false);
win.content.document.location.href = "about:blank";
finish();
info("Received onVisit: " + aURI.spec);
if (aURI.spec in this.visitCount)
this.visitCount[aURI.spec]++;
else
this.visitCount[aURI.spec] = 1;
},
onTitleChanged: function(aURI, aPageTitle) {},
onBeforeDeleteURI: function(aURI) {},
@ -61,56 +71,41 @@ function test()
onClearHistory: function() {},
onPageChanged: function(aURI, aWhat, aValue) {},
onPageExpired: function(aURI, aVisitTime, aWholeEntry) {},
QueryInterface: function(iid) {
if (iid.equals(Ci.nsINavHistoryObserver) ||
iid.equals(Ci.nsISupports)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
}
QueryInterface: XPCOMUtils.generateQI([Ci.nsINavHistoryObserver])
};
histsvc.addObserver(observer, false);
// If LAZY_ADD is ever disabled, this function will not be correct
var loadCount = 0;
hs.addObserver(historyObserver, false);
function confirm_results() {
var options = histsvc.getNewQueryOptions();
options.resultType = options.RESULTS_AS_VISIT;
options.includeHidden = true;
var query = histsvc.getNewQuery();
var uri = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService).
newURI(TEST_URI, null, null);
info("query uri is " + uri.spec);
query.uri = uri;
var result = histsvc.executeQuery(query, options);
var root = result.root;
root.containerOpen = true;
var cc = root.childCount;
is(cc, 1, "Visit count is what we expect");
ok(loadCount > 1, "Load count is greater than 1");
root.containerOpen = false;
hs.removeObserver(historyObserver, false);
for (let aURI in historyObserver.visitCount) {
is(historyObserver.visitCount[aURI], 1, "onVisit has been received right number of times for " + aURI);
}
hs.QueryInterface(Ci.nsIBrowserHistory).removeAllPages();
finish();
}
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
getService(Ci.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
var loadCount = 0;
function handleLoad(aEvent) {
info("location is " + aEvent.originalTarget.location.href);
loadCount++;
info("new load count is " + loadCount);
if (loadCount == 3)
win.getBrowser().removeEventListener("DOMContentLoaded", handleLoad, true);
if (loadCount == 3) {
window.getBrowser().removeEventListener("DOMContentLoaded", handleLoad, true);
window.content.document.location.href = "about:blank";
executeSoon(check_next_uri);
}
}
win.getBrowser().addEventListener("DOMContentLoaded", handleLoad, true);
// load page
win.content.document.location.href = TEST_URI;
// let our load handler handle the rest of the test
waitForExplicitFinish();
function check_next_uri() {
if (URIs.length) {
let uri = URIs.shift();
loadCount = 0;
window.getBrowser().addEventListener("DOMContentLoaded", handleLoad, true);
window.content.document.location.href = uri;
}
else {
setTimeout(confirm_results, LAZY_ADD_TIMER * 2);
}
}
executeSoon(check_next_uri);
}

View File

@ -1,116 +0,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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Shawn Wilsher <me@shawnwilsher.com> (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 ***** */
function test()
{
const TEST_URI = "http://example.com/tests/toolkit/components/places/tests/browser/399606-history.go-0.html";
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
// create and add history observer
var observer = {
onBeginUpdateBatch: function() {},
onEndUpdateBatch: function() {},
onVisit: function(aURI, aVisitID, aTime, aSessionID, aReferringID,
aTransitionType) {
info("onVisit: " + aURI.spec);
confirm_results();
histsvc.removeObserver(observer, false);
win.content.document.location.href = "about:blank";
finish();
},
onTitleChanged: function(aURI, aPageTitle) {},
onBeforeDeleteURI: function(aURI) {},
onDeleteURI: function(aURI) {},
onClearHistory: function() {},
onPageChanged: function(aURI, aWhat, aValue) {},
onPageExpired: function(aURI, aVisitTime, aWholeEntry) {},
QueryInterface: function(iid) {
if (iid.equals(Ci.nsINavHistoryObserver) ||
iid.equals(Ci.nsISupports)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
}
};
histsvc.addObserver(observer, false);
// If LAZY_ADD is ever disabled, this function will not be correct
var loadCount = 0;
function confirm_results() {
var options = histsvc.getNewQueryOptions();
options.resultType = options.RESULTS_AS_VISIT;
options.includeHidden = true;
var query = histsvc.getNewQuery();
var uri = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService).
newURI(TEST_URI, null, null);
info("query uri is " + uri.spec);
query.uri = uri;
var result = histsvc.executeQuery(query, options);
var root = result.root;
root.containerOpen = true;
var cc = root.childCount;
is(cc, 1, "Visit count is what we expect");
ok(loadCount > 1, "Load count is greater than 1");
root.containerOpen = false;
}
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
getService(Ci.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
function handleLoad(aEvent) {
info("location is " + aEvent.originalTarget.location.href);
loadCount++;
info("new load count is " + loadCount);
if (loadCount == 3)
win.getBrowser().removeEventListener("DOMContentLoaded", handleLoad, false);
}
win.getBrowser().addEventListener("DOMContentLoaded", handleLoad, false);
// load page
win.content.document.location.href = TEST_URI;
// let our load handler handle the rest of the test
waitForExplicitFinish();
}

View File

@ -1,116 +0,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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Shawn Wilsher <me@shawnwilsher.com> (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 ***** */
function test()
{
const TEST_URI = "http://example.com/tests/toolkit/components/places/tests/browser/399606-httprefresh.html";
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
// create and add history observer
var observer = {
onBeginUpdateBatch: function() {},
onEndUpdateBatch: function() {},
onVisit: function(aURI, aVisitID, aTime, aSessionID, aReferringID,
aTransitionType) {
info("onVisit: " + aURI.spec);
confirm_results();
histsvc.removeObserver(observer, false);
win.content.document.location.href = "about:blank";
finish();
},
onTitleChanged: function(aURI, aPageTitle) {},
onBeforeDeleteURI: function(aURI) {},
onDeleteURI: function(aURI) {},
onClearHistory: function() {},
onPageChanged: function(aURI, aWhat, aValue) {},
onPageExpired: function(aURI, aVisitTime, aWholeEntry) {},
QueryInterface: function(iid) {
if (iid.equals(Ci.nsINavHistoryObserver) ||
iid.equals(Ci.nsISupports)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
}
};
histsvc.addObserver(observer, false);
// If LAZY_ADD is ever disabled, this function will not be correct
var loadCount = 0;
function confirm_results() {
var options = histsvc.getNewQueryOptions();
options.resultType = options.RESULTS_AS_VISIT;
options.includeHidden = true;
var query = histsvc.getNewQuery();
var uri = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService).
newURI(TEST_URI, null, null);
info("query uri is " + uri.spec);
query.uri = uri;
var result = histsvc.executeQuery(query, options);
var root = result.root;
root.containerOpen = true;
var cc = root.childCount;
is(cc, 1, "Visit count is what we expect");
ok(loadCount > 1, "Load count is greater than 1");
root.containerOpen = false;
}
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
getService(Ci.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
function handleLoad(aEvent) {
info("location is " + aEvent.originalTarget.location.href);
loadCount++;
info("new load count is " + loadCount);
if (loadCount == 3)
win.getBrowser().removeEventListener("DOMContentLoaded", handleLoad, false);
}
win.getBrowser().addEventListener("DOMContentLoaded", handleLoad, false);
// load page
win.content.document.location.href = TEST_URI;
// let our load handler handle the rest of the test
waitForExplicitFinish();
}

View File

@ -1,116 +0,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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Shawn Wilsher <me@shawnwilsher.com> (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 ***** */
function test()
{
const TEST_URI = "http://example.com/tests/toolkit/components/places/tests/browser/399606-location.reload.html";
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
// create and add history observer
var observer = {
onBeginUpdateBatch: function() {},
onEndUpdateBatch: function() {},
onVisit: function(aURI, aVisitID, aTime, aSessionID, aReferringID,
aTransitionType) {
info("onVisit: " + aURI.spec);
confirm_results();
histsvc.removeObserver(observer, false);
win.content.document.location.href = "about:blank";
finish();
},
onTitleChanged: function(aURI, aPageTitle) {},
onBeforeDeleteURI: function(aURI) {},
onDeleteURI: function(aURI) {},
onClearHistory: function() {},
onPageChanged: function(aURI, aWhat, aValue) {},
onPageExpired: function(aURI, aVisitTime, aWholeEntry) {},
QueryInterface: function(iid) {
if (iid.equals(Ci.nsINavHistoryObserver) ||
iid.equals(Ci.nsISupports)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
}
};
histsvc.addObserver(observer, false);
// If LAZY_ADD is ever disabled, this function will not be correct
var loadCount = 0;
function confirm_results() {
var options = histsvc.getNewQueryOptions();
options.resultType = options.RESULTS_AS_VISIT;
options.includeHidden = true;
var query = histsvc.getNewQuery();
var uri = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService).
newURI(TEST_URI, null, null);
info("query uri is " + uri.spec);
query.uri = uri;
var result = histsvc.executeQuery(query, options);
var root = result.root;
root.containerOpen = true;
var cc = root.childCount;
is(cc, 1, "Visit count is what we expect");
ok(loadCount > 1, "Load count is greater than 1");
root.containerOpen = false;
}
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
getService(Ci.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
function handleLoad(aEvent) {
info("location is " + aEvent.originalTarget.location.href);
loadCount++;
info("new load count is " + loadCount);
if (loadCount == 3)
win.getBrowser().removeEventListener("DOMContentLoaded", handleLoad, true);
}
win.getBrowser().addEventListener("DOMContentLoaded", handleLoad, true);
// load page
win.content.document.location.href = TEST_URI;
// let our load handler handle the rest of the test
waitForExplicitFinish();
}

View File

@ -1,116 +0,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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Shawn Wilsher <me@shawnwilsher.com> (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 ***** */
function test()
{
const TEST_URI = "http://example.com/tests/toolkit/components/places/tests/browser/399606-location.replace.html";
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
// create and add history observer
var observer = {
onBeginUpdateBatch: function() {},
onEndUpdateBatch: function() {},
onVisit: function(aURI, aVisitID, aTime, aSessionID, aReferringID,
aTransitionType) {
info("onVisit: " + aURI.spec);
confirm_results();
histsvc.removeObserver(observer, false);
win.content.document.location.href = "about:blank";
finish();
},
onTitleChanged: function(aURI, aPageTitle) {},
onBeforeDeleteURI: function(aURI) {},
onDeleteURI: function(aURI) {},
onClearHistory: function() {},
onPageChanged: function(aURI, aWhat, aValue) {},
onPageExpired: function(aURI, aVisitTime, aWholeEntry) {},
QueryInterface: function(iid) {
if (iid.equals(Ci.nsINavHistoryObserver) ||
iid.equals(Ci.nsISupports)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
}
};
histsvc.addObserver(observer, false);
// If LAZY_ADD is ever disabled, this function will not be correct
var loadCount = 0;
function confirm_results() {
var options = histsvc.getNewQueryOptions();
options.resultType = options.RESULTS_AS_VISIT;
options.includeHidden = true;
var query = histsvc.getNewQuery();
var uri = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService).
newURI(TEST_URI, null, null);
info("query uri is " + uri.spec);
query.uri = uri;
var result = histsvc.executeQuery(query, options);
var root = result.root;
root.containerOpen = true;
var cc = root.childCount;
is(cc, 1, "Visit count is what we expect");
ok(loadCount > 1, "Load count is greater than 1");
root.containerOpen = false;
}
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
getService(Ci.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
function handleLoad(aEvent) {
info("location is " + aEvent.originalTarget.location.href);
loadCount++;
info("new load count is " + loadCount);
if (loadCount == 3)
win.getBrowser().removeEventListener("DOMContentLoaded", handleLoad, true);
}
win.getBrowser().addEventListener("DOMContentLoaded", handleLoad, true);
// load page
win.content.document.location.href = TEST_URI;
// let our load handler handle the rest of the test
waitForExplicitFinish();
}

View File

@ -1,116 +0,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 mozilla.org code.
*
* The Initial Developer of the Original Code is
* Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Shawn Wilsher <me@shawnwilsher.com> (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 ***** */
function test()
{
const TEST_URI = "http://example.com/tests/toolkit/components/places/tests/browser/399606-window.location.html";
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
// create and add history observer
var observer = {
onBeginUpdateBatch: function() {},
onEndUpdateBatch: function() {},
onVisit: function(aURI, aVisitID, aTime, aSessionID, aReferringID,
aTransitionType) {
info("onVisit: " + aURI.spec);
confirm_results();
histsvc.removeObserver(observer, false);
win.content.document.location.href = "about:blank";
finish();
},
onTitleChanged: function(aURI, aPageTitle) {},
onBeforeDeleteURI: function(aURI) {},
onDeleteURI: function(aURI) {},
onClearHistory: function() {},
onPageChanged: function(aURI, aWhat, aValue) {},
onPageExpired: function(aURI, aVisitTime, aWholeEntry) {},
QueryInterface: function(iid) {
if (iid.equals(Ci.nsINavHistoryObserver) ||
iid.equals(Ci.nsISupports)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
}
};
histsvc.addObserver(observer, false);
// If LAZY_ADD is ever disabled, this function will not be correct
var loadCount = 0;
function confirm_results() {
var options = histsvc.getNewQueryOptions();
options.resultType = options.RESULTS_AS_VISIT;
options.includeHidden = true;
var query = histsvc.getNewQuery();
var uri = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService).
newURI(TEST_URI, null, null);
info("query uri is " + uri.spec);
query.uri = uri;
var result = histsvc.executeQuery(query, options);
var root = result.root;
root.containerOpen = true;
var cc = root.childCount;
is(cc, 1, "Visit count is what we expect");
ok(loadCount > 1, "Load count is greater than 1");
root.containerOpen = false;
}
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
getService(Ci.nsIWindowMediator);
var win = wm.getMostRecentWindow("navigator:browser");
function handleLoad(aEvent) {
info("location is " + aEvent.originalTarget.location.href);
loadCount++;
info("new load count is " + loadCount);
if (loadCount == 3)
win.getBrowser().removeEventListener("DOMContentLoaded", handleLoad, true);
}
win.getBrowser().addEventListener("DOMContentLoaded", handleLoad, true);
// load page
win.content.document.location.href = TEST_URI;
// let our load handler handle the rest of the test
waitForExplicitFinish();
}