| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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.identity; | 5 package org.chromium.chrome.browser.identity; |
| 6 | 6 |
| 7 import android.support.test.filters.SmallTest; | 7 import android.support.test.filters.SmallTest; |
| 8 import android.test.InstrumentationTestCase; | 8 |
| 9 import org.junit.Assert; |
| 10 import org.junit.Test; |
| 11 import org.junit.runner.RunWith; |
| 9 | 12 |
| 10 import org.chromium.base.test.util.Feature; | 13 import org.chromium.base.test.util.Feature; |
| 14 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
| 11 | 15 |
| 12 import javax.annotation.Nullable; | 16 import javax.annotation.Nullable; |
| 13 | 17 |
| 14 public class UniqueIdentificationGeneratorFactoryTest extends InstrumentationTes
tCase { | 18 @RunWith(ChromeJUnit4ClassRunner.class) |
| 15 | 19 public class UniqueIdentificationGeneratorFactoryTest { |
| 20 @Test |
| 16 @SmallTest | 21 @SmallTest |
| 17 @Feature({"ChromeToMobile", "Omaha", "Sync"}) | 22 @Feature({"ChromeToMobile", "Omaha", "Sync"}) |
| 18 public void testSetAndGetGenerator() { | 23 public void testSetAndGetGenerator() { |
| 19 UniqueIdentificationGeneratorFactory.clearGeneratorMapForTest(); | 24 UniqueIdentificationGeneratorFactory.clearGeneratorMapForTest(); |
| 20 UniqueIdentificationGenerator gen = new TestGenerator(); | 25 UniqueIdentificationGenerator gen = new TestGenerator(); |
| 21 UniqueIdentificationGeneratorFactory.registerGenerator("generator", gen,
false); | 26 UniqueIdentificationGeneratorFactory.registerGenerator("generator", gen,
false); |
| 22 assertEquals(gen, UniqueIdentificationGeneratorFactory.getInstance("gene
rator")); | 27 Assert.assertEquals(gen, UniqueIdentificationGeneratorFactory.getInstanc
e("generator")); |
| 23 } | 28 } |
| 24 | 29 |
| 30 @Test |
| 25 @SmallTest | 31 @SmallTest |
| 26 @Feature({"ChromeToMobile", "Omaha", "Sync"}) | 32 @Feature({"ChromeToMobile", "Omaha", "Sync"}) |
| 27 public void testForceCanOverrideGenerator() { | 33 public void testForceCanOverrideGenerator() { |
| 28 UniqueIdentificationGeneratorFactory.clearGeneratorMapForTest(); | 34 UniqueIdentificationGeneratorFactory.clearGeneratorMapForTest(); |
| 29 UniqueIdentificationGenerator gen1 = new TestGenerator(); | 35 UniqueIdentificationGenerator gen1 = new TestGenerator(); |
| 30 UniqueIdentificationGenerator gen2 = new TestGenerator(); | 36 UniqueIdentificationGenerator gen2 = new TestGenerator(); |
| 31 UniqueIdentificationGenerator gen3 = new TestGenerator(); | 37 UniqueIdentificationGenerator gen3 = new TestGenerator(); |
| 32 UniqueIdentificationGeneratorFactory.registerGenerator("generator", gen1
, false); | 38 UniqueIdentificationGeneratorFactory.registerGenerator("generator", gen1
, false); |
| 33 assertEquals(gen1, UniqueIdentificationGeneratorFactory.getInstance("gen
erator")); | 39 Assert.assertEquals(gen1, UniqueIdentificationGeneratorFactory.getInstan
ce("generator")); |
| 34 UniqueIdentificationGeneratorFactory.registerGenerator("generator", gen2
, false); | 40 UniqueIdentificationGeneratorFactory.registerGenerator("generator", gen2
, false); |
| 35 assertEquals(gen1, UniqueIdentificationGeneratorFactory.getInstance("gen
erator")); | 41 Assert.assertEquals(gen1, UniqueIdentificationGeneratorFactory.getInstan
ce("generator")); |
| 36 UniqueIdentificationGeneratorFactory.registerGenerator("generator", gen3
, true); | 42 UniqueIdentificationGeneratorFactory.registerGenerator("generator", gen3
, true); |
| 37 assertEquals(gen3, UniqueIdentificationGeneratorFactory.getInstance("gen
erator")); | 43 Assert.assertEquals(gen3, UniqueIdentificationGeneratorFactory.getInstan
ce("generator")); |
| 38 } | 44 } |
| 39 | 45 |
| 46 @Test |
| 40 @SmallTest | 47 @SmallTest |
| 41 @Feature({"ChromeToMobile", "Omaha", "Sync"}) | 48 @Feature({"ChromeToMobile", "Omaha", "Sync"}) |
| 42 public void testGeneratorNotFoundThrows() { | 49 public void testGeneratorNotFoundThrows() { |
| 43 UniqueIdentificationGeneratorFactory.clearGeneratorMapForTest(); | 50 UniqueIdentificationGeneratorFactory.clearGeneratorMapForTest(); |
| 44 UniqueIdentificationGenerator generator = null; | 51 UniqueIdentificationGenerator generator = null; |
| 45 try { | 52 try { |
| 46 generator = UniqueIdentificationGeneratorFactory.getInstance("genera
tor"); | 53 generator = UniqueIdentificationGeneratorFactory.getInstance("genera
tor"); |
| 47 fail("The generator does not exist, so factory should throw an error
."); | 54 Assert.fail("The generator does not exist, so factory should throw a
n error."); |
| 48 } catch (RuntimeException e) { | 55 } catch (RuntimeException e) { |
| 49 assertEquals(null, generator); | 56 Assert.assertEquals(null, generator); |
| 50 } | 57 } |
| 51 } | 58 } |
| 52 | 59 |
| 53 private static class TestGenerator implements UniqueIdentificationGenerator
{ | 60 private static class TestGenerator implements UniqueIdentificationGenerator
{ |
| 54 @Override | 61 @Override |
| 55 public String getUniqueId(@Nullable String salt) { | 62 public String getUniqueId(@Nullable String salt) { |
| 56 return null; | 63 return null; |
| 57 } | 64 } |
| 58 } | 65 } |
| 59 } | 66 } |
| OLD | NEW |