Add ENABLE_MEDIA_ROUTER define to builds other than Android and iOS.
[chromium-blink-merge.git] / chrome / browser / extensions / app_sync_data_unittest.cc
blob5b906210034cd4f16955710b7c090aa7b297a012
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 {
20 public:
21 AppSyncDataTest() {}
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_incognito_enabled(true);
31 extension_specifics->set_remote_install(false);
32 extension_specifics->set_all_urls_enabled(true);
33 extension_specifics->set_installed_by_custodian(false);
34 extension_specifics->set_name(kName);
38 TEST_F(AppSyncDataTest, SyncDataToExtensionSyncDataForApp) {
39 sync_pb::EntitySpecifics entity;
40 sync_pb::AppSpecifics* app_specifics = entity.mutable_app();
41 app_specifics->set_app_launch_ordinal(
42 syncer::StringOrdinal::CreateInitialOrdinal().ToInternalValue());
43 app_specifics->set_page_ordinal(
44 syncer::StringOrdinal::CreateInitialOrdinal().ToInternalValue());
46 SetRequiredExtensionValues(app_specifics->mutable_extension());
48 syncer::SyncData sync_data =
49 syncer::SyncData::CreateLocalData("sync_tag", "non_unique_title", entity);
51 scoped_ptr<AppSyncData> app_sync_data =
52 AppSyncData::CreateFromSyncData(sync_data);
53 ASSERT_TRUE(app_sync_data.get());
54 EXPECT_EQ(app_specifics->app_launch_ordinal(),
55 app_sync_data->app_launch_ordinal().ToInternalValue());
56 EXPECT_EQ(app_specifics->page_ordinal(),
57 app_sync_data->page_ordinal().ToInternalValue());
62 TEST_F(AppSyncDataTest, ExtensionSyncDataToSyncDataForApp) {
63 sync_pb::EntitySpecifics entity;
64 sync_pb::AppSpecifics* input_specifics = entity.mutable_app();
65 input_specifics->set_app_launch_ordinal(
66 syncer::StringOrdinal::CreateInitialOrdinal().ToInternalValue());
67 input_specifics->set_page_ordinal(
68 syncer::StringOrdinal::CreateInitialOrdinal().ToInternalValue());
70 SetRequiredExtensionValues(input_specifics->mutable_extension());
72 syncer::SyncData sync_data =
73 syncer::SyncData::CreateLocalData("sync_tag", "non_unique_title", entity);
74 scoped_ptr<AppSyncData> app_sync_data =
75 AppSyncData::CreateFromSyncData(sync_data);
76 ASSERT_TRUE(app_sync_data.get());
78 syncer::SyncData output_sync_data = app_sync_data->GetSyncData();
79 EXPECT_TRUE(sync_data.GetSpecifics().has_app());
80 const sync_pb::AppSpecifics& output_specifics =
81 output_sync_data.GetSpecifics().app();
82 EXPECT_EQ(input_specifics->SerializeAsString(),
83 output_specifics.SerializeAsString());
86 // Ensures that invalid StringOrdinals don't break ExtensionSyncData.
87 TEST_F(AppSyncDataTest, ExtensionSyncDataInvalidOrdinal) {
88 sync_pb::EntitySpecifics entity;
89 sync_pb::AppSpecifics* app_specifics = entity.mutable_app();
90 // Set the ordinals as invalid.
91 app_specifics->set_app_launch_ordinal("");
92 app_specifics->set_page_ordinal("");
94 SetRequiredExtensionValues(app_specifics->mutable_extension());
96 syncer::SyncData sync_data =
97 syncer::SyncData::CreateLocalData("sync_tag", "non_unique_title", entity);
99 // There should be no issue loading the sync data.
100 scoped_ptr<AppSyncData> app_sync_data =
101 AppSyncData::CreateFromSyncData(sync_data);
102 ASSERT_TRUE(app_sync_data.get());
103 app_sync_data->GetSyncData();
106 } // namespace extensions