Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 Event::Event() : action(Action::NONE), value(0), modifiers(0) {} | |
| 13 | |
| 14 RemoteTestHelper::RemoteTestHelper(content::WebContents* web_content) | |
| 15 :web_content_(web_content) {} | |
|
Jamie
2015/01/06 19:31:38
Nit: indentation.
Mike Meade
2015/01/08 18:58:42
Done.
| |
| 16 | |
| 17 // static | |
| 18 bool RemoteTestHelper::ExecuteScriptAndExtractBool( | |
| 19 content::WebContents* web_contents, const std::string& script) { | |
| 20 bool result; | |
| 21 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 22 web_contents, | |
| 23 "window.domAutomationController.send(" + script + ");", | |
| 24 &result)); | |
| 25 | |
| 26 return result; | |
| 27 } | |
| 28 | |
| 29 // static | |
| 30 int RemoteTestHelper::ExecuteScriptAndExtractInt( | |
| 31 content::WebContents* web_contents, const std::string& script) { | |
| 32 int result; | |
| 33 _ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | |
| 34 web_contents, | |
| 35 "window.domAutomationController.send(" + script + ");", | |
| 36 &result)); | |
| 37 | |
| 38 return result; | |
| 39 } | |
| 40 | |
| 41 // static | |
| 42 std::string RemoteTestHelper::ExecuteScriptAndExtractString( | |
| 43 content::WebContents* web_contents, const std::string& script) { | |
| 44 std::string result; | |
| 45 _ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
| 46 web_contents, | |
| 47 "window.domAutomationController.send(" + script + ");", | |
| 48 &result)); | |
| 49 | |
| 50 return result; | |
| 51 } | |
| 52 | |
| 53 void RemoteTestHelper::ExecuteRpc(const std::string& method, | |
| 54 base::TimeDelta timeout, | |
| 55 base::TimeDelta interval) { | |
| 56 ASSERT_TRUE( | |
| 57 content::ExecuteScript( | |
|
Jamie
2015/01/06 19:31:39
This indentation is inconsistent with the _ASSERT_
Mike Meade
2015/01/08 18:58:42
Done.
| |
| 58 web_content_, | |
| 59 "jsonRpc.responseObject = null")); | |
| 60 ASSERT_TRUE( | |
| 61 content::ExecuteScript(web_content_, method)); | |
| 62 // Wait until the client tab sets the right variables | |
|
Jamie
2015/01/06 19:31:38
This comment is a bit vague. If I'm reading the co
Mike Meade
2015/01/08 18:58:42
Done.
| |
| 63 ConditionalTimeoutWaiter waiter( | |
| 64 timeout, | |
|
Jamie
2015/01/06 19:31:38
Nit: Indentation.
Mike Meade
2015/01/08 18:58:42
Done.
| |
| 65 interval, | |
| 66 base::Bind( | |
| 67 &RemoteTestHelper::ExecuteScriptAndExtractBool, | |
| 68 web_content_, | |
| 69 "jsonRpc.responseObject != null")); | |
| 70 EXPECT_TRUE(waiter.Wait()); | |
| 71 } | |
| 72 | |
| 73 void RemoteTestHelper::ClearLastEvent() { | |
| 74 ExecuteRpc("jsonRpc.clearLastEvent();"); | |
| 75 } | |
| 76 | |
| 77 bool RemoteTestHelper::IsValidEvent() { | |
| 78 // Reset the response | |
| 79 EXPECT_TRUE(content::ExecuteScript( | |
| 80 web_content_, "jsonRpc.responseObject = null")); | |
|
Jamie
2015/01/06 19:31:39
ExecuteRpc already does this, so you don't need th
Mike Meade
2015/01/08 18:58:42
Done.
| |
| 81 // Call GetLastEvent on the server | |
| 82 ExecuteRpc("jsonRpc.getLastEvent()", | |
| 83 base::TimeDelta::FromMilliseconds(250), | |
| 84 base::TimeDelta::FromMilliseconds(50)); | |
| 85 return ExecuteScriptAndExtractBool(web_content_, | |
| 86 "jsonRpc.responseObject.action != 0"); | |
| 87 } | |
| 88 | |
| 89 void RemoteTestHelper::GetLastEvent(Event* event) { | |
| 90 // Wait for a valid event | |
| 91 ConditionalTimeoutWaiter waiter( | |
| 92 base::TimeDelta::FromSeconds(2), | |
|
Jamie
2015/01/06 19:31:39
Indentation.
Mike Meade
2015/01/08 18:58:42
Done.
| |
| 93 base::TimeDelta::FromMilliseconds(500), | |
| 94 base::Bind(&RemoteTestHelper::IsValidEvent, | |
| 95 base::Unretained(this))); | |
| 96 EXPECT_TRUE(waiter.Wait()); | |
| 97 | |
| 98 // Extract the event's values | |
| 99 event->action = static_cast<Action>( | |
| 100 ExecuteScriptAndExtractInt( | |
| 101 web_content_, | |
| 102 "jsonRpc.responseObject.action")); | |
| 103 event->value = ExecuteScriptAndExtractInt( | |
| 104 web_content_, | |
| 105 "jsonRpc.responseObject.value"); | |
| 106 event->modifiers = ExecuteScriptAndExtractInt( | |
| 107 web_content_, | |
| 108 "jsonRpc.responseObject.modifiers"); | |
| 109 } | |
| 110 | |
| 111 } // namespace remoting | |
| OLD | NEW |