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
3 // found in the LICENSE file.
13 /** @type {sinon.TestStub} */
14 var mockIsAppsV2 = null;
15 var mockChromeStorage = {};
18 * @param {string} v1UserName
19 * @param {string} v1UserEmail
20 * @param {boolean} v1HasHosts
22 function setMigrationData_(v1UserName, v1UserEmail, v1HasHosts) {
23 /** @return {!Promise} */
24 remoting.identity.getUserInfo = function() {
25 if (base.isAppsV2()) {
26 return Promise.resolve(
27 {email: 'v2user@gmail.com', name: 'v2userName'});
29 return Promise.resolve(
30 {email: v1UserEmail, name: v1UserName});
33 /** @return {!Promise} */
34 remoting.identity.getEmail = function() {
35 return remoting.identity.getUserInfo().then(
36 /** @param {{email:string, name:string}} info */
42 mockIsAppsV2.returns(false);
44 remoting.AppsV2Migration.saveUserInfo();
48 QUnit.module('AppsV2Migration', {
49 beforeEach: function() {
50 mockIsAppsV2 = sinon.stub(base, 'isAppsV2');
51 remoting.identity = new remoting.Identity();
53 afterEach: function() {
54 mockIsAppsV2.restore();
55 remoting.identity = null;
60 'hasHostsInV1App() should reject the promise if v1 user has same identity',
63 setMigrationData_('v1userName', 'v2user@gmail.com', true);
64 mockIsAppsV2.returns(true);
65 return base.Promise.negate(remoting.AppsV2Migration.hasHostsInV1App());
69 'hasHostsInV1App() should reject the promise if v1 user has no hosts',
72 setMigrationData_('v1userName', 'v1user@gmail.com', false);
73 mockIsAppsV2.returns(true);
74 return base.Promise.negate(remoting.AppsV2Migration.hasHostsInV1App());
77 QUnit.test('hasHostsInV1App() should reject the promise in v1',
80 setMigrationData_('v1userName', 'v1user@gmail.com', true);
81 mockIsAppsV2.returns(false);
82 return base.Promise.negate(remoting.AppsV2Migration.hasHostsInV1App());
86 'saveUserInfo() should clear the preferences on v2',
89 setMigrationData_('v1userName', 'v1user@gmail.com', true);
90 mockIsAppsV2.returns(true);
91 remoting.AppsV2Migration.saveUserInfo();
92 return base.Promise.negate(remoting.AppsV2Migration.hasHostsInV1App());