| 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_UI_WEBUI_WEB_UI_TEST_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_WEB_UI_TEST_HANDLER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_WEB_UI_TEST_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_WEB_UI_TEST_HANDLER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/string16.h" | 9 #include "base/string16.h" |
| 10 #include "content/browser/webui/web_ui.h" | 10 #include "content/browser/webui/web_ui.h" |
| 11 #include "content/common/notification_observer.h" | 11 #include "content/common/notification_observer.h" |
| 12 | 12 |
| 13 namespace base { |
| 14 |
| 15 class ListValue; |
| 16 |
| 17 } // namespace base |
| 18 |
| 13 // This class registers test framework specific handlers on WebUI objects. | 19 // This class registers test framework specific handlers on WebUI objects. |
| 14 class WebUITestHandler : public WebUIMessageHandler, | 20 class WebUITestHandler : public WebUIMessageHandler, |
| 15 public NotificationObserver { | 21 public NotificationObserver { |
| 16 public: | 22 public: |
| 17 // Sends a message through |preload_host| with the |js_text| to preload at the | 23 // Sends a message through |preload_host| with the |js_text| to preload at the |
| 18 // appropriate time before the onload call is made. | 24 // appropriate time before the onload call is made. |
| 19 void PreloadJavaScript(const string16& js_text, | 25 void PreloadJavaScript(const string16& js_text, |
| 20 RenderViewHost* preload_host); | 26 RenderViewHost* preload_host); |
| 21 | 27 |
| 22 // Runs |js_text| in this object's WebUI frame. Does not wait for any result. | 28 // Runs |js_text| in this object's WebUI frame. Does not wait for any result. |
| 23 void RunJavaScript(const string16& js_text); | 29 void RunJavaScript(const string16& js_text); |
| 24 | 30 |
| 25 // Runs |js_text| in this object's WebUI frame. Waits for result, logging an | 31 // Runs |js_text| in this object's WebUI frame. Waits for result, logging an |
| 26 // error message on failure. Returns test pass/fail. | 32 // error message on failure. Returns test pass/fail. |
| 27 bool RunJavaScriptTestWithResult(const string16& js_text); | 33 bool RunJavaScriptTestWithResult(const string16& js_text); |
| 28 | 34 |
| 35 // Runs a message loop until async test finishes. Returns the result of the |
| 36 // test. |
| 37 bool WaitForAsyncResult(); |
| 38 |
| 29 private: | 39 private: |
| 30 // WebUIMessageHandler overrides. | 40 // WebUIMessageHandler overrides. |
| 31 // Add test handlers to the current WebUI object. | 41 // Add test handlers to the current WebUI object. |
| 32 virtual void RegisterMessages() OVERRIDE {} | 42 virtual void RegisterMessages() OVERRIDE; |
| 43 |
| 44 // Receives asyncTestResult messages. |
| 45 void HandleAsyncTestResult(const base::ListValue* test_result); |
| 46 |
| 47 // Populates |success| from |test_result|, logging messages to ERROR, upon |
| 48 // failure. |
| 49 void HandleTestResult(const base::ListValue* test_result, bool* success); |
| 33 | 50 |
| 34 // From NotificationObserver. | 51 // From NotificationObserver. |
| 35 virtual void Observe(int type, | 52 virtual void Observe(int type, |
| 36 const NotificationSource& source, | 53 const NotificationSource& source, |
| 37 const NotificationDetails& details) OVERRIDE; | 54 const NotificationDetails& details) OVERRIDE; |
| 38 | 55 |
| 39 // Runs a message loop until test finishes. Returns the result of the test. | 56 // Runs a message loop until test finishes. Returns the result of the test. |
| 40 bool WaitForResult(); | 57 bool WaitForResult(); |
| 41 | 58 |
| 42 // Pass fail result of current tests. | 59 // Pass fail result of current tests. |
| 43 bool test_succeeded_; | 60 bool test_succeeded_; |
| 44 | 61 |
| 45 // Waiting for a test to finish. | 62 // Waiting for a test to finish. |
| 46 bool is_waiting_; | 63 bool is_waiting_; |
| 64 |
| 65 // Received async completion pass/fail; |
| 66 bool test_done_async_; |
| 67 |
| 68 // When |test_done_async_| is true, this is the pass/fail of the tests. |
| 69 bool test_succeeded_async_; |
| 70 |
| 71 // Waiting for an async test to finish. |
| 72 bool is_waiting_async_; |
| 47 }; | 73 }; |
| 48 | 74 |
| 49 #endif // CHROME_BROWSER_UI_WEBUI_WEB_UI_TEST_HANDLER_H_ | 75 #endif // CHROME_BROWSER_UI_WEBUI_WEB_UI_TEST_HANDLER_H_ |
| OLD | NEW |