Convert cacheinvalidation_unittests to run exclusively on Swarming
[chromium-blink-merge.git] / remoting / webapp / crd / js / apps_v2_migration_unittest.js
blobfba100b6ffeaa4764414495a54f84c3560874bbe
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.
5 /**
6 * @fileoverview
7 */
9 (function() {
11 'use strict';
13 /** @type {sinon.TestStub} */
14 var mockIsAppsV2 = null;
15 var mockChromeStorage = {};
17 /**
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'});
28 } else {
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 */
37 function(info) {
38 return info.email;
39 });
42 mockIsAppsV2.returns(false);
43 if (v1HasHosts) {
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;
57 });
59 QUnit.test(
60 'hasHostsInV1App() should reject the promise if v1 user has same identity',
61 function(assert) {
62 assert.expect(0);
63 setMigrationData_('v1userName', 'v2user@gmail.com', true);
64 mockIsAppsV2.returns(true);
65 return base.Promise.negate(remoting.AppsV2Migration.hasHostsInV1App());
66 });
68 QUnit.test(
69 'hasHostsInV1App() should reject the promise if v1 user has no hosts',
70 function(assert) {
71 assert.expect(0);
72 setMigrationData_('v1userName', 'v1user@gmail.com', false);
73 mockIsAppsV2.returns(true);
74 return base.Promise.negate(remoting.AppsV2Migration.hasHostsInV1App());
75 });
77 QUnit.test('hasHostsInV1App() should reject the promise in v1',
78 function(assert) {
79 assert.expect(0);
80 setMigrationData_('v1userName', 'v1user@gmail.com', true);
81 mockIsAppsV2.returns(false);
82 return base.Promise.negate(remoting.AppsV2Migration.hasHostsInV1App());
83 });
85 QUnit.test(
86 'saveUserInfo() should clear the preferences on v2',
87 function(assert) {
88 assert.expect(0);
89 setMigrationData_('v1userName', 'v1user@gmail.com', true);
90 mockIsAppsV2.returns(true);
91 remoting.AppsV2Migration.saveUserInfo();
92 return base.Promise.negate(remoting.AppsV2Migration.hasHostsInV1App());
93 });
95 })();