Linux: Depend on liberation-fonts package for RPMs.
[chromium-blink-merge.git] / components / password_manager / sync / browser / password_sync_util_unittest.cc
blob6115ea152cecd0b95408d08b15e3ba8f7cc13399
1 // Copyright 2015 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.
5 #include "components/password_manager/sync/browser/password_sync_util.h"
7 #include "base/macros.h"
8 #include "components/autofill/core/common/password_form.h"
9 #include "components/password_manager/sync/browser/sync_username_test_base.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 using autofill::PasswordForm;
14 namespace password_manager {
15 namespace sync_util {
17 typedef SyncUsernameTestBase PasswordSyncUtilTest;
19 TEST_F(PasswordSyncUtilTest, GetSyncUsernameIfSyncingPasswords) {
20 const struct TestCase {
21 enum { SYNCING_PASSWORDS, NOT_SYNCING_PASSWORDS } password_sync;
22 std::string fake_sync_username;
23 std::string expected_result;
24 const sync_driver::SyncService* sync_service;
25 const SigninManagerBase* signin_manager;
26 } kTestCases[] = {
27 {TestCase::NOT_SYNCING_PASSWORDS, "a@example.org", std::string(),
28 sync_service(), signin_manager()},
30 {TestCase::SYNCING_PASSWORDS, "a@example.org", "a@example.org",
31 sync_service(), signin_manager()},
33 // If sync_service is not available, we assume passwords are synced, even
34 // if they are not.
35 {TestCase::NOT_SYNCING_PASSWORDS, "a@example.org", "a@example.org",
36 nullptr, signin_manager()},
38 {TestCase::SYNCING_PASSWORDS, "a@example.org", std::string(),
39 sync_service(), nullptr},
41 {TestCase::SYNCING_PASSWORDS, "a@example.org", std::string(), nullptr,
42 nullptr},
45 for (size_t i = 0; i < arraysize(kTestCases); ++i) {
46 SCOPED_TRACE(testing::Message() << "i=" << i);
47 SetSyncingPasswords(kTestCases[i].password_sync ==
48 TestCase::SYNCING_PASSWORDS);
49 FakeSigninAs(kTestCases[i].fake_sync_username);
50 EXPECT_EQ(kTestCases[i].expected_result,
51 GetSyncUsernameIfSyncingPasswords(kTestCases[i].sync_service,
52 kTestCases[i].signin_manager));
56 TEST_F(PasswordSyncUtilTest, IsSyncAccountCredential) {
57 const struct {
58 PasswordForm form;
59 std::string fake_sync_username;
60 bool expected_result;
61 } kTestCases[] = {
62 {SimpleGaiaForm("sync_user@example.org"), "sync_user@example.org", true},
63 {SimpleGaiaForm("non_sync_user@example.org"), "sync_user@example.org",
64 false},
65 {SimpleNonGaiaForm("sync_user@example.org"), "sync_user@example.org",
66 false},
69 for (size_t i = 0; i < arraysize(kTestCases); ++i) {
70 SCOPED_TRACE(testing::Message() << "i=" << i);
71 SetSyncingPasswords(true);
72 FakeSigninAs(kTestCases[i].fake_sync_username);
73 EXPECT_EQ(kTestCases[i].expected_result,
74 IsSyncAccountCredential(kTestCases[i].form, sync_service(),
75 signin_manager()));
79 } // namespace sync_util
80 } // namespace password_manager