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/browser/extensions/extension_test_message_listener.h" | 5 #include "chrome/browser/extensions/extension_test_message_listener.h" |
6 | 6 |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "chrome/browser/extensions/api/test/test_api.h" | 8 #include "chrome/browser/extensions/api/test/test_api.h" |
9 #include "chrome/common/chrome_notification_types.h" | 9 #include "chrome/common/chrome_notification_types.h" |
10 #include "chrome/test/base/ui_test_utils.h" | 10 #include "chrome/test/base/ui_test_utils.h" |
11 #include "content/public/browser/notification_service.h" | 11 #include "content/public/browser/notification_service.h" |
12 | 12 |
13 ExtensionTestMessageListener::ExtensionTestMessageListener( | 13 ExtensionTestMessageListener::ExtensionTestMessageListener( |
14 const std::string& expected_message, | 14 const std::string& expected_message, |
15 bool will_reply) | 15 bool will_reply) |
16 : expected_message_(expected_message), | 16 : expected_message_(expected_message), |
17 satisfied_(false), | 17 satisfied_(false), |
18 waiting_(false), | 18 waiting_(false), |
19 will_reply_(will_reply), | 19 will_reply_(will_reply), |
20 failure_message_(""), | |
21 failed_(false) { | 20 failed_(false) { |
22 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_TEST_MESSAGE, | 21 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_TEST_MESSAGE, |
23 content::NotificationService::AllSources()); | 22 content::NotificationService::AllSources()); |
24 } | 23 } |
25 | 24 |
26 ExtensionTestMessageListener::~ExtensionTestMessageListener() {} | 25 ExtensionTestMessageListener::~ExtensionTestMessageListener() {} |
27 | 26 |
28 bool ExtensionTestMessageListener::WaitUntilSatisfied() { | 27 bool ExtensionTestMessageListener::WaitUntilSatisfied() { |
29 if (satisfied_) | 28 if (satisfied_) |
30 return !failed_; | 29 return !failed_; |
(...skipping 21 matching lines...) Expand all Loading... |
52 const std::string& content = *content::Details<std::string>(details).ptr(); | 51 const std::string& content = *content::Details<std::string>(details).ptr(); |
53 if (!satisfied_ && (content == expected_message_ || | 52 if (!satisfied_ && (content == expected_message_ || |
54 (!failure_message_.empty() && (content == failure_message_)))) { | 53 (!failure_message_.empty() && (content == failure_message_)))) { |
55 if (!failed_) | 54 if (!failed_) |
56 failed_ = (content == failure_message_); | 55 failed_ = (content == failure_message_); |
57 function_ = content::Source<extensions::TestSendMessageFunction>( | 56 function_ = content::Source<extensions::TestSendMessageFunction>( |
58 source).ptr(); | 57 source).ptr(); |
59 satisfied_ = true; | 58 satisfied_ = true; |
60 registrar_.RemoveAll(); // Stop listening for more messages. | 59 registrar_.RemoveAll(); // Stop listening for more messages. |
61 if (!will_reply_) { | 60 if (!will_reply_) { |
62 function_->Reply(""); | 61 function_->Reply(std::string()); |
63 function_ = NULL; | 62 function_ = NULL; |
64 } | 63 } |
65 if (waiting_) { | 64 if (waiting_) { |
66 waiting_ = false; | 65 waiting_ = false; |
67 MessageLoopForUI::current()->Quit(); | 66 MessageLoopForUI::current()->Quit(); |
68 } | 67 } |
69 } | 68 } |
70 } | 69 } |
OLD | NEW |