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

Unified Diff: remoting/webapp/unittests/apps_v2_migration_unittest.js

Issue 848993002: Improve apps v2 upgrade UX (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor + UT Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: remoting/webapp/unittests/apps_v2_migration_unittest.js
diff --git a/remoting/webapp/unittests/apps_v2_migration_unittest.js b/remoting/webapp/unittests/apps_v2_migration_unittest.js
new file mode 100644
index 0000000000000000000000000000000000000000..a6bd3be28fed3b72c4577fe94ec32d51e2053557
--- /dev/null
+++ b/remoting/webapp/unittests/apps_v2_migration_unittest.js
@@ -0,0 +1,102 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+(function() {
+
+'use strict';
+
+var originalWindowsStorage = null;
+var mockIsAppsV2 = null;
+var mockChromeStorage = {};
+
+function pass() {
+ ok(true);
+ QUnit.start();
+}
+
+function fail() {
+ ok(false);
+ QUnit.start();
+}
+
+/**
+ * @param {string} v1UserName
+ * @param {string} v1UserEmail
+ * @param {string} currentEmail
+ * @param {boolean} v1HasHost
+ */
+function setup_(v1UserName, v1UserEmail, currentEmail, v1HasHosts) {
Jamie 2015/01/20 22:32:02 Assuming you need this because the module's setup
+ chromeMocks.activate(['storage']);
+ originalWindowsStorage = window.localStorage;
+ mockIsAppsV2 = sinon.stub(base, 'isAppsV2');
+ 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
+
+ remoting.identity.getUserInfo = function(onDone, onError) {
+ return onDone(currentEmail);
+ };
+
+ window.localStorage['remoting-email'] = v1UserEmail;
+ window.localStorage['remoting-fullname'] = v1UserName;
+
+ mockIsAppsV2.returns(false);
+ remoting.AppsV2Migration.savePreferences(v1HasHosts);
+}
+
+module('AppsV2Migration', {
+ teardown: function() {
+ chromeMocks.restore();
+ window.localStorage = originalWindowsStorage;
+ remoting.identity = null;
+ mockIsAppsV2.restore();
+ }
+});
+
+QUnit.asyncTest(
+ 'hasHostsInV1App() should reject the promise if v1 user has same identity',
+ function() {
+ setup_('v1userName', 'v2user@gmail.com', 'v2user@gmail.com', true);
+ mockIsAppsV2.returns(true);
+ remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass);
+});
+
+QUnit.asyncTest(
+ 'hasHostsInV1App() should reject the promise if v1 user has no hosts',
+ function() {
+ setup_('v1userName', 'v1user@gmail.com', 'v2user@gmail.com', false);
+ mockIsAppsV2.returns(true);
+ remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass);
+});
+
+QUnit.asyncTest(
+ '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.
+ function() {
+ setup_('v1userName', 'v1user@gmail.com', 'v2user@gmail.com', true);
+ mockIsAppsV2.returns(false);
+ remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass);
+});
+
+QUnit.asyncTest(
+ 'hasHostsInV1App() should return v1 identity if v1 user has hosts',
+ function() {
+ setup_('v1userName', 'v1user@gmail.com', 'v2user@gmail.com', true);
+ mockIsAppsV2.returns(true);
+ remoting.AppsV2Migration.hasHostsInV1App().then(
+ function(result) {
+ QUnit.equal(result.email, 'v1user@gmail.com');
+ QUnit.equal(result.fullName, 'v1userName');
+ pass();
+ }, fail
+ );
+});
+
+QUnit.asyncTest(
+ 'savePreferences() should clear the preferences on v2',
+ function() {
+ setup_('v1userName', 'v1user@gmail.com', 'v2user@gmail.com', true);
+ mockIsAppsV2.returns(true);
+ 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
+ remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass);
+});
+
+})();

Powered by Google App Engine
This is Rietveld 408576698