1 // Copyright (c) 2012 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 "chrome/browser/extensions/extension_sync_data.h"
7 #include "base/files/file_path.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/version.h"
10 #include "sync/protocol/extension_specifics.pb.h"
11 #include "sync/protocol/sync.pb.h"
12 #include "testing/gtest/include/gtest/gtest.h"
17 const char kValidId
[] = "abcdefghijklmnopabcdefghijklmnop";
18 const char kVersion
[] = "1.0.0.1";
19 const char kValidUpdateUrl
[] =
20 "https://clients2.google.com/service/update2/crx";
21 const char kName
[] = "MyExtension";
23 class ExtensionSyncDataTest
: public testing::Test
{
26 TEST_F(ExtensionSyncDataTest
, SyncDataToExtensionSyncDataForExtension
) {
27 sync_pb::EntitySpecifics entity
;
28 sync_pb::ExtensionSpecifics
* extension_specifics
= entity
.mutable_extension();
29 extension_specifics
->set_id(kValidId
);
30 extension_specifics
->set_update_url(kValidUpdateUrl
);
31 extension_specifics
->set_enabled(false);
32 extension_specifics
->set_incognito_enabled(true);
33 extension_specifics
->set_version(kVersion
);
34 extension_specifics
->set_name(kName
);
35 syncer::SyncData sync_data
=
36 syncer::SyncData::CreateLocalData("sync_tag", "non_unique_title", entity
);
38 extensions::ExtensionSyncData
extension_sync_data(sync_data
);
39 EXPECT_EQ(extension_specifics
->id(), extension_sync_data
.id());
40 EXPECT_EQ(extension_specifics
->version(),
41 extension_sync_data
.version().GetString());
42 EXPECT_EQ(extension_specifics
->update_url(),
43 extension_sync_data
.update_url().spec());
44 EXPECT_EQ(extension_specifics
->enabled(), extension_sync_data
.enabled());
45 EXPECT_EQ(extension_specifics
->incognito_enabled(),
46 extension_sync_data
.incognito_enabled());
47 EXPECT_EQ(extension_specifics
->name(), extension_sync_data
.name());
48 EXPECT_FALSE(extension_sync_data
.uninstalled());
51 TEST_F(ExtensionSyncDataTest
, ExtensionSyncDataToSyncDataForExtension
) {
52 sync_pb::EntitySpecifics entity
;
53 sync_pb::ExtensionSpecifics
* input_extension
= entity
.mutable_extension();
54 input_extension
->set_id(kValidId
);
55 input_extension
->set_update_url(kValidUpdateUrl
);
56 input_extension
->set_enabled(true);
57 input_extension
->set_incognito_enabled(false);
58 input_extension
->set_version(kVersion
);
59 input_extension
->set_name(kName
);
60 syncer::SyncData sync_data
=
61 syncer::SyncData::CreateLocalData("sync_tag", "non_unique_title", entity
);
62 extensions::ExtensionSyncData
extension_sync_data(sync_data
);
64 syncer::SyncData output_sync_data
= extension_sync_data
.GetSyncData();
65 const sync_pb::ExtensionSpecifics
& output_specifics
=
66 output_sync_data
.GetSpecifics().extension();
67 EXPECT_EQ(extension_sync_data
.id(), output_specifics
.id());
68 EXPECT_EQ(extension_sync_data
.update_url().spec(),
69 output_specifics
.update_url());
70 EXPECT_EQ(extension_sync_data
.enabled(), output_specifics
.enabled());
71 EXPECT_EQ(extension_sync_data
.incognito_enabled(),
72 output_specifics
.incognito_enabled());
73 EXPECT_EQ(extension_sync_data
.version().GetString(),
74 output_specifics
.version());
75 EXPECT_EQ(extension_sync_data
.name(), output_specifics
.name());