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