Index: chrome/android/javatests/src/org/chromium/chrome/browser/ProcessIsolationTest.java |
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/ProcessIsolationTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/ProcessIsolationTest.java |
index bc21ffe2fdafa97fa4aa0dc77b2710780d6bc10c..513f2cd7a1bb567f44b89abba6d6a879419a873c 100644 |
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/ProcessIsolationTest.java |
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/ProcessIsolationTest.java |
@@ -7,11 +7,19 @@ package org.chromium.chrome.browser; |
import android.support.test.filters.MediumTest; |
import android.text.TextUtils; |
+import org.junit.Assert; |
+import org.junit.Before; |
+import org.junit.Rule; |
+import org.junit.Test; |
+import org.junit.runner.RunWith; |
+ |
import org.chromium.base.BuildInfo; |
+import org.chromium.base.test.util.CommandLineFlags; |
import org.chromium.base.test.util.DisableIf; |
import org.chromium.base.test.util.Feature; |
import org.chromium.base.test.util.RetryOnFailure; |
-import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
+import org.chromium.chrome.test.ChromeActivityTestRule; |
+import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
import java.io.BufferedReader; |
import java.io.IOException; |
@@ -22,29 +30,33 @@ import java.util.HashSet; |
/** |
* Test to make sure browser and renderer are seperated process. |
*/ |
-public class ProcessIsolationTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
- public ProcessIsolationTest() { |
- super(ChromeActivity.class); |
- } |
+@RunWith(ChromeJUnit4ClassRunner.class) |
+@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, |
+ ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG}) |
+public class ProcessIsolationTest { |
+ @Rule |
+ public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = |
+ new ChromeActivityTestRule<>(ChromeActivity.class); |
/** |
* Verifies that process isolation works, i.e., that the browser and |
* renderer processes use different user IDs. |
* @throws InterruptedException |
*/ |
+ @Test |
@MediumTest |
@DisableIf.Build(sdk_is_greater_than = 22, message = "crbug.com/517611") |
@Feature({"Browser", "Security"}) |
@RetryOnFailure |
public void testProcessIsolationForRenderers() throws InterruptedException { |
- int tabsCount = getActivity().getCurrentTabModel().getCount(); |
+ int tabsCount = mActivityTestRule.getActivity().getCurrentTabModel().getCount(); |
// The ActivityManager can be used to retrieve the current processes, but the reported UID |
// in the RunningAppProcessInfo for isolated processes is the same as the parent process |
// (see b/7724486, closed as "Working as intended"). |
// So we have to resort to parsing the ps output. |
String packageName = BuildInfo.getPackageName(); |
- assertFalse("Failed to retrieve package name for current version of Chrome.", |
- TextUtils.isEmpty(packageName)); |
+ Assert.assertFalse("Failed to retrieve package name for current version of Chrome.", |
+ TextUtils.isEmpty(packageName)); |
ArrayList<String> uids = new ArrayList<String>(); |
BufferedReader reader = null; |
@@ -55,7 +67,7 @@ public class ProcessIsolationTest extends ChromeActivityTestCaseBase<ChromeActiv |
Process psProcess = Runtime.getRuntime().exec("ps"); |
reader = new BufferedReader(new InputStreamReader(psProcess.getInputStream())); |
String line = reader.readLine(); |
- assertNotNull(line); |
+ Assert.assertNotNull(line); |
final String[] lineSections = line.split("\\s+"); |
int pidIndex = -1; |
for (int index = 0; index < lineSections.length; index++) { |
@@ -64,13 +76,13 @@ public class ProcessIsolationTest extends ChromeActivityTestCaseBase<ChromeActiv |
break; |
} |
} |
- assertNotSame(-1, pidIndex); |
+ Assert.assertNotSame(-1, pidIndex); |
while ((line = reader.readLine()) != null) { |
sb.append(line).append('\n'); |
if (line.indexOf(packageName) != -1) { |
final String uid = line.split("\\s+")[pidIndex]; |
- assertNotNull("Failed to retrieve UID from " + line, uid); |
+ Assert.assertNotNull("Failed to retrieve UID from " + line, uid); |
if (line.indexOf("sandboxed_process") != -1) { |
// Renderer process. |
uids.add(uid); |
@@ -91,7 +103,7 @@ public class ProcessIsolationTest extends ChromeActivityTestCaseBase<ChromeActiv |
} |
} |
} catch (IOException ioe) { |
- fail("Failed to read ps output."); |
+ Assert.fail("Failed to read ps output."); |
} finally { |
if (reader != null) { |
try { |
@@ -101,22 +113,21 @@ public class ProcessIsolationTest extends ChromeActivityTestCaseBase<ChromeActiv |
} |
} |
} |
- assertTrue("Browser process not found in ps output: \n" + sb.toString(), |
- hasBrowserProcess); |
+ Assert.assertTrue( |
+ "Browser process not found in ps output: \n" + sb.toString(), hasBrowserProcess); |
// We should have the same number of process as tabs count. Sometimes |
// there can be extra utility sandbox process so we check for greater than. |
- assertTrue( |
- "Renderer processes not found in ps output: \n" + sb.toString(), |
+ Assert.assertTrue("Renderer processes not found in ps output: \n" + sb.toString(), |
rendererProcessesCount >= tabsCount); |
- assertEquals("Found at least two processes with the same UID in ps output: \n" |
- + sb.toString(), |
+ Assert.assertEquals( |
+ "Found at least two processes with the same UID in ps output: \n" + sb.toString(), |
uids.size(), new HashSet<String>(uids).size()); |
} |
- @Override |
- public void startMainActivity() throws InterruptedException { |
- startMainActivityFromLauncher(); |
+ @Before |
+ public void setUp() throws InterruptedException { |
+ mActivityTestRule.startMainActivityFromLauncher(); |
} |
} |