Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1938)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/identity/SettingsSecureBasedIdentificationGeneratorTest.java

Issue 12313075: [sync] Upstream the Android ProfileSyncService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/javatests/src/org/chromium/chrome/browser/identity/SettingsSecureBasedIdentificationGeneratorTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/identity/SettingsSecureBasedIdentificationGeneratorTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/identity/SettingsSecureBasedIdentificationGeneratorTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..0755c3f9873eb2505e605320e30c88f0d70e44f8
--- /dev/null
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/identity/SettingsSecureBasedIdentificationGeneratorTest.java
@@ -0,0 +1,78 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.identity;
+
+import android.test.InstrumentationTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import org.chromium.base.test.util.AdvancedMockContext;
+import org.chromium.base.test.util.Feature;
+import org.chromium.chrome.browser.util.HashUtil;
+
+public class SettingsSecureBasedIdentificationGeneratorTest extends InstrumentationTestCase {
+
+ private static final String FLAG_ANDROID_ID = "android_id";
+
+ @SmallTest
+ @Feature({"ChromeToMobile", "Omaha"})
+ public void testAndroidIdSuccessWithSalt() {
+ String androidId = "42";
+ String salt = "mySalt";
+ String expected = HashUtil.getMd5Hash(new HashUtil.Params(androidId).withSalt(salt));
+ runTest(androidId, salt, expected);
+ }
+
+ @SmallTest
+ @Feature({"ChromeToMobile", "Omaha"})
+ public void testAndroidIdSuccessWithoutSalt() {
+ String androidId = "42";
+ String expected = HashUtil.getMd5Hash(new HashUtil.Params(androidId));
+ runTest(androidId, null, expected);
+ }
+
+ @SmallTest
+ @Feature({"ChromeToMobile", "Omaha"})
+ public void testAndroidIdFailureWithSalt() {
+ String androidId = null;
+ String salt = "mySalt";
+ String expected = "";
+ runTest(androidId, salt, expected);
+ }
+
+ @SmallTest
+ @Feature({"ChromeToMobile", "Omaha"})
+ public void testAndroidIdFailureWithoutSalt() {
+ String androidId = null;
+ String salt = null;
+ String expected = "";
+ runTest(androidId, salt, expected);
+ }
+
+ private void runTest(String androidId, String salt, String expectedUniqueId) {
+ AdvancedMockContext context = new AdvancedMockContext();
+ TestGenerator generator = new TestGenerator(context, androidId);
+
+ // Get a unique ID and ensure it is as expected.
+ String result = generator.getUniqueId(salt);
+ assertEquals(expectedUniqueId, result);
+ }
+
+ private static class TestGenerator extends SettingsSecureBasedIdentificationGenerator {
+ private final AdvancedMockContext mContext;
+ private final String mAndroidId;
+
+ TestGenerator(AdvancedMockContext context, String androidId) {
+ super(context);
+ mContext = context;
+ mAndroidId = androidId;
+ }
+
+ @Override
+ String getAndroidId() {
+ mContext.setFlag(FLAG_ANDROID_ID);
+ return mAndroidId;
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698