OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/gdata/gdata_files.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_files.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
| 10 #include "chrome/browser/chromeos/gdata/gdata.pb.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 | 12 |
12 namespace gdata { | 13 namespace gdata { |
13 | 14 |
14 TEST(GDataRootDirectoryTest, RemoveTemporaryFilesFromCacheMap) { | 15 TEST(GDataRootDirectoryTest, RemoveTemporaryFilesFromCacheMap) { |
15 scoped_ptr<GDataRootDirectory> root(new GDataRootDirectory); | 16 scoped_ptr<GDataRootDirectory> root(new GDataRootDirectory); |
16 GDataRootDirectory::CacheMap cache_map; | 17 GDataRootDirectory::CacheMap cache_map; |
17 cache_map.insert(std::make_pair( | 18 cache_map.insert(std::make_pair( |
18 "<resource_id_1>", | 19 "<resource_id_1>", |
19 new GDataRootDirectory::CacheEntry( | 20 new GDataRootDirectory::CacheEntry( |
(...skipping 21 matching lines...) Expand all Loading... |
41 root->SetCacheMap(cache_map); | 42 root->SetCacheMap(cache_map); |
42 root->RemoveTemporaryFilesFromCacheMap(); | 43 root->RemoveTemporaryFilesFromCacheMap(); |
43 // resource 1 and 4 should be gone, as these are CACHE_TYPE_TMP. | 44 // resource 1 and 4 should be gone, as these are CACHE_TYPE_TMP. |
44 ASSERT_TRUE(root->GetCacheEntry("<resource_id_1>", "") == NULL); | 45 ASSERT_TRUE(root->GetCacheEntry("<resource_id_1>", "") == NULL); |
45 ASSERT_TRUE(root->GetCacheEntry("<resource_id_2>", "") != NULL); | 46 ASSERT_TRUE(root->GetCacheEntry("<resource_id_2>", "") != NULL); |
46 ASSERT_TRUE(root->GetCacheEntry("<resource_id_3>", "") != NULL); | 47 ASSERT_TRUE(root->GetCacheEntry("<resource_id_3>", "") != NULL); |
47 ASSERT_TRUE(root->GetCacheEntry("<resource_id_4>", "") == NULL); | 48 ASSERT_TRUE(root->GetCacheEntry("<resource_id_4>", "") == NULL); |
48 | 49 |
49 } | 50 } |
50 | 51 |
| 52 TEST(GDataRootDirectoryTest, ParseFromString_DetectBadTitle) { |
| 53 GDataRootDirectoryProto proto; |
| 54 GDataEntryProto* mutable_entry = |
| 55 proto.mutable_gdata_directory()->mutable_gdata_entry(); |
| 56 mutable_entry->mutable_file_info()->set_is_directory(true); |
| 57 |
| 58 std::string serialized_proto; |
| 59 ASSERT_TRUE(proto.SerializeToString(&serialized_proto)); |
| 60 |
| 61 GDataRootDirectory root; |
| 62 // This should fail as the title is empty. |
| 63 // root.title() should be unchanged. |
| 64 ASSERT_FALSE(root.ParseFromString(serialized_proto)); |
| 65 ASSERT_EQ("drive", root.title()); |
| 66 |
| 67 // Setting the title to "gdata". |
| 68 mutable_entry->set_title("gdata"); |
| 69 ASSERT_TRUE(proto.SerializeToString(&serialized_proto)); |
| 70 |
| 71 // This should fail as the title is not "drive". |
| 72 // root.title() should be unchanged. |
| 73 ASSERT_FALSE(root.ParseFromString(serialized_proto)); |
| 74 ASSERT_EQ("drive", root.title()); |
| 75 |
| 76 // Setting the title to "drive". |
| 77 mutable_entry->set_title("drive"); |
| 78 ASSERT_TRUE(proto.SerializeToString(&serialized_proto)); |
| 79 |
| 80 // This should succeed as the title is "drive". |
| 81 ASSERT_TRUE(root.ParseFromString(serialized_proto)); |
| 82 ASSERT_EQ("drive", root.title()); |
| 83 } |
| 84 |
51 } // namespace gdata | 85 } // namespace gdata |
OLD | NEW |