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/app_sync_data.h"
7 #include "sync/api/string_ordinal.h"
8 #include "sync/protocol/app_specifics.pb.h"
9 #include "sync/protocol/sync.pb.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace extensions
{
14 const char kValidId
[] = "abcdefghijklmnopabcdefghijklmnop";
15 const char kName
[] = "MyExtension";
16 const char kValidVersion
[] = "0.0.0.0";
17 const char kValidUpdateUrl
[] = "http://clients2.google.com/service/update2/crx";
19 class AppSyncDataTest
: public testing::Test
{
22 virtual ~AppSyncDataTest() {}
24 void SetRequiredExtensionValues(
25 sync_pb::ExtensionSpecifics
* extension_specifics
) {
26 extension_specifics
->set_id(kValidId
);
27 extension_specifics
->set_update_url(kValidUpdateUrl
);
28 extension_specifics
->set_version(kValidVersion
);
29 extension_specifics
->set_enabled(false);
30 extension_specifics
->set_incognito_enabled(true);
31 extension_specifics
->set_remote_install(false);
32 extension_specifics
->set_installed_by_custodian(false);
33 extension_specifics
->set_name(kName
);
37 TEST_F(AppSyncDataTest
, SyncDataToExtensionSyncDataForApp
) {
38 sync_pb::EntitySpecifics entity
;
39 sync_pb::AppSpecifics
* app_specifics
= entity
.mutable_app();
40 app_specifics
->set_app_launch_ordinal(
41 syncer::StringOrdinal::CreateInitialOrdinal().ToInternalValue());
42 app_specifics
->set_page_ordinal(
43 syncer::StringOrdinal::CreateInitialOrdinal().ToInternalValue());
45 SetRequiredExtensionValues(app_specifics
->mutable_extension());
47 syncer::SyncData sync_data
=
48 syncer::SyncData::CreateLocalData("sync_tag", "non_unique_title", entity
);
50 AppSyncData
app_sync_data(sync_data
);
51 EXPECT_EQ(app_specifics
->app_launch_ordinal(),
52 app_sync_data
.app_launch_ordinal().ToInternalValue());
53 EXPECT_EQ(app_specifics
->page_ordinal(),
54 app_sync_data
.page_ordinal().ToInternalValue());
59 TEST_F(AppSyncDataTest
, ExtensionSyncDataToSyncDataForApp
) {
60 sync_pb::EntitySpecifics entity
;
61 sync_pb::AppSpecifics
* input_specifics
= entity
.mutable_app();
62 input_specifics
->set_app_launch_ordinal(
63 syncer::StringOrdinal::CreateInitialOrdinal().ToInternalValue());
64 input_specifics
->set_page_ordinal(
65 syncer::StringOrdinal::CreateInitialOrdinal().ToInternalValue());
67 SetRequiredExtensionValues(input_specifics
->mutable_extension());
69 syncer::SyncData sync_data
=
70 syncer::SyncData::CreateLocalData("sync_tag", "non_unique_title", entity
);
71 AppSyncData
app_sync_data(sync_data
);
73 syncer::SyncData output_sync_data
= app_sync_data
.GetSyncData();
74 EXPECT_TRUE(sync_data
.GetSpecifics().has_app());
75 const sync_pb::AppSpecifics
& output_specifics
=
76 output_sync_data
.GetSpecifics().app();
77 EXPECT_EQ(input_specifics
->SerializeAsString(),
78 output_specifics
.SerializeAsString());
81 // Ensures that invalid StringOrdinals don't break ExtensionSyncData.
82 TEST_F(AppSyncDataTest
, ExtensionSyncDataInvalidOrdinal
) {
83 sync_pb::EntitySpecifics entity
;
84 sync_pb::AppSpecifics
* app_specifics
= entity
.mutable_app();
85 // Set the ordinals as invalid.
86 app_specifics
->set_app_launch_ordinal("");
87 app_specifics
->set_page_ordinal("");
89 SetRequiredExtensionValues(app_specifics
->mutable_extension());
91 syncer::SyncData sync_data
=
92 syncer::SyncData::CreateLocalData("sync_tag", "non_unique_title", entity
);
94 // There should be no issue loading the sync data.
95 AppSyncData
app_sync_data(sync_data
);
96 app_sync_data
.GetSyncData();
99 } // namespace extensions