| 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 "chrome/utility/importer/firefox_importer_unittest_utils.h" | 5 #include "chrome/utility/importer/firefox_importer_unittest_utils.h" |
| 6 | 6 |
| 7 #include "base/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 : got_result(false), sender_(NULL) {} | 71 : got_result(false), sender_(NULL) {} |
| 72 | 72 |
| 73 void SetSender(IPC::Sender* sender) { | 73 void SetSender(IPC::Sender* sender) { |
| 74 sender_ = sender; | 74 sender_ = sender; |
| 75 } | 75 } |
| 76 | 76 |
| 77 void OnInitDecryptorResponse(bool result) { | 77 void OnInitDecryptorResponse(bool result) { |
| 78 DCHECK(!got_result); | 78 DCHECK(!got_result); |
| 79 result_bool = result; | 79 result_bool = result; |
| 80 got_result = true; | 80 got_result = true; |
| 81 base::MessageLoop::current()->Quit(); | 81 base::MessageLoop::current()->QuitWhenIdle(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void OnDecryptedTextResponse(const base::string16& decrypted_text) { | 84 void OnDecryptedTextResponse(const base::string16& decrypted_text) { |
| 85 DCHECK(!got_result); | 85 DCHECK(!got_result); |
| 86 result_string = decrypted_text; | 86 result_string = decrypted_text; |
| 87 got_result = true; | 87 got_result = true; |
| 88 base::MessageLoop::current()->Quit(); | 88 base::MessageLoop::current()->QuitWhenIdle(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void OnParseSignonsResponse( | 91 void OnParseSignonsResponse( |
| 92 const std::vector<autofill::PasswordForm>& parsed_vector) { | 92 const std::vector<autofill::PasswordForm>& parsed_vector) { |
| 93 DCHECK(!got_result); | 93 DCHECK(!got_result); |
| 94 result_vector = parsed_vector; | 94 result_vector = parsed_vector; |
| 95 got_result = true; | 95 got_result = true; |
| 96 base::MessageLoop::current()->Quit(); | 96 base::MessageLoop::current()->QuitWhenIdle(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void QuitClient() { | 99 void QuitClient() { |
| 100 if (sender_) | 100 if (sender_) |
| 101 sender_->Send(new Msg_Decryptor_Quit()); | 101 sender_->Send(new Msg_Decryptor_Quit()); |
| 102 } | 102 } |
| 103 | 103 |
| 104 bool OnMessageReceived(const IPC::Message& msg) override { | 104 bool OnMessageReceived(const IPC::Message& msg) override { |
| 105 bool handled = true; | 105 bool handled = true; |
| 106 IPC_BEGIN_MESSAGE_MAP(FFDecryptorServerChannelListener, msg) | 106 IPC_BEGIN_MESSAGE_MAP(FFDecryptorServerChannelListener, msg) |
| 107 IPC_MESSAGE_HANDLER(Msg_Decryptor_InitReturnCode, OnInitDecryptorResponse) | 107 IPC_MESSAGE_HANDLER(Msg_Decryptor_InitReturnCode, OnInitDecryptorResponse) |
| 108 IPC_MESSAGE_HANDLER(Msg_Decryptor_Response, OnDecryptedTextResponse) | 108 IPC_MESSAGE_HANDLER(Msg_Decryptor_Response, OnDecryptedTextResponse) |
| 109 IPC_MESSAGE_HANDLER(Msg_ParseSignons_Response, OnParseSignonsResponse) | 109 IPC_MESSAGE_HANDLER(Msg_ParseSignons_Response, OnParseSignonsResponse) |
| 110 IPC_MESSAGE_UNHANDLED(handled = false) | 110 IPC_MESSAGE_UNHANDLED(handled = false) |
| 111 IPC_END_MESSAGE_MAP() | 111 IPC_END_MESSAGE_MAP() |
| 112 return handled; | 112 return handled; |
| 113 } | 113 } |
| 114 | 114 |
| 115 // If an error occured, just kill the message Loop. | 115 // If an error occured, just kill the message Loop. |
| 116 void OnChannelError() override { | 116 void OnChannelError() override { |
| 117 got_result = false; | 117 got_result = false; |
| 118 base::MessageLoop::current()->Quit(); | 118 base::MessageLoop::current()->QuitWhenIdle(); |
| 119 } | 119 } |
| 120 | 120 |
| 121 // Results of IPC calls. | 121 // Results of IPC calls. |
| 122 base::string16 result_string; | 122 base::string16 result_string; |
| 123 std::vector<autofill::PasswordForm> result_vector; | 123 std::vector<autofill::PasswordForm> result_vector; |
| 124 bool result_bool; | 124 bool result_bool; |
| 125 // True if IPC call succeeded and data in above variables is valid. | 125 // True if IPC call succeeded and data in above variables is valid. |
| 126 bool got_result; | 126 bool got_result; |
| 127 | 127 |
| 128 private: | 128 private: |
| (...skipping 28 matching lines...) Expand all Loading... |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 | 159 |
| 160 // A message_loop task that quits the message loop when invoked, setting cancel | 160 // A message_loop task that quits the message loop when invoked, setting cancel |
| 161 // causes the task to do nothing when invoked. | 161 // causes the task to do nothing when invoked. |
| 162 class CancellableQuitMsgLoop : public base::RefCounted<CancellableQuitMsgLoop> { | 162 class CancellableQuitMsgLoop : public base::RefCounted<CancellableQuitMsgLoop> { |
| 163 public: | 163 public: |
| 164 CancellableQuitMsgLoop() : cancelled_(false) {} | 164 CancellableQuitMsgLoop() : cancelled_(false) {} |
| 165 void QuitNow() { | 165 void QuitNow() { |
| 166 if (!cancelled_) | 166 if (!cancelled_) |
| 167 base::MessageLoop::current()->Quit(); | 167 base::MessageLoop::current()->QuitWhenIdle(); |
| 168 } | 168 } |
| 169 bool cancelled_; | 169 bool cancelled_; |
| 170 | 170 |
| 171 private: | 171 private: |
| 172 friend class base::RefCounted<CancellableQuitMsgLoop>; | 172 friend class base::RefCounted<CancellableQuitMsgLoop>; |
| 173 ~CancellableQuitMsgLoop() {} | 173 ~CancellableQuitMsgLoop() {} |
| 174 }; | 174 }; |
| 175 | 175 |
| 176 // Spin until either a client response arrives or a timeout occurs. | 176 // Spin until either a client response arrives or a timeout occurs. |
| 177 bool FFUnitTestDecryptorProxy::WaitForClientResponse() { | 177 bool FFUnitTestDecryptorProxy::WaitForClientResponse() { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 base::string16 unencrypted_str = decryptor_.Decrypt(crypt); | 249 base::string16 unencrypted_str = decryptor_.Decrypt(crypt); |
| 250 sender_->Send(new Msg_Decryptor_Response(unencrypted_str)); | 250 sender_->Send(new Msg_Decryptor_Response(unencrypted_str)); |
| 251 } | 251 } |
| 252 | 252 |
| 253 void OnParseSignons(base::FilePath signons_path) { | 253 void OnParseSignons(base::FilePath signons_path) { |
| 254 std::vector<autofill::PasswordForm> forms; | 254 std::vector<autofill::PasswordForm> forms; |
| 255 decryptor_.ReadAndParseSignons(signons_path, &forms); | 255 decryptor_.ReadAndParseSignons(signons_path, &forms); |
| 256 sender_->Send(new Msg_ParseSignons_Response(forms)); | 256 sender_->Send(new Msg_ParseSignons_Response(forms)); |
| 257 } | 257 } |
| 258 | 258 |
| 259 void OnQuitRequest() { | 259 void OnQuitRequest() { base::MessageLoop::current()->QuitWhenIdle(); } |
| 260 base::MessageLoop::current()->Quit(); | |
| 261 } | |
| 262 | 260 |
| 263 bool OnMessageReceived(const IPC::Message& msg) override { | 261 bool OnMessageReceived(const IPC::Message& msg) override { |
| 264 bool handled = true; | 262 bool handled = true; |
| 265 IPC_BEGIN_MESSAGE_MAP(FFDecryptorClientChannelListener, msg) | 263 IPC_BEGIN_MESSAGE_MAP(FFDecryptorClientChannelListener, msg) |
| 266 IPC_MESSAGE_HANDLER(Msg_Decryptor_Init, OnDecryptor_Init) | 264 IPC_MESSAGE_HANDLER(Msg_Decryptor_Init, OnDecryptor_Init) |
| 267 IPC_MESSAGE_HANDLER(Msg_Decrypt, OnDecrypt) | 265 IPC_MESSAGE_HANDLER(Msg_Decrypt, OnDecrypt) |
| 268 IPC_MESSAGE_HANDLER(Msg_ParseSignons, OnParseSignons) | 266 IPC_MESSAGE_HANDLER(Msg_ParseSignons, OnParseSignons) |
| 269 IPC_MESSAGE_HANDLER(Msg_Decryptor_Quit, OnQuitRequest) | 267 IPC_MESSAGE_HANDLER(Msg_Decryptor_Quit, OnQuitRequest) |
| 270 IPC_MESSAGE_UNHANDLED(handled = false) | 268 IPC_MESSAGE_UNHANDLED(handled = false) |
| 271 IPC_END_MESSAGE_MAP() | 269 IPC_END_MESSAGE_MAP() |
| 272 return handled; | 270 return handled; |
| 273 } | 271 } |
| 274 | 272 |
| 275 void OnChannelError() override { base::MessageLoop::current()->Quit(); } | 273 void OnChannelError() override { |
| 274 base::MessageLoop::current()->QuitWhenIdle(); |
| 275 } |
| 276 | 276 |
| 277 private: | 277 private: |
| 278 NSSDecryptor decryptor_; | 278 NSSDecryptor decryptor_; |
| 279 IPC::Sender* sender_; | 279 IPC::Sender* sender_; |
| 280 }; | 280 }; |
| 281 | 281 |
| 282 // Entry function in child process. | 282 // Entry function in child process. |
| 283 MULTIPROCESS_IPC_TEST_MAIN(NSSDecrypterChildProcess) { | 283 MULTIPROCESS_IPC_TEST_MAIN(NSSDecrypterChildProcess) { |
| 284 base::MessageLoopForIO main_message_loop; | 284 base::MessageLoopForIO main_message_loop; |
| 285 FFDecryptorClientChannelListener listener; | 285 FFDecryptorClientChannelListener listener; |
| 286 | 286 |
| 287 scoped_ptr<IPC::Channel> channel = IPC::Channel::CreateClient( | 287 scoped_ptr<IPC::Channel> channel = IPC::Channel::CreateClient( |
| 288 kTestChannelID, &listener); | 288 kTestChannelID, &listener); |
| 289 CHECK(channel->Connect()); | 289 CHECK(channel->Connect()); |
| 290 listener.SetSender(channel.get()); | 290 listener.SetSender(channel.get()); |
| 291 | 291 |
| 292 // run message loop | 292 // run message loop |
| 293 base::MessageLoop::current()->Run(); | 293 base::MessageLoop::current()->Run(); |
| 294 | 294 |
| 295 return 0; | 295 return 0; |
| 296 } | 296 } |
| OLD | NEW |