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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_MESSAGE_LISTENER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_MESSAGE_LISTENER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_MESSAGE_LISTENER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_MESSAGE_LISTENER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 // Note that when using it in browser tests, you need to make sure it gets | 40 // Note that when using it in browser tests, you need to make sure it gets |
41 // destructed *before* the browser gets torn down. Two common patterns are to | 41 // destructed *before* the browser gets torn down. Two common patterns are to |
42 // either make it a local variable inside your test body, or if it's a member | 42 // either make it a local variable inside your test body, or if it's a member |
43 // variable of a ExtensionBrowserTest subclass, override the | 43 // variable of a ExtensionBrowserTest subclass, override the |
44 // InProcessBrowserTest::CleanUpOnMainThread() method and clean it up there. | 44 // InProcessBrowserTest::CleanUpOnMainThread() method and clean it up there. |
45 class ExtensionTestMessageListener : public NotificationObserver { | 45 class ExtensionTestMessageListener : public NotificationObserver { |
46 public: | 46 public: |
47 // We immediately start listening for |expected_message|. | 47 // We immediately start listening for |expected_message|. |
48 ExtensionTestMessageListener(const std::string& expected_message, | 48 ExtensionTestMessageListener(const std::string& expected_message, |
49 bool will_reply); | 49 bool will_reply); |
50 ~ExtensionTestMessageListener(); | 50 virtual ~ExtensionTestMessageListener(); |
51 | 51 |
52 // This returns true immediately if we've already gotten the expected | 52 // This returns true immediately if we've already gotten the expected |
53 // message, or waits until it arrives. Returns false if the wait is | 53 // message, or waits until it arrives. Returns false if the wait is |
54 // interrupted and we still haven't gotten the message. | 54 // interrupted and we still haven't gotten the message. |
55 bool WaitUntilSatisfied(); | 55 bool WaitUntilSatisfied(); |
56 | 56 |
57 // Send the given message as a reply. It is only valid to call this after | 57 // Send the given message as a reply. It is only valid to call this after |
58 // WaitUntilSatisfied has returned true, and if will_reply is true. | 58 // WaitUntilSatisfied has returned true, and if will_reply is true. |
59 void Reply(const std::string& message); | 59 void Reply(const std::string& message); |
60 | 60 |
(...skipping 19 matching lines...) Expand all Loading... |
80 | 80 |
81 // If true, we expect the calling code to manually send a reply. Otherwise, | 81 // If true, we expect the calling code to manually send a reply. Otherwise, |
82 // we send an automatic empty reply to the extension. | 82 // we send an automatic empty reply to the extension. |
83 bool will_reply_; | 83 bool will_reply_; |
84 | 84 |
85 // The function we need to reply to. | 85 // The function we need to reply to. |
86 ExtensionTestSendMessageFunction* function_; | 86 ExtensionTestSendMessageFunction* function_; |
87 }; | 87 }; |
88 | 88 |
89 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_MESSAGE_LISTENER_H_ | 89 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TEST_MESSAGE_LISTENER_H_ |
OLD | NEW |