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

Unified Diff: components/autofill/core/browser/webdata/autocomplete_sync_bridge_unittest.cc

Issue 2598113002: [Sync] Use a proto to generate AutofillSyncStorageKey's storage keys. (Closed)
Patch Set: Created 4 years 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: components/autofill/core/browser/webdata/autocomplete_sync_bridge_unittest.cc
diff --git a/components/autofill/core/browser/webdata/autocomplete_sync_bridge_unittest.cc b/components/autofill/core/browser/webdata/autocomplete_sync_bridge_unittest.cc
index b9e257638d98b20251f045ada395bb1f4202dc68..0d22b909e15b56dbd4f15b48e2df2f3317834cb9 100644
--- a/components/autofill/core/browser/webdata/autocomplete_sync_bridge_unittest.cc
+++ b/components/autofill/core/browser/webdata/autocomplete_sync_bridge_unittest.cc
@@ -4,7 +4,8 @@
#include "components/autofill/core/browser/webdata/autocomplete_sync_bridge.h"
-#include <memory>
+#include <map>
+#include <vector>
#include "base/bind.h"
#include "base/files/scoped_temp_dir.h"
@@ -25,6 +26,9 @@
#include "testing/gtest/include/gtest/gtest.h"
using sync_pb::AutofillSpecifics;
+using sync_pb::EntitySpecifics;
+using syncer::EntityDataPtr;
+using syncer::EntityData;
using syncer::SyncError;
namespace autofill {
@@ -74,6 +78,14 @@ AutofillEntry CreateAutofillEntry(
return AutofillEntry(key, date_created, date_last_used);
}
+// Creates an EntityData/EntityDataPtr around a copy of the given specifics.
+EntityDataPtr SpecificsToEntity(const AutofillSpecifics& specifics) {
+ EntityData data;
+ data.client_tag_hash = "ignored";
+ *data.specifics.mutable_autofill() = specifics;
+ return data.PassToPtr();
+}
+
class FakeAutofillBackend : public AutofillWebDataBackend {
public:
FakeAutofillBackend() {}
@@ -129,8 +141,7 @@ class AutocompleteSyncBridgeTest : public testing::Test {
}
std::string GetStorageKey(const AutofillSpecifics& specifics) {
- return net::EscapePath(specifics.name()) + "|" +
- net::EscapePath(specifics.value());
+ return bridge()->GetStorageKey(SpecificsToEntity(specifics).value());
}
private:
@@ -144,6 +155,57 @@ class AutocompleteSyncBridgeTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(AutocompleteSyncBridgeTest);
};
+TEST_F(AutocompleteSyncBridgeTest, GetClientTag) {
+ // TODO(skym, crbug.com/675991): Implementation.
+}
+
+TEST_F(AutocompleteSyncBridgeTest, GetStorageKeyRelative) {
+ AutofillSpecifics specifics1 = CreateSpecifics(1);
+ AutofillSpecifics specifics2 = CreateSpecifics(2);
+ std::string key_1_no_time = GetStorageKey(specifics1);
+ std::string key_2_no_time = GetStorageKey(specifics2);
+
+ specifics1.add_usage_timestamp(123);
+ specifics1.add_usage_timestamp(1234);
+ specifics1.add_usage_timestamp(12345);
+ specifics2.add_usage_timestamp(-12345);
+ std::string key_1_with_time = GetStorageKey(specifics1);
+ std::string key_2_with_time = GetStorageKey(specifics2);
+
+ std::string key_empty =
+ bridge()->GetStorageKey(SpecificsToEntity(AutofillSpecifics()).value());
+
+ EXPECT_FALSE(key_1_no_time.empty());
+ EXPECT_FALSE(key_1_with_time.empty());
+ EXPECT_FALSE(key_2_no_time.empty());
+ EXPECT_FALSE(key_2_with_time.empty());
+ EXPECT_FALSE(key_empty.empty());
+
+ // Timestamps should not affect storage keys.
+ EXPECT_EQ(key_1_no_time, key_1_with_time);
+ EXPECT_EQ(key_2_no_time, key_2_with_time);
+
+ EXPECT_NE(key_1_no_time, key_2_no_time);
+ EXPECT_NE(key_1_no_time, key_empty);
+ EXPECT_NE(key_2_no_time, key_empty);
+}
+
+// The storage key should never accidentally change for existing data. This
+// would cause lookups to fail and either lose or duplicate user data. It should
+// be possible for the model type to migrate storage key formats, but doing so
+// would need to be done very carefully.
+TEST_F(AutocompleteSyncBridgeTest, GetStorageKeyFixed) {
+ EXPECT_EQ("\n\x6name 1\x12\avalue 1", GetStorageKey(CreateSpecifics(1)));
+ EXPECT_EQ("\n\x6name 2\x12\avalue 2", GetStorageKey(CreateSpecifics(2)));
+ // This literal contains the null terminating character, which causes
+ // std::string to stop copying early if we don't tell it how much to read.
+ EXPECT_EQ(std::string("\n\0\x12\0", 4), GetStorageKey(AutofillSpecifics()));
+ AutofillSpecifics specifics;
+ specifics.set_name("\xEC\xA4\x91");
+ specifics.set_value("\xD0\x80");
+ EXPECT_EQ("\n\x3\xEC\xA4\x91\x12\x2\xD0\x80", GetStorageKey(specifics));
+}
+
TEST_F(AutocompleteSyncBridgeTest, GetData) {
const AutofillSpecifics specifics1 = CreateSpecifics(1);
const AutofillSpecifics specifics2 = CreateSpecifics(2);

Powered by Google App Engine
This is Rietveld 408576698