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