OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview | 6 * @fileoverview |
7 * Unit tests for host_controller.js. | 7 * Unit tests for host_controller.js. |
8 */ | 8 */ |
9 | 9 |
10 (function() { | 10 (function() { |
(...skipping 13 matching lines...) Expand all Loading... |
24 }, | 24 }, |
25 afterEach: function(/** QUnit.Assert */ assert) { | 25 afterEach: function(/** QUnit.Assert */ assert) { |
26 remoting.MockXhr.restore(); | 26 remoting.MockXhr.restore(); |
27 remoting.settings = null; | 27 remoting.settings = null; |
28 } | 28 } |
29 }); | 29 }); |
30 | 30 |
31 /** | 31 /** |
32 * Install an HTTP response for requests to the registry. | 32 * Install an HTTP response for requests to the registry. |
33 * @param {QUnit.Assert} assert | 33 * @param {QUnit.Assert} assert |
34 * @param {boolean} withAuthCode | |
35 */ | 34 */ |
36 function queueRegistryResponse(assert, withAuthCode) { | 35 function queueRegistryResponse(assert) { |
37 var responseJson = { | 36 var responseJson = { |
38 data: { | 37 data: { |
39 authorizationCode: FAKE_AUTH_CODE | 38 authorizationCode: FAKE_AUTH_CODE |
40 } | 39 } |
41 }; | 40 }; |
42 if (!withAuthCode) { | |
43 delete responseJson.data.authorizationCode; | |
44 } | |
45 | 41 |
46 remoting.MockXhr.setResponseFor( | 42 remoting.MockXhr.setResponseFor( |
47 'POST', 'DIRECTORY_API_BASE_URL/@me/hosts', | 43 'POST', 'DIRECTORY_API_BASE_URL/@me/hosts', |
48 function(/** remoting.MockXhr */ xhr) { | 44 function(/** remoting.MockXhr */ xhr) { |
49 assert.deepEqual( | 45 assert.deepEqual( |
50 xhr.params.jsonContent, | 46 xhr.params.jsonContent, |
51 { data: { | 47 { data: { |
52 hostId: FAKE_HOST_ID, | 48 hostId: FAKE_HOST_ID, |
53 hostName: FAKE_HOST_NAME, | 49 hostName: FAKE_HOST_NAME, |
54 publicKey: FAKE_PUBLIC_KEY | 50 publicKey: FAKE_PUBLIC_KEY |
55 } }); | 51 } }); |
56 xhr.setJsonResponse(200, responseJson); | 52 xhr.setJsonResponse(200, responseJson); |
57 }); | 53 }); |
58 } | 54 } |
59 | 55 |
60 QUnit.test('register with auth code', function(assert) { | 56 QUnit.test('register', function(assert) { |
61 var impl = new remoting.HostListApiImpl(); | 57 var impl = new remoting.HostListApiImpl(); |
62 queueRegistryResponse(assert, true); | 58 queueRegistryResponse(assert); |
63 return impl.register( | 59 return impl.register( |
64 FAKE_HOST_ID, | 60 FAKE_HOST_ID, |
65 FAKE_HOST_NAME, | 61 FAKE_HOST_NAME, |
66 FAKE_PUBLIC_KEY, | 62 FAKE_PUBLIC_KEY, |
67 FAKE_HOST_CLIENT_ID | 63 FAKE_HOST_CLIENT_ID |
68 ). then(function(authCode) { | 64 ). then(function(regResult) { |
69 assert.equal(authCode, FAKE_AUTH_CODE); | 65 assert.equal(regResult.authCode, FAKE_AUTH_CODE); |
| 66 assert.equal(regResult.email, ''); |
70 }); | 67 }); |
71 }); | 68 }); |
72 | 69 |
73 QUnit.test('register without auth code', function(assert) { | |
74 var impl = new remoting.HostListApiImpl(); | |
75 queueRegistryResponse(assert, false); | |
76 return impl.register( | |
77 FAKE_HOST_ID, | |
78 FAKE_HOST_NAME, | |
79 FAKE_PUBLIC_KEY, | |
80 FAKE_HOST_CLIENT_ID | |
81 ). then(function(authCode) { | |
82 assert.equal(authCode, ''); | |
83 }); | |
84 }); | |
85 | |
86 QUnit.test('register failure', function(assert) { | 70 QUnit.test('register failure', function(assert) { |
87 var impl = new remoting.HostListApiImpl(); | 71 var impl = new remoting.HostListApiImpl(); |
88 remoting.MockXhr.setEmptyResponseFor( | 72 remoting.MockXhr.setEmptyResponseFor( |
89 'POST', 'DIRECTORY_API_BASE_URL/@me/hosts', 500); | 73 'POST', 'DIRECTORY_API_BASE_URL/@me/hosts', 500); |
90 return impl.register( | 74 return impl.register( |
91 FAKE_HOST_ID, | 75 FAKE_HOST_ID, |
92 FAKE_HOST_NAME, | 76 FAKE_HOST_NAME, |
93 FAKE_PUBLIC_KEY, | 77 FAKE_PUBLIC_KEY, |
94 FAKE_HOST_CLIENT_ID | 78 FAKE_HOST_CLIENT_ID |
95 ).then(function(authCode) { | 79 ).then(function(authCode) { |
96 throw 'test failed'; | 80 throw 'test failed'; |
97 }, function(/** remoting.Error */ e) { | 81 }, function(/** remoting.Error */ e) { |
98 assert.equal(e.getTag(), remoting.Error.Tag.REGISTRATION_FAILED); | 82 assert.equal(e.getTag(), remoting.Error.Tag.REGISTRATION_FAILED); |
99 }); | 83 }); |
100 }); | 84 }); |
101 | 85 |
102 })(); | 86 })(); |
OLD | NEW |