Bug 726272 - [Page Thumbnails] don't capture error pages; r=dietrich
authorTim Taubert <tim.taubert@gmx.de>
Fri, 16 Mar 2012 16:13:58 +0100
changeset 89591 657e7edcb91c9637610ff8e867c6e249828ed3d0
parent 89590 1b34bd4a54250dc7c074146602389762164c52f2
child 89592 a53f34be3b811c202e75123a9d5f974bf7d94e8a
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersdietrich
bugs726272
milestone14.0a1
Bug 726272 - [Page Thumbnails] don't capture error pages; r=dietrich
browser/base/content/browser-thumbnails.js
browser/components/thumbnails/test/Makefile.in
browser/components/thumbnails/test/browser_thumbnails_bug726727.js
--- a/browser/base/content/browser-thumbnails.js
+++ b/browser/base/content/browser-thumbnails.js
@@ -105,16 +105,21 @@ let gBrowserThumbnails = {
       return false;
 
     // Don't take screenshots of about: pages.
     if (aBrowser.currentURI.schemeIs("about"))
       return false;
 
     let channel = aBrowser.docShell.currentDocumentChannel;
 
+    // Don't take screenshots of internally redirecting about: pages.
+    // This includes error pages.
+    if (channel.originalURI.schemeIs("about"))
+      return false;
+
     try {
       // If the channel is a nsIHttpChannel get its http status code.
       let httpChannel = channel.QueryInterface(Ci.nsIHttpChannel);
 
       // Continue only if we have a 2xx status code.
       return Math.floor(httpChannel.responseStatus / 100) == 2;
     } catch (e) {
       // Not a http channel, we just assume a success status code.
--- a/browser/components/thumbnails/test/Makefile.in
+++ b/browser/components/thumbnails/test/Makefile.in
@@ -8,13 +8,14 @@ srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir  = browser/components/thumbnails/test
 
 include $(DEPTH)/config/autoconf.mk
 include $(topsrcdir)/config/rules.mk
 
 _BROWSER_FILES = \
 	browser_thumbnails_capture.js \
+	browser_thumbnails_bug726727.js \
 	head.js \
 	$(NULL)
 
 libs::	$(_BROWSER_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/browser/components/thumbnails/test/browser_thumbnails_bug726727.js
@@ -0,0 +1,19 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * These tests ensure that capturing a sites's thumbnail, saving it and
+ * retrieving it from the cache works.
+ */
+function runTests() {
+  // Create a tab that shows an error page.
+  let tab = gBrowser.addTab("http://non-existant.url/");
+  let browser = tab.linkedBrowser;
+
+  yield browser.addEventListener("DOMContentLoaded", function onLoad() {
+    browser.removeEventListener("DOMContentLoaded", onLoad, false);
+    executeSoon(next);
+  }, false);
+
+  ok(!gBrowserThumbnails._shouldCapture(browser), "we're not going to capture an error page");
+}