Bug 1631945 - Add API to junit test harness that enables tests to query for all web content pids r=geckoview-reviewers,aklotz

Differential Revision: https://phabricator.services.mozilla.com/D106861
This commit is contained in:
owlishDeveloper 2021-03-08 20:05:32 +00:00
parent c960da7b90
commit bdd6620010
5 changed files with 37 additions and 27 deletions

View File

@ -26,6 +26,9 @@ const APIS = {
GetPidForTab({ tab }) {
return browser.test.getPidForTab(tab.id);
},
GetAllBrowserPids() {
return browser.test.getAllBrowserPids();
},
GetPrefs({ prefs }) {
return browser.test.getPrefs(prefs);
},

View File

@ -140,6 +140,17 @@ this.test = class extends ExtensionAPI {
return pids[0];
},
async getAllBrowserPids() {
const pids = [];
const processes = ChromeUtils.getAllDOMProcesses();
for (const process of processes) {
if (process.remoteType && process.remoteType.startsWith("web")) {
pids.push(process.osPid);
}
}
return pids;
},
async addHistogram(id, value) {
return Services.telemetry.getHistogramById(id).add(value);
},

View File

@ -157,6 +157,13 @@
}
]
},
{
"name": "getAllBrowserPids",
"type": "function",
"async": true,
"description": "Gets the list of pids of the running browser processes",
"parameters": []
},
{
"name": "flushApzRepaints",
"type": "function",

View File

@ -4,41 +4,20 @@
package org.mozilla.geckoview.test
import android.app.ActivityManager
import android.content.Context
import android.graphics.Matrix
import android.graphics.SurfaceTexture
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.LocaleList
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
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.WithDisplay
import org.mozilla.geckoview.test.util.Callbacks
import androidx.annotation.AnyThread
import androidx.test.filters.MediumTest
import androidx.test.ext.junit.runners.AndroidJUnit4
import android.util.Pair
import android.util.SparseArray
import android.view.Surface
import android.view.View
import android.view.ViewStructure
import android.view.autofill.AutofillId
import android.view.autofill.AutofillValue
import org.hamcrest.Matchers.*
import org.json.JSONObject
import org.junit.Assume.assumeThat
import org.junit.Before
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
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.NullDelegate
@RunWith(AndroidJUnit4::class)
@ -48,12 +27,9 @@ class ContentDelegateMultipleSessionsTest : BaseSessionTest() {
@AnyThread
fun killAllContentProcesses() {
val context = GeckoAppShell.getApplicationContext()
val manager = context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
for (info in manager.runningAppProcesses) {
if (info.processName.matches(contentProcNameRegex)) {
Process.killProcess(info.pid)
}
val contentProcessPids = sessionRule.getAllSessionPids()
for (pid in contentProcessPids) {
Process.killProcess(pid)
}
}

View File

@ -1921,6 +1921,19 @@ public class GeckoSessionTestRule implements TestRule {
return dblPid.intValue();
}
public int[] getAllSessionPids() {
final JSONArray jsonPids = (JSONArray) webExtensionApiCall("GetAllBrowserPids", null);
final int[] pids = new int[jsonPids.length()];
for (int i = 0; i < jsonPids.length(); i++) {
try {
pids[i] = jsonPids.getInt(i);
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
return pids;
}
public boolean getActive(final @NonNull GeckoSession session) {
final Boolean isActive = (Boolean)
webExtensionApiCall(session, "GetActive", null);