Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(868)

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/gsa/GSAServiceClientTest.java

Issue 2766373004: Convert the rest of chrome_public_test_apk InstrumentationTestCases to JUnit4 (Closed)
Patch Set: nits and rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.gsa; 5 package org.chromium.chrome.browser.gsa;
6 6
7 import android.content.ComponentName; 7 import android.content.ComponentName;
8 import android.content.Context; 8 import android.content.Context;
9 import android.content.Intent; 9 import android.content.Intent;
10 import android.content.ServiceConnection; 10 import android.content.ServiceConnection;
11 import android.os.IBinder; 11 import android.os.IBinder;
12 import android.support.test.InstrumentationRegistry;
12 import android.support.test.filters.SmallTest; 13 import android.support.test.filters.SmallTest;
13 import android.test.InstrumentationTestCase; 14
15 import org.junit.Assert;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
14 18
15 import org.chromium.base.Log; 19 import org.chromium.base.Log;
20 import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
16 21
17 import java.util.concurrent.Semaphore; 22 import java.util.concurrent.Semaphore;
18 import java.util.concurrent.TimeUnit; 23 import java.util.concurrent.TimeUnit;
19 import java.util.concurrent.atomic.AtomicReference; 24 import java.util.concurrent.atomic.AtomicReference;
20 25
21 /** Tests for GSAServiceClient. */ 26 /** Tests for GSAServiceClient. */
22 public class GSAServiceClientTest extends InstrumentationTestCase { 27 @RunWith(ChromeJUnit4ClassRunner.class)
28 public class GSAServiceClientTest {
23 private static final String TAG = "GSAServiceClientTest"; 29 private static final String TAG = "GSAServiceClientTest";
24 30
31 @Test
25 @SmallTest 32 @SmallTest
26 public void testGetPssForService() throws Exception { 33 public void testGetPssForService() throws Exception {
27 Context context = getInstrumentation().getTargetContext(); 34 Context context = InstrumentationRegistry.getInstrumentation().getTarget Context();
28 35
29 if (!GSAState.getInstance(context).isGsaAvailable()) { 36 if (!GSAState.getInstance(context).isGsaAvailable()) {
30 Log.w(TAG, "GSA is not available"); 37 Log.w(TAG, "GSA is not available");
31 return; 38 return;
32 } 39 }
33 40
34 final AtomicReference<ComponentName> componentNameRef = new AtomicRefere nce<>(); 41 final AtomicReference<ComponentName> componentNameRef = new AtomicRefere nce<>();
35 final Semaphore semaphore = new Semaphore(0); 42 final Semaphore semaphore = new Semaphore(0);
36 Intent intent = 43 Intent intent =
37 new Intent(GSAServiceClient.GSA_SERVICE).setPackage(GSAState.SEA RCH_INTENT_PACKAGE); 44 new Intent(GSAServiceClient.GSA_SERVICE).setPackage(GSAState.SEA RCH_INTENT_PACKAGE);
38 45
39 ServiceConnection connection = new ServiceConnection() { 46 ServiceConnection connection = new ServiceConnection() {
40 @Override 47 @Override
41 public void onServiceConnected(ComponentName name, IBinder service) { 48 public void onServiceConnected(ComponentName name, IBinder service) {
42 componentNameRef.set(name); 49 componentNameRef.set(name);
43 semaphore.release(); 50 semaphore.release();
44 } 51 }
45 52
46 @Override 53 @Override
47 public void onServiceDisconnected(ComponentName name) {} 54 public void onServiceDisconnected(ComponentName name) {}
48 }; 55 };
49 context.bindService(intent, connection, Context.BIND_AUTO_CREATE); 56 context.bindService(intent, connection, Context.BIND_AUTO_CREATE);
50 try { 57 try {
51 assertTrue("Timeout", semaphore.tryAcquire(10, TimeUnit.SECONDS)); 58 Assert.assertTrue("Timeout", semaphore.tryAcquire(10, TimeUnit.SECON DS));
52 59
53 int pss = GSAServiceClient.getPssForService(componentNameRef.get()); 60 int pss = GSAServiceClient.getPssForService(componentNameRef.get());
54 assertTrue(pss != GSAServiceClient.INVALID_PSS); 61 Assert.assertTrue(pss != GSAServiceClient.INVALID_PSS);
55 assertTrue(pss > 0); 62 Assert.assertTrue(pss > 0);
56 } finally { 63 } finally {
57 context.unbindService(connection); 64 context.unbindService(connection);
58 } 65 }
59 } 66 }
60 67
68 @Test
61 @SmallTest 69 @SmallTest
62 public void testGetPssForServiceServiceNotFound() throws Exception { 70 public void testGetPssForServiceServiceNotFound() throws Exception {
63 ComponentName componentName = new ComponentName("unknown.package.name", "UnknownClass"); 71 ComponentName componentName = new ComponentName("unknown.package.name", "UnknownClass");
64 int pss = GSAServiceClient.getPssForService(componentName); 72 int pss = GSAServiceClient.getPssForService(componentName);
65 assertTrue(pss == GSAServiceClient.INVALID_PSS); 73 Assert.assertTrue(pss == GSAServiceClient.INVALID_PSS);
66 } 74 }
67 } 75 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698