| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 * @suppress {checkTypes|checkVars|reportUnknownTypes|visibility} | |
| 8 */ | 7 */ |
| 9 | 8 |
| 10 (function() { | 9 (function() { |
| 11 | 10 |
| 12 'use strict'; | 11 'use strict'; |
| 13 | 12 |
| 14 /** @type {sinon.TestStub} */ | 13 /** @type {sinon.TestStub} */ |
| 15 var mockIsAppsV2 = null; | 14 var mockIsAppsV2 = null; |
| 16 var mockChromeStorage = {}; | 15 var mockChromeStorage = {}; |
| 17 | 16 |
| 18 function pass() { | |
| 19 ok(true); | |
| 20 QUnit.start(); | |
| 21 } | |
| 22 | |
| 23 function fail() { | |
| 24 ok(false); | |
| 25 QUnit.start(); | |
| 26 } | |
| 27 | |
| 28 /** | 17 /** |
| 29 * @param {string} v1UserName | 18 * @param {string} v1UserName |
| 30 * @param {string} v1UserEmail | 19 * @param {string} v1UserEmail |
| 31 * @param {boolean} v1HasHosts | 20 * @param {boolean} v1HasHosts |
| 32 */ | 21 */ |
| 33 function setMigrationData_(v1UserName, v1UserEmail, v1HasHosts) { | 22 function setMigrationData_(v1UserName, v1UserEmail, v1HasHosts) { |
| 34 /** @return {!Promise} */ | 23 /** @return {!Promise} */ |
| 35 remoting.identity.getUserInfo = function() { | 24 remoting.identity.getUserInfo = function() { |
| 36 if (base.isAppsV2()) { | 25 if (base.isAppsV2()) { |
| 37 return Promise.resolve( | 26 return Promise.resolve( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 49 return info.email; | 38 return info.email; |
| 50 }); | 39 }); |
| 51 }; | 40 }; |
| 52 | 41 |
| 53 mockIsAppsV2.returns(false); | 42 mockIsAppsV2.returns(false); |
| 54 if (v1HasHosts) { | 43 if (v1HasHosts) { |
| 55 remoting.AppsV2Migration.saveUserInfo(); | 44 remoting.AppsV2Migration.saveUserInfo(); |
| 56 } | 45 } |
| 57 } | 46 } |
| 58 | 47 |
| 59 module('AppsV2Migration', { | 48 QUnit.module('AppsV2Migration', { |
| 60 setup: function() { | 49 beforeEach: function() { |
| 61 chromeMocks.activate(['storage']); | 50 chromeMocks.activate(['storage']); |
| 62 mockIsAppsV2 = sinon.stub(base, 'isAppsV2'); | 51 mockIsAppsV2 = sinon.stub(base, 'isAppsV2'); |
| 63 remoting.identity = new remoting.Identity(); | 52 remoting.identity = new remoting.Identity(); |
| 64 }, | 53 }, |
| 65 teardown: function() { | 54 afterEach: function() { |
| 66 chromeMocks.restore(); | 55 chromeMocks.restore(); |
| 67 mockIsAppsV2.restore(); | 56 mockIsAppsV2.restore(); |
| 68 remoting.identity = null; | 57 remoting.identity = null; |
| 69 } | 58 } |
| 70 }); | 59 }); |
| 71 | 60 |
| 72 QUnit.asyncTest( | 61 QUnit.test( |
| 73 'hasHostsInV1App() should reject the promise if v1 user has same identity', | 62 'hasHostsInV1App() should reject the promise if v1 user has same identity', |
| 74 function() { | 63 function(assert) { |
| 64 assert.expect(0); |
| 75 setMigrationData_('v1userName', 'v2user@gmail.com', true); | 65 setMigrationData_('v1userName', 'v2user@gmail.com', true); |
| 76 mockIsAppsV2.returns(true); | 66 mockIsAppsV2.returns(true); |
| 77 remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass); | 67 return base.Promise.negate(remoting.AppsV2Migration.hasHostsInV1App()); |
| 78 }); | 68 }); |
| 79 | 69 |
| 80 QUnit.asyncTest( | 70 QUnit.test( |
| 81 'hasHostsInV1App() should reject the promise if v1 user has no hosts', | 71 'hasHostsInV1App() should reject the promise if v1 user has no hosts', |
| 82 function() { | 72 function(assert) { |
| 73 assert.expect(0); |
| 83 setMigrationData_('v1userName', 'v1user@gmail.com', false); | 74 setMigrationData_('v1userName', 'v1user@gmail.com', false); |
| 84 mockIsAppsV2.returns(true); | 75 mockIsAppsV2.returns(true); |
| 85 remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass); | 76 return base.Promise.negate(remoting.AppsV2Migration.hasHostsInV1App()); |
| 86 }); | 77 }); |
| 87 | 78 |
| 88 QUnit.asyncTest( | 79 QUnit.test('hasHostsInV1App() should reject the promise in v1', |
| 89 'hasHostsInV1App() should reject the promise in v1', function() { | 80 function(assert) { |
| 90 setMigrationData_('v1userName', 'v1user@gmail.com', true); | 81 assert.expect(0); |
| 91 mockIsAppsV2.returns(false); | 82 setMigrationData_('v1userName', 'v1user@gmail.com', true); |
| 92 remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass); | 83 mockIsAppsV2.returns(false); |
| 84 return base.Promise.negate(remoting.AppsV2Migration.hasHostsInV1App()); |
| 93 }); | 85 }); |
| 94 | 86 |
| 95 QUnit.asyncTest( | 87 QUnit.test( |
| 96 'hasHostsInV1App() should return v1 identity if v1 user has hosts', | 88 'hasHostsInV1App() should return v1 identity if v1 user has hosts', |
| 97 function() { | 89 function(assert) { |
| 98 setMigrationData_('v1userName', 'v1user@gmail.com', true); | 90 setMigrationData_('v1userName', 'v1user@gmail.com', true); |
| 99 mockIsAppsV2.returns(true); | 91 mockIsAppsV2.returns(true); |
| 100 remoting.AppsV2Migration.hasHostsInV1App().then( | 92 return remoting.AppsV2Migration.hasHostsInV1App().then( |
| 101 /** @param {{email:string, name:string}} result */ | 93 function(/** {email:string, fullName:string} */ result) { |
| 102 function(result) { | 94 assert.equal(result.email, 'v1user@gmail.com'); |
| 103 QUnit.equal(result.email, 'v1user@gmail.com'); | 95 assert.equal(result.fullName, 'v1userName'); |
| 104 QUnit.equal(result.fullName, 'v1userName'); | 96 }); |
| 105 pass(); | |
| 106 }, fail | |
| 107 ); | |
| 108 }); | 97 }); |
| 109 | 98 |
| 110 QUnit.asyncTest( | 99 QUnit.test( |
| 111 'saveUserInfo() should clear the preferences on v2', | 100 'saveUserInfo() should clear the preferences on v2', |
| 112 function() { | 101 function(assert) { |
| 102 assert.expect(0); |
| 113 setMigrationData_('v1userName', 'v1user@gmail.com', true); | 103 setMigrationData_('v1userName', 'v1user@gmail.com', true); |
| 114 mockIsAppsV2.returns(true); | 104 mockIsAppsV2.returns(true); |
| 115 remoting.AppsV2Migration.saveUserInfo(); | 105 remoting.AppsV2Migration.saveUserInfo(); |
| 116 remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass); | 106 return base.Promise.negate(remoting.AppsV2Migration.hasHostsInV1App()); |
| 117 }); | 107 }); |
| 118 | 108 |
| 119 })(); | 109 })(); |
| OLD | NEW |