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.chrome.browser.identity; |
| 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 javax.annotation.Nullable; |
| 13 |
| 14 public class UniqueIdentificationGeneratorFactoryTest extends InstrumentationTes
tCase { |
| 15 |
| 16 @SmallTest |
| 17 @Feature({"ChromeToMobile", "Omaha", "Sync"}) |
| 18 public void testSetAndGetGenerator() { |
| 19 UniqueIdentificationGeneratorFactory.clearGeneratorMapForTest(); |
| 20 UniqueIdentificationGenerator gen = new TestGenerator(); |
| 21 UniqueIdentificationGeneratorFactory.registerGenerator("generator", gen,
false); |
| 22 assertEquals(gen, UniqueIdentificationGeneratorFactory.getInstance("gene
rator")); |
| 23 } |
| 24 |
| 25 @SmallTest |
| 26 @Feature({"ChromeToMobile", "Omaha", "Sync"}) |
| 27 public void testForceCanOverrideGenerator() { |
| 28 UniqueIdentificationGeneratorFactory.clearGeneratorMapForTest(); |
| 29 UniqueIdentificationGenerator gen1 = new TestGenerator(); |
| 30 UniqueIdentificationGenerator gen2 = new TestGenerator(); |
| 31 UniqueIdentificationGenerator gen3 = new TestGenerator(); |
| 32 UniqueIdentificationGeneratorFactory.registerGenerator("generator", gen1
, false); |
| 33 assertEquals(gen1, UniqueIdentificationGeneratorFactory.getInstance("gen
erator")); |
| 34 UniqueIdentificationGeneratorFactory.registerGenerator("generator", gen2
, false); |
| 35 assertEquals(gen1, UniqueIdentificationGeneratorFactory.getInstance("gen
erator")); |
| 36 UniqueIdentificationGeneratorFactory.registerGenerator("generator", gen3
, true); |
| 37 assertEquals(gen3, UniqueIdentificationGeneratorFactory.getInstance("gen
erator")); |
| 38 } |
| 39 |
| 40 @SmallTest |
| 41 @Feature({"ChromeToMobile", "Omaha", "Sync"}) |
| 42 public void testGeneratorNotFoundThrows() { |
| 43 UniqueIdentificationGeneratorFactory.clearGeneratorMapForTest(); |
| 44 UniqueIdentificationGenerator generator = null; |
| 45 try { |
| 46 generator = UniqueIdentificationGeneratorFactory.getInstance("genera
tor"); |
| 47 fail("The generator does not exist, so factory should throw an error
."); |
| 48 } catch (RuntimeException e) { |
| 49 assertEquals(null, generator); |
| 50 } |
| 51 } |
| 52 |
| 53 private static class TestGenerator implements UniqueIdentificationGenerator
{ |
| 54 @Override |
| 55 public String getUniqueId(@Nullable String salt) { |
| 56 return null; |
| 57 } |
| 58 } |
| 59 } |
OLD | NEW |