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 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/string16.h" | 9 #include "base/string16.h" |
10 #include "content/public/browser/notification_observer.h" | |
11 #include "content/public/browser/web_ui_message_handler.h" | 10 #include "content/public/browser/web_ui_message_handler.h" |
12 | 11 |
13 namespace base { | 12 namespace base { |
14 class ListValue; | 13 class ListValue; |
| 14 class Value; |
15 } | 15 } |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 class RenderViewHost; | 18 class RenderViewHost; |
19 } | 19 } |
20 | 20 |
21 // This class registers test framework specific handlers on WebUI objects. | 21 // This class registers test framework specific handlers on WebUI objects. |
22 class WebUITestHandler : public content::WebUIMessageHandler, | 22 class WebUITestHandler : public content::WebUIMessageHandler { |
23 public content::NotificationObserver { | |
24 public: | 23 public: |
25 WebUITestHandler(); | 24 WebUITestHandler(); |
26 | 25 |
27 // Sends a message through |preload_host| with the |js_text| to preload at the | 26 // Sends a message through |preload_host| with the |js_text| to preload at the |
28 // appropriate time before the onload call is made. | 27 // appropriate time before the onload call is made. |
29 void PreloadJavaScript(const string16& js_text, | 28 void PreloadJavaScript(const string16& js_text, |
30 content::RenderViewHost* preload_host); | 29 content::RenderViewHost* preload_host); |
31 | 30 |
32 // Runs |js_text| in this object's WebUI frame. Does not wait for any result. | 31 // Runs |js_text| in this object's WebUI frame. Does not wait for any result. |
33 void RunJavaScript(const string16& js_text); | 32 void RunJavaScript(const string16& js_text); |
34 | 33 |
35 // Runs |js_text| in this object's WebUI frame. Waits for result, logging an | 34 // Runs |js_text| in this object's WebUI frame. Waits for result, logging an |
36 // error message on failure. Returns test pass/fail. | 35 // error message on failure. Returns test pass/fail. |
37 bool RunJavaScriptTestWithResult(const string16& js_text); | 36 bool RunJavaScriptTestWithResult(const string16& js_text); |
38 | 37 |
39 // WebUIMessageHandler overrides. | 38 // WebUIMessageHandler overrides. |
40 // Add test handlers to the current WebUI object. | 39 // Add test handlers to the current WebUI object. |
41 virtual void RegisterMessages() OVERRIDE; | 40 virtual void RegisterMessages() OVERRIDE; |
42 | 41 |
43 private: | 42 private: |
44 // Receives testResult messages. | 43 // Receives testResult messages. |
45 void HandleTestResult(const base::ListValue* test_result); | 44 void HandleTestResult(const base::ListValue* test_result); |
46 | 45 |
47 // From content::NotificationObserver. | 46 // Gets the callback that Javascript execution is complete. |
48 virtual void Observe(int type, | 47 void JavaScriptComplete(const base::Value* result); |
49 const content::NotificationSource& source, | |
50 const content::NotificationDetails& details) OVERRIDE; | |
51 | 48 |
52 // Runs a message loop until test finishes. Returns the result of the | 49 // Runs a message loop until test finishes. Returns the result of the |
53 // test. | 50 // test. |
54 bool WaitForResult(); | 51 bool WaitForResult(); |
55 | 52 |
56 // Received test pass/fail; | 53 // Received test pass/fail; |
57 bool test_done_; | 54 bool test_done_; |
58 | 55 |
59 // Pass fail result of current test. | 56 // Pass fail result of current test. |
60 bool test_succeeded_; | 57 bool test_succeeded_; |
61 | 58 |
62 // Test code finished trying to execute. This will be set to true when the | 59 // Test code finished trying to execute. This will be set to true when the |
63 // selected tab is done with this execution request whether it was able to | 60 // selected tab is done with this execution request whether it was able to |
64 // parse/execute the javascript or not. | 61 // parse/execute the javascript or not. |
65 bool run_test_done_; | 62 bool run_test_done_; |
66 | 63 |
67 // Test code was able to execute successfully. This is *NOT* the test | 64 // Test code was able to execute successfully. This is *NOT* the test |
68 // pass/fail. | 65 // pass/fail. |
69 bool run_test_succeeded_; | 66 bool run_test_succeeded_; |
70 | 67 |
71 // Waiting for a test to finish. | 68 // Waiting for a test to finish. |
72 bool is_waiting_; | 69 bool is_waiting_; |
73 | 70 |
74 DISALLOW_COPY_AND_ASSIGN(WebUITestHandler); | 71 DISALLOW_COPY_AND_ASSIGN(WebUITestHandler); |
75 }; | 72 }; |
76 | 73 |
77 #endif // CHROME_BROWSER_UI_WEBUI_WEB_UI_TEST_HANDLER_H_ | 74 #endif // CHROME_BROWSER_UI_WEBUI_WEB_UI_TEST_HANDLER_H_ |
OLD | NEW |