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

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

Issue 984203003: Move mocks and unittest JS files to sit alongside production code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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
« no previous file with comments | « remoting/webapp/js_proto/chrome_mocks.js ('k') | remoting/webapp/unittests/base_unittest.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 /**
6 * @fileoverview
7 * @suppress {checkTypes|checkVars|reportUnknownTypes|visibility}
8 */
9
10 (function() {
11
12 'use strict';
13
14 /** @type {sinon.TestStub} */
15 var mockIsAppsV2 = null;
16 var mockChromeStorage = {};
17
18 function pass() {
19 ok(true);
20 QUnit.start();
21 }
22
23 function fail() {
24 ok(false);
25 QUnit.start();
26 }
27
28 /**
29 * @param {string} v1UserName
30 * @param {string} v1UserEmail
31 * @param {boolean} v1HasHosts
32 */
33 function setMigrationData_(v1UserName, v1UserEmail, v1HasHosts) {
34 /** @return {!Promise} */
35 remoting.identity.getUserInfo = function() {
36 if (base.isAppsV2()) {
37 return Promise.resolve(
38 {email: 'v2user@gmail.com', name: 'v2userName'});
39 } else {
40 return Promise.resolve(
41 {email: v1UserEmail, name: v1UserName});
42 }
43 };
44 /** @return {!Promise} */
45 remoting.identity.getEmail = function() {
46 return remoting.identity.getUserInfo().then(
47 /** @param {{email:string, name:string}} info */
48 function(info) {
49 return info.email;
50 });
51 };
52
53 mockIsAppsV2.returns(false);
54 if (v1HasHosts) {
55 remoting.AppsV2Migration.saveUserInfo();
56 }
57 }
58
59 module('AppsV2Migration', {
60 setup: function() {
61 chromeMocks.activate(['storage']);
62 mockIsAppsV2 = sinon.stub(base, 'isAppsV2');
63 remoting.identity = new remoting.Identity();
64 },
65 teardown: function() {
66 chromeMocks.restore();
67 mockIsAppsV2.restore();
68 remoting.identity = null;
69 }
70 });
71
72 QUnit.asyncTest(
73 'hasHostsInV1App() should reject the promise if v1 user has same identity',
74 function() {
75 setMigrationData_('v1userName', 'v2user@gmail.com', true);
76 mockIsAppsV2.returns(true);
77 remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass);
78 });
79
80 QUnit.asyncTest(
81 'hasHostsInV1App() should reject the promise if v1 user has no hosts',
82 function() {
83 setMigrationData_('v1userName', 'v1user@gmail.com', false);
84 mockIsAppsV2.returns(true);
85 remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass);
86 });
87
88 QUnit.asyncTest(
89 'hasHostsInV1App() should reject the promise in v1', function() {
90 setMigrationData_('v1userName', 'v1user@gmail.com', true);
91 mockIsAppsV2.returns(false);
92 remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass);
93 });
94
95 QUnit.asyncTest(
96 'hasHostsInV1App() should return v1 identity if v1 user has hosts',
97 function() {
98 setMigrationData_('v1userName', 'v1user@gmail.com', true);
99 mockIsAppsV2.returns(true);
100 remoting.AppsV2Migration.hasHostsInV1App().then(
101 /** @param {{email:string, name:string}} result */
102 function(result) {
103 QUnit.equal(result.email, 'v1user@gmail.com');
104 QUnit.equal(result.fullName, 'v1userName');
105 pass();
106 }, fail
107 );
108 });
109
110 QUnit.asyncTest(
111 'saveUserInfo() should clear the preferences on v2',
112 function() {
113 setMigrationData_('v1userName', 'v1user@gmail.com', true);
114 mockIsAppsV2.returns(true);
115 remoting.AppsV2Migration.saveUserInfo();
116 remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass);
117 });
118
119 })();
OLDNEW
« no previous file with comments | « remoting/webapp/js_proto/chrome_mocks.js ('k') | remoting/webapp/unittests/base_unittest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698