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: |
23 WebUITestHandler(); | |
24 | |
17 // Sends a message through |preload_host| with the |js_text| to preload at the | 25 // Sends a message through |preload_host| with the |js_text| to preload at the |
18 // appropriate time before the onload call is made. | 26 // appropriate time before the onload call is made. |
19 void PreloadJavaScript(const string16& js_text, | 27 void PreloadJavaScript(const string16& js_text, |
20 RenderViewHost* preload_host); | 28 RenderViewHost* preload_host); |
21 | 29 |
22 // Runs |js_text| in this object's WebUI frame. Does not wait for any result. | 30 // Runs |js_text| in this object's WebUI frame. Does not wait for any result. |
23 void RunJavaScript(const string16& js_text); | 31 void RunJavaScript(const string16& js_text); |
24 | 32 |
25 // Runs |js_text| in this object's WebUI frame. Waits for result, logging an | 33 // Runs |js_text| in this object's WebUI frame. Waits for result, logging an |
26 // error message on failure. Returns test pass/fail. | 34 // error message on failure. Returns test pass/fail. When |is_async| is true, |
27 bool RunJavaScriptTestWithResult(const string16& js_text); | 35 // waits for asyncTestDone() to be called from javascript code. |
36 bool RunJavaScriptTestWithResult(const string16& js_text, bool is_async); | |
28 | 37 |
29 private: | 38 private: |
30 // WebUIMessageHandler overrides. | 39 // WebUIMessageHandler overrides. |
31 // Add test handlers to the current WebUI object. | 40 // Add test handlers to the current WebUI object. |
32 virtual void RegisterMessages() OVERRIDE {} | 41 virtual void RegisterMessages() OVERRIDE; |
42 | |
43 // Receives asyncTestResult messages. | |
44 void HandleAsyncTestResult(const base::ListValue* test_result); | |
45 | |
46 // Populates |success| from |test_result|, logging messages to ERROR, upon | |
mmenke
2011/08/10 17:23:40
nit: Second comma not needed.
Sheridan Rawlins
2011/08/11 01:58:44
Done.
| |
47 // failure. | |
48 void HandleTestResult(const base::ListValue* test_result, bool* success); | |
33 | 49 |
34 // From NotificationObserver. | 50 // From NotificationObserver. |
35 virtual void Observe(int type, | 51 virtual void Observe(int type, |
36 const NotificationSource& source, | 52 const NotificationSource& source, |
37 const NotificationDetails& details) OVERRIDE; | 53 const NotificationDetails& details) OVERRIDE; |
38 | 54 |
39 // Runs a message loop until test finishes. Returns the result of the test. | 55 // Runs a message loop until test finishes. Returns the result of the |
40 bool WaitForResult(); | 56 // test. When |is_async| is true, waits for asyncTestDone() to be called from |
57 // javascript code. | |
58 bool WaitForResult(bool is_async); | |
41 | 59 |
42 // Pass fail result of current tests. | 60 // Pass fail result of current test. |
43 bool test_succeeded_; | 61 bool test_succeeded_; |
44 | 62 |
63 // Pass fail result of current async test. | |
64 bool test_succeeded_async_; | |
65 | |
45 // Waiting for a test to finish. | 66 // Waiting for a test to finish. |
46 bool is_waiting_; | 67 bool is_waiting_; |
68 | |
69 // Received sync completion pass/fail; | |
70 bool test_done_; | |
71 | |
72 // Received async completion pass/fail; | |
73 bool test_done_async_; | |
74 | |
75 DISALLOW_COPY_AND_ASSIGN(WebUITestHandler); | |
47 }; | 76 }; |
48 | 77 |
49 #endif // CHROME_BROWSER_UI_WEBUI_WEB_UI_TEST_HANDLER_H_ | 78 #endif // CHROME_BROWSER_UI_WEBUI_WEB_UI_TEST_HANDLER_H_ |
OLD | NEW |