Bug 720157 - Don't crash when OnLocationChange sends a null URI. r=smaug
authorJustin Lebar <justin.lebar@gmail.com>
Sun, 22 Jan 2012 15:46:55 -0500
changeset 86304 10c3bb782afffebe365e5dc5800ccf40557bc1c2
parent 86303 14810f6dd6a78b6d5eaa41fac21180ab25ea6461
child 86305 9a67d6f21b3de20f348562aa16d8193dd0aee239
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs720157
milestone12.0a1
Bug 720157 - Don't crash when OnLocationChange sends a null URI. r=smaug
content/html/content/src/nsGenericHTMLFrameElement.cpp
dom/tests/mochitest/general/Makefile.in
dom/tests/mochitest/general/test_browserFrame4.html
dom/tests/mochitest/general/test_browserFrame5.html
--- a/content/html/content/src/nsGenericHTMLFrameElement.cpp
+++ b/content/html/content/src/nsGenericHTMLFrameElement.cpp
@@ -380,16 +380,21 @@ nsGenericHTMLFrameElement::MaybeFireBrow
 }
 
 NS_IMETHODIMP
 nsGenericHTMLFrameElement::OnLocationChange(nsIWebProgress* aWebProgress,
                                             nsIRequest* aRequest,
                                             nsIURI* aURI,
                                             PRUint32 aFlags)
 {
+  // aURI may be null, but that indicates an error case we don't care about.
+  if (!aURI) {
+    return NS_OK;
+  }
+
   nsCAutoString spec;
   aURI->GetSpec(spec);
 
   MaybeFireBrowserEvent(NS_LITERAL_STRING("locationchange"),
                         NS_LITERAL_STRING("customevent"),
                         NS_ConvertUTF8toUTF16(spec));
   return NS_OK;
 }
--- a/dom/tests/mochitest/general/Makefile.in
+++ b/dom/tests/mochitest/general/Makefile.in
@@ -74,16 +74,17 @@ include $(topsrcdir)/config/rules.mk
 		test_focusrings.xul \
 		file_moving_xhr.html \
 		test_vibrator.html \
 		browserFrameHelpers.js \
 		test_browserFrame1.html \
 		test_browserFrame2.html \
 		test_browserFrame3.html \
 		test_browserFrame4.html \
+		test_browserFrame5.html \
 		$(NULL)
 
 _CHROME_FILES = \
 		test_innerScreen.xul \
 		test_offsets.xul \
 		test_offsets.js \
 		$(NULL)
 
--- a/dom/tests/mochitest/general/test_browserFrame4.html
+++ b/dom/tests/mochitest/general/test_browserFrame4.html
@@ -42,16 +42,17 @@ function runTest() {
   });
 
   iframe.addEventListener('mozbrowserlocationchange', function(e) {
     ok(!seenLocationChange, 'Just one locationchange event.');
     seenLocationChange = true;
     ok(seenLoadStart, 'Location change after load start.');
     ok(!seenLoad, 'Location change before load.');
     ok(!seenLoadEnd, 'Location change before load end.');
+    ok(e.detail, 'http://example.com', "event's reported location");
   });
 
   iframe.addEventListener('load', function() {
     ok(!seenLoad, 'Just one load event.');
     seenLoad = true;
     ok(seenLoadStart, 'Load after loadstart.');
     ok(seenLocationChange, 'Load after locationchange.');
     ok(!seenLoadEnd, 'Load before loadend.');
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/general/test_browserFrame5.html
@@ -0,0 +1,56 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=720157
+-->
+<head>
+  <title>Test for Bug 720157</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="browserFrameHelpers.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=720157">Mozilla Bug 720157</a>
+
+<!--
+  Test that data: URIs work with mozbrowserlocationchange events.
+-->
+
+<script type="application/javascript;version=1.7">
+"use strict";
+
+SimpleTest.waitForExplicitFinish();
+
+function runTest() {
+  browserFrameHelpers.setEnabledPref(true);
+  browserFrameHelpers.addToWhitelist();
+
+  var iframe = document.getElementById('iframe');
+  var sawLoad = false;
+  var sawLocationChange = false;
+
+  iframe.addEventListener('mozbrowserlocationchange', function(e) {
+    ok(!sawLocationChange, 'Just one locationchange event.');
+    ok(!sawLoad, 'locationchange before load.');
+    is(e.detail, 'data:text/html,1', "event's reported location");
+    sawLocationChange = true;
+  });
+
+  iframe.addEventListener('load', function() {
+    ok(sawLocationChange, 'Load after locationchange.');
+    ok(!sawLoad, 'Just one load event.');
+    sawLoad = true;
+    SimpleTest.finish();
+  });
+
+  iframe.src = 'data:text/html,1';
+}
+
+addEventListener('load', function() { SimpleTest.executeSoon(runTest); });
+
+</script>
+
+<iframe id='iframe' mozbrowser></iframe>
+
+</body>
+</html>