| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 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.sync.notifier; | |
| 6 | |
| 7 import android.test.InstrumentationTestCase; | |
| 8 import android.test.suitebuilder.annotation.SmallTest; | |
| 9 | |
| 10 import org.chromium.base.test.util.Feature; | |
| 11 | |
| 12 import java.util.Arrays; | |
| 13 | |
| 14 /** Tests for the {@link InvalidationClientNameProvider} */ | |
| 15 public class InvalidationClientNameProviderTest extends InstrumentationTestCase
{ | |
| 16 private InvalidationClientNameProvider mProvider; | |
| 17 | |
| 18 @Override | |
| 19 protected void setUp() { | |
| 20 mProvider = new InvalidationClientNameProvider(); | |
| 21 } | |
| 22 | |
| 23 @SmallTest | |
| 24 @Feature({"Sync"}) | |
| 25 public void testFallbackClientId() { | |
| 26 // Test that the InvalidationController consistently returns the same ID
even when it has to | |
| 27 // resort to its "fallback" ID generation code. | |
| 28 byte[] id1 = mProvider.getInvalidatorClientName(); | |
| 29 byte[] id2 = mProvider.getInvalidatorClientName(); | |
| 30 | |
| 31 // We expect the returned IDs to be consistent in every call. | |
| 32 assertTrue("Expected returned IDs to be consistent", Arrays.equals(id1,
id2)); | |
| 33 | |
| 34 // Even if initialize the generator late, the ID will remain consistent. | |
| 35 registerHardCodedGenerator(mProvider); | |
| 36 | |
| 37 // IDs should still be consistent, even if we change the generator. | |
| 38 // (In the real program, the generator should be set before anyone invok
es the | |
| 39 // getInvalidatorClientName() and never change afterwards. We test this
anyway to make sure | |
| 40 // nothing will blow up if someone accidentally violates that constraint
.) | |
| 41 byte[] id3 = mProvider.getInvalidatorClientName(); | |
| 42 assertTrue("Changing generators should not affect returned ID consistenc
y", | |
| 43 Arrays.equals(id2, id3)); | |
| 44 } | |
| 45 | |
| 46 @SmallTest | |
| 47 @Feature({"Sync"}) | |
| 48 public void testPreRegisteredGenerator() { | |
| 49 registerHardCodedGenerator(mProvider); | |
| 50 | |
| 51 byte[] id = mProvider.getInvalidatorClientName(); | |
| 52 byte[] id2 = mProvider.getInvalidatorClientName(); | |
| 53 | |
| 54 // Expect that consistent IDs are maintained when using a custom generat
or, too. | |
| 55 assertTrue("Custom generators should return consistent IDs", Arrays.equa
ls(id, id2)); | |
| 56 } | |
| 57 | |
| 58 private static void registerHardCodedGenerator(InvalidationClientNameProvide
r provider) { | |
| 59 provider.setPreferredClientNameGenerator(new InvalidationClientNameGener
ator() { | |
| 60 @Override | |
| 61 public byte[] generateInvalidatorClientName() { | |
| 62 return "Testable ID".getBytes(); | |
| 63 } | |
| 64 }); | |
| 65 } | |
| 66 } | |
| OLD | NEW |