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

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: Fixing comments and merge issues. Created 5 years, 11 months 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.
Jamie 2015/01/08 20:34:37 {integer} is not a valid type annotation. I think
Mike Meade 2015/01/12 18:04:26 I fixed this to be {number=} and assigned a defaul
29 * @return The JSON-RPC request object
30 **/
31 jsonRpc.generateJsonRpcRequest = function(methodname, params, ident) {
32 ident = ident == undefined ? '...' : ident;
Jamie 2015/01/06 19:31:39 Why is this needed? Under what circumstances will
Mike Meade 2015/01/08 18:58:42 I wrote this to be a general library module for an
Jamie 2015/01/08 20:34:37 I think the problem I have with it is that you've
Mike Meade 2015/01/12 18:04:26 Done.
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) {
Jamie 2015/01/06 19:31:39 I think it would be better to clear the responseOb
Mike Meade 2015/01/08 18:58:42 Done.
47 var xhr = new XMLHttpRequest();
48 xhr.open('POST', '/RPC2', true);
49 xhr.onreadystatechange = function () {
50 if (xhr.readyState == 4 && xhr.status == 200) {
51 try {
52 var response = xhr.responseText;
53 jsonRpc.responseObject = JSON.parse(response).response;
54 } catch (err) {
55 console.error('Could not parse server response.');
56 return;
57 }
58 }
59 }
60 string_request = JSON.stringify(json_request);
61 xhr.send(string_request);
62 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698