Index: components/devtools_bridge/android/client/javatests/src/org/chromium/components/devtools_bridge/WebClientTest.java |
diff --git a/components/devtools_bridge/android/client/javatests/src/org/chromium/components/devtools_bridge/WebClientTest.java b/components/devtools_bridge/android/client/javatests/src/org/chromium/components/devtools_bridge/WebClientTest.java |
index 2c4299dc468180245810a708a9cb225a69b81fc9..8c021ab60dee2d23472491561ccf39e30d763f92 100644 |
--- a/components/devtools_bridge/android/client/javatests/src/org/chromium/components/devtools_bridge/WebClientTest.java |
+++ b/components/devtools_bridge/android/client/javatests/src/org/chromium/components/devtools_bridge/WebClientTest.java |
@@ -12,14 +12,16 @@ import org.chromium.chrome.browser.profiles.Profile; |
import org.chromium.content.browser.BrowserStartupController; |
import java.util.concurrent.Callable; |
+import java.util.concurrent.CountDownLatch; |
/** |
* Tests for {@link WebClient}. WebClient is not intended to run on Android but |
* it can. It is useful for tests: we can test it against the server in the |
* same process (without dependency on network and cloud services). |
*/ |
-public class WebClientTest extends InstrumentationTestCase { |
+public class WebClientTest extends InstrumentationTestCase implements WebClient.Delegate { |
mnaganov (inactive)
2014/11/24 11:47:20
I think test classes usually serve as containers o
|
private Profile mProfile; |
+ private WebClient mWebClient; |
protected void startChromeBrowserProcessSyncOnUIThread() throws Exception { |
BrowserStartupController.get(getInstrumentation().getTargetContext()) |
@@ -27,17 +29,54 @@ public class WebClientTest extends InstrumentationTestCase { |
mProfile = Profile.getLastUsedProfile(); |
} |
- @SmallTest |
- public void testCreationWebClient() throws Exception { |
+ @Override |
+ protected void tearDown() throws Exception { |
+ super.tearDown(); |
mnaganov (inactive)
2014/11/24 11:47:20
super's tearDown() should be called last, I guess.
|
+ if (mWebClient == null) return; |
+ |
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
+ @Override |
+ public void run() { |
+ mWebClient.dispose(); |
+ } |
+ }); |
+ } |
+ |
+ private void createWebClient() throws Exception { |
ThreadUtils.runOnUiThreadBlocking(new Callable<Void>() { |
@Override |
public Void call() throws Exception { |
startChromeBrowserProcessSyncOnUIThread(); |
assert mProfile != null; |
- new WebClient(mProfile).dispose(); |
+ mWebClient = new WebClient(mProfile, WebClientTest.this); |
return null; |
} |
}); |
} |
+ |
+ @SmallTest |
+ public void testCreationWebClient() throws Exception { |
+ createWebClient(); |
+ } |
+ |
+ @SmallTest |
+ public void testStartingSession() throws Exception { |
+ createWebClient(); |
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
+ @Override |
+ public void run() { |
+ mWebClient.connect("DEVICE_ID"); |
+ } |
+ }); |
+ |
+ mCommandSent.await(); |
+ } |
+ |
+ private final CountDownLatch mCommandSent = new CountDownLatch(1); |
+ |
+ @Override |
+ public void sendCommand(String json) { |
+ mCommandSent.countDown(); |
+ } |
} |