1 // Copyright 2016 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/android/unguessable_token_android.h"
7 #include "base/android/jni_android.h"
8 #include "testing/gtest/include/gtest/gtest.h"
13 TEST(UnguessableTokenAndroid, BasicCreateToken) {
14 JNIEnv* env = AttachCurrentThread();
15 uint64_t high = 0x1234567812345678;
16 uint64_t low = 0x0583503029282304;
17 base::UnguessableToken token =
18 base::UnguessableToken::CreateForTesting(high, low);
19 ScopedJavaLocalRef<jobject> jtoken =
20 UnguessableTokenAndroid::Create(env, token);
21 absl::optional<base::UnguessableToken> result =
22 UnguessableTokenAndroid::FromJavaUnguessableToken(env, jtoken);
24 ASSERT_TRUE(result.has_value());
25 EXPECT_EQ(token, result.value());
28 TEST(UnguessableTokenAndroid, ParcelAndUnparcel) {
29 JNIEnv* env = AttachCurrentThread();
30 uint64_t high = 0x1234567812345678;
31 uint64_t low = 0x0583503029282304;
32 base::UnguessableToken token =
33 base::UnguessableToken::CreateForTesting(high, low);
34 ScopedJavaLocalRef<jobject> jtoken =
35 UnguessableTokenAndroid::Create(env, token);
36 ScopedJavaLocalRef<jobject> jtoken_clone =
37 UnguessableTokenAndroid::ParcelAndUnparcelForTesting(env, jtoken);
38 absl::optional<base::UnguessableToken> token_clone =
39 UnguessableTokenAndroid::FromJavaUnguessableToken(env, jtoken_clone);
41 ASSERT_TRUE(token_clone.has_value());
42 EXPECT_EQ(token, token_clone.value());
45 } // namespace android