| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 5 #include <string> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 class TestDebugDaemonClient : public chromeos::FakeDebugDaemonClient { | 27 class TestDebugDaemonClient : public chromeos::FakeDebugDaemonClient { |
| 28 public: | 28 public: |
| 29 explicit TestDebugDaemonClient(const base::FilePath& test_file) | 29 explicit TestDebugDaemonClient(const base::FilePath& test_file) |
| 30 : test_file_(test_file) {} | 30 : test_file_(test_file) {} |
| 31 | 31 |
| 32 ~TestDebugDaemonClient() override {} | 32 ~TestDebugDaemonClient() override {} |
| 33 | 33 |
| 34 void DumpDebugLogs(bool is_compressed, | 34 void DumpDebugLogs(bool is_compressed, |
| 35 base::File file, | 35 int file_descriptor, |
| 36 scoped_refptr<base::TaskRunner> task_runner, | |
| 37 const GetDebugLogsCallback& callback) override { | 36 const GetDebugLogsCallback& callback) override { |
| 38 base::File* file_param = new base::File(std::move(file)); | 37 // dup() is needed as the file descriptor will be closed on the client side. |
| 39 task_runner->PostTaskAndReply( | 38 base::File* file_param = new base::File(dup(file_descriptor)); |
| 40 FROM_HERE, | 39 content::BrowserThread::PostBlockingPoolTaskAndReply( |
| 41 base::Bind( | 40 FROM_HERE, base::Bind(&GenerateTestLogDumpFile, test_file_, |
| 42 &GenerateTestLogDumpFile, test_file_, base::Owned(file_param)), | 41 base::Owned(file_param)), |
| 43 base::Bind(callback, true)); | 42 base::Bind(callback, true)); |
| 44 } | 43 } |
| 45 | 44 |
| 46 static void GenerateTestLogDumpFile(const base::FilePath& test_tar_file, | 45 static void GenerateTestLogDumpFile(const base::FilePath& test_tar_file, |
| 47 base::File* file) { | 46 base::File* file) { |
| 48 std::string test_file_content; | 47 std::string test_file_content; |
| 49 EXPECT_TRUE(base::ReadFileToString(test_tar_file, &test_file_content)) | 48 EXPECT_TRUE(base::ReadFileToString(test_tar_file, &test_file_content)) |
| 50 << "Cannot read content of file " << test_tar_file.value(); | 49 << "Cannot read content of file " << test_tar_file.value(); |
| 51 const int data_size = static_cast<int>(test_file_content.size()); | 50 const int data_size = static_cast<int>(test_file_content.size()); |
| 52 EXPECT_EQ(data_size, file->Write(0, test_file_content.data(), data_size)); | 51 EXPECT_EQ(data_size, file->Write(0, test_file_content.data(), data_size)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 // Setup dummy HTTP server. | 90 // Setup dummy HTTP server. |
| 92 host_resolver()->AddRule("www.test.com", "127.0.0.1"); | 91 host_resolver()->AddRule("www.test.com", "127.0.0.1"); |
| 93 ASSERT_TRUE(StartEmbeddedTestServer()); | 92 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 94 embedded_test_server()->RegisterRequestHandler( | 93 embedded_test_server()->RegisterRequestHandler( |
| 95 base::Bind(&LogPrivateApiTest::HandleRequest, base::Unretained(this))); | 94 base::Bind(&LogPrivateApiTest::HandleRequest, base::Unretained(this))); |
| 96 | 95 |
| 97 ASSERT_TRUE(RunExtensionTest("log_private/dump_logs")); | 96 ASSERT_TRUE(RunExtensionTest("log_private/dump_logs")); |
| 98 } | 97 } |
| 99 | 98 |
| 100 } // namespace extensions | 99 } // namespace extensions |
| OLD | NEW |