Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / test / remoting / remote_test_helper.h
blobca26186b50bb9ae99008e240f5a56d83f1ddc14e
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.
5 #ifndef CHROME_TEST_REMOTING_REMOTE_TEST_HELPER_H_
6 #define CHROME_TEST_REMOTING_REMOTE_TEST_HELPER_H_
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"
13 namespace {
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();
25 ASSERT_TRUE(condition);
26 return;
29 } // namespace
31 namespace remoting {
33 // Mirrored in remoting/tools/remote_test_helper/host.js
34 enum class Action : int {
35 Error = 0,
36 None = 1,
37 Keydown = 2,
38 Buttonpress = 3,
39 Mousemove = 4,
40 Mousewheel = 5,
41 Drag = 6,
44 struct Event {
45 Event();
47 Action action;
48 int value;
49 int modifiers;
53 class RemoteTestHelper {
54 public:
55 explicit RemoteTestHelper(content::WebContents* web_content);
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);
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);
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);
69 // Helper method to set the clear the last event
70 void ClearLastEvent();
72 // Helper method to get the last event
73 void GetLastEvent(Event* event);
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));
81 void ExecuteRpc(const std::string& method,
82 base::TimeDelta timeout,
83 base::TimeDelta interval);
85 private:
86 content::WebContents* web_content_;
88 // Check for a valid last event
89 bool IsValidEvent();
90 DISALLOW_COPY_AND_ASSIGN(RemoteTestHelper);
93 } // namespace remoting
95 #endif // CHROME_TEST_REMOTING_REMOTE_TEST_HELPER_H_