OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "components/sync/engine_impl/sync_manager_impl.h" | 5 #include "components/sync/engine_impl/sync_manager_impl.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
14 #include "base/format_macros.h" | 14 #include "base/format_macros.h" |
15 #include "base/location.h" | 15 #include "base/location.h" |
16 #include "base/metrics/field_trial.h" | 16 #include "base/metrics/field_trial.h" |
17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/test/scoped_feature_list.h" |
21 #include "base/test/values_test_util.h" | 22 #include "base/test/values_test_util.h" |
22 #include "base/values.h" | 23 #include "base/values.h" |
23 #include "components/sync/base/attachment_id_proto.h" | 24 #include "components/sync/base/attachment_id_proto.h" |
24 #include "components/sync/base/cancelation_signal.h" | 25 #include "components/sync/base/cancelation_signal.h" |
25 #include "components/sync/base/extensions_activity.h" | 26 #include "components/sync/base/extensions_activity.h" |
26 #include "components/sync/base/fake_encryptor.h" | 27 #include "components/sync/base/fake_encryptor.h" |
27 #include "components/sync/base/mock_unrecoverable_error_handler.h" | 28 #include "components/sync/base/mock_unrecoverable_error_handler.h" |
28 #include "components/sync/base/model_type_test_util.h" | 29 #include "components/sync/base/model_type_test_util.h" |
29 #include "components/sync/base/sync_features.h" | 30 #include "components/sync/base/sync_features.h" |
30 #include "components/sync/engine/engine_util.h" | 31 #include "components/sync/engine/engine_util.h" |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 ReadNode node(&trans); | 498 ReadNode node(&trans); |
498 EXPECT_EQ(BaseNode::INIT_OK, | 499 EXPECT_EQ(BaseNode::INIT_OK, |
499 node.InitByClientTagLookup(BOOKMARKS, "testtag")); | 500 node.InitByClientTagLookup(BOOKMARKS, "testtag")); |
500 EXPECT_EQ(node.GetTitle(), test_title); | 501 EXPECT_EQ(node.GetTitle(), test_title); |
501 EXPECT_EQ(node.GetModelType(), BOOKMARKS); | 502 EXPECT_EQ(node.GetModelType(), BOOKMARKS); |
502 } | 503 } |
503 } | 504 } |
504 | 505 |
505 TEST_F(SyncApiTest, WriteAndReadPassword) { | 506 TEST_F(SyncApiTest, WriteAndReadPassword) { |
506 KeyParams params = {"localhost", "username", "passphrase"}; | 507 KeyParams params = {"localhost", "username", "passphrase"}; |
507 base::FeatureList::ClearInstanceForTesting(); | |
508 EXPECT_FALSE(base::FeatureList::IsEnabled(kFillPasswordMetadata)); | 508 EXPECT_FALSE(base::FeatureList::IsEnabled(kFillPasswordMetadata)); |
509 | 509 |
510 { | 510 { |
511 ReadTransaction trans(FROM_HERE, user_share()); | 511 ReadTransaction trans(FROM_HERE, user_share()); |
512 trans.GetCryptographer()->AddKey(params); | 512 trans.GetCryptographer()->AddKey(params); |
513 } | 513 } |
514 | 514 |
515 { | 515 { |
516 WriteTransaction trans(FROM_HERE, user_share()); | 516 WriteTransaction trans(FROM_HERE, user_share()); |
517 ReadNode root_node(&trans); | 517 ReadNode root_node(&trans); |
(...skipping 24 matching lines...) Expand all Loading... |
542 } | 542 } |
543 } | 543 } |
544 | 544 |
545 TEST_F(SyncApiTest, WritePasswordAndCheckMetadata) { | 545 TEST_F(SyncApiTest, WritePasswordAndCheckMetadata) { |
546 KeyParams params = {"localhost", "username", "passphrase"}; | 546 KeyParams params = {"localhost", "username", "passphrase"}; |
547 { | 547 { |
548 ReadTransaction trans(FROM_HERE, user_share()); | 548 ReadTransaction trans(FROM_HERE, user_share()); |
549 trans.GetCryptographer()->AddKey(params); | 549 trans.GetCryptographer()->AddKey(params); |
550 } | 550 } |
551 | 551 |
552 base::FeatureList::ClearInstanceForTesting(); | |
553 base::FieldTrialList field_trial_list(nullptr); | 552 base::FieldTrialList field_trial_list(nullptr); |
554 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 553 base::test::ScopedFeatureList scoped_feature_list; |
555 feature_list->InitializeFromCommandLine(kFillPasswordMetadata.name, | 554 scoped_feature_list.InitAndEnableFeature(kFillPasswordMetadata); |
556 std::string()); | |
557 base::FeatureList::SetInstance(std::move(feature_list)); | |
558 | 555 |
559 EXPECT_TRUE(base::FeatureList::IsEnabled(kFillPasswordMetadata)); | 556 EXPECT_TRUE(base::FeatureList::IsEnabled(kFillPasswordMetadata)); |
560 { | 557 { |
561 WriteTransaction trans(FROM_HERE, user_share()); | 558 WriteTransaction trans(FROM_HERE, user_share()); |
562 ReadNode root_node(&trans); | 559 ReadNode root_node(&trans); |
563 root_node.InitByRootLookup(); | 560 root_node.InitByRootLookup(); |
564 | 561 |
565 WriteNode password_node(&trans); | 562 WriteNode password_node(&trans); |
566 WriteNode::InitUniqueByCreationResult result = | 563 WriteNode::InitUniqueByCreationResult result = |
567 password_node.InitUniqueByCreation(PASSWORDS, root_node, kClientTag); | 564 password_node.InitUniqueByCreation(PASSWORDS, root_node, kClientTag); |
(...skipping 1525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2093 const syncable::Entry* node_entry = node.GetEntry(); | 2090 const syncable::Entry* node_entry = node.GetEntry(); |
2094 EXPECT_TRUE(node_entry->GetIsUnsynced()); | 2091 EXPECT_TRUE(node_entry->GetIsUnsynced()); |
2095 } | 2092 } |
2096 } | 2093 } |
2097 | 2094 |
2098 // Passwords have their own handling for encryption. Verify setting a new | 2095 // Passwords have their own handling for encryption. Verify setting a new |
2099 // passphrase updates the data and clears the unencrypted metadta for passwords. | 2096 // passphrase updates the data and clears the unencrypted metadta for passwords. |
2100 TEST_F(SyncManagerTest, UpdatePasswordNewPassphrase) { | 2097 TEST_F(SyncManagerTest, UpdatePasswordNewPassphrase) { |
2101 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2098 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
2102 sync_pb::EntitySpecifics entity_specifics; | 2099 sync_pb::EntitySpecifics entity_specifics; |
2103 base::FeatureList::ClearInstanceForTesting(); | |
2104 base::FieldTrialList field_trial_list(nullptr); | 2100 base::FieldTrialList field_trial_list(nullptr); |
2105 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 2101 base::test::ScopedFeatureList scoped_feature_list; |
2106 feature_list->InitializeFromCommandLine(kFillPasswordMetadata.name, | 2102 scoped_feature_list.InitAndEnableFeature(kFillPasswordMetadata); |
2107 std::string()); | |
2108 base::FeatureList::SetInstance(std::move(feature_list)); | |
2109 { | 2103 { |
2110 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2104 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
2111 Cryptographer* cryptographer = trans.GetCryptographer(); | 2105 Cryptographer* cryptographer = trans.GetCryptographer(); |
2112 sync_pb::PasswordSpecificsData data; | 2106 sync_pb::PasswordSpecificsData data; |
2113 data.set_password_value(kPasswordValue); | 2107 data.set_password_value(kPasswordValue); |
2114 entity_specifics.mutable_password() | 2108 entity_specifics.mutable_password() |
2115 ->mutable_unencrypted_metadata() | 2109 ->mutable_unencrypted_metadata() |
2116 ->set_url(kUrl); | 2110 ->set_url(kUrl); |
2117 cryptographer->Encrypt( | 2111 cryptographer->Encrypt( |
2118 data, entity_specifics.mutable_password()->mutable_encrypted()); | 2112 data, entity_specifics.mutable_password()->mutable_encrypted()); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2174 EXPECT_EQ(kPasswordValue, data.password_value()); | 2168 EXPECT_EQ(kPasswordValue, data.password_value()); |
2175 EXPECT_FALSE(password_node.GetEntitySpecifics() | 2169 EXPECT_FALSE(password_node.GetEntitySpecifics() |
2176 .password() | 2170 .password() |
2177 .has_unencrypted_metadata()); | 2171 .has_unencrypted_metadata()); |
2178 } | 2172 } |
2179 } | 2173 } |
2180 | 2174 |
2181 // Passwords have their own handling for encryption. Verify it does not result | 2175 // Passwords have their own handling for encryption. Verify it does not result |
2182 // in unnecessary writes via ReencryptEverything. | 2176 // in unnecessary writes via ReencryptEverything. |
2183 TEST_F(SyncManagerTest, UpdatePasswordReencryptEverything) { | 2177 TEST_F(SyncManagerTest, UpdatePasswordReencryptEverything) { |
2184 base::FeatureList::ClearInstanceForTesting(); | |
2185 EXPECT_FALSE(base::FeatureList::IsEnabled(kFillPasswordMetadata)); | 2178 EXPECT_FALSE(base::FeatureList::IsEnabled(kFillPasswordMetadata)); |
2186 | 2179 |
2187 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2180 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
2188 sync_pb::EntitySpecifics entity_specifics; | 2181 sync_pb::EntitySpecifics entity_specifics; |
2189 { | 2182 { |
2190 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2183 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
2191 Cryptographer* cryptographer = trans.GetCryptographer(); | 2184 Cryptographer* cryptographer = trans.GetCryptographer(); |
2192 sync_pb::PasswordSpecificsData data; | 2185 sync_pb::PasswordSpecificsData data; |
2193 data.set_password_value("secret"); | 2186 data.set_password_value("secret"); |
2194 cryptographer->Encrypt( | 2187 cryptographer->Encrypt( |
(...skipping 12 matching lines...) Expand all Loading... |
2207 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false)); | 2200 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false)); |
2208 sync_manager_.GetEncryptionHandler()->Init(); | 2201 sync_manager_.GetEncryptionHandler()->Init(); |
2209 PumpLoop(); | 2202 PumpLoop(); |
2210 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, kClientTag)); | 2203 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, kClientTag)); |
2211 } | 2204 } |
2212 | 2205 |
2213 // Metadata filling can happen during ReencryptEverything, check that data is | 2206 // Metadata filling can happen during ReencryptEverything, check that data is |
2214 // written when it's applicable, namely that password specifics entity is marked | 2207 // written when it's applicable, namely that password specifics entity is marked |
2215 // unsynced, when data was written to the unencrypted metadata field. | 2208 // unsynced, when data was written to the unencrypted metadata field. |
2216 TEST_F(SyncManagerTest, UpdatePasswordReencryptEverythingFillMetadata) { | 2209 TEST_F(SyncManagerTest, UpdatePasswordReencryptEverythingFillMetadata) { |
2217 base::FeatureList::ClearInstanceForTesting(); | |
2218 base::FieldTrialList field_trial_list(nullptr); | 2210 base::FieldTrialList field_trial_list(nullptr); |
2219 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 2211 base::test::ScopedFeatureList scoped_feature_list; |
2220 feature_list->InitializeFromCommandLine(kFillPasswordMetadata.name, | 2212 scoped_feature_list.InitAndEnableFeature(kFillPasswordMetadata); |
2221 std::string()); | |
2222 base::FeatureList::SetInstance(std::move(feature_list)); | |
2223 EXPECT_TRUE(base::FeatureList::IsEnabled(kFillPasswordMetadata)); | 2213 EXPECT_TRUE(base::FeatureList::IsEnabled(kFillPasswordMetadata)); |
2224 | 2214 |
2225 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2215 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
2226 sync_pb::EntitySpecifics entity_specifics; | 2216 sync_pb::EntitySpecifics entity_specifics; |
2227 { | 2217 { |
2228 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2218 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
2229 Cryptographer* cryptographer = trans.GetCryptographer(); | 2219 Cryptographer* cryptographer = trans.GetCryptographer(); |
2230 sync_pb::PasswordSpecificsData data; | 2220 sync_pb::PasswordSpecificsData data; |
2231 data.set_password_value("secret"); | 2221 data.set_password_value("secret"); |
2232 data.set_signon_realm(kUrl); | 2222 data.set_signon_realm(kUrl); |
(...skipping 27 matching lines...) Expand all Loading... |
2260 .url()); | 2250 .url()); |
2261 } | 2251 } |
2262 | 2252 |
2263 EXPECT_TRUE(ResetUnsyncedEntry(PASSWORDS, kClientTag)); | 2253 EXPECT_TRUE(ResetUnsyncedEntry(PASSWORDS, kClientTag)); |
2264 } | 2254 } |
2265 | 2255 |
2266 // Check that when the data in PasswordSpecifics hasn't changed during | 2256 // Check that when the data in PasswordSpecifics hasn't changed during |
2267 // ReEncryption, entity is not marked as unsynced. | 2257 // ReEncryption, entity is not marked as unsynced. |
2268 TEST_F(SyncManagerTest, | 2258 TEST_F(SyncManagerTest, |
2269 UpdatePasswordReencryptEverythingDontMarkUnsyncWhenNotNeeded) { | 2259 UpdatePasswordReencryptEverythingDontMarkUnsyncWhenNotNeeded) { |
2270 base::FeatureList::ClearInstanceForTesting(); | |
2271 base::FieldTrialList field_trial_list(nullptr); | 2260 base::FieldTrialList field_trial_list(nullptr); |
2272 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 2261 base::test::ScopedFeatureList scoped_feature_list; |
2273 feature_list->InitializeFromCommandLine(kFillPasswordMetadata.name, | 2262 scoped_feature_list.InitAndEnableFeature(kFillPasswordMetadata); |
2274 std::string()); | |
2275 base::FeatureList::SetInstance(std::move(feature_list)); | |
2276 EXPECT_TRUE(base::FeatureList::IsEnabled(kFillPasswordMetadata)); | 2263 EXPECT_TRUE(base::FeatureList::IsEnabled(kFillPasswordMetadata)); |
2277 | 2264 |
2278 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2265 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
2279 sync_pb::EntitySpecifics entity_specifics; | 2266 sync_pb::EntitySpecifics entity_specifics; |
2280 { | 2267 { |
2281 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2268 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
2282 Cryptographer* cryptographer = trans.GetCryptographer(); | 2269 Cryptographer* cryptographer = trans.GetCryptographer(); |
2283 sync_pb::PasswordSpecificsData data; | 2270 sync_pb::PasswordSpecificsData data; |
2284 data.set_password_value("secret"); | 2271 data.set_password_value("secret"); |
2285 data.set_signon_realm(kUrl); | 2272 data.set_signon_realm(kUrl); |
(...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3536 // SyncManagerInitInvalidStorageTest::GetFactory will return | 3523 // SyncManagerInitInvalidStorageTest::GetFactory will return |
3537 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. | 3524 // DirectoryBackingStore that ensures that SyncManagerImpl::OpenDirectory fails. |
3538 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's | 3525 // SyncManagerImpl initialization is done in SyncManagerTest::SetUp. This test's |
3539 // task is to ensure that SyncManagerImpl reported initialization failure in | 3526 // task is to ensure that SyncManagerImpl reported initialization failure in |
3540 // OnInitializationComplete callback. | 3527 // OnInitializationComplete callback. |
3541 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { | 3528 TEST_F(SyncManagerInitInvalidStorageTest, FailToOpenDatabase) { |
3542 EXPECT_FALSE(initialization_succeeded_); | 3529 EXPECT_FALSE(initialization_succeeded_); |
3543 } | 3530 } |
3544 | 3531 |
3545 } // namespace syncer | 3532 } // namespace syncer |
OLD | NEW |