Bug 1450358 P1 Add an event listener runtime leak check for XHR. r=baku
authorBen Kelly <ben@wanderview.com>
Wed, 04 Apr 2018 07:47:24 -0700
changeset 1473483 db76b6474358f4ca81d52bbae84c9182949817a1
parent 1473482 8f1955e145b43d99cbd3dbb063e5c918b49b0f26
child 1473484 e31b5fcef600c43c5600fd36b787227c6b5c2f1b
child 1473784 5899c86d8e9b3f47c9b4ebd22bf74019936f2b30
push id262728
push userbkelly@mozilla.com
push dateWed, 04 Apr 2018 16:31:13 +0000
treeherdertry@851c4cf8e817 [default view] [failures only]
reviewersbaku
bugs1450358
milestone61.0a1
Bug 1450358 P1 Add an event listener runtime leak check for XHR. r=baku
dom/xhr/tests/mochitest.ini
dom/xhr/tests/slow.sjs
dom/xhr/tests/test_event_listener_leaks.html
--- a/dom/xhr/tests/mochitest.ini
+++ b/dom/xhr/tests/mochitest.ini
@@ -59,16 +59,18 @@ support-files =
   subdir/relativeLoad_sub_import.js
   common_temporaryFileBlob.js
   worker_temporaryFileBlob.js
   worker_bug1300552.js
   sync_xhr_unload.sjs
   iframe_sync_xhr_unload.html
   empty.html
   file_sync_xhr_document_write_with_iframe.html
+  slow.sjs
+  !/dom/events/test/event_leak_utils.js
 
 [test_bug1300552.html]
 [test_html_in_xhr.html]
 [test_relativeLoad.html]
 skip-if = buildapp == 'b2g' # b2g(Failed to load script: relativeLoad_import.js) b2g-debug(Failed to load script: relativeLoad_import.js) b2g-desktop(Failed to load script: relativeLoad_import.js)
 [test_sync_xhr_timer.xhtml]
 skip-if = toolkit == 'android'
 [test_sync_xhr_unload.html]
@@ -109,8 +111,9 @@ skip-if = (buildapp == 'b2g') # b2g-debu
 skip-if = buildapp == 'b2g' || (android_version == '18' && debug) # b2g(flaky on B2G, bug 960743) b2g-debug(flaky on B2G, bug 960743) b2g-desktop(flaky on B2G, bug 960743)
 support-files = test_XHR_timeout.js
 [test_xhr_withCredentials.html]
 [test_XHRDocURI.html]
 [test_XHRResponseURL.html]
 [test_XHRSendData.html]
 [test_sync_xhr_document_write_with_iframe.html]
 [test_nestedSyncXHR.html]
+[test_event_listener_leaks.html]
new file mode 100644
--- /dev/null
+++ b/dom/xhr/tests/slow.sjs
@@ -0,0 +1,11 @@
+function handleRequest(request, response)
+{
+  response.processAsync();
+
+  timer = Components.classes["@mozilla.org/timer;1"].
+          createInstance(Components.interfaces.nsITimer);
+  timer.init(function() {
+    response.write("Here the content. But slowly.");
+    response.finish();
+  }, 5000, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
+}
new file mode 100644
--- /dev/null
+++ b/dom/xhr/tests/test_event_listener_leaks.html
@@ -0,0 +1,46 @@
+<!--
+  Any copyright is dedicated to the Public Domain.
+  http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Bug 1450271 - Test XHR event listener leak conditions</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="/tests/dom/events/test/event_leak_utils.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<p id="display"></p>
+<script class="testbody" type="text/javascript">
+// Manipulate XHR.  Its important here that we create a
+// listener callback from the DOM objects back to the frame's global
+// in order to exercise the leak condition.
+async function useXHR(contentWindow) {
+  let xhr = new contentWindow.XMLHttpRequest();
+  xhr.onabort = _ => {
+    contentWindow.abortCount += 1;
+  };
+  xhr.onreadystate = _ => {
+    contentWindow.stateCount += 1;
+  };
+  xhr.open("GET", "slow.sjs");
+}
+
+async function runTest() {
+  try {
+    await checkForEventListenerLeaks("XHR", useXHR);
+  } catch (e) {
+    ok(false, e);
+  } finally {
+    SimpleTest.finish();
+  }
+}
+
+SimpleTest.waitForExplicitFinish();
+addEventListener("load", runTest, { once: true });
+</script>
+</pre>
+</body>
+</html>
+