Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(685)

Side by Side Diff: remoting/webapp/crd/js/apps_v2_migration_unittest.js

Issue 1017613002: Migrate Remoting Webapp Unittests to use QUnit 2.0 syntax. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Async test migration Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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} 7 * @suppress {checkTypes|checkVars|reportUnknownTypes|visibility}
8 */ 8 */
9 9
10 (function() { 10 (function() {
11 11
12 'use strict'; 12 'use strict';
13 13
14 /** @type {sinon.TestStub} */ 14 /** @type {sinon.TestStub} */
15 var mockIsAppsV2 = null; 15 var mockIsAppsV2 = null;
16 var mockChromeStorage = {}; 16 var mockChromeStorage = {};
17 17
18 function pass() {
19 ok(true);
20 QUnit.start();
21 }
22
23 function fail() {
24 ok(false);
25 QUnit.start();
26 }
27
28 /** 18 /**
29 * @param {string} v1UserName 19 * @param {string} v1UserName
30 * @param {string} v1UserEmail 20 * @param {string} v1UserEmail
31 * @param {boolean} v1HasHosts 21 * @param {boolean} v1HasHosts
32 */ 22 */
33 function setMigrationData_(v1UserName, v1UserEmail, v1HasHosts) { 23 function setMigrationData_(v1UserName, v1UserEmail, v1HasHosts) {
34 /** @return {!Promise} */ 24 /** @return {!Promise} */
35 remoting.identity.getUserInfo = function() { 25 remoting.identity.getUserInfo = function() {
36 if (base.isAppsV2()) { 26 if (base.isAppsV2()) {
37 return Promise.resolve( 27 return Promise.resolve(
(...skipping 11 matching lines...) Expand all
49 return info.email; 39 return info.email;
50 }); 40 });
51 }; 41 };
52 42
53 mockIsAppsV2.returns(false); 43 mockIsAppsV2.returns(false);
54 if (v1HasHosts) { 44 if (v1HasHosts) {
55 remoting.AppsV2Migration.saveUserInfo(); 45 remoting.AppsV2Migration.saveUserInfo();
56 } 46 }
57 } 47 }
58 48
59 module('AppsV2Migration', { 49 QUnit.module('AppsV2Migration', {
60 setup: function() { 50 beforeEach: function() {
61 chromeMocks.activate(['storage']); 51 chromeMocks.activate(['storage']);
62 mockIsAppsV2 = sinon.stub(base, 'isAppsV2'); 52 mockIsAppsV2 = sinon.stub(base, 'isAppsV2');
63 remoting.identity = new remoting.Identity(); 53 remoting.identity = new remoting.Identity();
64 }, 54 },
65 teardown: function() { 55 afterEach: function() {
66 chromeMocks.restore(); 56 chromeMocks.restore();
67 mockIsAppsV2.restore(); 57 mockIsAppsV2.restore();
68 remoting.identity = null; 58 remoting.identity = null;
69 } 59 }
70 }); 60 });
71 61
72 QUnit.asyncTest( 62 QUnit.test(
73 'hasHostsInV1App() should reject the promise if v1 user has same identity', 63 'hasHostsInV1App() should reject the promise if v1 user has same identity',
74 function() { 64 function() {
65 QUnit.expect(0);
75 setMigrationData_('v1userName', 'v2user@gmail.com', true); 66 setMigrationData_('v1userName', 'v2user@gmail.com', true);
76 mockIsAppsV2.returns(true); 67 mockIsAppsV2.returns(true);
77 remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass); 68 return base.Promise.negate(remoting.AppsV2Migration.hasHostsInV1App());
78 }); 69 });
79 70
80 QUnit.asyncTest( 71 QUnit.test(
81 'hasHostsInV1App() should reject the promise if v1 user has no hosts', 72 'hasHostsInV1App() should reject the promise if v1 user has no hosts',
82 function() { 73 function() {
74 QUnit.expect(0);
83 setMigrationData_('v1userName', 'v1user@gmail.com', false); 75 setMigrationData_('v1userName', 'v1user@gmail.com', false);
84 mockIsAppsV2.returns(true); 76 mockIsAppsV2.returns(true);
85 remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass); 77 return base.Promise.negate(remoting.AppsV2Migration.hasHostsInV1App());
86 }); 78 });
87 79
88 QUnit.asyncTest( 80 QUnit.test(
89 'hasHostsInV1App() should reject the promise in v1', function() { 81 'hasHostsInV1App() should reject the promise in v1', function() {
82 QUnit.expect(0);
90 setMigrationData_('v1userName', 'v1user@gmail.com', true); 83 setMigrationData_('v1userName', 'v1user@gmail.com', true);
91 mockIsAppsV2.returns(false); 84 mockIsAppsV2.returns(false);
92 remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass); 85 return base.Promise.negate(remoting.AppsV2Migration.hasHostsInV1App());
93 }); 86 });
94 87
95 QUnit.asyncTest( 88 QUnit.test(
96 'hasHostsInV1App() should return v1 identity if v1 user has hosts', 89 'hasHostsInV1App() should return v1 identity if v1 user has hosts',
97 function() { 90 function() {
98 setMigrationData_('v1userName', 'v1user@gmail.com', true); 91 setMigrationData_('v1userName', 'v1user@gmail.com', true);
99 mockIsAppsV2.returns(true); 92 mockIsAppsV2.returns(true);
100 remoting.AppsV2Migration.hasHostsInV1App().then( 93 return remoting.AppsV2Migration.hasHostsInV1App().then(
101 /** @param {{email:string, name:string}} result */ 94 function(/** {email:string, name:string} */ result) {
102 function(result) {
103 QUnit.equal(result.email, 'v1user@gmail.com'); 95 QUnit.equal(result.email, 'v1user@gmail.com');
104 QUnit.equal(result.fullName, 'v1userName'); 96 QUnit.equal(result.fullName, 'v1userName');
105 pass(); 97 });
106 }, fail
107 );
108 }); 98 });
109 99
110 QUnit.asyncTest( 100 QUnit.test(
111 'saveUserInfo() should clear the preferences on v2', 101 'saveUserInfo() should clear the preferences on v2',
112 function() { 102 function() {
103 QUnit.expect(0);
113 setMigrationData_('v1userName', 'v1user@gmail.com', true); 104 setMigrationData_('v1userName', 'v1user@gmail.com', true);
114 mockIsAppsV2.returns(true); 105 mockIsAppsV2.returns(true);
115 remoting.AppsV2Migration.saveUserInfo(); 106 remoting.AppsV2Migration.saveUserInfo();
116 remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass); 107 return base.Promise.negate(remoting.AppsV2Migration.hasHostsInV1App());
117 }); 108 });
118 109
119 })(); 110 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698