Index: chrome/android/javatests/src/org/chromium/chrome/browser/TabTest.java |
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/TabTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/TabTest.java |
index 802c3ea1a73cb84bed8a23b84650e9cac235a72b..1b430e0b3c36d4f223d6634fcd55e4549cd9b46f 100644 |
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/TabTest.java |
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/TabTest.java |
@@ -5,17 +5,26 @@ |
package org.chromium.chrome.browser; |
import android.app.Activity; |
+import android.support.test.InstrumentationRegistry; |
import android.support.test.filters.SmallTest; |
+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.ThreadUtils; |
import org.chromium.base.test.util.CallbackHelper; |
+import org.chromium.base.test.util.CommandLineFlags; |
import org.chromium.base.test.util.Feature; |
import org.chromium.base.test.util.RetryOnFailure; |
import org.chromium.chrome.browser.tab.EmptyTabObserver; |
import org.chromium.chrome.browser.tab.Tab; |
import org.chromium.chrome.browser.tab.TabObserver; |
import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType; |
-import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
+import org.chromium.chrome.test.ChromeActivityTestRule; |
+import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
import org.chromium.chrome.test.util.ApplicationTestUtils; |
import org.chromium.components.security_state.ConnectionSecurityLevel; |
import org.chromium.content.browser.test.util.Criteria; |
@@ -24,8 +33,15 @@ import org.chromium.content.browser.test.util.CriteriaHelper; |
/** |
* Tests for Tab class. |
*/ |
+@RunWith(ChromeJUnit4ClassRunner.class) |
@RetryOnFailure |
-public class TabTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
+@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, |
+ ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG}) |
+public class TabTest { |
+ @Rule |
+ public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = |
+ new ChromeActivityTestRule<>(ChromeActivity.class); |
+ |
private Tab mTab; |
private CallbackHelper mOnTitleUpdatedHelper; |
@@ -36,46 +52,39 @@ public class TabTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
} |
}; |
- public TabTest() { |
- super(ChromeActivity.class); |
- } |
- |
- @Override |
- public void startMainActivity() throws InterruptedException { |
- startMainActivityOnBlankPage(); |
- } |
- |
- @Override |
- protected void setUp() throws Exception { |
- super.setUp(); |
- mTab = getActivity().getActivityTab(); |
+ @Before |
+ public void setUp() throws Exception { |
+ mActivityTestRule.startMainActivityOnBlankPage(); |
+ mTab = mActivityTestRule.getActivity().getActivityTab(); |
mTab.addObserver(mTabObserver); |
mOnTitleUpdatedHelper = new CallbackHelper(); |
} |
+ @Test |
@SmallTest |
@Feature({"Tab"}) |
public void testTabContext() throws Throwable { |
- assertFalse("The tab context cannot be an activity", |
+ Assert.assertFalse("The tab context cannot be an activity", |
mTab.getContentViewCore().getContext() instanceof Activity); |
- assertNotSame("The tab context's theme should have been updated", |
+ Assert.assertNotSame("The tab context's theme should have been updated", |
mTab.getContentViewCore().getContext().getTheme(), |
- getActivity().getApplication().getTheme()); |
+ mActivityTestRule.getActivity().getApplication().getTheme()); |
} |
+ @Test |
@SmallTest |
@Feature({"Tab"}) |
public void testTitleDelayUpdate() throws Throwable { |
final String oldTitle = "oldTitle"; |
final String newTitle = "newTitle"; |
- loadUrl("data:text/html;charset=utf-8,<html><head><title>" |
- + oldTitle + "</title></head><body/></html>"); |
- assertEquals("title does not match initial title", oldTitle, mTab.getTitle()); |
+ mActivityTestRule.loadUrl("data:text/html;charset=utf-8,<html><head><title>" + oldTitle |
+ + "</title></head><body/></html>"); |
+ Assert.assertEquals("title does not match initial title", oldTitle, mTab.getTitle()); |
int currentCallCount = mOnTitleUpdatedHelper.getCallCount(); |
- runJavaScriptCodeInCurrentTab("document.title='" + newTitle + "';"); |
+ mActivityTestRule.runJavaScriptCodeInCurrentTab("document.title='" + newTitle + "';"); |
mOnTitleUpdatedHelper.waitForCallback(currentCallCount); |
- assertEquals("title does not update", newTitle, mTab.getTitle()); |
+ Assert.assertEquals("title does not update", newTitle, mTab.getTitle()); |
} |
/** |
@@ -84,6 +93,7 @@ public class TabTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
* Note that document mode is explicitly disabled, as the document activity |
* may be fully recreated if its contents is killed while in the background. |
*/ |
+ @Test |
@SmallTest |
@Feature({"Tab"}) |
public void testTabRestoredIfKilledWhileActivityStopped() throws Exception { |
@@ -95,12 +105,13 @@ public class TabTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
} |
}); |
- assertFalse(mTab.needsReload()); |
- assertFalse(mTab.isHidden()); |
- assertFalse(mTab.isShowingSadTab()); |
+ Assert.assertFalse(mTab.needsReload()); |
+ Assert.assertFalse(mTab.isHidden()); |
+ Assert.assertFalse(mTab.isShowingSadTab()); |
// Stop the activity and simulate a killed renderer. |
- ApplicationTestUtils.fireHomeScreenIntent(getInstrumentation().getTargetContext()); |
+ ApplicationTestUtils.fireHomeScreenIntent( |
+ InstrumentationRegistry.getInstrumentation().getTargetContext()); |
ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
@Override |
public void run() { |
@@ -114,10 +125,11 @@ public class TabTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
return mTab.isHidden(); |
} |
}); |
- assertTrue(mTab.needsReload()); |
- assertFalse(mTab.isShowingSadTab()); |
+ Assert.assertTrue(mTab.needsReload()); |
+ Assert.assertFalse(mTab.isShowingSadTab()); |
- ApplicationTestUtils.launchChrome(getInstrumentation().getTargetContext()); |
+ ApplicationTestUtils.launchChrome( |
+ InstrumentationRegistry.getInstrumentation().getTargetContext()); |
// The tab should be restored and visible. |
CriteriaHelper.pollUiThread(new Criteria() { |
@@ -126,17 +138,18 @@ public class TabTest extends ChromeActivityTestCaseBase<ChromeActivity> { |
return !mTab.isHidden(); |
} |
}); |
- assertFalse(mTab.needsReload()); |
- assertFalse(mTab.isShowingSadTab()); |
+ Assert.assertFalse(mTab.needsReload()); |
+ Assert.assertFalse(mTab.isShowingSadTab()); |
} |
+ @Test |
@SmallTest |
@Feature({"Tab"}) |
public void testTabSecurityLevel() { |
ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
@Override |
public void run() { |
- assertEquals(ConnectionSecurityLevel.NONE, mTab.getSecurityLevel()); |
+ Assert.assertEquals(ConnectionSecurityLevel.NONE, mTab.getSecurityLevel()); |
} |
}); |
} |