| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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.BroadcastReceiver; | 7 import android.content.BroadcastReceiver; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.Intent; | 9 import android.content.Intent; |
| 10 import android.content.IntentFilter; | 10 import android.content.IntentFilter; |
| 11 import android.support.test.InstrumentationRegistry; |
| 11 import android.support.test.filters.SmallTest; | 12 import android.support.test.filters.SmallTest; |
| 12 import android.test.InstrumentationTestCase; | |
| 13 | 13 |
| 14 import junit.framework.AssertionFailedError; | 14 import junit.framework.AssertionFailedError; |
| 15 | 15 |
| 16 import org.junit.Assert; |
| 17 import org.junit.Before; |
| 18 import org.junit.Test; |
| 19 import org.junit.runner.RunWith; |
| 20 |
| 16 import org.chromium.base.metrics.RecordHistogram; | 21 import org.chromium.base.metrics.RecordHistogram; |
| 22 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
| 17 import org.chromium.content.browser.test.util.Criteria; | 23 import org.chromium.content.browser.test.util.Criteria; |
| 18 import org.chromium.content.browser.test.util.CriteriaHelper; | 24 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 19 | 25 |
| 20 /** Tests for GSAAccountChangeListener. */ | 26 /** Tests for GSAAccountChangeListener. */ |
| 21 public class GSAAccountChangeListenerTest extends InstrumentationTestCase { | 27 @RunWith(ChromeJUnit4ClassRunner.class) |
| 28 public class GSAAccountChangeListenerTest { |
| 22 private static final String ACCOUNT_NAME = "me@gmail.com"; | 29 private static final String ACCOUNT_NAME = "me@gmail.com"; |
| 23 private static final String ACCOUNT_NAME2 = "you@gmail.com"; | 30 private static final String ACCOUNT_NAME2 = "you@gmail.com"; |
| 24 private static final String PERMISSION = "permission.you.dont.have"; | 31 private static final String PERMISSION = "permission.you.dont.have"; |
| 25 | 32 |
| 26 @Override | 33 @Before |
| 27 protected void setUp() throws Exception { | 34 public void setUp() throws Exception { |
| 28 super.setUp(); | |
| 29 RecordHistogram.setDisabledForTests(true); | 35 RecordHistogram.setDisabledForTests(true); |
| 30 } | 36 } |
| 31 | 37 |
| 38 @Test |
| 32 @SmallTest | 39 @SmallTest |
| 33 public void testReceivesBroadcastIntents() throws Exception { | 40 public void testReceivesBroadcastIntents() throws Exception { |
| 34 final Context context = getInstrumentation().getTargetContext(); | 41 final Context context = InstrumentationRegistry.getInstrumentation().get
TargetContext(); |
| 35 BroadcastReceiver receiver = new GSAAccountChangeListener.AccountChangeB
roadcastReceiver(); | 42 BroadcastReceiver receiver = new GSAAccountChangeListener.AccountChangeB
roadcastReceiver(); |
| 36 context.registerReceiver(receiver, | 43 context.registerReceiver(receiver, |
| 37 new IntentFilter(GSAAccountChangeListener.ACCOUNT_UPDATE_BROADCA
ST_INTENT)); | 44 new IntentFilter(GSAAccountChangeListener.ACCOUNT_UPDATE_BROADCA
ST_INTENT)); |
| 38 | 45 |
| 39 // Send a broadcast without the permission, should be received. | 46 // Send a broadcast without the permission, should be received. |
| 40 Intent intent = new Intent(); | 47 Intent intent = new Intent(); |
| 41 intent.setPackage(context.getPackageName()); | 48 intent.setPackage(context.getPackageName()); |
| 42 intent.setAction(GSAAccountChangeListener.ACCOUNT_UPDATE_BROADCAST_INTEN
T); | 49 intent.setAction(GSAAccountChangeListener.ACCOUNT_UPDATE_BROADCAST_INTEN
T); |
| 43 intent.putExtra(GSAAccountChangeListener.BROADCAST_INTENT_ACCOUNT_NAME_E
XTRA, ACCOUNT_NAME); | 50 intent.putExtra(GSAAccountChangeListener.BROADCAST_INTENT_ACCOUNT_NAME_E
XTRA, ACCOUNT_NAME); |
| 44 context.sendBroadcast(intent); | 51 context.sendBroadcast(intent); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 66 @Override | 73 @Override |
| 67 public boolean isSatisfied() { | 74 public boolean isSatisfied() { |
| 68 String currentAccount = | 75 String currentAccount = |
| 69 GSAState.getInstance(context.getApplicationContext()
).getGsaAccount(); | 76 GSAState.getInstance(context.getApplicationContext()
).getGsaAccount(); |
| 70 return ACCOUNT_NAME2.equals(currentAccount); | 77 return ACCOUNT_NAME2.equals(currentAccount); |
| 71 } | 78 } |
| 72 }, 1000, 100); | 79 }, 1000, 100); |
| 73 } catch (AssertionFailedError e) { | 80 } catch (AssertionFailedError e) { |
| 74 return; | 81 return; |
| 75 } | 82 } |
| 76 fail("The broadcast was received."); | 83 Assert.fail("The broadcast was received."); |
| 77 } | 84 } |
| 78 } | 85 } |
| OLD | NEW |