| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/run_loop.h" |
| 11 #include "components/crx_file/id_util.h" | 12 #include "components/crx_file/id_util.h" |
| 12 #include "content/public/test/test_browser_thread.h" | 13 #include "content/public/test/test_browser_thread.h" |
| 13 #include "extensions/browser/file_reader.h" | 14 #include "extensions/browser/file_reader.h" |
| 14 #include "extensions/common/extension_paths.h" | 15 #include "extensions/common/extension_paths.h" |
| 15 #include "extensions/common/extension_resource.h" | 16 #include "extensions/common/extension_resource.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 18 |
| 18 using content::BrowserThread; | 19 using content::BrowserThread; |
| 19 | 20 |
| 20 namespace extensions { | 21 namespace extensions { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 | 63 |
| 63 std::string file_contents; | 64 std::string file_contents; |
| 64 ASSERT_TRUE(base::ReadFileToString(path, &file_contents)); | 65 ASSERT_TRUE(base::ReadFileToString(path, &file_contents)); |
| 65 | 66 |
| 66 Receiver receiver; | 67 Receiver receiver; |
| 67 | 68 |
| 68 scoped_refptr<FileReader> file_reader( | 69 scoped_refptr<FileReader> file_reader( |
| 69 new FileReader(resource, receiver.NewCallback())); | 70 new FileReader(resource, receiver.NewCallback())); |
| 70 file_reader->Start(); | 71 file_reader->Start(); |
| 71 | 72 |
| 72 base::MessageLoop::current()->Run(); | 73 base::RunLoop().Run(); |
| 73 | 74 |
| 74 EXPECT_TRUE(receiver.succeeded()); | 75 EXPECT_TRUE(receiver.succeeded()); |
| 75 EXPECT_EQ(file_contents, receiver.data()); | 76 EXPECT_EQ(file_contents, receiver.data()); |
| 76 } | 77 } |
| 77 | 78 |
| 78 TEST_F(FileReaderTest, SmallFile) { | 79 TEST_F(FileReaderTest, SmallFile) { |
| 79 RunBasicTest("smallfile"); | 80 RunBasicTest("smallfile"); |
| 80 } | 81 } |
| 81 | 82 |
| 82 TEST_F(FileReaderTest, BiggerFile) { | 83 TEST_F(FileReaderTest, BiggerFile) { |
| 83 RunBasicTest("bigfile"); | 84 RunBasicTest("bigfile"); |
| 84 } | 85 } |
| 85 | 86 |
| 86 TEST_F(FileReaderTest, NonExistantFile) { | 87 TEST_F(FileReaderTest, NonExistantFile) { |
| 87 base::FilePath path; | 88 base::FilePath path; |
| 88 PathService::Get(DIR_TEST_DATA, &path); | 89 PathService::Get(DIR_TEST_DATA, &path); |
| 89 std::string extension_id = crx_file::id_util::GenerateId("test"); | 90 std::string extension_id = crx_file::id_util::GenerateId("test"); |
| 90 ExtensionResource resource(extension_id, path, base::FilePath( | 91 ExtensionResource resource(extension_id, path, base::FilePath( |
| 91 FILE_PATH_LITERAL("file_that_does_not_exist"))); | 92 FILE_PATH_LITERAL("file_that_does_not_exist"))); |
| 92 path = path.AppendASCII("file_that_does_not_exist"); | 93 path = path.AppendASCII("file_that_does_not_exist"); |
| 93 | 94 |
| 94 Receiver receiver; | 95 Receiver receiver; |
| 95 | 96 |
| 96 scoped_refptr<FileReader> file_reader( | 97 scoped_refptr<FileReader> file_reader( |
| 97 new FileReader(resource, receiver.NewCallback())); | 98 new FileReader(resource, receiver.NewCallback())); |
| 98 file_reader->Start(); | 99 file_reader->Start(); |
| 99 | 100 |
| 100 base::MessageLoop::current()->Run(); | 101 base::RunLoop().Run(); |
| 101 | 102 |
| 102 EXPECT_FALSE(receiver.succeeded()); | 103 EXPECT_FALSE(receiver.succeeded()); |
| 103 } | 104 } |
| 104 | 105 |
| 105 } // namespace extensions | 106 } // namespace extensions |
| OLD | NEW |