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.
9 var mockIsAppsV2 = null;
10 var mockChromeStorage = {};
23 * @param {string} v1UserName
24 * @param {string} v1UserEmail
25 * @param {string} currentEmail
26 * @param {boolean} v1HasHost
28 function setMigrationData_(v1UserName, v1UserEmail, v1HasHosts) {
29 remoting.identity.getUserInfo = function() {
30 if (base.isAppsV2()) {
31 return Promise.resolve(
32 {email: 'v2user@gmail.com', name: 'v2userName'});
34 return Promise.resolve(
35 {email: v1UserEmail, name: v1UserName});
38 remoting.identity.getEmail = function() {
39 return remoting.identity.getUserInfo().then(function(info) {
44 mockIsAppsV2.returns(false);
46 remoting.AppsV2Migration.saveUserInfo();
50 module('AppsV2Migration', {
52 chromeMocks.activate(['storage']);
53 mockIsAppsV2 = sinon.stub(base, 'isAppsV2');
54 remoting.identity = {};
56 teardown: function() {
57 chromeMocks.restore();
58 mockIsAppsV2.restore();
59 remoting.identity = null;
64 'hasHostsInV1App() should reject the promise if v1 user has same identity',
66 setMigrationData_('v1userName', 'v2user@gmail.com', true);
67 mockIsAppsV2.returns(true);
68 remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass);
72 'hasHostsInV1App() should reject the promise if v1 user has no hosts',
74 setMigrationData_('v1userName', 'v1user@gmail.com', false);
75 mockIsAppsV2.returns(true);
76 remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass);
80 'hasHostsInV1App() should reject the promise in v1', function() {
81 setMigrationData_('v1userName', 'v1user@gmail.com', true);
82 mockIsAppsV2.returns(false);
83 remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass);
87 'hasHostsInV1App() should return v1 identity if v1 user has hosts',
89 setMigrationData_('v1userName', 'v1user@gmail.com', true);
90 mockIsAppsV2.returns(true);
91 remoting.AppsV2Migration.hasHostsInV1App().then(
93 QUnit.equal(result.email, 'v1user@gmail.com');
94 QUnit.equal(result.fullName, 'v1userName');
101 'saveUserInfo() should clear the preferences on v2',
103 setMigrationData_('v1userName', 'v1user@gmail.com', 'v2user@gmail.com',
105 mockIsAppsV2.returns(true);
106 remoting.AppsV2Migration.saveUserInfo(true);
107 remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass);