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

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

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.cc
diff --git a/chrome/test/remoting/remote_test_helper.cc b/chrome/test/remoting/remote_test_helper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c647271046309fb46eb3dee3eb053de47fdba657
--- /dev/null
+++ b/chrome/test/remoting/remote_test_helper.cc
@@ -0,0 +1,105 @@
+// 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.
+
+#include "chrome/test/remoting/remote_test_helper.h"
+
+#include "base/bind.h"
+#include "chrome/test/remoting/waiter.h"
+
+namespace remoting {
+
+// static
+bool RemoteTestHelper::ExecuteScriptAndExtractBool(
+ content::WebContents* web_contents, const std::string& script) {
+ bool result;
+ EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
+ web_contents,
+ "window.domAutomationController.send(" + script + ");",
+ &result));
+
+ return result;
+}
+
+// static
+int RemoteTestHelper::ExecuteScriptAndExtractInt(
+ content::WebContents* web_contents, const std::string& script) {
+ int result;
+ _ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
+ web_contents,
+ "window.domAutomationController.send(" + script + ");",
+ &result));
+
+ return result;
+}
+
+// static
+std::string RemoteTestHelper::ExecuteScriptAndExtractString(
+ content::WebContents* web_contents, const std::string& script) {
+ std::string result;
+ _ASSERT_TRUE(content::ExecuteScriptAndExtractString(
+ web_contents,
+ "window.domAutomationController.send(" + script + ");",
+ &result));
+
+ return result;
+}
+
+void RemoteTestHelper::ExecuteRpc(const std::string& method,
+ base::TimeDelta timeout,
+ base::TimeDelta interval) {
+ ASSERT_TRUE(
+ content::ExecuteScript(
+ web_content_,
+ "jsonRpc.responseObject = null"));
+ ASSERT_TRUE(
+ content::ExecuteScript(web_content_, method));
+ // Wait until the client tab sets the right variables
+ ConditionalTimeoutWaiter waiter(
+ timeout,
+ interval,
+ base::Bind(
+ &RemoteTestHelper::ExecuteScriptAndExtractBool,
+ web_content_,
+ "jsonRpc.responseObject != null"));
+ EXPECT_TRUE(waiter.Wait());
+}
+
+void RemoteTestHelper::ClearLastEvent() {
+ ExecuteRpc("jsonRpc.clearLastEvent();");
+}
+
+bool RemoteTestHelper::IsValidEvent() {
+ // Reset the response
+ EXPECT_TRUE(content::ExecuteScript(
+ web_content_, "jsonRpc.responseObject = null"));
+ // Call GetLastEvent on the server
+ ExecuteRpc("jsonRpc.getLastEvent()",
+ base::TimeDelta::FromMilliseconds(250),
+ base::TimeDelta::FromMilliseconds(50));
+ return ExecuteScriptAndExtractBool(web_content_,
+ "jsonRpc.responseObject.action != 0");
+}
+
+void RemoteTestHelper::GetLastEvent(Event* event) {
+ // Wait for a valid event
+ ConditionalTimeoutWaiter waiter(
+ base::TimeDelta::FromSeconds(2),
+ base::TimeDelta::FromMilliseconds(500),
+ base::Bind(&RemoteTestHelper::IsValidEvent, this));
+ EXPECT_TRUE(waiter.Wait());
+
+ // Extract the event's values
+ event->action = static_cast<Action>(
+ ExecuteScriptAndExtractInt(
+ web_content_,
+ "jsonRpc.responseObject.action"));
+ event->value = ExecuteScriptAndExtractInt(
+ web_content_,
+ "jsonRpc.responseObject.value");
+ event->modifiers = ExecuteScriptAndExtractInt(
+ web_content_,
+ "jsonRpc.responseObject.modifiers");
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698