Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Unified Diff: chrome/test/remoting/remote_test_helper.h

Issue 807343002: Adding the first set of remote test cases and associated framework. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: First round of fixes for the remote me2me tests and the associated remote_test_helper code. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/remoting/remote_test_helper.h
diff --git a/chrome/test/remoting/remote_test_helper.h b/chrome/test/remoting/remote_test_helper.h
new file mode 100644
index 0000000000000000000000000000000000000000..668af12c9b9d4f044fab5ca8a3a09f31ac21333c
--- /dev/null
+++ b/chrome/test/remoting/remote_test_helper.h
@@ -0,0 +1,100 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_TEST_REMOTING_REMOTE_TEST_HELPER_H_
+#define CHROME_TEST_REMOTING_REMOTE_TEST_HELPER_H_
+
+#include "base/debug/stack_trace.h"
+#include "base/timer/timer.h"
+#include "content/public/test/browser_test_utils.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+// ASSERT_TRUE can only be used in void returning functions. This version
+// should be used in non-void-returning functions.
+inline void _ASSERT_TRUE(bool condition) {
+ if (!condition) {
+ // ASSERT_TRUE only prints the first call frame in the error message.
+ // In our case, this is the _ASSERT_TRUE wrapper function, which is not
+ // useful. To help with debugging, we will dump the full callstack.
+ LOG(ERROR) << "Assertion failed.";
+ LOG(ERROR) << base::debug::StackTrace().ToString();
+ }
+ ASSERT_TRUE(condition);
+ return;
+}
+
+} // namespace
+
+namespace remoting {
+
+// Mirrored in host.js
+enum Action {
+ ERROR = -1,
+ NONE = 0,
+ KEYDOWN = 1,
+ BUTTONPRESS = 2,
+ MOUSEMOVE = 3,
+ MOUSEWHEEL = 4,
+ DRAG = 5,
+};
+
+typedef struct {
+ Action action = Action::NONE;
+ int value = 0;
+ int modifiers = 0;
+} Event;
+
+
+class RemoteTestHelper {
+ public:
+
+ explicit RemoteTestHelper(content::WebContents* web_content)
+ :web_content_(web_content) {}
+
+ // We do this so we can be used in a Callback.
Jamie 2014/12/18 21:31:44 If you're sure that the reference to this object w
+ void AddRef() {}
+ void Release() {}
+
+ // Helper to execute a JavaScript code snippet and extract the boolean result.
+ static bool ExecuteScriptAndExtractBool(content::WebContents* web_contents,
+ const std::string& script);
+
+ // Helper to execute a JavaScript code snippet and extract the int result.
+ static int ExecuteScriptAndExtractInt(content::WebContents* web_contents,
+ const std::string& script);
+
+ // Helper to execute a JavaScript code snippet and extract the string result.
+ static std::string ExecuteScriptAndExtractString(
+ content::WebContents* web_contents, const std::string& script);
+
+ // Helper method to set the clear the last event
+ void ClearLastEvent();
+
+ // Helper method to get the last event
+ void GetLastEvent(Event* event);
+
+ // Execute an RPC call
+ void ExecuteRpc(const std::string& method) {
+ ExecuteRpc(method,
+ base::TimeDelta::FromSeconds(2),
+ base::TimeDelta::FromMilliseconds(500));
+ }
+ void ExecuteRpc(const std::string& method,
+ base::TimeDelta timeout,
+ base::TimeDelta interval);
+
+ private:
+ content::WebContents* web_content_;
+
+ // Check for a valid last event
+ bool IsValidEvent();
+
+ DISALLOW_COPY_AND_ASSIGN(RemoteTestHelper);
+};
+
+} // namespace remoting
+
+#endif // CHROME_TEST_REMOTING_REMOTE_TEST_HELPER_H_

Powered by Google App Engine
This is Rietveld 408576698