Index: chrome/browser/extensions/extension_sync_data_unittest.cc |
=================================================================== |
--- chrome/browser/extensions/extension_sync_data_unittest.cc (revision 97482) |
+++ chrome/browser/extensions/extension_sync_data_unittest.cc (working copy) |
@@ -6,86 +6,81 @@ |
#include "base/memory/scoped_ptr.h" |
#include "base/version.h" |
-#include "chrome/browser/sync/protocol/app_specifics.pb.h" |
-#include "chrome/browser/sync/protocol/extension_specifics.pb.h" |
#include "googleurl/src/gurl.h" |
#include "testing/gtest/include/gtest/gtest.h" |
namespace { |
-#if defined(OS_WIN) |
-const FilePath::CharType kExtensionFilePath[] = FILE_PATH_LITERAL("c:\\foo"); |
-#elif defined(OS_POSIX) |
-const FilePath::CharType kExtensionFilePath[] = FILE_PATH_LITERAL("/foo"); |
-#endif |
- |
-const char kValidId[] = "abcdefghijklmnopabcdefghijklmnop"; |
-const char kValidVersion[] = "0.0.0.0"; |
-const char kVersion1[] = "1.0.0.1"; |
-const char kVersion2[] = "1.0.1.0"; |
-const char kVersion3[] = "1.1.0.0"; |
-const char kValidUpdateUrl1[] = |
- "http://clients2.google.com/service/update2/crx"; |
-const char kValidUpdateUrl2[] = |
- "https://clients2.google.com/service/update2/crx"; |
-const char kName[] = "MyExtension"; |
-const char kName2[] = "MyExtension2"; |
- |
class ExtensionSyncDataTest : public testing::Test { |
}; |
-TEST_F(ExtensionSyncDataTest, SyncDataToExtensionSyncData) { |
- sync_pb::EntitySpecifics entity; |
- sync_pb::ExtensionSpecifics* extension_specifics = |
- entity.MutableExtension(sync_pb::extension); |
- extension_specifics->set_id(kValidId); |
- extension_specifics->set_update_url(kValidUpdateUrl2); |
- extension_specifics->set_enabled(false); |
- extension_specifics->set_incognito_enabled(true); |
- extension_specifics->set_version(kVersion1); |
- extension_specifics->set_name(kName); |
- SyncData sync_data = |
- SyncData::CreateLocalData("sync_tag", "non_unique_title", entity); |
+bool ExtensionSyncDataEqual(const ExtensionSyncData& a, |
+ const ExtensionSyncData& b) { |
+ return |
+ (a.id == b.id) && |
+ (a.enabled == b.enabled) && |
+ (a.incognito_enabled == b.incognito_enabled) && |
+ (a.version.Equals(b.version)) && |
+ (a.update_url == b.update_url) && |
+ (a.name == b.name); |
+} |
- ExtensionSyncData extension_sync_data(sync_data); |
- EXPECT_EQ(extension_specifics->id(), extension_sync_data.id()); |
- EXPECT_EQ(extension_specifics->version(), |
- extension_sync_data.version().GetString()); |
- EXPECT_EQ(extension_specifics->update_url(), |
- extension_sync_data.update_url().spec()); |
- EXPECT_EQ(extension_specifics->enabled(), extension_sync_data.enabled()); |
- EXPECT_EQ(extension_specifics->incognito_enabled(), |
- extension_sync_data.incognito_enabled()); |
- EXPECT_EQ(extension_specifics->name(), extension_sync_data.name()); |
- EXPECT_FALSE(extension_sync_data.uninstalled()); |
+TEST_F(ExtensionSyncDataTest, MergeOlder) { |
+ ExtensionSyncData data; |
+ data.id = "id"; |
+ data.enabled = true; |
+ data.incognito_enabled = false; |
+ { |
+ scoped_ptr<Version> version(Version::GetVersionFromString("1.2.0.0")); |
+ data.version = *version; |
+ } |
+ data.update_url = GURL("http://www.old.com"); |
+ data.name = "data"; |
+ |
+ ExtensionSyncData new_data; |
+ new_data.id = "id"; |
+ new_data.enabled = false; |
+ new_data.incognito_enabled = true; |
+ { |
+ scoped_ptr<Version> version(Version::GetVersionFromString("1.1.0.0")); |
+ new_data.version = *version; |
+ } |
+ new_data.update_url = GURL("http://www.new.com"); |
+ new_data.name = "new_data"; |
+ |
+ ExtensionSyncData expected_data = data; |
+ expected_data.enabled = new_data.enabled; |
+ expected_data.incognito_enabled = new_data.incognito_enabled; |
+ |
+ data.Merge(new_data); |
+ EXPECT_TRUE(ExtensionSyncDataEqual(data, expected_data)); |
} |
-TEST_F(ExtensionSyncDataTest, ExtensionSyncDataToSyncData) { |
- sync_pb::EntitySpecifics entity; |
- sync_pb::ExtensionSpecifics* input_extension = |
- entity.MutableExtension(sync_pb::extension); |
- input_extension->set_id(kValidId); |
- input_extension->set_update_url(kValidUpdateUrl2); |
- input_extension->set_enabled(true); |
- input_extension->set_incognito_enabled(false); |
- input_extension->set_version(kVersion1); |
- input_extension->set_name(kName); |
- SyncData sync_data = |
- SyncData::CreateLocalData("sync_tag", "non_unique_title", entity); |
- ExtensionSyncData extension_sync_data(sync_data); |
+TEST_F(ExtensionSyncDataTest, MergeNewer) { |
+ ExtensionSyncData data; |
+ data.id = "id"; |
+ data.enabled = true; |
+ data.incognito_enabled = false; |
+ { |
+ scoped_ptr<Version> version(Version::GetVersionFromString("1.2.0.0")); |
+ data.version = *version; |
+ } |
+ data.update_url = GURL("http://www.old.com"); |
+ data.name = "data"; |
- SyncData output_sync_data = extension_sync_data.GetSyncData(); |
- const sync_pb::ExtensionSpecifics& output_specifics = |
- output_sync_data.GetSpecifics().GetExtension(sync_pb::extension); |
- EXPECT_EQ(extension_sync_data.id(), output_specifics.id()); |
- EXPECT_EQ(extension_sync_data.update_url().spec(), |
- output_specifics.update_url()); |
- EXPECT_EQ(extension_sync_data.enabled(), output_specifics.enabled()); |
- EXPECT_EQ(extension_sync_data.incognito_enabled(), |
- output_specifics.incognito_enabled()); |
- EXPECT_EQ(extension_sync_data.version().GetString(), |
- output_specifics.version()); |
- EXPECT_EQ(extension_sync_data.name(), output_specifics.name()); |
+ ExtensionSyncData new_data; |
+ new_data.id = "id"; |
+ new_data.enabled = false; |
+ new_data.incognito_enabled = true; |
+ { |
+ scoped_ptr<Version> version(Version::GetVersionFromString("1.3.0.0")); |
+ new_data.version = *version; |
+ } |
+ new_data.update_url = GURL("http://www.new.com"); |
+ new_data.name = "new_data"; |
+ |
+ data.Merge(new_data); |
+ EXPECT_TRUE(ExtensionSyncDataEqual(data, new_data)); |
} |
} // namespace |