OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/callback.h" | 5 #include "base/callback.h" |
6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "chrome/browser/chrome_thread.h" | 10 #include "chrome/browser/chrome_thread.h" |
11 #include "chrome/browser/extensions/file_reader.h" | 11 #include "chrome/browser/extensions/file_reader.h" |
12 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
| 13 #include "chrome/common/extensions/extension.h" |
13 #include "chrome/common/extensions/extension_resource.h" | 14 #include "chrome/common/extensions/extension_resource.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 class FileReaderTest : public testing::Test { | 19 class FileReaderTest : public testing::Test { |
19 public: | 20 public: |
20 FileReaderTest() : file_thread_(ChromeThread::FILE) { | 21 FileReaderTest() : file_thread_(ChromeThread::FILE) { |
21 file_thread_.Start(); | 22 file_thread_.Start(); |
22 } | 23 } |
(...skipping 21 matching lines...) Expand all Loading... |
44 MessageLoop::current()->Quit(); | 45 MessageLoop::current()->Quit(); |
45 } | 46 } |
46 | 47 |
47 bool succeeded_; | 48 bool succeeded_; |
48 std::string data_; | 49 std::string data_; |
49 }; | 50 }; |
50 | 51 |
51 void RunBasicTest(const char* filename) { | 52 void RunBasicTest(const char* filename) { |
52 FilePath path; | 53 FilePath path; |
53 PathService::Get(chrome::DIR_TEST_DATA, &path); | 54 PathService::Get(chrome::DIR_TEST_DATA, &path); |
54 ExtensionResource resource(path, FilePath().AppendASCII(filename)); | 55 std::string extension_id; |
| 56 Extension::GenerateId("test", &extension_id); |
| 57 ExtensionResource resource(extension_id, path, |
| 58 FilePath().AppendASCII(filename)); |
55 path = path.AppendASCII(filename); | 59 path = path.AppendASCII(filename); |
56 | 60 |
57 std::string file_contents; | 61 std::string file_contents; |
58 bool file_exists = file_util::ReadFileToString(path, &file_contents); | 62 bool file_exists = file_util::ReadFileToString(path, &file_contents); |
59 | 63 |
60 Receiver receiver; | 64 Receiver receiver; |
61 | 65 |
62 scoped_refptr<FileReader> file_reader( | 66 scoped_refptr<FileReader> file_reader( |
63 new FileReader(resource, receiver.NewCallback())); | 67 new FileReader(resource, receiver.NewCallback())); |
64 file_reader->Start(); | 68 file_reader->Start(); |
65 | 69 |
66 MessageLoop::current()->Run(); | 70 MessageLoop::current()->Run(); |
67 | 71 |
68 EXPECT_EQ(file_exists, receiver.succeeded()); | 72 EXPECT_EQ(file_exists, receiver.succeeded()); |
69 EXPECT_EQ(file_contents, receiver.data()); | 73 EXPECT_EQ(file_contents, receiver.data()); |
70 } | 74 } |
71 | 75 |
72 TEST_F(FileReaderTest, SmallFile) { | 76 TEST_F(FileReaderTest, SmallFile) { |
73 RunBasicTest("title1.html"); | 77 RunBasicTest("title1.html"); |
74 } | 78 } |
75 | 79 |
76 TEST_F(FileReaderTest, BiggerFile) { | 80 TEST_F(FileReaderTest, BiggerFile) { |
77 RunBasicTest("download-test1.lib"); | 81 RunBasicTest("download-test1.lib"); |
78 } | 82 } |
79 | 83 |
80 TEST_F(FileReaderTest, NonExistantFile) { | 84 TEST_F(FileReaderTest, NonExistantFile) { |
81 FilePath path; | 85 FilePath path; |
82 PathService::Get(chrome::DIR_TEST_DATA, &path); | 86 PathService::Get(chrome::DIR_TEST_DATA, &path); |
83 ExtensionResource resource(path, FilePath( | 87 std::string extension_id; |
| 88 Extension::GenerateId("test", &extension_id); |
| 89 ExtensionResource resource(extension_id, path, FilePath( |
84 FILE_PATH_LITERAL("file_that_does_not_exist"))); | 90 FILE_PATH_LITERAL("file_that_does_not_exist"))); |
85 path = path.AppendASCII("file_that_does_not_exist"); | 91 path = path.AppendASCII("file_that_does_not_exist"); |
86 | 92 |
87 Receiver receiver; | 93 Receiver receiver; |
88 | 94 |
89 scoped_refptr<FileReader> file_reader( | 95 scoped_refptr<FileReader> file_reader( |
90 new FileReader(resource, receiver.NewCallback())); | 96 new FileReader(resource, receiver.NewCallback())); |
91 file_reader->Start(); | 97 file_reader->Start(); |
92 | 98 |
93 MessageLoop::current()->Run(); | 99 MessageLoop::current()->Run(); |
94 | 100 |
95 EXPECT_FALSE(receiver.succeeded()); | 101 EXPECT_FALSE(receiver.succeeded()); |
96 } | 102 } |
97 | 103 |
98 } // namespace | 104 } // namespace |
OLD | NEW |