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

Side by Side Diff: remoting/tools/remote_test_helper/jsonrpc.js

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 (c) 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 var jsonRpc = {};
6 jsonRpc.responseObject = null;
7
8 jsonRpc.setLastEvent = function(action, value, modifiers) {
9 var request = jsonRpc.generateJsonRpcRequest(
10 'SetLastEvent', [action, value, modifiers]);
11 return jsonRpc.sendRpcRequest(request);
12 }
13
14 jsonRpc.getLastEvent = function() {
15 var request = jsonRpc.generateJsonRpcRequest('GetLastEvent', []);
16 return jsonRpc.sendRpcRequest(request);
17 }
18
19 jsonRpc.clearLastEvent = function() {
20 var request = jsonRpc.generateJsonRpcRequest('ClearLastEvent', []);
21 return jsonRpc.sendRpcRequest(request);
22 }
23
24 /**
25 * Generate the JSON request.
26 * @param {string} methodname The name of the remote method.
27 * @param {list} params The method parameters to pass.
28 * @param {integer} ident The request id.
29 * @return The JSON-RPC request object
30 **/
31 jsonRpc.generateJsonRpcRequest = function(methodname, params, ident) {
32 ident = ident == undefined ? '...' : ident;
33 var request = {
34 "jsonrpc": "2.0",
35 "method": methodname,
36 "params": params,
37 "id": ident
38 };
39 return request;
40 }
41
42 /**
43 * Method to POST the request to the RPC server.
44 * @param {object} json_request The JSON request object.
45 **/
46 jsonRpc.sendRpcRequest = function(json_request) {
47 var xhr = new XMLHttpRequest();
48 xhr.open('POST', '/RPC2', true);
49 xhr.onreadystatechange = function () {
50 if (xhr.readyState == 4 && xhr.status == 200) {
51 // console.log('Response text: ' + xhr.responseText);
Jamie 2014/12/17 03:15:41 Remove, or reinstate.
Mike Meade 2014/12/18 18:54:25 Done.
52 try {
53 var response = xhr.responseText;
54 jsonRpc.responseObject = JSON.parse(response).response;
55 } catch (err) {
56 console.log('Could not parse server response.');
Jamie 2014/12/17 03:15:41 console.error?
Mike Meade 2014/12/18 18:54:25 Done.
57 return;
58 }
59 }
60 }
61 string_request = JSON.stringify(json_request);
62 // console.log('Request text: ' + string_request);
63 xhr.send(string_request);
64 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698