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

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: 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 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace remoting {
12
13 // static
14 bool RemoteTestHelper::ExecuteScriptAndExtractBool(
15 content::WebContents* web_content, const std::string& script) {
16 bool result;
17 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
18 web_content,
19 "window.domAutomationController.send(" + script + ");",
20 &result));
21
22 return result;
23 }
24
25 // static
26 int RemoteTestHelper::ExecuteScriptAndExtractInt(
27 content::WebContents* web_content, const std::string& script) {
28 int result;
29 EXPECT_TRUE(content::ExecuteScriptAndExtractInt(
30 web_content,
31 "window.domAutomationController.send(" + script + ");",
32 &result));
33
34 return result;
35 }
36
37 // Static
38 void RemoteTestHelper::ExecuteRpc(
39 content::WebContents* web_content,
Jamie 2014/12/17 03:15:40 Nit: Line-wrap for these parameters looks odd. I t
Mike Meade 2014/12/18 18:54:24 Done.
40 const std::string& method,
41 int timeout_secs,
42 int poll_ms) {
43 ASSERT_TRUE(
44 content::ExecuteScript(
45 web_content,
46 "jsonRpc.responseObject = null"));
47 ASSERT_TRUE(
48 content::ExecuteScript(web_content, method));
49 // Wait until the client tab sets the right variables
50 ConditionalTimeoutWaiter waiter(
51 base::TimeDelta::FromSeconds(timeout_secs),
52 base::TimeDelta::FromMilliseconds(poll_ms),
53 base::Bind(&ExecuteScriptAndExtractBool,
54 web_content,
55 "jsonRpc.responseObject != null"));
56 EXPECT_TRUE(waiter.Wait());
57 }
58
59 // static
60 void RemoteTestHelper::ClearLastEvent(content::WebContents* web_content) {
61 ExecuteRpc(web_content, "jsonRpc.clearLastEvent();");
62 }
63
64 // static
65 bool RemoteTestHelper::CheckForLastEvent(content::WebContents* web_content) {
66 // Reset the response
67 EXPECT_TRUE(content::ExecuteScript(
68 web_content, "jsonRpc.responseObject = null"));
69 // Call GetLastEvent on the server
70 ExecuteRpc(web_content, "jsonRpc.getLastEvent()", 250, 50);
71 return ExecuteScriptAndExtractBool(web_content,
72 "jsonRpc.responseObject.action != 0");
73 }
74
75 // static
76 void RemoteTestHelper::GetLastEvent(
77 content::WebContents* web_content,
78 Event& event) {
79 // Wait for a valid event
80 ConditionalTimeoutWaiter waiter(
81 base::TimeDelta::FromSeconds(2),
82 base::TimeDelta::FromMilliseconds(500),
83 base::Bind(&CheckForLastEvent,
84 web_content));
85 EXPECT_TRUE(waiter.Wait());
86
87 // Extract the event's values
88 event.action = static_cast<Action>(
89 ExecuteScriptAndExtractInt(
90 web_content,
91 "jsonRpc.responseObject.action"));
92 event.value = ExecuteScriptAndExtractInt(
93 web_content,
94 "jsonRpc.responseObject.value");
95 event.modifiers = ExecuteScriptAndExtractInt(
96 web_content,
97 "jsonRpc.responseObject.modifiers");
98 }
99 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698