| 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" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 class Receiver { | 33 class Receiver { |
| 34 public: | 34 public: |
| 35 Receiver() : succeeded_(false) { | 35 Receiver() : succeeded_(false) { |
| 36 } | 36 } |
| 37 | 37 |
| 38 FileReader::Callback NewCallback() { | 38 FileReader::Callback NewCallback() { |
| 39 return base::Bind(&Receiver::DidReadFile, base::Unretained(this)); | 39 return base::Bind(&Receiver::DidReadFile, base::Unretained(this)); |
| 40 } | 40 } |
| 41 | 41 |
| 42 bool succeeded() const { return succeeded_; } | 42 bool succeeded() const { return succeeded_; } |
| 43 const std::string& data() const { return data_; } | 43 const std::string& data() const { return *data_; } |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 void DidReadFile(bool success, const std::string& data) { | 46 void DidReadFile(bool success, std::unique_ptr<std::string> data) { |
| 47 succeeded_ = success; | 47 succeeded_ = success; |
| 48 data_ = data; | 48 data_ = std::move(data); |
| 49 base::MessageLoop::current()->QuitWhenIdle(); | 49 base::MessageLoop::current()->QuitWhenIdle(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 bool succeeded_; | 52 bool succeeded_; |
| 53 std::string data_; | 53 std::unique_ptr<std::string> data_; |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 void RunBasicTest(const char* filename) { | 56 void RunBasicTest(const char* filename) { |
| 57 base::FilePath path; | 57 base::FilePath path; |
| 58 PathService::Get(DIR_TEST_DATA, &path); | 58 PathService::Get(DIR_TEST_DATA, &path); |
| 59 std::string extension_id = crx_file::id_util::GenerateId("test"); | 59 std::string extension_id = crx_file::id_util::GenerateId("test"); |
| 60 ExtensionResource resource( | 60 ExtensionResource resource( |
| 61 extension_id, path, base::FilePath().AppendASCII(filename)); | 61 extension_id, path, base::FilePath().AppendASCII(filename)); |
| 62 path = path.AppendASCII(filename); | 62 path = path.AppendASCII(filename); |
| 63 | 63 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 scoped_refptr<FileReader> file_reader( | 97 scoped_refptr<FileReader> file_reader( |
| 98 new FileReader(resource, receiver.NewCallback())); | 98 new FileReader(resource, receiver.NewCallback())); |
| 99 file_reader->Start(); | 99 file_reader->Start(); |
| 100 | 100 |
| 101 base::RunLoop().Run(); | 101 base::RunLoop().Run(); |
| 102 | 102 |
| 103 EXPECT_FALSE(receiver.succeeded()); | 103 EXPECT_FALSE(receiver.succeeded()); |
| 104 } | 104 } |
| 105 | 105 |
| 106 } // namespace extensions | 106 } // namespace extensions |
| OLD | NEW |