diff --git a/toolkit/content/tests/Makefile.in b/toolkit/content/tests/Makefile.in --- a/toolkit/content/tests/Makefile.in +++ b/toolkit/content/tests/Makefile.in @@ -42,11 +42,11 @@ VPATH = @srcdir@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk MODULE = test_toolkit_general XPCSHELL_TESTS = unit -DIRS = chrome widgets +DIRS = browser chrome widgets include $(topsrcdir)/config/rules.mk diff --git a/toolkit/content/tests/browser/Makefile.in b/toolkit/content/tests/browser/Makefile.in new file mode 100644 --- /dev/null +++ b/toolkit/content/tests/browser/Makefile.in @@ -0,0 +1,55 @@ +# +# ***** 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 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 ***** + +DEPTH = ../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ +relativesrcdir = toolkit/content/tests/browser + +include $(DEPTH)/config/autoconf.mk +include $(topsrcdir)/config/rules.mk + +_BROWSER_FILES = \ + bug471962_testpage_inner.sjs \ + bug471962_testpage_outer.sjs \ + browser_bug471962.js \ + $(NULL) + +libs:: $(_BROWSER_FILES) + $(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir) diff --git a/toolkit/content/tests/browser/browser_bug471962.js b/toolkit/content/tests/browser/browser_bug471962.js new file mode 100644 --- /dev/null +++ b/toolkit/content/tests/browser/browser_bug471962.js @@ -0,0 +1,53 @@ +function test() +{ + var innerFrame; + + function startTest() { + waitForExplicitFinish(); + + // Display the outer page + gBrowser.addEventListener("pageshow", onPageShow, false); + gBrowser.loadURI("http://localhost:8888/browser/toolkit/content/tests/browser/bug471962_testpage_outer.sjs"); + } + + function onPageShow() { + gBrowser.removeEventListener("pageshow", onPageShow, false); + + // Submit the form in the outer page + gBrowser.addEventListener("DOMContentLoaded", onOuterSubmitted, false); + gBrowser.contentDocument.getElementById("postForm").submit(); + } + + function onOuterSubmitted() { + gBrowser.removeEventListener("DOMContentLoaded", onOuterSubmitted, false); + + // Wait for the inner frame in the outer page to be loaded + gBrowser.addEventListener("DOMContentLoaded", onInnerReady, false); + } + + function onInnerReady() { + gBrowser.removeEventListener("DOMContentLoaded", onInnerReady, false); + + // Save a reference to the inner frame for later + innerFrame = gBrowser.contentDocument.getElementById("innerFrame"); + + // Submit the form in the inner page + gBrowser.addEventListener("DOMContentLoaded", onInnerSubmitted, false); + innerFrame.contentDocument.getElementById("postForm").submit(); + } + + function onInnerSubmitted() { + gBrowser.removeEventListener("DOMContentLoaded", onInnerSubmitted, false); + + // Call the internal save function defined in contentAreaUtils.js + saveDocument(innerFrame.contentDocument); + + // TODO: Search for outer POST data in the saved file + + ok(true, "The saved inner frame does not contain outer POST data"); + finish(); + } + + // Start the test now that all the inner functions are defined + startTest(); +} diff --git a/toolkit/content/tests/browser/bug471962_testpage_inner.sjs b/toolkit/content/tests/browser/bug471962_testpage_inner.sjs new file mode 100644 --- /dev/null +++ b/toolkit/content/tests/browser/bug471962_testpage_inner.sjs @@ -0,0 +1,27 @@ +const CC = Components.Constructor; +const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1", + "nsIBinaryInputStream", + "setInputStream"); + +function handleRequest(request, response) +{ + var body = + '\ + \ + Inner POST data: '; + + var bodyStream = new BinaryInputStream(request.bodyInputStream); + var bytes = [], avail = 0; + while ((avail = bodyStream.available()) > 0) + body += String.fromCharCode.apply(String, bodyStream.readByteArray(avail)); + + body += + '
\ + \ + \ +
\ + \ + '; + + response.bodyOutputStream.write(body, body.length); +} diff --git a/toolkit/content/tests/browser/bug471962_testpage_outer.sjs b/toolkit/content/tests/browser/bug471962_testpage_outer.sjs new file mode 100644 --- /dev/null +++ b/toolkit/content/tests/browser/bug471962_testpage_outer.sjs @@ -0,0 +1,30 @@ +const CC = Components.Constructor; +const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1", + "nsIBinaryInputStream", + "setInputStream"); + +function handleRequest(request, response) +{ + var body = + '\ + \ + Outer POST data: '; + + var bodyStream = new BinaryInputStream(request.bodyInputStream); + var bytes = [], avail = 0; + while ((avail = bodyStream.available()) > 0) + body += String.fromCharCode.apply(String, bodyStream.readByteArray(avail)); + + body += + '
\ + \ + \ +
\ + \ +