1 // Copyright (c) 2010 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. 4 5 #include "chrome/browser/sync/glue/extension_data.h" 6 7 #include "chrome/browser/sync/glue/extension_util.h" 8 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" 9 #include "testing/gtest/include/gtest/gtest.h" 10 11 namespace browser_sync { 12 13 namespace { 14 15 class ExtensionDataTest : public testing::Test { 16 }; 17 18 const char kValidId[] = "abcdefghijklmnopabcdefghijklmnop"; 19 const char kValidUpdateUrl1[] = "http://www.google.com"; 20 const char kValidUpdateUrl2[] = "http://www.bing.com"; 21 const char kValidVersion1[] = "1.0.0.0"; 22 const char kValidVersion2[] = "1.1.0.0"; 23 24 TEST_F(ExtensionDataTest, FromData) { 25 sync_pb::ExtensionSpecifics client_data; 26 client_data.set_id(kValidId); 27 client_data.set_update_url(kValidUpdateUrl1); 28 client_data.set_version(kValidVersion1); 29 ExtensionData extension_data = 30 ExtensionData::FromData(ExtensionData::CLIENT, client_data); 31 EXPECT_FALSE(extension_data.NeedsUpdate(ExtensionData::CLIENT)); 32 EXPECT_TRUE(extension_data.NeedsUpdate(ExtensionData::SERVER)); 33 EXPECT_TRUE(AreExtensionSpecificsEqual( 34 client_data, extension_data.merged_data())); 35 } 36 37 TEST_F(ExtensionDataTest, SetData) { 38 sync_pb::ExtensionSpecifics client_data; 39 client_data.set_id(kValidId); 40 client_data.set_update_url(kValidUpdateUrl1); 41 client_data.set_version(kValidVersion1); 42 ExtensionData extension_data = 43 ExtensionData::FromData(ExtensionData::CLIENT, client_data); 44 45 { 46 sync_pb::ExtensionSpecifics server_data; 47 server_data.set_id(kValidId); 48 server_data.set_update_url(kValidUpdateUrl2); 49 server_data.set_version(kValidVersion2); 50 server_data.set_enabled(true); 51 extension_data.SetData(ExtensionData::SERVER, false, server_data); 52 EXPECT_TRUE(extension_data.NeedsUpdate(ExtensionData::CLIENT)); 53 EXPECT_TRUE(extension_data.NeedsUpdate(ExtensionData::SERVER)); 54 } 55 56 { 57 sync_pb::ExtensionSpecifics server_data; 58 server_data.set_id(kValidId); 59 server_data.set_update_url(kValidUpdateUrl2); 60 server_data.set_version(kValidVersion2); 61 server_data.set_enabled(true); 62 extension_data.SetData(ExtensionData::SERVER, true, server_data); 63 EXPECT_TRUE(extension_data.NeedsUpdate(ExtensionData::CLIENT)); 64 EXPECT_FALSE(extension_data.NeedsUpdate(ExtensionData::SERVER)); 65 EXPECT_TRUE(AreExtensionSpecificsEqual( 66 server_data, extension_data.merged_data())); 67 } 68 } 69 70 TEST_F(ExtensionDataTest, ResolveData) { 71 sync_pb::ExtensionSpecifics client_data; 72 client_data.set_id(kValidId); 73 client_data.set_update_url(kValidUpdateUrl1); 74 client_data.set_version(kValidVersion1); 75 ExtensionData extension_data = 76 ExtensionData::FromData(ExtensionData::CLIENT, client_data); 77 78 sync_pb::ExtensionSpecifics server_data; 79 server_data.set_id(kValidId); 80 server_data.set_update_url(kValidUpdateUrl2); 81 server_data.set_version(kValidVersion2); 82 extension_data.SetData(ExtensionData::SERVER, true, server_data); 83 84 extension_data.ResolveData(ExtensionData::CLIENT); 85 EXPECT_FALSE(extension_data.NeedsUpdate(ExtensionData::CLIENT)); 86 EXPECT_FALSE(extension_data.NeedsUpdate(ExtensionData::SERVER)); 87 EXPECT_TRUE(AreExtensionSpecificsEqual( 88 server_data, extension_data.merged_data())); 89 } 90 91 } // namespace 92 93 } // namespace browser_sync 94