OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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_TEST_REMOTING_REMOTE_TEST_HELPER_H_ | |
6 #define CHROME_TEST_REMOTING_REMOTE_TEST_HELPER_H_ | |
7 | |
8 #include "base/debug/stack_trace.h" | |
9 #include "base/timer/timer.h" | |
10 #include "content/public/test/browser_test_utils.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 namespace { | |
14 | |
15 // ASSERT_TRUE can only be used in void returning functions. This version | |
16 // should be used in non-void-returning functions. | |
17 inline void _ASSERT_TRUE(bool condition) { | |
18 if (!condition) { | |
19 // ASSERT_TRUE only prints the first call frame in the error message. | |
20 // In our case, this is the _ASSERT_TRUE wrapper function, which is not | |
21 // useful. To help with debugging, we will dump the full callstack. | |
22 LOG(ERROR) << "Assertion failed."; | |
23 LOG(ERROR) << base::debug::StackTrace().ToString(); | |
24 } | |
25 ASSERT_TRUE(condition); | |
26 return; | |
27 } | |
28 | |
29 } // namespace | |
30 | |
31 namespace remoting { | |
32 | |
33 // Mirrored in host.js | |
34 enum Action { | |
35 ERROR = -1, | |
36 NONE = 0, | |
37 KEYDOWN = 1, | |
38 BUTTONPRESS = 2, | |
39 MOUSEMOVE = 3, | |
40 MOUSEWHEEL = 4, | |
41 DRAG = 5, | |
42 }; | |
43 | |
44 struct Event { | |
45 Action action = Action::NONE; | |
46 int value = 0; | |
47 int modifiers = 0; | |
Jamie
2015/01/06 19:31:39
These initializers are no longer needed. Also, the
Mike Meade
2015/01/08 18:58:42
Done.
| |
48 Event(); | |
49 }; | |
50 | |
51 | |
52 class RemoteTestHelper { | |
53 public: | |
54 | |
Jamie
2015/01/06 19:31:39
No need for this blank line.
Mike Meade
2015/01/08 18:58:42
Done.
| |
55 explicit RemoteTestHelper(content::WebContents* web_content); | |
56 | |
57 // Helper to execute a JavaScript code snippet and extract the boolean result. | |
58 static bool ExecuteScriptAndExtractBool(content::WebContents* web_contents, | |
59 const std::string& script); | |
60 | |
61 // Helper to execute a JavaScript code snippet and extract the int result. | |
62 static int ExecuteScriptAndExtractInt(content::WebContents* web_contents, | |
63 const std::string& script); | |
64 | |
65 // Helper to execute a JavaScript code snippet and extract the string result. | |
66 static std::string ExecuteScriptAndExtractString( | |
67 content::WebContents* web_contents, const std::string& script); | |
68 | |
69 // Helper method to set the clear the last event | |
70 void ClearLastEvent(); | |
71 | |
72 // Helper method to get the last event | |
73 void GetLastEvent(Event* event); | |
74 | |
75 // Execute an RPC call | |
76 void ExecuteRpc(const std::string& method) { | |
77 ExecuteRpc(method, | |
78 base::TimeDelta::FromSeconds(2), | |
79 base::TimeDelta::FromMilliseconds(500)); | |
80 } | |
81 void ExecuteRpc(const std::string& method, | |
82 base::TimeDelta timeout, | |
83 base::TimeDelta interval); | |
84 | |
85 private: | |
86 content::WebContents* web_content_; | |
87 | |
88 // Check for a valid last event | |
89 bool IsValidEvent(); | |
90 DISALLOW_COPY_AND_ASSIGN(RemoteTestHelper); | |
91 }; | |
92 | |
93 } // namespace remoting | |
94 | |
95 #endif // CHROME_TEST_REMOTING_REMOTE_TEST_HELPER_H_ | |
OLD | NEW |