summaryrefslogtreecommitdiffstats
path: root/dom/browser-element/mochitest/priority
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/browser-element/mochitest/priority
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/browser-element/mochitest/priority')
-rw-r--r--dom/browser-element/mochitest/priority/chrome.ini19
-rw-r--r--dom/browser-element/mochitest/priority/file_Audio.html19
-rw-r--r--dom/browser-element/mochitest/priority/file_HighPriority.html20
-rw-r--r--dom/browser-element/mochitest/priority/file_MultipleFrames.html14
-rw-r--r--dom/browser-element/mochitest/priority/file_NestedFramesOuter.html20
-rw-r--r--dom/browser-element/mochitest/priority/file_WebGLContextLost.html22
-rw-r--r--dom/browser-element/mochitest/priority/mochitest.ini19
-rw-r--r--dom/browser-element/mochitest/priority/silence.oggbin0 -> 5940 bytes
-rw-r--r--dom/browser-element/mochitest/priority/test_Activity.html62
-rw-r--r--dom/browser-element/mochitest/priority/test_Audio.html53
-rw-r--r--dom/browser-element/mochitest/priority/test_Background.html53
-rw-r--r--dom/browser-element/mochitest/priority/test_HighPriority.html133
-rw-r--r--dom/browser-element/mochitest/priority/test_Keyboard.html54
-rw-r--r--dom/browser-element/mochitest/priority/test_MultipleFrames.html58
-rw-r--r--dom/browser-element/mochitest/priority/test_NestedFrames.html62
-rw-r--r--dom/browser-element/mochitest/priority/test_Preallocated.html71
-rw-r--r--dom/browser-element/mochitest/priority/test_Simple.html59
-rw-r--r--dom/browser-element/mochitest/priority/test_Visibility.html51
-rw-r--r--dom/browser-element/mochitest/priority/test_WebGLContextLost.html99
19 files changed, 888 insertions, 0 deletions
diff --git a/dom/browser-element/mochitest/priority/chrome.ini b/dom/browser-element/mochitest/priority/chrome.ini
new file mode 100644
index 000000000..e1852f6ff
--- /dev/null
+++ b/dom/browser-element/mochitest/priority/chrome.ini
@@ -0,0 +1,19 @@
+[DEFAULT]
+# Good luck running these tests on anything but desktop Linux.
+run-if = os == 'linux' && buildapp == 'browser' && !e10s
+support-files =
+ file_Audio.html
+ file_MultipleFrames.html
+ file_NestedFramesOuter.html
+ file_WebGLContextLost.html
+ silence.ogg
+ !/dom/browser-element/mochitest/browserElementTestHelpers.js
+ !/dom/browser-element/mochitest/file_empty.html
+
+[test_Activity.html]
+[test_Audio.html]
+[test_Background.html]
+[test_Keyboard.html]
+[test_MultipleFrames.html]
+[test_NestedFrames.html]
+[test_Visibility.html]
diff --git a/dom/browser-element/mochitest/priority/file_Audio.html b/dom/browser-element/mochitest/priority/file_Audio.html
new file mode 100644
index 000000000..97f4dc64d
--- /dev/null
+++ b/dom/browser-element/mochitest/priority/file_Audio.html
@@ -0,0 +1,19 @@
+<html>
+<body>
+
+<script>
+addEventListener('load', function() {
+ setTimeout(function() {
+ var a = document.getElementById('audio');
+ a.onplay = function() {
+ alert('onplay');
+ };
+ a.play();
+ }, 0);
+});
+</script>
+
+<audio id='audio' loop src='silence.ogg'>
+
+</body>
+</html>
diff --git a/dom/browser-element/mochitest/priority/file_HighPriority.html b/dom/browser-element/mochitest/priority/file_HighPriority.html
new file mode 100644
index 000000000..dc7197bba
--- /dev/null
+++ b/dom/browser-element/mochitest/priority/file_HighPriority.html
@@ -0,0 +1,20 @@
+<!DOCTYPE HTML>
+<html>
+<body>
+
+<script>
+var lock = navigator.requestWakeLock('high-priority');
+alert('step0');
+
+lock.unlock();
+alert('step1');
+
+lock = navigator.requestWakeLock('cpu');
+alert('step2');
+
+lock.unlock();
+alert('step3');
+</script>
+
+</body>
+</html>
diff --git a/dom/browser-element/mochitest/priority/file_MultipleFrames.html b/dom/browser-element/mochitest/priority/file_MultipleFrames.html
new file mode 100644
index 000000000..b3b56f560
--- /dev/null
+++ b/dom/browser-element/mochitest/priority/file_MultipleFrames.html
@@ -0,0 +1,14 @@
+<html>
+<body>
+<p>file_MultipleFrames.html</p>
+
+<script>
+addEventListener('load', function() {
+ setTimeout(function() {
+ window.open('../file_empty.html');
+ }, 0);
+});
+</script>
+
+</body>
+</html>
diff --git a/dom/browser-element/mochitest/priority/file_NestedFramesOuter.html b/dom/browser-element/mochitest/priority/file_NestedFramesOuter.html
new file mode 100644
index 000000000..e4378935f
--- /dev/null
+++ b/dom/browser-element/mochitest/priority/file_NestedFramesOuter.html
@@ -0,0 +1,20 @@
+<html>
+<body>
+<p>file_NestedFramesOuter.html</p>
+<script>
+
+addEventListener('load', function() {
+ setTimeout(createIframe, 0);
+});
+
+function createIframe()
+{
+ var iframe = document.createElement('iframe');
+ iframe.setAttribute('mozbrowser', true);
+ iframe.src = location.hash.substr(1);
+ document.body.appendChild(iframe);
+}
+
+</script>
+</body>
+</html>
diff --git a/dom/browser-element/mochitest/priority/file_WebGLContextLost.html b/dom/browser-element/mochitest/priority/file_WebGLContextLost.html
new file mode 100644
index 000000000..bd5c84f11
--- /dev/null
+++ b/dom/browser-element/mochitest/priority/file_WebGLContextLost.html
@@ -0,0 +1,22 @@
+<html>
+<body>
+file_WebGLContextLost.html
+<canvas id='canvas'></canvas>
+
+<script>
+function runTest()
+{
+ var canvas = document.getElementById('canvas');
+ canvas.addEventListener('webglcontextlost', function() {
+ alert('webglcontextlost');
+ });
+
+ var context = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
+ context.viewport(0, 0, 10, 10);
+ alert('ready');
+}
+
+addEventListener('load', function() { setTimeout(runTest, 0) });
+</script>
+</body>
+</html>
diff --git a/dom/browser-element/mochitest/priority/mochitest.ini b/dom/browser-element/mochitest/priority/mochitest.ini
new file mode 100644
index 000000000..8118aedd7
--- /dev/null
+++ b/dom/browser-element/mochitest/priority/mochitest.ini
@@ -0,0 +1,19 @@
+[DEFAULT]
+# Good luck running these tests on anything but desktop Linux.
+run-if = os == 'linux' && buildapp == 'browser' && !e10s
+support-files =
+ file_HighPriority.html
+ silence.ogg
+ !/dom/browser-element/mochitest/browserElementTestHelpers.js
+ !/dom/browser-element/mochitest/file_empty.html
+
+# Note: ../browserElementTestHelpers.js makes all tests in this directory OOP,
+# because testing the process-priority manager without OOP frames does not make
+# much sense.
+
+[test_Simple.html]
+[test_HighPriority.html]
+[test_Preallocated.html]
+disabled = bug 968604, bug 987164
+[test_WebGLContextLost.html]
+disabled = bug 865844
diff --git a/dom/browser-element/mochitest/priority/silence.ogg b/dom/browser-element/mochitest/priority/silence.ogg
new file mode 100644
index 000000000..6e0b352a3
--- /dev/null
+++ b/dom/browser-element/mochitest/priority/silence.ogg
Binary files differ
diff --git a/dom/browser-element/mochitest/priority/test_Activity.html b/dom/browser-element/mochitest/priority/test_Activity.html
new file mode 100644
index 000000000..ae4049d96
--- /dev/null
+++ b/dom/browser-element/mochitest/priority/test_Activity.html
@@ -0,0 +1,62 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+Test that calling setVisible("false") on an iframe that has an open activity
+causes its priority to change.
+-->
+<head>
+ <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="application/javascript" src="../browserElementTestHelpers.js"></script>
+ <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+</head>
+<body>
+
+<script type="application/javascript;version=1.7">
+"use strict";
+
+SimpleTest.waitForExplicitFinish();
+browserElementTestHelpers.setEnabledPref(true);
+browserElementTestHelpers.enableProcessPriorityManager();
+
+function runTest() {
+ var os = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
+ .getService(SpecialPowers.Ci.nsIObserverService);
+ var iframe = document.createElement("iframe");
+ iframe.setAttribute("mozbrowser", true);
+
+ iframe.src = browserElementTestHelpers.emptyPage1;
+
+ var childID = null;
+ Promise.all([
+ expectOnlyOneProcessCreated("FOREGROUND").then(function(chid) {
+ childID = chid;
+ }),
+ expectMozbrowserEvent(iframe, "loadend")
+ ]).then(function() {
+ var p = expectPriorityChange(childID, "BACKGROUND_PERCEIVABLE");
+
+ // We simulate opening an activity
+ os.notifyObservers(null, "activity-opened", childID);
+
+ // We wait until mozbrowserloadend before calling setVisible, because
+ // setVisible isn't available until mozbrowser has loaded. In practice, that
+ // means we can call setVisible once we've gotten /any/ mozbrowser event.
+ iframe.setVisible(false);
+ return p;
+ }).then(function() {
+ var p = expectPriorityChange(childID, "BACKGROUND");
+
+ // Now we simulate closing an activity
+ os.notifyObservers(null, "activity-closed", childID);
+
+ return p;
+ }).then(SimpleTest.finish);
+
+ document.body.appendChild(iframe);
+}
+
+addEventListener("testready", runTest);
+
+</script>
+</body>
+</html>
diff --git a/dom/browser-element/mochitest/priority/test_Audio.html b/dom/browser-element/mochitest/priority/test_Audio.html
new file mode 100644
index 000000000..d39b1c9f3
--- /dev/null
+++ b/dom/browser-element/mochitest/priority/test_Audio.html
@@ -0,0 +1,53 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+Test that frames playing audio get BACKGROUND_PERCEIVABLE priority.
+-->
+<head>
+ <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="application/javascript" src="../browserElementTestHelpers.js"></script>
+ <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+</head>
+<body>
+
+<script type="application/javascript;version=1.7">
+"use strict";
+
+SimpleTest.waitForExplicitFinish();
+browserElementTestHelpers.setEnabledPref(true);
+browserElementTestHelpers.enableProcessPriorityManager();
+
+function runTest() {
+ var iframe = document.createElement('iframe');
+ iframe.setAttribute('mozbrowser', true);
+ iframe.src = 'file_Audio.html';
+
+ var childID = null;
+ Promise.all([
+ expectOnlyOneProcessCreated("FOREGROUND").then(function(chid) {
+ childID = chid;
+ }),
+ expectMozbrowserEvent(iframe, 'loadend'),
+ expectMozbrowserEvent(iframe, 'showmodalprompt').then(function(e) {
+ is(e.detail.message, 'onplay', 'showmodalprompt message');
+ })
+ ]).then(function() {
+ // Send the child process into the background. Because it's playing audio,
+ // it should get priority BACKGROUND_PERCEIVABLE, not vanilla BACKGROUND.
+ var p = expectPriorityChange(childID, 'BACKGROUND_PERCEIVABLE');
+ iframe.setVisible(false);
+ return p;
+ }).then(function() {
+ var p = expectPriorityChange(childID, 'FOREGROUND');
+ iframe.setVisible(true);
+ return p;
+ }).then(SimpleTest.finish);
+
+ document.body.appendChild(iframe);
+}
+
+addEventListener('testready', runTest);
+
+</script>
+</body>
+</html>
diff --git a/dom/browser-element/mochitest/priority/test_Background.html b/dom/browser-element/mochitest/priority/test_Background.html
new file mode 100644
index 000000000..59eb16863
--- /dev/null
+++ b/dom/browser-element/mochitest/priority/test_Background.html
@@ -0,0 +1,53 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+Test that calling setVisible('false') on an iframe causes its visibility to
+change.
+-->
+<head>
+ <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="application/javascript" src="../browserElementTestHelpers.js"></script>
+ <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+</head>
+<body>
+
+<script type="application/javascript;version=1.7">
+"use strict";
+
+SimpleTest.waitForExplicitFinish();
+browserElementTestHelpers.setEnabledPref(true);
+browserElementTestHelpers.enableProcessPriorityManager();
+
+function runTest() {
+ var iframe = document.createElement('iframe');
+ iframe.setAttribute('mozbrowser', true);
+
+ iframe.src = browserElementTestHelpers.emptyPage1;
+
+ var childID = null;
+ Promise.all([
+ expectOnlyOneProcessCreated('FOREGROUND').then(function(chid) {
+ childID = chid;
+ }),
+ expectMozbrowserEvent(iframe, 'loadend')
+ ]).then(function() {
+ var p = expectPriorityChange(childID, 'BACKGROUND');
+
+ // We wait until mozbrowserloadend before calling setVisible, because
+ // setVisible isn't available until mozbrowser has loaded. In practice, that
+ // means we can call setVisible once we've gotten /any/ mozbrowser event.
+ iframe.setVisible(false);
+ return p;
+ }).then(function() {
+ var p = expectPriorityChange(childID, 'FOREGROUND');
+ iframe.setVisible(true);
+ }).then(SimpleTest.finish);
+
+ document.body.appendChild(iframe);
+}
+
+addEventListener('testready', runTest);
+
+</script>
+</body>
+</html>
diff --git a/dom/browser-element/mochitest/priority/test_HighPriority.html b/dom/browser-element/mochitest/priority/test_HighPriority.html
new file mode 100644
index 000000000..d3396d65b
--- /dev/null
+++ b/dom/browser-element/mochitest/priority/test_HighPriority.html
@@ -0,0 +1,133 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+Test that frames with mozapptype=critical which hold the "high-priority" or
+"cpu" wake locks get elevated process priority.
+-->
+<head>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="application/javascript" src="../browserElementTestHelpers.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+
+<script type="application/javascript;version=1.7">
+"use strict";
+
+SimpleTest.waitForExplicitFinish();
+browserElementTestHelpers.setEnabledPref(true);
+browserElementTestHelpers.addPermission();
+browserElementTestHelpers.enableProcessPriorityManager();
+
+function runTest() {
+ // To test bug 870480, run this test while holding the CPU and high-priority
+ // wake locks. Without the fix for bug 870480, we won't set the priority of
+ // the child process if the main process holds these wake locks and the test
+ // will hang.
+ navigator.requestWakeLock('cpu');
+ navigator.requestWakeLock('high-priority');
+
+ var iframe = document.createElement('iframe');
+ iframe.setAttribute('mozbrowser', true);
+ iframe.setAttribute('mozapptype', 'critical');
+ iframe.src = 'file_HighPriority.html';
+
+ // We expect the following to happen:
+ //
+ // - Process is created.
+ // - Its priority is set to FOREGROUND (when the process starts).
+ // - wait_alert('step0', FOREGROUND_HIGH)
+ // - wait_alert('step1', FOREGROUND)
+ // - wait_alert('step2', FOREGROUND_HIGH)
+ //
+ // Where wait_alert(M, P) means that we expect the subprocess to
+ // * do alert(M) and
+ // * be set to priority P
+ // in some order. If the alert occurs before the priority change, we block
+ // the alert until we observe the priority change. So the subprocess only
+ // has to do
+ //
+ // // set priority to FOREGROUND_HIGH
+ // alert('step0');
+ // // set priority to FOREGROUND
+ // alert('step1');
+ //
+ // etc.
+
+ var childID = null;
+ var alertTimes = [];
+
+ // Return a promise that's resolved once the child process calls alert() and
+ // we get a priority change, in some order.
+ //
+ // We check that the text of the alert is |"step" + index|.
+ //
+ // If gracePeriod is given, we check that the priority change occurred at
+ // least gracePeriod ms since the alert from the previous step (with a fudge
+ // factor to account for inaccurate timers).
+ function expectAlertAndPriorityChange(index, priority, /* optional */ gracePeriod) {
+ function checkAlertInfo(e) {
+ is(e.detail.message, 'step' + index, 'alert() number ' + index);
+ alertTimes.push(new Date());
+
+ // Block the alert; we'll unblock it by calling e.detail.unblock() later.
+ e.preventDefault();
+ return Promise.resolve(e.detail.unblock);
+ }
+
+ function checkGracePeriod() {
+ if (gracePeriod) {
+ var msSinceLastAlert = (new Date()) - alertTimes[index - 1];
+
+ // 50ms fudge factor. This test is set up so that, if nsITimers are
+ // accurate, we don't need any fudge factor. Unfortunately our timers
+ // are not accurate! There's little we can do here except fudge.
+ // Thankfully all we're trying to test is that we get /some/ delay; the
+ // exact amount of delay isn't so important.
+ ok(msSinceLastAlert + 50 >= gracePeriod,
+ msSinceLastAlert + "ms since last alert >= (" + gracePeriod + " - 50ms)");
+ }
+ }
+
+ return Promise.all([
+ new Promise(function(resolve, reject) {
+ iframe.addEventListener('mozbrowsershowmodalprompt', function check(e) {
+ iframe.removeEventListener('mozbrowsershowmodalprompt', check);
+ resolve(checkAlertInfo(e));
+ });
+ }),
+ expectPriorityChange(childID, priority).then(checkGracePeriod)
+ ]).then(function(results) {
+ // checkAlertInfo returns the function to call to unblock the alert.
+ // It comes to us as the first element of the results array.
+ results[0]();
+ });
+ }
+
+ expectProcessCreated('FOREGROUND').then(function(chid) {
+ childID = chid;
+ }).then(function() {
+ return expectAlertAndPriorityChange(0, 'FOREGROUND_HIGH');
+ }).then(function() {
+ return expectAlertAndPriorityChange(1, 'FOREGROUND', priorityChangeGracePeriod);
+ }).then(function() {
+ return expectAlertAndPriorityChange(2, 'FOREGROUND_HIGH');
+ }).then(function() {
+ return expectAlertAndPriorityChange(3, 'FOREGROUND', priorityChangeGracePeriod);
+ }).then(SimpleTest.finish);
+
+ document.body.appendChild(iframe);
+}
+
+const priorityChangeGracePeriod = 100;
+addEventListener('testready', function() {
+ SpecialPowers.pushPrefEnv(
+ {set: [['dom.ipc.processPriorityManager.backgroundGracePeriodMS',
+ priorityChangeGracePeriod],
+ ['dom.wakelock.enabled', true]]},
+ runTest);
+});
+
+</script>
+</body>
+</html>
diff --git a/dom/browser-element/mochitest/priority/test_Keyboard.html b/dom/browser-element/mochitest/priority/test_Keyboard.html
new file mode 100644
index 000000000..a36f954ba
--- /dev/null
+++ b/dom/browser-element/mochitest/priority/test_Keyboard.html
@@ -0,0 +1,54 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+Test that frames with mozapptype=inputmethod gets the keyboard-specific
+priority level when in the foreground.
+-->
+<head>
+ <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="application/javascript" src="../browserElementTestHelpers.js"></script>
+ <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+</head>
+<body>
+
+<script type="application/javascript;version=1.7">
+"use strict";
+
+SimpleTest.waitForExplicitFinish();
+browserElementTestHelpers.setEnabledPref(true);
+browserElementTestHelpers.enableProcessPriorityManager();
+
+function runTest() {
+ var iframe = document.createElement('iframe');
+ iframe.setAttribute('mozbrowser', true);
+ iframe.setAttribute('mozapptype', 'inputmethod');
+ iframe.src = browserElementTestHelpers.emptyPage1;
+
+ var childID = null;
+ Promise.all([
+ expectOnlyOneProcessCreated('FOREGROUND_KEYBOARD').then(function(chid) {
+ childID = chid;
+ }),
+ expectMozbrowserEvent(iframe, 'loadend')
+ ]).then(function() {
+ var p = expectPriorityChange(childID, 'BACKGROUND');
+
+ /* We wait until mozbrowserloadend before calling setVisible, because
+ * setVisible isn't available until mozbrowser has loaded. In practice,
+ * that means we can call setVisible once we've gotten /any/ mozbrowser
+ * event. */
+ iframe.setVisible(false);
+ return p;
+ }).then(function() {
+ var p = expectPriorityChange(childID, 'FOREGROUND_KEYBOARD');
+ iframe.setVisible(true);
+ }).then(SimpleTest.finish);
+
+ document.body.appendChild(iframe);
+}
+
+addEventListener('testready', runTest);
+
+</script>
+</body>
+</html>
diff --git a/dom/browser-element/mochitest/priority/test_MultipleFrames.html b/dom/browser-element/mochitest/priority/test_MultipleFrames.html
new file mode 100644
index 000000000..57d9563e7
--- /dev/null
+++ b/dom/browser-element/mochitest/priority/test_MultipleFrames.html
@@ -0,0 +1,58 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+Test that when we remove one of a process's frames from the DOM, the process's
+priority is recomputed.
+-->
+<head>
+ <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="application/javascript" src="../browserElementTestHelpers.js"></script>
+ <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+</head>
+<body>
+
+<script type="application/javascript;version=1.7">
+"use strict";
+
+SimpleTest.waitForExplicitFinish();
+browserElementTestHelpers.setEnabledPref(true);
+browserElementTestHelpers.enableProcessPriorityManager();
+
+function runTest() {
+ var iframe = document.createElement('iframe');
+ iframe.setAttribute('mozbrowser', true);
+ iframe.src = 'file_MultipleFrames.html';
+
+ var childID = null;
+ var iframe2;
+ Promise.all([
+ expectProcessCreated('FOREGROUND').then(function(chid) {
+ childID = chid;
+ }),
+ new Promise(function(resolve, reject) {
+ iframe.addEventListener('mozbrowseropenwindow', function(e) {
+ iframe2 = e.detail.frameElement;
+ var p = expectMozbrowserEvent(iframe2, 'loadend');
+ document.body.appendChild(iframe2);
+ resolve(p);
+ });
+ })
+ ]).then(function() {
+ // At this point, the child process has been set to FOREGROUND, and the popup
+ // opened by file_MultipleFrames has finished loading.
+ //
+ // Now setVisible(false) the popup frame and remove the popup frame from the
+ // DOM. This should cause the process to take on BACKGROUND priority.
+ var p = expectPriorityChange(childID, 'BACKGROUND');
+ iframe.setVisible(false);
+ document.body.removeChild(iframe2);
+ return p;
+ }).then(SimpleTest.finish);
+
+ document.body.appendChild(iframe);
+}
+
+addEventListener('testready', runTest);
+</script>
+</body>
+</html>
diff --git a/dom/browser-element/mochitest/priority/test_NestedFrames.html b/dom/browser-element/mochitest/priority/test_NestedFrames.html
new file mode 100644
index 000000000..e5381bcc5
--- /dev/null
+++ b/dom/browser-element/mochitest/priority/test_NestedFrames.html
@@ -0,0 +1,62 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+Test changing the visibility of an <iframe mozbrowser> changes the visibility
+(and thus the priority) of any <iframe mozbrowser>s it contains.
+-->
+<head>
+ <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="application/javascript" src="../browserElementTestHelpers.js"></script>
+ <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+</head>
+<body>
+
+<script type="application/javascript;version=1.7">
+"use strict";
+
+SimpleTest.waitForExplicitFinish();
+browserElementTestHelpers.setEnabledPref(true);
+browserElementTestHelpers.enableProcessPriorityManager();
+
+function runTest() {
+ // Set up the following hierarchy of frames:
+ //
+ // <iframe mozbrowser remote=false src='file_NestedFramesOuter.html'>
+ // <iframe mozbrowser remote=true src='file_empty.html'>
+ //
+ // When we change the visibility of the outer iframe, it should change the
+ // priority of the inner one.
+
+ var iframe = document.createElement('iframe');
+ iframe.setAttribute('mozbrowser', true);
+ iframe.setAttribute('remote', false);
+ iframe.src = 'file_NestedFramesOuter.html#' + browserElementTestHelpers.emptyPage1;
+
+ // Note that this is the process corresponding to the /inner/ iframe. The
+ // outer iframe runs in-process (because it has remote=false).
+ var childID = null;
+ Promise.all(
+ [expectOnlyOneProcessCreated('FOREGROUND').then(function(child) {
+ childID = child;
+ }),
+ expectMozbrowserEvent(iframe, 'loadend')]
+ ).then(function() {
+ // Send the outer iframe into the background. This should change the
+ // priority of the inner frame's process to BACKGROUND.
+ var p = expectPriorityChange(childID, 'BACKGROUND');
+ iframe.setVisible(false);
+ return p;
+ }).then(function() {
+ var p = expectPriorityChange(childID, 'FOREGROUND');
+ iframe.setVisible(true);
+ return p;
+ }).then(SimpleTest.finish);
+
+ document.body.appendChild(iframe);
+}
+
+addEventListener('testready', runTest);
+
+</script>
+</body>
+</html>
diff --git a/dom/browser-element/mochitest/priority/test_Preallocated.html b/dom/browser-element/mochitest/priority/test_Preallocated.html
new file mode 100644
index 000000000..b2cb0335e
--- /dev/null
+++ b/dom/browser-element/mochitest/priority/test_Preallocated.html
@@ -0,0 +1,71 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+Test that the preallocated process starts up with priority BACKGROUND.
+-->
+<head>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="application/javascript" src="../browserElementTestHelpers.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+
+<script type="application/javascript;version=1.7">
+"use strict";
+
+SimpleTest.waitForExplicitFinish();
+browserElementTestHelpers.setEnabledPref(true);
+browserElementTestHelpers.addPermission();
+browserElementTestHelpers.enableProcessPriorityManager();
+
+var preallocationEnabledPref = null;
+try {
+ preallocationEnabledPref = SpecialPowers.getBoolPref('dom.ipc.processPrelaunch.enabled');
+}
+catch(e) {
+ preallocationEnabledPref = null;
+}
+
+var childID = null;
+
+var cleanedUp = false;
+function cleanUp()
+{
+ if (cleanedUp) {
+ return;
+ }
+
+ cleanedUp = true;
+}
+
+// Even if this test times out, we still want to run cleanUp so as to set the
+// pref back.
+addEventListener('unload', cleanUp);
+
+function runTest()
+{
+ if (preallocationEnabledPref) {
+ ok(false, "dom.ipc.processPrelaunch.enabled must be " +
+ "false for this test to work.");
+ SimpleTest.finish();
+ return;
+ }
+
+ // Ensure that the preallocated process initially gets BACKGROUND priority.
+ // That's it.
+ expectProcessCreated('PREALLOC').then(function() {
+ // We need to set the pref asynchoronously or the preallocated process won't
+ // be shut down.
+ SimpleTest.executeSoon(function(){
+ cleanUp();
+ SimpleTest.finish();
+ });
+ });
+}
+// Setting this pref to true should cause us to prelaunch a process.
+addEventListener('testready', function() {
+ SpecialPowers.pushPrefEnv({'set':[["dom.ipc.processPrelaunch.enabled",true]]},runTest);
+});
+</script>
+</body>
+</html>
diff --git a/dom/browser-element/mochitest/priority/test_Simple.html b/dom/browser-element/mochitest/priority/test_Simple.html
new file mode 100644
index 000000000..7cc801e54
--- /dev/null
+++ b/dom/browser-element/mochitest/priority/test_Simple.html
@@ -0,0 +1,59 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+A simple test of the process priority manager.
+
+https://bugzilla.mozilla.org/show_bug.cgi?id=844323
+
+Note: If you run this test alone (i.e. not as part of the larger mochitest
+suite), you may see some IPC assertions, e.g. "Can't allocate graphics
+resources."
+
+What appears to be happening is that we close the Firefox window before the
+frame we create in this tab finishes starting up. Then the frame finishes
+loading, and it tries to show itself. But it's too late to show a remote frame
+at that point, so we kill the child process.
+
+In other words, I think these errors are nothing to worry about.
+-->
+<head>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="application/javascript" src="../browserElementTestHelpers.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+
+<script type="application/javascript;version=1.7">
+"use strict";
+
+SimpleTest.waitForExplicitFinish();
+browserElementTestHelpers.setEnabledPref(true);
+browserElementTestHelpers.addPermission();
+browserElementTestHelpers.enableProcessPriorityManager();
+
+var allCompleted = 0;
+var allExpected = 2;
+function finish() {
+ allCompleted++;
+ if (allCompleted === allExpected) {
+ SimpleTest.finish();
+ }
+}
+
+function runTest() {
+ var iframeLoaded = false;
+ var iframe = document.createElement('iframe');
+ iframe.setAttribute('mozbrowser', true);
+ iframe.src = browserElementTestHelpers.emptyPage1;
+
+ iframe.addEventListener('mozbrowserloadend', finish);
+ expectProcessCreated('FOREGROUND').then(finish);
+
+ document.body.appendChild(iframe);
+}
+
+addEventListener('testready', runTest);
+
+</script>
+</body>
+</html>
diff --git a/dom/browser-element/mochitest/priority/test_Visibility.html b/dom/browser-element/mochitest/priority/test_Visibility.html
new file mode 100644
index 000000000..58648b99f
--- /dev/null
+++ b/dom/browser-element/mochitest/priority/test_Visibility.html
@@ -0,0 +1,51 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+Test that setVisible() changes a process's priority.
+-->
+<head>
+ <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="application/javascript" src="../browserElementTestHelpers.js"></script>
+ <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+</head>
+<body>
+
+<script type="application/javascript;version=1.7">
+"use strict";
+
+SimpleTest.waitForExplicitFinish();
+browserElementTestHelpers.setEnabledPref(true);
+browserElementTestHelpers.enableProcessPriorityManager();
+
+function runTest() {
+ var iframe = document.createElement('iframe');
+ iframe.setAttribute('mozbrowser', true);
+ iframe.src = browserElementTestHelpers.emptyPage1;
+
+ var childID = null;
+ Promise.all([
+ expectOnlyOneProcessCreated('FOREGROUND').then(function(chid) {
+ childID = chid;
+ }),
+ expectMozbrowserEvent(iframe, 'loadend')
+ ]).then(function() {
+ // Mark the frame as not visible. This should cause its priority to drop
+ // to BACKGROUND.
+ var p = expectPriorityChange(childID, 'BACKGROUND');
+ iframe.setVisible(false);
+ return p;
+ }).then(function() {
+ // Mark the frame as visible again. This should cause its priority change
+ // back to FOREGROUND.
+ var p = expectPriorityChange(childID, 'FOREGROUND');
+ iframe.setVisible(true);
+ return p;
+ }).then(SimpleTest.finish);
+
+ document.body.appendChild(iframe);
+}
+
+addEventListener('testready', runTest);
+</script>
+</body>
+</html>
diff --git a/dom/browser-element/mochitest/priority/test_WebGLContextLost.html b/dom/browser-element/mochitest/priority/test_WebGLContextLost.html
new file mode 100644
index 000000000..383506ec6
--- /dev/null
+++ b/dom/browser-element/mochitest/priority/test_WebGLContextLost.html
@@ -0,0 +1,99 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+Test that calling setVisible('false') and then sending a low-memory
+notification causes a WebGL context loss event.
+-->
+<head>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="application/javascript" src="../browserElementTestHelpers.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+
+<script type="application/javascript;version=1.7">
+"use strict";
+
+SimpleTest.waitForExplicitFinish();
+browserElementTestHelpers.setEnabledPref(true);
+browserElementTestHelpers.addPermission();
+browserElementTestHelpers.enableProcessPriorityManager();
+
+function runTest() {
+ var iframe = document.createElement('iframe');
+ iframe.setAttribute('mozbrowser', true);
+ iframe.src = 'file_WebGLContextLost.html';
+
+ // We use this to ensure that we don't call SimpleTest.finish() twice.
+ var finished = false;
+ function finishOnce() {
+ if (!finished) {
+ SimpleTest.finish();
+ finished = true;
+ }
+ }
+
+ expectMozbrowserEvent(iframe, 'error').then(function(e) {
+ if (finished) {
+ // We don't care if the frame dies after the test finishes.
+ return;
+ }
+ todo(false, "child process is crashing; this probably indicates that " +
+ "something is wrong with WebGL in child processes on your machine.");
+ is(e.detail.type, 'fatal');
+ }).then(finishOnce);
+
+ var childID = null;
+ Promise.all([
+ expectOnlyOneProcessCreated('FOREGROUND').then(function(chid) {
+ childID = chid;
+ }),
+ expectMozbrowserEvent(iframe, 'loadend'),
+ expectMozbrowserEvent(iframe, 'showmodalprompt').then(function(e) {
+ is(e.detail.message, 'ready');
+ })
+ ]).then(function() {
+ // Fire a low-memory notification once the process goes into the background
+ // due to the setVisible(false) call below.
+ expectPriorityChange(childID, 'BACKGROUND').then(function() {
+ SimpleTest.executeSoon(function() {
+ var os = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
+ .getService(SpecialPowers.Ci.nsIObserverService);
+ os.notifyObservers(null, "memory-pressure", "low-memory");
+ ok(true, 'Successfully notified observers.');
+ });
+ });
+
+ // This test isn't the only possible source of a low-memory notification; the
+ // browser can fire one whenever it likes. So it's fine if we lose the
+ // WebGL context before we fire the low-memory notification ourself.
+
+ var p = expectMozbrowserEvent(iframe, 'showmodalprompt').then(function(e) {
+ is(e.detail.message, 'webglcontextlost');
+ });
+
+ iframe.setVisible(false);
+ return p;
+ }).then(finishOnce);
+
+ document.body.appendChild(iframe);
+}
+
+addEventListener('testready', function() {
+ // At the time this test was written, webgl was blocklisted inside child
+ // processes on desktop Linux. The issue is that we spawn a child process to
+ // read driver info, but we only did this on the main prrocess. Child
+ // processes never read the driver info themselves, nor do they get it from
+ // their parent, so they refuse to start up WebGL.
+ //
+ // This isn't a problem on B2G because we force WebGL on there. But it
+ // obviously makes this test difficult. bjacob says forcing WebGL on here
+ // shouldn't hurt things, and anyway this setting mirrors what we do on B2G,
+ // which is what we're trying to test!
+ SpecialPowers.pushPrefEnv({set: [["webgl.force-enabled", true]]},
+ runTest);
+});
+
+</script>
+</body>
+</html>