1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/sync/glue/extension_data.h"
#include "chrome/browser/sync/glue/extension_util.h"
#include "chrome/browser/sync/protocol/extension_specifics.pb.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace browser_sync {
namespace {
class ExtensionDataTest : public testing::Test {
};
const char kValidId[] = "abcdefghijklmnopabcdefghijklmnop";
const char kValidUpdateUrl1[] = "http://www.google.com";
const char kValidUpdateUrl2[] = "http://www.bing.com";
const char kValidVersion1[] = "1.0.0.0";
const char kValidVersion2[] = "1.1.0.0";
TEST_F(ExtensionDataTest, FromData) {
sync_pb::ExtensionSpecifics client_data;
client_data.set_id(kValidId);
client_data.set_update_url(kValidUpdateUrl1);
client_data.set_version(kValidVersion1);
ExtensionData extension_data =
ExtensionData::FromData(ExtensionData::CLIENT, client_data);
EXPECT_FALSE(extension_data.NeedsUpdate(ExtensionData::CLIENT));
EXPECT_TRUE(extension_data.NeedsUpdate(ExtensionData::SERVER));
EXPECT_TRUE(AreExtensionSpecificsEqual(
client_data, extension_data.merged_data()));
}
TEST_F(ExtensionDataTest, SetData) {
sync_pb::ExtensionSpecifics client_data;
client_data.set_id(kValidId);
client_data.set_update_url(kValidUpdateUrl1);
client_data.set_version(kValidVersion1);
ExtensionData extension_data =
ExtensionData::FromData(ExtensionData::CLIENT, client_data);
{
sync_pb::ExtensionSpecifics server_data;
server_data.set_id(kValidId);
server_data.set_update_url(kValidUpdateUrl2);
server_data.set_version(kValidVersion2);
server_data.set_enabled(true);
extension_data.SetData(ExtensionData::SERVER, false, server_data);
EXPECT_TRUE(extension_data.NeedsUpdate(ExtensionData::CLIENT));
EXPECT_TRUE(extension_data.NeedsUpdate(ExtensionData::SERVER));
}
{
sync_pb::ExtensionSpecifics server_data;
server_data.set_id(kValidId);
server_data.set_update_url(kValidUpdateUrl2);
server_data.set_version(kValidVersion2);
server_data.set_enabled(true);
extension_data.SetData(ExtensionData::SERVER, true, server_data);
EXPECT_TRUE(extension_data.NeedsUpdate(ExtensionData::CLIENT));
EXPECT_FALSE(extension_data.NeedsUpdate(ExtensionData::SERVER));
EXPECT_TRUE(AreExtensionSpecificsEqual(
server_data, extension_data.merged_data()));
}
}
TEST_F(ExtensionDataTest, ResolveData) {
sync_pb::ExtensionSpecifics client_data;
client_data.set_id(kValidId);
client_data.set_update_url(kValidUpdateUrl1);
client_data.set_version(kValidVersion1);
ExtensionData extension_data =
ExtensionData::FromData(ExtensionData::CLIENT, client_data);
sync_pb::ExtensionSpecifics server_data;
server_data.set_id(kValidId);
server_data.set_update_url(kValidUpdateUrl2);
server_data.set_version(kValidVersion2);
extension_data.SetData(ExtensionData::SERVER, true, server_data);
extension_data.ResolveData(ExtensionData::CLIENT);
EXPECT_FALSE(extension_data.NeedsUpdate(ExtensionData::CLIENT));
EXPECT_FALSE(extension_data.NeedsUpdate(ExtensionData::SERVER));
EXPECT_TRUE(AreExtensionSpecificsEqual(
server_data, extension_data.merged_data()));
}
} // namespace
} // namespace browser_sync
|