| 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/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.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 "components/crx_file/id_util.h" |
| 11 #include "content/public/test/test_browser_thread.h" | 12 #include "content/public/test/test_browser_thread.h" |
| 12 #include "extensions/browser/file_reader.h" | 13 #include "extensions/browser/file_reader.h" |
| 13 #include "extensions/common/extension_paths.h" | 14 #include "extensions/common/extension_paths.h" |
| 14 #include "extensions/common/extension_resource.h" | 15 #include "extensions/common/extension_resource.h" |
| 15 #include "extensions/common/id_util.h" | |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 using content::BrowserThread; | 18 using content::BrowserThread; |
| 19 | 19 |
| 20 namespace extensions { | 20 namespace extensions { |
| 21 | 21 |
| 22 class FileReaderTest : public testing::Test { | 22 class FileReaderTest : public testing::Test { |
| 23 public: | 23 public: |
| 24 FileReaderTest() : file_thread_(BrowserThread::FILE) { | 24 FileReaderTest() : file_thread_(BrowserThread::FILE) { |
| 25 file_thread_.Start(); | 25 file_thread_.Start(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 48 base::MessageLoop::current()->Quit(); | 48 base::MessageLoop::current()->Quit(); |
| 49 } | 49 } |
| 50 | 50 |
| 51 bool succeeded_; | 51 bool succeeded_; |
| 52 std::string data_; | 52 std::string data_; |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 void RunBasicTest(const char* filename) { | 55 void RunBasicTest(const char* filename) { |
| 56 base::FilePath path; | 56 base::FilePath path; |
| 57 PathService::Get(DIR_TEST_DATA, &path); | 57 PathService::Get(DIR_TEST_DATA, &path); |
| 58 std::string extension_id = id_util::GenerateId("test"); | 58 std::string extension_id = crx_file::id_util::GenerateId("test"); |
| 59 ExtensionResource resource( | 59 ExtensionResource resource( |
| 60 extension_id, path, base::FilePath().AppendASCII(filename)); | 60 extension_id, path, base::FilePath().AppendASCII(filename)); |
| 61 path = path.AppendASCII(filename); | 61 path = path.AppendASCII(filename); |
| 62 | 62 |
| 63 std::string file_contents; | 63 std::string file_contents; |
| 64 ASSERT_TRUE(base::ReadFileToString(path, &file_contents)); | 64 ASSERT_TRUE(base::ReadFileToString(path, &file_contents)); |
| 65 | 65 |
| 66 Receiver receiver; | 66 Receiver receiver; |
| 67 | 67 |
| 68 scoped_refptr<FileReader> file_reader( | 68 scoped_refptr<FileReader> file_reader( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 79 RunBasicTest("smallfile"); | 79 RunBasicTest("smallfile"); |
| 80 } | 80 } |
| 81 | 81 |
| 82 TEST_F(FileReaderTest, BiggerFile) { | 82 TEST_F(FileReaderTest, BiggerFile) { |
| 83 RunBasicTest("bigfile"); | 83 RunBasicTest("bigfile"); |
| 84 } | 84 } |
| 85 | 85 |
| 86 TEST_F(FileReaderTest, NonExistantFile) { | 86 TEST_F(FileReaderTest, NonExistantFile) { |
| 87 base::FilePath path; | 87 base::FilePath path; |
| 88 PathService::Get(DIR_TEST_DATA, &path); | 88 PathService::Get(DIR_TEST_DATA, &path); |
| 89 std::string extension_id = id_util::GenerateId("test"); | 89 std::string extension_id = crx_file::id_util::GenerateId("test"); |
| 90 ExtensionResource resource(extension_id, path, base::FilePath( | 90 ExtensionResource resource(extension_id, path, base::FilePath( |
| 91 FILE_PATH_LITERAL("file_that_does_not_exist"))); | 91 FILE_PATH_LITERAL("file_that_does_not_exist"))); |
| 92 path = path.AppendASCII("file_that_does_not_exist"); | 92 path = path.AppendASCII("file_that_does_not_exist"); |
| 93 | 93 |
| 94 Receiver receiver; | 94 Receiver receiver; |
| 95 | 95 |
| 96 scoped_refptr<FileReader> file_reader( | 96 scoped_refptr<FileReader> file_reader( |
| 97 new FileReader(resource, receiver.NewCallback())); | 97 new FileReader(resource, receiver.NewCallback())); |
| 98 file_reader->Start(); | 98 file_reader->Start(); |
| 99 | 99 |
| 100 base::MessageLoop::current()->Run(); | 100 base::MessageLoop::current()->Run(); |
| 101 | 101 |
| 102 EXPECT_FALSE(receiver.succeeded()); | 102 EXPECT_FALSE(receiver.succeeded()); |
| 103 } | 103 } |
| 104 | 104 |
| 105 } // namespace extensions | 105 } // namespace extensions |
| OLD | NEW |