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

Side by Side 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 unified diff | Download patch
OLDNEW
(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 #include "chrome/test/remoting/remote_test_helper.h"
6
7 #include "base/bind.h"
8 #include "chrome/test/remoting/waiter.h"
9
10 namespace remoting {
11
12 // static
13 bool RemoteTestHelper::ExecuteScriptAndExtractBool(
14 content::WebContents* web_contents, const std::string& script) {
15 bool result;
16 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
17 web_contents,
18 "window.domAutomationController.send(" + script + ");",
19 &result));
20
21 return result;
22 }
23
24 // static
25 int RemoteTestHelper::ExecuteScriptAndExtractInt(
26 content::WebContents* web_contents, const std::string& script) {
27 int result;
28 _ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
29 web_contents,
30 "window.domAutomationController.send(" + script + ");",
31 &result));
32
33 return result;
34 }
35
36 // static
37 std::string RemoteTestHelper::ExecuteScriptAndExtractString(
38 content::WebContents* web_contents, const std::string& script) {
39 std::string result;
40 _ASSERT_TRUE(content::ExecuteScriptAndExtractString(
41 web_contents,
42 "window.domAutomationController.send(" + script + ");",
43 &result));
44
45 return result;
46 }
47
48 void RemoteTestHelper::ExecuteRpc(const std::string& method,
49 base::TimeDelta timeout,
50 base::TimeDelta interval) {
51 ASSERT_TRUE(
52 content::ExecuteScript(
53 web_content_,
54 "jsonRpc.responseObject = null"));
55 ASSERT_TRUE(
56 content::ExecuteScript(web_content_, method));
57 // Wait until the client tab sets the right variables
58 ConditionalTimeoutWaiter waiter(
59 timeout,
60 interval,
61 base::Bind(
62 &RemoteTestHelper::ExecuteScriptAndExtractBool,
63 web_content_,
64 "jsonRpc.responseObject != null"));
65 EXPECT_TRUE(waiter.Wait());
66 }
67
68 void RemoteTestHelper::ClearLastEvent() {
69 ExecuteRpc("jsonRpc.clearLastEvent();");
70 }
71
72 bool RemoteTestHelper::IsValidEvent() {
73 // Reset the response
74 EXPECT_TRUE(content::ExecuteScript(
75 web_content_, "jsonRpc.responseObject = null"));
76 // Call GetLastEvent on the server
77 ExecuteRpc("jsonRpc.getLastEvent()",
78 base::TimeDelta::FromMilliseconds(250),
79 base::TimeDelta::FromMilliseconds(50));
80 return ExecuteScriptAndExtractBool(web_content_,
81 "jsonRpc.responseObject.action != 0");
82 }
83
84 void RemoteTestHelper::GetLastEvent(Event* event) {
85 // Wait for a valid event
86 ConditionalTimeoutWaiter waiter(
87 base::TimeDelta::FromSeconds(2),
88 base::TimeDelta::FromMilliseconds(500),
89 base::Bind(&RemoteTestHelper::IsValidEvent, this));
90 EXPECT_TRUE(waiter.Wait());
91
92 // Extract the event's values
93 event->action = static_cast<Action>(
94 ExecuteScriptAndExtractInt(
95 web_content_,
96 "jsonRpc.responseObject.action"));
97 event->value = ExecuteScriptAndExtractInt(
98 web_content_,
99 "jsonRpc.responseObject.value");
100 event->modifiers = ExecuteScriptAndExtractInt(
101 web_content_,
102 "jsonRpc.responseObject.modifiers");
103 }
104
105 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698