OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.test.gcore; |
| 6 |
| 7 import static junit.framework.Assert.assertEquals; |
| 8 |
| 9 import org.chromium.chrome.browser.gcore.ChromeGoogleApiClient; |
| 10 |
| 11 /** |
| 12 * Mock of ChromeGoogleApiClient that tracks which methods are called. |
| 13 */ |
| 14 public class MockChromeGoogleApiClient implements ChromeGoogleApiClient { |
| 15 private final Object mLock = new Object(); |
| 16 |
| 17 private boolean mConnectionResult; |
| 18 private boolean mIsGooglePlayServicesAvailable; |
| 19 |
| 20 private int mConnectWithTimeoutCount; |
| 21 private int mDisconnectCount; |
| 22 private int mIsGooglePlayServicesAvailableCount; |
| 23 |
| 24 @Override |
| 25 public boolean connectWithTimeout(long timeout) { |
| 26 synchronized (mLock) { |
| 27 mConnectWithTimeoutCount++; |
| 28 return mConnectionResult; |
| 29 } |
| 30 } |
| 31 |
| 32 @Override |
| 33 public void disconnect() { |
| 34 synchronized (mLock) { |
| 35 mDisconnectCount++; |
| 36 } |
| 37 } |
| 38 |
| 39 @Override |
| 40 public boolean isGooglePlayServicesAvailable() { |
| 41 synchronized (mLock) { |
| 42 mIsGooglePlayServicesAvailableCount++; |
| 43 return mIsGooglePlayServicesAvailable; |
| 44 } |
| 45 } |
| 46 |
| 47 public void setConnectionResult(boolean result) { |
| 48 synchronized (mLock) { |
| 49 mConnectionResult = result; |
| 50 } |
| 51 } |
| 52 |
| 53 public void setIsGooglePlayServicesAvailable(boolean available) { |
| 54 synchronized (mLock) { |
| 55 mIsGooglePlayServicesAvailable = available; |
| 56 } |
| 57 } |
| 58 |
| 59 public void assertConnectWithTimeoutCalled(int times) { |
| 60 synchronized (mLock) { |
| 61 assertEquals(times, mConnectWithTimeoutCount); |
| 62 mConnectWithTimeoutCount = 0; |
| 63 } |
| 64 } |
| 65 |
| 66 public void assertDisconnectCalled(int times) { |
| 67 synchronized (mLock) { |
| 68 assertEquals(times, mDisconnectCount); |
| 69 mDisconnectCount = 0; |
| 70 } |
| 71 } |
| 72 |
| 73 public void assertIsGooglePlayServicesAvailableCalled(int times) { |
| 74 synchronized (mLock) { |
| 75 assertEquals(times, mIsGooglePlayServicesAvailableCount); |
| 76 mIsGooglePlayServicesAvailableCount = 0; |
| 77 } |
| 78 } |
| 79 |
| 80 public void assertNoOtherMethodsCalled() { |
| 81 synchronized (mLock) { |
| 82 assertEquals(0, mConnectWithTimeoutCount); |
| 83 assertEquals(0, mDisconnectCount); |
| 84 assertEquals(0, mIsGooglePlayServicesAvailableCount); |
| 85 } |
| 86 } |
| 87 |
| 88 protected Object getLock() { |
| 89 return mLock; |
| 90 } |
| 91 } |
OLD | NEW |