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_name(kName
);
35 TEST_F(AppSyncDataTest
, SyncDataToExtensionSyncDataForApp
) {
36 sync_pb::EntitySpecifics entity
;
37 sync_pb::AppSpecifics
* app_specifics
= entity
.mutable_app();
38 app_specifics
->set_app_launch_ordinal(
39 syncer::StringOrdinal::CreateInitialOrdinal().ToInternalValue());
40 app_specifics
->set_page_ordinal(
41 syncer::StringOrdinal::CreateInitialOrdinal().ToInternalValue());
43 SetRequiredExtensionValues(app_specifics
->mutable_extension());
45 syncer::SyncData sync_data
=
46 syncer::SyncData::CreateLocalData("sync_tag", "non_unique_title", entity
);
48 AppSyncData
app_sync_data(sync_data
);
49 EXPECT_EQ(app_specifics
->app_launch_ordinal(),
50 app_sync_data
.app_launch_ordinal().ToInternalValue());
51 EXPECT_EQ(app_specifics
->page_ordinal(),
52 app_sync_data
.page_ordinal().ToInternalValue());
57 TEST_F(AppSyncDataTest
, ExtensionSyncDataToSyncDataForApp
) {
58 sync_pb::EntitySpecifics entity
;
59 sync_pb::AppSpecifics
* input_specifics
= entity
.mutable_app();
60 input_specifics
->set_app_launch_ordinal(
61 syncer::StringOrdinal::CreateInitialOrdinal().ToInternalValue());
62 input_specifics
->set_page_ordinal(
63 syncer::StringOrdinal::CreateInitialOrdinal().ToInternalValue());
65 SetRequiredExtensionValues(input_specifics
->mutable_extension());
67 syncer::SyncData sync_data
=
68 syncer::SyncData::CreateLocalData("sync_tag", "non_unique_title", entity
);
69 AppSyncData
app_sync_data(sync_data
);
71 syncer::SyncData output_sync_data
= app_sync_data
.GetSyncData();
72 EXPECT_TRUE(sync_data
.GetSpecifics().has_app());
73 const sync_pb::AppSpecifics
& output_specifics
=
74 output_sync_data
.GetSpecifics().app();
75 EXPECT_EQ(input_specifics
->SerializeAsString(),
76 output_specifics
.SerializeAsString());
79 // Ensures that invalid StringOrdinals don't break ExtensionSyncData.
80 TEST_F(AppSyncDataTest
, ExtensionSyncDataInvalidOrdinal
) {
81 sync_pb::EntitySpecifics entity
;
82 sync_pb::AppSpecifics
* app_specifics
= entity
.mutable_app();
83 // Set the ordinals as invalid.
84 app_specifics
->set_app_launch_ordinal("");
85 app_specifics
->set_page_ordinal("");
87 SetRequiredExtensionValues(app_specifics
->mutable_extension());
89 syncer::SyncData sync_data
=
90 syncer::SyncData::CreateLocalData("sync_tag", "non_unique_title", entity
);
92 // There should be no issue loading the sync data.
93 AppSyncData
app_sync_data(sync_data
);
94 app_sync_data
.GetSyncData();
97 } // namespace extensions