OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/scoped_file.h" | 9 #include "base/files/scoped_file.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 | 135 |
136 virtual void CloseChannel(int port_id, | 136 virtual void CloseChannel(int port_id, |
137 const std::string& error_message) OVERRIDE { | 137 const std::string& error_message) OVERRIDE { |
138 channel_closed_ = true; | 138 channel_closed_ = true; |
139 if (run_loop_) | 139 if (run_loop_) |
140 run_loop_->Quit(); | 140 run_loop_->Quit(); |
141 } | 141 } |
142 | 142 |
143 protected: | 143 protected: |
144 std::string FormatMessage(const std::string& message) { | 144 std::string FormatMessage(const std::string& message) { |
145 Pickle pickle; | 145 uint32_t length = message.length(); |
146 pickle.WriteString(message); | 146 return std::string(reinterpret_cast<char*>(&length), 4).append(message); |
147 return std::string(const_cast<const Pickle*>(&pickle)->payload(), | |
148 pickle.payload_size()); | |
149 } | 147 } |
150 | 148 |
151 base::FilePath CreateTempFileWithMessage(const std::string& message) { | 149 base::FilePath CreateTempFileWithMessage(const std::string& message) { |
152 base::FilePath filename; | 150 base::FilePath filename; |
153 if (!base::CreateTemporaryFileInDir(temp_dir_.path(), &filename)) | 151 if (!base::CreateTemporaryFileInDir(temp_dir_.path(), &filename)) |
154 return base::FilePath(); | 152 return base::FilePath(); |
155 | 153 |
156 std::string message_with_header = FormatMessage(message); | 154 std::string message_with_header = FormatMessage(message); |
157 int bytes_written = base::WriteFile( | 155 int bytes_written = base::WriteFile( |
158 filename, message_with_header.data(), message_with_header.size()); | 156 filename, message_with_header.data(), message_with_header.size()); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 ScopedTestNativeMessagingHost::kHostName, 0, false); | 312 ScopedTestNativeMessagingHost::kHostName, 0, false); |
315 ASSERT_TRUE(native_message_process_host_.get()); | 313 ASSERT_TRUE(native_message_process_host_.get()); |
316 run_loop_.reset(new base::RunLoop()); | 314 run_loop_.reset(new base::RunLoop()); |
317 run_loop_->Run(); | 315 run_loop_->Run(); |
318 | 316 |
319 // The host should fail to start. | 317 // The host should fail to start. |
320 ASSERT_TRUE(channel_closed_); | 318 ASSERT_TRUE(channel_closed_); |
321 } | 319 } |
322 | 320 |
323 } // namespace extensions | 321 } // namespace extensions |
OLD | NEW |