1 // Copyright 2014 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 "base/files/file_path.h"
6 #include "base/json/json_reader.h"
7 #include "chrome/browser/local_discovery/storage/privet_filesystem_attribute_cache.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace local_discovery
{
14 const char kPrivetStorageJSON
[] =
19 " { \"name\": \"bar\", \"type\": \"dir\" },"
20 " { \"name\": \"baz.txt\", \"type\": \"file\", \"size\": 12345 }"
23 class PrivetFileSystemAttributeCacheTest
: public ::testing::Test
{
25 PrivetFileSystemAttributeCacheTest() {}
27 virtual ~PrivetFileSystemAttributeCacheTest() {}
29 PrivetFileSystemAttributeCache cache_
;
32 TEST_F(PrivetFileSystemAttributeCacheTest
, AllAdded
) {
33 scoped_ptr
<base::Value
> json(base::JSONReader::Read(kPrivetStorageJSON
));
34 const base::DictionaryValue
* dictionary_json
;
35 json
->GetAsDictionary(&dictionary_json
);
37 cache_
.AddFileInfoFromJSON(
38 base::FilePath(FILE_PATH_LITERAL("/test/path/foo")), dictionary_json
);
40 const base::File::Info
* info_foo
=
41 cache_
.GetFileInfo(base::FilePath(FILE_PATH_LITERAL("/test/path/foo")));
42 EXPECT_TRUE(info_foo
->is_directory
);
43 EXPECT_FALSE(info_foo
->is_symbolic_link
);
45 const base::File::Info
* info_bar
= cache_
.GetFileInfo(
46 base::FilePath(FILE_PATH_LITERAL("/test/path/foo/bar")));
47 EXPECT_TRUE(info_bar
->is_directory
);
48 EXPECT_FALSE(info_bar
->is_symbolic_link
);
50 const base::File::Info
* info_baz
= cache_
.GetFileInfo(
51 base::FilePath(FILE_PATH_LITERAL("/test/path/foo/baz.txt")));
52 EXPECT_FALSE(info_baz
->is_directory
);
53 EXPECT_FALSE(info_baz
->is_symbolic_link
);
54 EXPECT_EQ(12345, info_baz
->size
);
56 const base::File::Info
* info_notfound
= cache_
.GetFileInfo(
57 base::FilePath(FILE_PATH_LITERAL("/test/path/foo/notfound.txt")));
58 EXPECT_EQ(NULL
, info_notfound
);
63 } // namespace local_discovery