Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 (function() { | |
| 6 | |
| 7 'use strict'; | |
| 8 | |
| 9 var originalWindowsStorage = null; | |
| 10 var mockIsAppsV2 = null; | |
| 11 var mockChromeStorage = {}; | |
| 12 | |
| 13 function pass() { | |
| 14 ok(true); | |
| 15 QUnit.start(); | |
| 16 } | |
| 17 | |
| 18 function fail() { | |
| 19 ok(false); | |
| 20 QUnit.start(); | |
| 21 } | |
| 22 | |
| 23 /** | |
| 24 * @param {string} v1UserName | |
| 25 * @param {string} v1UserEmail | |
| 26 * @param {string} currentEmail | |
| 27 * @param {boolean} v1HasHost | |
| 28 */ | |
| 29 function setup_(v1UserName, v1UserEmail, currentEmail, v1HasHosts) { | |
|
Jamie
2015/01/20 22:32:02
Assuming you need this because the module's setup
| |
| 30 chromeMocks.activate(['storage']); | |
| 31 originalWindowsStorage = window.localStorage; | |
| 32 mockIsAppsV2 = sinon.stub(base, 'isAppsV2'); | |
| 33 remoting.identity = {}; | |
|
Jamie
2015/01/20 22:32:01
There is already a MockIdentity class you can use
kelvinp
2015/01/21 21:16:21
The mock identify class mocks chrome.identity but
| |
| 34 | |
| 35 remoting.identity.getUserInfo = function(onDone, onError) { | |
| 36 return onDone(currentEmail); | |
| 37 }; | |
| 38 | |
| 39 window.localStorage['remoting-email'] = v1UserEmail; | |
| 40 window.localStorage['remoting-fullname'] = v1UserName; | |
| 41 | |
| 42 mockIsAppsV2.returns(false); | |
| 43 remoting.AppsV2Migration.savePreferences(v1HasHosts); | |
| 44 } | |
| 45 | |
| 46 module('AppsV2Migration', { | |
| 47 teardown: function() { | |
| 48 chromeMocks.restore(); | |
| 49 window.localStorage = originalWindowsStorage; | |
| 50 remoting.identity = null; | |
| 51 mockIsAppsV2.restore(); | |
| 52 } | |
| 53 }); | |
| 54 | |
| 55 QUnit.asyncTest( | |
| 56 'hasHostsInV1App() should reject the promise if v1 user has same identity', | |
| 57 function() { | |
| 58 setup_('v1userName', 'v2user@gmail.com', 'v2user@gmail.com', true); | |
| 59 mockIsAppsV2.returns(true); | |
| 60 remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass); | |
| 61 }); | |
| 62 | |
| 63 QUnit.asyncTest( | |
| 64 'hasHostsInV1App() should reject the promise if v1 user has no hosts', | |
| 65 function() { | |
| 66 setup_('v1userName', 'v1user@gmail.com', 'v2user@gmail.com', false); | |
| 67 mockIsAppsV2.returns(true); | |
| 68 remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass); | |
| 69 }); | |
| 70 | |
| 71 QUnit.asyncTest( | |
| 72 'hasHostsInV1App() should reject always reject the promise in v1', | |
|
Jamie
2015/01/20 22:32:01
Duplicate "reject".
kelvinp
2015/01/21 21:16:21
Done.
| |
| 73 function() { | |
| 74 setup_('v1userName', 'v1user@gmail.com', 'v2user@gmail.com', true); | |
| 75 mockIsAppsV2.returns(false); | |
| 76 remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass); | |
| 77 }); | |
| 78 | |
| 79 QUnit.asyncTest( | |
| 80 'hasHostsInV1App() should return v1 identity if v1 user has hosts', | |
| 81 function() { | |
| 82 setup_('v1userName', 'v1user@gmail.com', 'v2user@gmail.com', true); | |
| 83 mockIsAppsV2.returns(true); | |
| 84 remoting.AppsV2Migration.hasHostsInV1App().then( | |
| 85 function(result) { | |
| 86 QUnit.equal(result.email, 'v1user@gmail.com'); | |
| 87 QUnit.equal(result.fullName, 'v1userName'); | |
| 88 pass(); | |
| 89 }, fail | |
| 90 ); | |
| 91 }); | |
| 92 | |
| 93 QUnit.asyncTest( | |
| 94 'savePreferences() should clear the preferences on v2', | |
| 95 function() { | |
| 96 setup_('v1userName', 'v1user@gmail.com', 'v2user@gmail.com', true); | |
| 97 mockIsAppsV2.returns(true); | |
| 98 remoting.AppsV2Migration.savePreferences(true); | |
|
Jamie
2015/01/20 22:32:01
As stated earlier, there is some subtlety to this
kelvinp
2015/01/21 21:16:21
I have removed the hostHost parameter from the met
| |
| 99 remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass); | |
| 100 }); | |
| 101 | |
| 102 })(); | |
| OLD | NEW |