OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 /** | |
6 * @fileoverview | |
7 * Unit tests for host_controller.js. | |
8 */ | |
9 | |
10 (function() { | |
11 | |
12 'use strict'; | |
13 | |
14 var FAKE_HOST_ID = '0bad0bad-0bad-0bad-0bad-0bad0bad0bad'; | |
15 var FAKE_HOST_NAME = '<FAKE_HOST_NAME>'; | |
16 var FAKE_PUBLIC_KEY = '<FAKE_PUBLIC_KEY>'; | |
17 var FAKE_HOST_CLIENT_ID = '<FAKE_HOST_CLIENT_ID>'; | |
18 var FAKE_AUTH_CODE = '<FAKE_AUTH_CODE>'; | |
19 | |
20 QUnit.module('host_list_api_impl', { | |
21 beforeEach: function(/** QUnit.Assert */ assert) { | |
22 remoting.settings = new remoting.Settings(); | |
23 remoting.MockXhr.activate(); | |
24 }, | |
25 afterEach: function(/** QUnit.Assert */ assert) { | |
26 remoting.MockXhr.restore(); | |
27 remoting.settings = null; | |
28 } | |
29 }); | |
30 | |
31 /** | |
32 * Install an HTTP response for requests to the registry. | |
33 * @param {QUnit.Assert} assert | |
34 */ | |
35 function queueRegistryResponse(assert) { | |
36 var responseJson = { | |
37 data: { | |
38 authorizationCode: FAKE_AUTH_CODE | |
39 } | |
40 }; | |
41 | |
42 remoting.MockXhr.setResponseFor( | |
43 'POST', 'DIRECTORY_API_BASE_URL/@me/hosts', | |
44 function(/** remoting.MockXhr */ xhr) { | |
45 assert.deepEqual( | |
46 xhr.params.jsonContent, | |
47 { data: { | |
48 hostId: FAKE_HOST_ID, | |
49 hostName: FAKE_HOST_NAME, | |
50 publicKey: FAKE_PUBLIC_KEY | |
51 } }); | |
52 xhr.setJsonResponse(200, responseJson); | |
53 }); | |
54 } | |
55 | |
56 QUnit.test('register', function(assert) { | |
57 var impl = new remoting.HostListApiImpl(); | |
58 queueRegistryResponse(assert); | |
59 return impl.register( | |
60 FAKE_HOST_ID, | |
61 FAKE_HOST_NAME, | |
62 FAKE_PUBLIC_KEY, | |
63 FAKE_HOST_CLIENT_ID | |
64 ). then(function(regResult) { | |
65 assert.equal(regResult.authCode, FAKE_AUTH_CODE); | |
66 assert.equal(regResult.email, ''); | |
67 }); | |
68 }); | |
69 | |
70 QUnit.test('register failure', function(assert) { | |
71 var impl = new remoting.HostListApiImpl(); | |
72 remoting.MockXhr.setEmptyResponseFor( | |
73 'POST', 'DIRECTORY_API_BASE_URL/@me/hosts', 500); | |
74 return impl.register( | |
75 FAKE_HOST_ID, | |
76 FAKE_HOST_NAME, | |
77 FAKE_PUBLIC_KEY, | |
78 FAKE_HOST_CLIENT_ID | |
79 ).then(function(authCode) { | |
80 throw 'test failed'; | |
81 }, function(/** remoting.Error */ e) { | |
82 assert.equal(e.getTag(), remoting.Error.Tag.REGISTRATION_FAILED); | |
83 }); | |
84 }); | |
85 | |
86 })(); | |
OLD | NEW |