зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1693416: Rewrite reset processes in tests to be compatible with isolated process r=geckoview-reviewers,agi
Differential Revision: https://phabricator.services.mozilla.com/D106862
This commit is contained in:
Родитель
f33597d71d
Коммит
8a5e082ba7
|
@ -0,0 +1,28 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
var EXPORTED_SYMBOLS = ["TestSupportProcessChild"];
|
||||
|
||||
const { GeckoViewUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/GeckoViewUtils.jsm"
|
||||
);
|
||||
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const ProcessTools = Cc["@mozilla.org/processtools-service;1"].getService(
|
||||
Ci.nsIProcessToolsService
|
||||
);
|
||||
|
||||
class TestSupportProcessChild extends JSProcessActorChild {
|
||||
receiveMessage(aMsg) {
|
||||
debug`receiveMessage: ${aMsg.name}`;
|
||||
|
||||
switch (aMsg.name) {
|
||||
case "KillContentProcess":
|
||||
ProcessTools.kill(Services.appinfo.processID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const { debug } = GeckoViewUtils.initLogging("TestSupportProcess[C]");
|
|
@ -29,6 +29,9 @@ const APIS = {
|
|||
GetAllBrowserPids() {
|
||||
return browser.test.getAllBrowserPids();
|
||||
},
|
||||
KillContentProcess({ pid }) {
|
||||
return browser.test.killContentProcess(pid);
|
||||
},
|
||||
GetPrefs({ prefs }) {
|
||||
return browser.test.getPrefs(prefs);
|
||||
},
|
||||
|
|
|
@ -56,6 +56,12 @@ this.test = class extends ExtensionAPI {
|
|||
},
|
||||
allFrames: true,
|
||||
});
|
||||
ChromeUtils.registerProcessActor("TestSupportProcess", {
|
||||
child: {
|
||||
moduleURI:
|
||||
"resource://android/assets/web_extensions/test-support/TestSupportProcessChild.jsm",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
onShutdown(isAppShutdown) {
|
||||
|
@ -151,6 +157,17 @@ this.test = class extends ExtensionAPI {
|
|||
return pids;
|
||||
},
|
||||
|
||||
async killContentProcess(pid) {
|
||||
const procs = ChromeUtils.getAllDOMProcesses();
|
||||
for (const proc of procs) {
|
||||
if (pid === proc.osPid) {
|
||||
proc
|
||||
.getActor("TestSupportProcess")
|
||||
.sendAsyncMessage("KillContentProcess");
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
async addHistogram(id, value) {
|
||||
return Services.telemetry.getHistogramById(id).add(value);
|
||||
},
|
||||
|
|
|
@ -164,6 +164,18 @@
|
|||
"description": "Gets the list of pids of the running browser processes",
|
||||
"parameters": []
|
||||
},
|
||||
{
|
||||
"name": "killContentProcess",
|
||||
"type": "function",
|
||||
"async": true,
|
||||
"description": "Crash all content processes",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "number",
|
||||
"name": "pid"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "flushApzRepaints",
|
||||
"type": "function",
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
package org.mozilla.geckoview.test
|
||||
|
||||
import android.os.Process
|
||||
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled
|
||||
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.IgnoreCrash
|
||||
import org.mozilla.geckoview.test.util.Callbacks
|
||||
|
@ -29,7 +28,7 @@ class ContentDelegateMultipleSessionsTest : BaseSessionTest() {
|
|||
fun killAllContentProcesses() {
|
||||
val contentProcessPids = sessionRule.getAllSessionPids()
|
||||
for (pid in contentProcessPids) {
|
||||
Process.killProcess(pid)
|
||||
sessionRule.killContentProcess(pid)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,11 +4,8 @@
|
|||
|
||||
package org.mozilla.geckoview.test
|
||||
|
||||
import android.app.ActivityManager
|
||||
import android.content.Context
|
||||
import android.graphics.SurfaceTexture
|
||||
import android.net.Uri
|
||||
import android.os.Process
|
||||
import org.mozilla.geckoview.GeckoSession.NavigationDelegate.LoadRequest
|
||||
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled
|
||||
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.IgnoreCrash
|
||||
|
@ -24,7 +21,6 @@ import org.json.JSONObject
|
|||
import org.junit.Assume.assumeThat
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mozilla.gecko.GeckoAppShell
|
||||
import org.mozilla.geckoview.*
|
||||
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.NullDelegate
|
||||
|
||||
|
@ -118,13 +114,9 @@ class ContentDelegateTest : BaseSessionTest() {
|
|||
|
||||
@AnyThread
|
||||
fun killAllContentProcesses() {
|
||||
val context = GeckoAppShell.getApplicationContext()
|
||||
val manager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
||||
val expr = ".*:tab\\d+$".toRegex()
|
||||
for (info in manager.runningAppProcesses) {
|
||||
if (info.processName.matches(expr)) {
|
||||
Process.killProcess(info.pid)
|
||||
}
|
||||
val contentProcessPids = sessionRule.getAllSessionPids()
|
||||
for (pid in contentProcessPids) {
|
||||
sessionRule.killContentProcess(pid)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1934,6 +1934,12 @@ public class GeckoSessionTestRule implements TestRule {
|
|||
return pids;
|
||||
}
|
||||
|
||||
public void killContentProcess(final int pid) {
|
||||
webExtensionApiCall("KillContentProcess", args -> {
|
||||
args.put("pid", pid);
|
||||
});
|
||||
}
|
||||
|
||||
public boolean getActive(final @NonNull GeckoSession session) {
|
||||
final Boolean isActive = (Boolean)
|
||||
webExtensionApiCall(session, "GetActive", null);
|
||||
|
|
Загрузка…
Ссылка в новой задаче