diff --git a/mozilla/toolkit/components/places/src/nsNavHistory.cpp b/mozilla/toolkit/components/places/src/nsNavHistory.cpp index cab20ee0f74..571c73bbea9 100644 --- a/mozilla/toolkit/components/places/src/nsNavHistory.cpp +++ b/mozilla/toolkit/components/places/src/nsNavHistory.cpp @@ -3654,6 +3654,13 @@ nsNavHistory::AddVisitChain(nsIURI* aURI, PRTime aTime, transitionType = nsINavHistoryService::TRANSITION_EMBED; } } else if (aReferrer) { + // We do not want to add a new visit if the referring site is the same as + // the new site. This is the situation where a page refreshes itself to + // give the user updated information. + PRBool referrerIsSame; + if (NS_SUCCEEDED(aURI->Equals(aReferrer, &referrerIsSame)) && referrerIsSame) + return NS_OK; + // If there is a referrer, we know you came from somewhere, either manually // or automatically. For toplevel windows, assume its manual and you want // to see this in history. For other things, it's some kind of embedded @@ -3679,8 +3686,9 @@ nsNavHistory::AddVisitChain(nsIURI* aURI, PRTime aTime, // most commonly happens on redirects. visitTime = PR_Now(); - // try to turn the referrer into a visit - if (! FindLastVisit(aReferrer, &referringVisit, aSessionID)) { + // Try to turn the referrer into a visit. + // This also populates the session id. + if (!FindLastVisit(aReferrer, &referringVisit, aSessionID)) { // we couldn't find a visit for the referrer, don't set it *aSessionID = GetNewSessionID(); } diff --git a/mozilla/toolkit/components/places/tests/Makefile.in b/mozilla/toolkit/components/places/tests/Makefile.in index c6a7e3621e9..bf22ec0cdeb 100644 --- a/mozilla/toolkit/components/places/tests/Makefile.in +++ b/mozilla/toolkit/components/places/tests/Makefile.in @@ -50,7 +50,10 @@ XPCSHELL_TESTS = unit \ $(NULL) ifdef MOZ_MOCHITEST -DIRS = chrome +DIRS = \ + chrome \ + browser \ + $(NULL) endif include $(topsrcdir)/config/rules.mk diff --git a/mozilla/toolkit/components/places/tests/browser/399606-history.go-0.html b/mozilla/toolkit/components/places/tests/browser/399606-history.go-0.html new file mode 100644 index 00000000000..039708ed71c --- /dev/null +++ b/mozilla/toolkit/components/places/tests/browser/399606-history.go-0.html @@ -0,0 +1,11 @@ + + +history.go(0) + + + +Testing history.go(0) + + diff --git a/mozilla/toolkit/components/places/tests/browser/399606-httprefresh.html b/mozilla/toolkit/components/places/tests/browser/399606-httprefresh.html new file mode 100644 index 00000000000..e43455ee058 --- /dev/null +++ b/mozilla/toolkit/components/places/tests/browser/399606-httprefresh.html @@ -0,0 +1,8 @@ + + + + +httprefresh + +Testing httprefresh + diff --git a/mozilla/toolkit/components/places/tests/browser/399606-location.reload.html b/mozilla/toolkit/components/places/tests/browser/399606-location.reload.html new file mode 100644 index 00000000000..0f46538cdd6 --- /dev/null +++ b/mozilla/toolkit/components/places/tests/browser/399606-location.reload.html @@ -0,0 +1,11 @@ + + +location.reload() + + + +Testing location.reload(); + + diff --git a/mozilla/toolkit/components/places/tests/browser/399606-location.replace.html b/mozilla/toolkit/components/places/tests/browser/399606-location.replace.html new file mode 100644 index 00000000000..36705402ccf --- /dev/null +++ b/mozilla/toolkit/components/places/tests/browser/399606-location.replace.html @@ -0,0 +1,11 @@ + + +location.replace + + + +Testing location.replace + + diff --git a/mozilla/toolkit/components/places/tests/browser/399606-window.location.href.html b/mozilla/toolkit/components/places/tests/browser/399606-window.location.href.html new file mode 100644 index 00000000000..61a2c8ba011 --- /dev/null +++ b/mozilla/toolkit/components/places/tests/browser/399606-window.location.href.html @@ -0,0 +1,11 @@ + + +window.location.href + + + +Testing window.location.href + + diff --git a/mozilla/toolkit/components/places/tests/browser/399606-window.location.html b/mozilla/toolkit/components/places/tests/browser/399606-window.location.html new file mode 100644 index 00000000000..e77f7307161 --- /dev/null +++ b/mozilla/toolkit/components/places/tests/browser/399606-window.location.html @@ -0,0 +1,11 @@ + + +window.location + + + +Testing window.location + + diff --git a/mozilla/toolkit/components/places/tests/browser/Makefile.in b/mozilla/toolkit/components/places/tests/browser/Makefile.in new file mode 100644 index 00000000000..52a8c195728 --- /dev/null +++ b/mozilla/toolkit/components/places/tests/browser/Makefile.in @@ -0,0 +1,72 @@ +# +# ***** 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 (Original Author) +# +# 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 = toolkit/components/places/tests/browser + +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) + +# 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) + +libs:: $(_BROWSER_FILES) + $(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir) + +libs:: $(_HTTP_FILES) + $(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir) diff --git a/mozilla/toolkit/components/places/tests/browser/browser_bug413985-history.go-0.js b/mozilla/toolkit/components/places/tests/browser/browser_bug413985-history.go-0.js new file mode 100644 index 00000000000..471ce503b86 --- /dev/null +++ b/mozilla/toolkit/components/places/tests/browser/browser_bug413985-history.go-0.js @@ -0,0 +1,116 @@ +/* ***** 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 (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) { + dump("onVisit: " + aURI.spec + "\n"); + confirm_results(); + + histsvc.removeObserver(observer, false); + win.content.document.location.href = "about:blank"; + finish(); + }, + onTitleChanged: function(aURI, aPageTitle) {}, + 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); + dump("query uri is " + uri.spec + "\n"); + query.uri = uri; + var result = histsvc.executeQuery(query, options); + var root = result.root; + root.containerOpen = true; + var cc = root.childCount; + // TODO bug 415004 + todo_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) { + dump("location is " + aEvent.originalTarget.location.href + "\n"); + loadCount++; + dump("new load count is " + loadCount + "\n"); + + 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(); +} diff --git a/mozilla/toolkit/components/places/tests/browser/browser_bug413985-httprefresh.js b/mozilla/toolkit/components/places/tests/browser/browser_bug413985-httprefresh.js new file mode 100644 index 00000000000..4d5b3c091a9 --- /dev/null +++ b/mozilla/toolkit/components/places/tests/browser/browser_bug413985-httprefresh.js @@ -0,0 +1,115 @@ +/* ***** 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 (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) { + dump("onVisit: " + aURI.spec + "\n"); + confirm_results(); + + histsvc.removeObserver(observer, false); + win.content.document.location.href = "about:blank"; + finish(); + }, + onTitleChanged: function(aURI, aPageTitle) {}, + 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); + dump("query uri is " + uri.spec + "\n"); + 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) { + dump("location is " + aEvent.originalTarget.location.href + "\n"); + loadCount++; + dump("new load count is " + loadCount + "\n"); + + 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(); +} diff --git a/mozilla/toolkit/components/places/tests/browser/browser_bug413985-location.reload.js b/mozilla/toolkit/components/places/tests/browser/browser_bug413985-location.reload.js new file mode 100644 index 00000000000..afd4228fcdb --- /dev/null +++ b/mozilla/toolkit/components/places/tests/browser/browser_bug413985-location.reload.js @@ -0,0 +1,115 @@ +/* ***** 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 (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) { + dump("onVisit: " + aURI.spec + "\n"); + confirm_results(); + + histsvc.removeObserver(observer, false); + win.content.document.location.href = "about:blank"; + finish(); + }, + onTitleChanged: function(aURI, aPageTitle) {}, + 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); + dump("query uri is " + uri.spec + "\n"); + 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) { + dump("location is " + aEvent.originalTarget.location.href + "\n"); + loadCount++; + dump("new load count is " + loadCount + "\n"); + + 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(); +} diff --git a/mozilla/toolkit/components/places/tests/browser/browser_bug413985-location.replace.js b/mozilla/toolkit/components/places/tests/browser/browser_bug413985-location.replace.js new file mode 100644 index 00000000000..632670ff411 --- /dev/null +++ b/mozilla/toolkit/components/places/tests/browser/browser_bug413985-location.replace.js @@ -0,0 +1,115 @@ +/* ***** 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 (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) { + dump("onVisit: " + aURI.spec + "\n"); + confirm_results(); + + histsvc.removeObserver(observer, false); + win.content.document.location.href = "about:blank"; + finish(); + }, + onTitleChanged: function(aURI, aPageTitle) {}, + 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); + dump("query uri is " + uri.spec + "\n"); + 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) { + dump("location is " + aEvent.originalTarget.location.href + "\n"); + loadCount++; + dump("new load count is " + loadCount + "\n"); + + 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(); +} diff --git a/mozilla/toolkit/components/places/tests/browser/browser_bug413985-window.location.href.js b/mozilla/toolkit/components/places/tests/browser/browser_bug413985-window.location.href.js new file mode 100644 index 00000000000..7d753e00662 --- /dev/null +++ b/mozilla/toolkit/components/places/tests/browser/browser_bug413985-window.location.href.js @@ -0,0 +1,115 @@ +/* ***** 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 (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.href.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) { + dump("onVisit: " + aURI.spec + "\n"); + confirm_results(); + + histsvc.removeObserver(observer, false); + win.content.document.location.href = "about:blank"; + finish(); + }, + onTitleChanged: function(aURI, aPageTitle) {}, + 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); + dump("query uri is " + uri.spec + "\n"); + 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) { + dump("location is " + aEvent.originalTarget.location.href + "\n"); + loadCount++; + dump("new load count is " + loadCount + "\n"); + + 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(); +} diff --git a/mozilla/toolkit/components/places/tests/browser/browser_bug413985-window.location.js b/mozilla/toolkit/components/places/tests/browser/browser_bug413985-window.location.js new file mode 100644 index 00000000000..de5584417b2 --- /dev/null +++ b/mozilla/toolkit/components/places/tests/browser/browser_bug413985-window.location.js @@ -0,0 +1,115 @@ +/* ***** 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 (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) { + dump("onVisit: " + aURI.spec + "\n"); + confirm_results(); + + histsvc.removeObserver(observer, false); + win.content.document.location.href = "about:blank"; + finish(); + }, + onTitleChanged: function(aURI, aPageTitle) {}, + 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); + dump("query uri is " + uri.spec + "\n"); + 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) { + dump("location is " + aEvent.originalTarget.location.href + "\n"); + loadCount++; + dump("new load count is " + loadCount + "\n"); + + 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(); +} diff --git a/mozilla/toolkit/components/places/tests/unit/test_399606.js b/mozilla/toolkit/components/places/tests/unit/test_399606.js new file mode 100644 index 00000000000..a8a3488b369 --- /dev/null +++ b/mozilla/toolkit/components/places/tests/unit/test_399606.js @@ -0,0 +1,102 @@ +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et: */ +/* ***** 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 Google Inc. + * Portions created by the Initial Developer are Copyright (C) 2005 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Darin Fisher + * Dietrich Ayala + * Dan Mills + * Seth Spitzer + * + * 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 ***** */ + +// AddURI transactions are created lazily. +do_test_pending(); + +// Get history service +try { + var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].getService(Ci.nsINavHistoryService); +} catch(ex) { + do_throw("Could not get history service\n"); +} + +var ghist = Cc["@mozilla.org/browser/global-history;2"].getService(Ci.nsIGlobalHistory2); + +// create and add history observer +var observer = { + onBeginUpdateBatch: function() {}, + onEndUpdateBatch: function() {}, + visitCount: 0, + onVisit: function(aURI, aVisitID, aTime, aSessionID, aReferringID, aTransitionType) { + this.visitCount++; + dump("onVisit: " + aURI.spec + "\n"); + confirm_results(); + }, + onTitleChanged: function(aURI, aPageTitle) {}, + 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); + +// main +function run_test() { + var now = Date.now(); + var testURI = uri("http://fez.com"); + ghist.addURI(testURI, false, true, null); + ghist.addURI(testURI, false, true, testURI); + // lazy message timer is 3000, see LAZY_MESSAGE_TIMEOUT + do_timeout(3500, "confirm_results();"); +} + +function confirm_results() { + var options = histsvc.getNewQueryOptions(); + options.resultType = options.RESULTS_AS_VISIT; + options.includeHidden = true; + var query = histsvc.getNewQuery(); + var result = histsvc.executeQuery(query, options); + var root = result.root; + root.containerOpen = true; + var cc = root.childCount; + do_check_eq(cc, 1); + root.containerOpen = false; + do_test_finished(); +}