| 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 (function() { | 5 (function() { |
| 6 | 6 |
| 7 'use strict'; | 7 'use strict'; |
| 8 | 8 |
| 9 /** @type {sinon.$testStub} */ |
| 9 var mockIsAppsV2 = null; | 10 var mockIsAppsV2 = null; |
| 10 var mockChromeStorage = {}; | 11 var mockChromeStorage = {}; |
| 11 | 12 |
| 12 function pass() { | 13 function pass() { |
| 13 ok(true); | 14 ok(true); |
| 14 QUnit.start(); | 15 QUnit.start(); |
| 15 } | 16 } |
| 16 | 17 |
| 17 function fail() { | 18 function fail() { |
| 18 ok(false); | 19 ok(false); |
| 19 QUnit.start(); | 20 QUnit.start(); |
| 20 } | 21 } |
| 21 | 22 |
| 22 /** | 23 /** |
| 23 * @param {string} v1UserName | 24 * @param {string} v1UserName |
| 24 * @param {string} v1UserEmail | 25 * @param {string} v1UserEmail |
| 25 * @param {string} currentEmail | 26 * @param {boolean} v1HasHosts |
| 26 * @param {boolean} v1HasHost | |
| 27 */ | 27 */ |
| 28 function setMigrationData_(v1UserName, v1UserEmail, v1HasHosts) { | 28 function setMigrationData_(v1UserName, v1UserEmail, v1HasHosts) { |
| 29 /** |
| 30 * @param {function(string,string):void} onDone |
| 31 * @param {function(remoting.Error):void} onError |
| 32 */ |
| 29 remoting.identity.getUserInfo = function(onDone, onError) { | 33 remoting.identity.getUserInfo = function(onDone, onError) { |
| 30 if (base.isAppsV2()) { | 34 if (base.isAppsV2()) { |
| 31 onDone('v2user@gmail.com','v2userName'); | 35 onDone('v2user@gmail.com','v2userName'); |
| 32 } else { | 36 } else { |
| 33 onDone(v1UserEmail, v1UserName); | 37 onDone(v1UserEmail, v1UserName); |
| 34 } | 38 } |
| 35 }; | 39 }; |
| 36 | 40 |
| 37 mockIsAppsV2.returns(false); | 41 mockIsAppsV2.returns(false); |
| 38 if (v1HasHosts) { | 42 if (v1HasHosts) { |
| 39 remoting.AppsV2Migration.saveUserInfo(); | 43 remoting.AppsV2Migration.saveUserInfo(); |
| 40 } | 44 } |
| 41 } | 45 } |
| 42 | 46 |
| 43 module('AppsV2Migration', { | 47 module('AppsV2Migration', { |
| 44 setup: function() { | 48 setup: function() { |
| 45 chromeMocks.activate(['storage']); | 49 mockIsAppsV2 = sinon.$setupStub(base, 'isAppsV2'); |
| 46 mockIsAppsV2 = sinon.stub(base, 'isAppsV2'); | 50 remoting.identity = new remoting.Identity(); |
| 47 remoting.identity = {}; | |
| 48 }, | 51 }, |
| 49 teardown: function() { | 52 teardown: function() { |
| 50 chromeMocks.restore(); | |
| 51 mockIsAppsV2.restore(); | 53 mockIsAppsV2.restore(); |
| 52 remoting.identity = null; | 54 remoting.identity = null; |
| 53 } | 55 } |
| 54 }); | 56 }); |
| 55 | 57 |
| 56 QUnit.asyncTest( | 58 QUnit.asyncTest( |
| 57 'hasHostsInV1App() should reject the promise if v1 user has same identity', | 59 'hasHostsInV1App() should reject the promise if v1 user has same identity', |
| 58 function() { | 60 function() { |
| 59 setMigrationData_('v1userName', 'v2user@gmail.com', true); | 61 setMigrationData_('v1userName', 'v2user@gmail.com', true); |
| 60 mockIsAppsV2.returns(true); | 62 mockIsAppsV2.returns(true); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 75 mockIsAppsV2.returns(false); | 77 mockIsAppsV2.returns(false); |
| 76 remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass); | 78 remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass); |
| 77 }); | 79 }); |
| 78 | 80 |
| 79 QUnit.asyncTest( | 81 QUnit.asyncTest( |
| 80 'hasHostsInV1App() should return v1 identity if v1 user has hosts', | 82 'hasHostsInV1App() should return v1 identity if v1 user has hosts', |
| 81 function() { | 83 function() { |
| 82 setMigrationData_('v1userName', 'v1user@gmail.com', true); | 84 setMigrationData_('v1userName', 'v1user@gmail.com', true); |
| 83 mockIsAppsV2.returns(true); | 85 mockIsAppsV2.returns(true); |
| 84 remoting.AppsV2Migration.hasHostsInV1App().then( | 86 remoting.AppsV2Migration.hasHostsInV1App().then( |
| 87 /** @param {{email:string, fullName:string}} result */ |
| 85 function(result) { | 88 function(result) { |
| 86 QUnit.equal(result.email, 'v1user@gmail.com'); | 89 QUnit.equal(result.email, 'v1user@gmail.com'); |
| 87 QUnit.equal(result.fullName, 'v1userName'); | 90 QUnit.equal(result.fullName, 'v1userName'); |
| 88 pass(); | 91 pass(); |
| 89 }, fail | 92 }, fail |
| 90 ); | 93 ); |
| 91 }); | 94 }); |
| 92 | 95 |
| 93 QUnit.asyncTest( | 96 QUnit.asyncTest( |
| 94 'saveUserInfo() should clear the preferences on v2', | 97 'saveUserInfo() should clear the preferences on v2', |
| 95 function() { | 98 function() { |
| 96 setMigrationData_('v1userName', 'v1user@gmail.com', 'v2user@gmail.com', | 99 setMigrationData_('v1userName', 'v1user@gmail.com', true); |
| 97 true); | |
| 98 mockIsAppsV2.returns(true); | 100 mockIsAppsV2.returns(true); |
| 99 remoting.AppsV2Migration.saveUserInfo(true); | 101 remoting.AppsV2Migration.saveUserInfo(); |
| 100 remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass); | 102 remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass); |
| 101 }); | 103 }); |
| 102 | 104 |
| 103 })(); | 105 })(); |
| OLD | NEW |