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"
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
) {
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
);
33 // Mirrored in remoting/tools/remote_test_helper/host.js
34 enum class Action
: int {
53 class RemoteTestHelper
{
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
) {
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
);
86 content::WebContents
* web_content_
;
88 // Check for a valid last event
90 DISALLOW_COPY_AND_ASSIGN(RemoteTestHelper
);
93 } // namespace remoting
95 #endif // CHROME_TEST_REMOTING_REMOTE_TEST_HELPER_H_