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 ~AppSyncDataTest() override
{}
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_disable_reasons(0);
31 extension_specifics
->set_incognito_enabled(true);
32 extension_specifics
->set_remote_install(false);
33 extension_specifics
->set_all_urls_enabled(true);
34 extension_specifics
->set_installed_by_custodian(false);
35 extension_specifics
->set_name(kName
);
39 TEST_F(AppSyncDataTest
, SyncDataToExtensionSyncDataForApp
) {
40 sync_pb::EntitySpecifics entity
;
41 sync_pb::AppSpecifics
* app_specifics
= entity
.mutable_app();
42 app_specifics
->set_app_launch_ordinal(
43 syncer::StringOrdinal::CreateInitialOrdinal().ToInternalValue());
44 app_specifics
->set_page_ordinal(
45 syncer::StringOrdinal::CreateInitialOrdinal().ToInternalValue());
47 SetRequiredExtensionValues(app_specifics
->mutable_extension());
49 syncer::SyncData sync_data
=
50 syncer::SyncData::CreateLocalData("sync_tag", "non_unique_title", entity
);
52 scoped_ptr
<AppSyncData
> app_sync_data
=
53 AppSyncData::CreateFromSyncData(sync_data
);
54 ASSERT_TRUE(app_sync_data
.get());
55 EXPECT_EQ(app_specifics
->app_launch_ordinal(),
56 app_sync_data
->app_launch_ordinal().ToInternalValue());
57 EXPECT_EQ(app_specifics
->page_ordinal(),
58 app_sync_data
->page_ordinal().ToInternalValue());
63 TEST_F(AppSyncDataTest
, ExtensionSyncDataToSyncDataForApp
) {
64 sync_pb::EntitySpecifics entity
;
65 sync_pb::AppSpecifics
* input_specifics
= entity
.mutable_app();
66 input_specifics
->set_app_launch_ordinal(
67 syncer::StringOrdinal::CreateInitialOrdinal().ToInternalValue());
68 input_specifics
->set_page_ordinal(
69 syncer::StringOrdinal::CreateInitialOrdinal().ToInternalValue());
71 SetRequiredExtensionValues(input_specifics
->mutable_extension());
73 syncer::SyncData sync_data
=
74 syncer::SyncData::CreateLocalData("sync_tag", "non_unique_title", entity
);
75 scoped_ptr
<AppSyncData
> app_sync_data
=
76 AppSyncData::CreateFromSyncData(sync_data
);
77 ASSERT_TRUE(app_sync_data
.get());
79 syncer::SyncData output_sync_data
= app_sync_data
->GetSyncData();
80 EXPECT_TRUE(sync_data
.GetSpecifics().has_app());
81 const sync_pb::AppSpecifics
& output_specifics
=
82 output_sync_data
.GetSpecifics().app();
83 EXPECT_EQ(input_specifics
->SerializeAsString(),
84 output_specifics
.SerializeAsString());
87 // Ensures that invalid StringOrdinals don't break ExtensionSyncData.
88 TEST_F(AppSyncDataTest
, ExtensionSyncDataInvalidOrdinal
) {
89 sync_pb::EntitySpecifics entity
;
90 sync_pb::AppSpecifics
* app_specifics
= entity
.mutable_app();
91 // Set the ordinals as invalid.
92 app_specifics
->set_app_launch_ordinal("");
93 app_specifics
->set_page_ordinal("");
95 SetRequiredExtensionValues(app_specifics
->mutable_extension());
97 syncer::SyncData sync_data
=
98 syncer::SyncData::CreateLocalData("sync_tag", "non_unique_title", entity
);
100 // There should be no issue loading the sync data.
101 scoped_ptr
<AppSyncData
> app_sync_data
=
102 AppSyncData::CreateFromSyncData(sync_data
);
103 ASSERT_TRUE(app_sync_data
.get());
104 app_sync_data
->GetSyncData();
107 } // namespace extensions