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

Side by Side Diff: chrome/browser/signin/local_auth_unittest.cc

Issue 1086733002: Ensure tests have an active task runner (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 years, 7 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 unified diff | Download patch
OLDNEW
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 #include "chrome/browser/signin/local_auth.h" 5 #include "chrome/browser/signin/local_auth.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile_manager.h" 9 #include "chrome/browser/profiles/profile_manager.h"
10 #include "chrome/test/base/testing_browser_process.h" 10 #include "chrome/test/base/testing_browser_process.h"
11 #include "chrome/test/base/testing_pref_service_syncable.h" 11 #include "chrome/test/base/testing_pref_service_syncable.h"
12 #include "chrome/test/base/testing_profile.h" 12 #include "chrome/test/base/testing_profile.h"
13 #include "chrome/test/base/testing_profile_manager.h" 13 #include "chrome/test/base/testing_profile_manager.h"
14 #include "components/os_crypt/os_crypt.h" 14 #include "components/os_crypt/os_crypt.h"
15 #include "content/public/test/test_browser_thread_bundle.h"
15 16
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 TEST(LocalAuthTest, SetAndCheckCredentials) { 19 class LocalAuthTest : public testing::Test {
20 content::TestBrowserThreadBundle thread_bundle_;
21 };
22
23 TEST_F(LocalAuthTest, SetAndCheckCredentials) {
19 TestingProfileManager testing_profile_manager( 24 TestingProfileManager testing_profile_manager(
20 TestingBrowserProcess::GetGlobal()); 25 TestingBrowserProcess::GetGlobal());
21 ASSERT_TRUE(testing_profile_manager.SetUp()); 26 ASSERT_TRUE(testing_profile_manager.SetUp());
22 Profile* prof = testing_profile_manager.CreateTestingProfile("p1"); 27 Profile* prof = testing_profile_manager.CreateTestingProfile("p1");
23 ProfileInfoCache& cache = 28 ProfileInfoCache& cache =
24 testing_profile_manager.profile_manager()->GetProfileInfoCache(); 29 testing_profile_manager.profile_manager()->GetProfileInfoCache();
25 EXPECT_EQ(1U, cache.GetNumberOfProfiles()); 30 EXPECT_EQ(1U, cache.GetNumberOfProfiles());
26 EXPECT_EQ("", cache.GetLocalAuthCredentialsOfProfileAtIndex(0)); 31 EXPECT_EQ("", cache.GetLocalAuthCredentialsOfProfileAtIndex(0));
27 32
28 #if defined(OS_MACOSX) 33 #if defined(OS_MACOSX)
(...skipping 19 matching lines...) Expand all
48 EXPECT_FALSE(decodedhash.empty()); 53 EXPECT_FALSE(decodedhash.empty());
49 EXPECT_EQ(decodedhash.find(password), std::string::npos); 54 EXPECT_EQ(decodedhash.find(password), std::string::npos);
50 55
51 EXPECT_TRUE(LocalAuth::ValidateLocalAuthCredentials(prof, password)); 56 EXPECT_TRUE(LocalAuth::ValidateLocalAuthCredentials(prof, password));
52 EXPECT_FALSE(LocalAuth::ValidateLocalAuthCredentials(prof, password + "1")); 57 EXPECT_FALSE(LocalAuth::ValidateLocalAuthCredentials(prof, password + "1"));
53 58
54 LocalAuth::SetLocalAuthCredentials(prof, password); // makes different salt 59 LocalAuth::SetLocalAuthCredentials(prof, password); // makes different salt
55 EXPECT_NE(passhash, cache.GetLocalAuthCredentialsOfProfileAtIndex(0)); 60 EXPECT_NE(passhash, cache.GetLocalAuthCredentialsOfProfileAtIndex(0));
56 } 61 }
57 62
58 63 TEST_F(LocalAuthTest, SetUpgradeAndCheckCredentials) {
59 TEST(LocalAuthTest, SetUpgradeAndCheckCredentials) {
60 TestingProfileManager testing_profile_manager( 64 TestingProfileManager testing_profile_manager(
61 TestingBrowserProcess::GetGlobal()); 65 TestingBrowserProcess::GetGlobal());
62 ASSERT_TRUE(testing_profile_manager.SetUp()); 66 ASSERT_TRUE(testing_profile_manager.SetUp());
63 Profile* prof = testing_profile_manager.CreateTestingProfile("p1"); 67 Profile* prof = testing_profile_manager.CreateTestingProfile("p1");
64 ProfileInfoCache& cache = 68 ProfileInfoCache& cache =
65 testing_profile_manager.profile_manager()->GetProfileInfoCache(); 69 testing_profile_manager.profile_manager()->GetProfileInfoCache();
66 70
67 #if defined(OS_MACOSX) 71 #if defined(OS_MACOSX)
68 OSCrypt::UseMockKeychain(true); 72 OSCrypt::UseMockKeychain(true);
69 #endif 73 #endif
(...skipping 15 matching lines...) Expand all
85 profile_index); 89 profile_index);
86 EXPECT_EQ('2', newpasshash[0]); 90 EXPECT_EQ('2', newpasshash[0]);
87 // Encoding '2' writes fewer bytes than encoding '1'. 91 // Encoding '2' writes fewer bytes than encoding '1'.
88 EXPECT_LE(newpasshash.length(), oldpasshash.length()); 92 EXPECT_LE(newpasshash.length(), oldpasshash.length());
89 93
90 // Validate, ensure we validate against the new encoding. 94 // Validate, ensure we validate against the new encoding.
91 EXPECT_TRUE(LocalAuth::ValidateLocalAuthCredentials(prof, password)); 95 EXPECT_TRUE(LocalAuth::ValidateLocalAuthCredentials(prof, password));
92 } 96 }
93 97
94 // Test truncation where each byte is left whole. 98 // Test truncation where each byte is left whole.
95 TEST(LocalAuthTest, TruncateStringEvenly) { 99 TEST_F(LocalAuthTest, TruncateStringEvenly) {
96 std::string two_chars = "A6"; 100 std::string two_chars = "A6";
97 std::string three_chars = "A6C"; 101 std::string three_chars = "A6C";
98 EXPECT_EQ(two_chars, LocalAuth::TruncateStringByBits(two_chars, 16)); 102 EXPECT_EQ(two_chars, LocalAuth::TruncateStringByBits(two_chars, 16));
99 EXPECT_EQ(two_chars, LocalAuth::TruncateStringByBits(three_chars, 16)); 103 EXPECT_EQ(two_chars, LocalAuth::TruncateStringByBits(three_chars, 16));
100 104
101 EXPECT_EQ(two_chars, LocalAuth::TruncateStringByBits(two_chars, 14)); 105 EXPECT_EQ(two_chars, LocalAuth::TruncateStringByBits(two_chars, 14));
102 EXPECT_EQ(two_chars, LocalAuth::TruncateStringByBits(three_chars, 14)); 106 EXPECT_EQ(two_chars, LocalAuth::TruncateStringByBits(three_chars, 14));
103 } 107 }
104 108
105 // Test truncation that affects the results within a byte. 109 // Test truncation that affects the results within a byte.
106 TEST(LocalAuthTest, TruncateStringUnevenly) { 110 TEST_F(LocalAuthTest, TruncateStringUnevenly) {
107 std::string two_chars = "Az"; 111 std::string two_chars = "Az";
108 std::string three_chars = "AzC"; 112 std::string three_chars = "AzC";
109 // 'z' = 0x7A, ':' = 0x3A. 113 // 'z' = 0x7A, ':' = 0x3A.
110 std::string two_chars_truncated = "A:"; 114 std::string two_chars_truncated = "A:";
111 EXPECT_EQ(two_chars_truncated, 115 EXPECT_EQ(two_chars_truncated,
112 LocalAuth::TruncateStringByBits(two_chars, 14)); 116 LocalAuth::TruncateStringByBits(two_chars, 14));
113 EXPECT_EQ(two_chars_truncated, 117 EXPECT_EQ(two_chars_truncated,
114 LocalAuth::TruncateStringByBits(three_chars, 14)); 118 LocalAuth::TruncateStringByBits(three_chars, 14));
115 } 119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698