summaryrefslogtreecommitdiffstats
path: root/remoting/webapp
diff options
context:
space:
mode:
authorkelvinp <kelvinp@chromium.org>2015-05-26 14:32:52 -0700
committerCommit bot <commit-bot@chromium.org>2015-05-26 21:33:31 +0000
commit1a8d5b2da013f3149fe601331125ef8d9205289e (patch)
tree9efbe8e8cb685373324c8441a132b6c3fe7f2c28 /remoting/webapp
parent663a3a2fee3f20a58791219f10ec528c55c08928 (diff)
downloadchromium_src-1a8d5b2da013f3149fe601331125ef8d9205289e.zip
chromium_src-1a8d5b2da013f3149fe601331125ef8d9205289e.tar.gz
chromium_src-1a8d5b2da013f3149fe601331125ef8d9205289e.tar.bz2
[Chromoting] Separates chrome mocks from chrome protos in unittests.
The current unittest reuses the chrome_proto.js as stubs in the unittest. chrome_proto.js is subjected to changes as JSCompile augments the existing set of functions through externs. Summary of changes: 1. Auto activate/restore chrome mocks in each unittest. 2. Separates chrome mocks from chrome protos. Review URL: https://codereview.chromium.org/1143033004 Cr-Commit-Position: refs/heads/master@{#331441}
Diffstat (limited to 'remoting/webapp')
-rw-r--r--remoting/webapp/base/js/client_session_factory_unittest.js2
-rw-r--r--remoting/webapp/base/js/client_session_unittest.js2
-rw-r--r--remoting/webapp/base/js/identity_unittest.js2
-rw-r--r--remoting/webapp/base/js/ipc_unittest.js2
-rw-r--r--remoting/webapp/base/js/xhr_unittest.js2
-rw-r--r--remoting/webapp/crd/js/apps_v2_migration_unittest.js14
-rw-r--r--remoting/webapp/crd/js/gcd_client_unittest.js2
-rw-r--r--remoting/webapp/crd/js/gcd_client_with_mock_xhr_unittest.js2
-rw-r--r--remoting/webapp/crd/js/host_controller_unittest.js2
-rw-r--r--remoting/webapp/crd/js/host_daemon_facade_unittest.js2
-rw-r--r--remoting/webapp/files.gni5
-rw-r--r--remoting/webapp/js_proto/chrome_mocks.js55
-rw-r--r--remoting/webapp/js_proto/qunit_proto.js8
-rw-r--r--remoting/webapp/unittests/qunit_callbacks.js17
14 files changed, 70 insertions, 47 deletions
diff --git a/remoting/webapp/base/js/client_session_factory_unittest.js b/remoting/webapp/base/js/client_session_factory_unittest.js
index 5ca8c023..1a42fb2 100644
--- a/remoting/webapp/base/js/client_session_factory_unittest.js
+++ b/remoting/webapp/base/js/client_session_factory_unittest.js
@@ -25,7 +25,6 @@ SessionListener.prototype.onError = function(error) {};
QUnit.module('ClientSessionFactory', {
beforeEach: function() {
- chromeMocks.activate(['identity']);
chromeMocks.identity.mock$setToken('fake_token');
mockConnection = new remoting.MockConnection();
@@ -36,7 +35,6 @@ QUnit.module('ClientSessionFactory', {
},
afterEach: function() {
mockConnection.restore();
- chromeMocks.restore();
}
});
diff --git a/remoting/webapp/base/js/client_session_unittest.js b/remoting/webapp/base/js/client_session_unittest.js
index b178c8e..c3735ed 100644
--- a/remoting/webapp/base/js/client_session_unittest.js
+++ b/remoting/webapp/base/js/client_session_unittest.js
@@ -60,7 +60,6 @@ function connect(opt_error) {
QUnit.module('ClientSession', {
beforeEach: function() {
- chromeMocks.activate(['identity']);
chromeMocks.identity.mock$setToken('fake_token');
mockConnection = new remoting.MockConnection();
@@ -78,7 +77,6 @@ QUnit.module('ClientSession', {
afterEach: function() {
session.dispose();
mockConnection.restore();
- chromeMocks.restore();
}
});
diff --git a/remoting/webapp/base/js/identity_unittest.js b/remoting/webapp/base/js/identity_unittest.js
index a187129..55ce092 100644
--- a/remoting/webapp/base/js/identity_unittest.js
+++ b/remoting/webapp/base/js/identity_unittest.js
@@ -45,14 +45,12 @@ MockConsent.prototype.show = function() {
QUnit.module('Identity', {
beforeEach: function(/** QUnit.Assert*/ assert) {
chromeMocks.identity.mock$clearToken();
- chromeMocks.activate(['identity', 'runtime']);
consentDialog = new MockConsent(assert);
promptForConsent = sinon.spy(consentDialog, 'show');
identity = new remoting.Identity(consentDialog);
getAuthToken = sinon.spy(chromeMocks.identity, 'getAuthToken');
},
afterEach: function() {
- chromeMocks.restore();
getAuthToken.restore();
}
});
diff --git a/remoting/webapp/base/js/ipc_unittest.js b/remoting/webapp/base/js/ipc_unittest.js
index 1634d86..ebddb37 100644
--- a/remoting/webapp/base/js/ipc_unittest.js
+++ b/remoting/webapp/base/js/ipc_unittest.js
@@ -11,13 +11,11 @@ var ipc_;
QUnit.module('base.Ipc', {
beforeEach: function() {
- chromeMocks.activate(['runtime']);
ipc_ = base.Ipc.getInstance();
},
afterEach: function() {
base.Ipc.deleteInstance();
ipc_ = null;
- chromeMocks.restore();
}
});
diff --git a/remoting/webapp/base/js/xhr_unittest.js b/remoting/webapp/base/js/xhr_unittest.js
index fc711ad..4245415 100644
--- a/remoting/webapp/base/js/xhr_unittest.js
+++ b/remoting/webapp/base/js/xhr_unittest.js
@@ -25,11 +25,9 @@ QUnit.module('xhr', {
fakeXhr = xhr;
};
remoting.identity = new remoting.Identity();
- chromeMocks.activate(['identity']);
chromeMocks.identity.mock$setToken('my_token');
},
afterEach: function() {
- chromeMocks.restore();
remoting.identity = null;
}
});
diff --git a/remoting/webapp/crd/js/apps_v2_migration_unittest.js b/remoting/webapp/crd/js/apps_v2_migration_unittest.js
index 456cc47..fba100b 100644
--- a/remoting/webapp/crd/js/apps_v2_migration_unittest.js
+++ b/remoting/webapp/crd/js/apps_v2_migration_unittest.js
@@ -47,12 +47,10 @@ function setMigrationData_(v1UserName, v1UserEmail, v1HasHosts) {
QUnit.module('AppsV2Migration', {
beforeEach: function() {
- chromeMocks.activate(['storage']);
mockIsAppsV2 = sinon.stub(base, 'isAppsV2');
remoting.identity = new remoting.Identity();
},
afterEach: function() {
- chromeMocks.restore();
mockIsAppsV2.restore();
remoting.identity = null;
}
@@ -85,18 +83,6 @@ QUnit.test('hasHostsInV1App() should reject the promise in v1',
});
QUnit.test(
- 'hasHostsInV1App() should return v1 identity if v1 user has hosts',
- function(assert) {
- setMigrationData_('v1userName', 'v1user@gmail.com', true);
- mockIsAppsV2.returns(true);
- return remoting.AppsV2Migration.hasHostsInV1App().then(
- function(/** {email:string, fullName:string} */ result) {
- assert.equal(result.email, 'v1user@gmail.com');
- assert.equal(result.fullName, 'v1userName');
- });
-});
-
-QUnit.test(
'saveUserInfo() should clear the preferences on v2',
function(assert) {
assert.expect(0);
diff --git a/remoting/webapp/crd/js/gcd_client_unittest.js b/remoting/webapp/crd/js/gcd_client_unittest.js
index 38d9c0d..5137822 100644
--- a/remoting/webapp/crd/js/gcd_client_unittest.js
+++ b/remoting/webapp/crd/js/gcd_client_unittest.js
@@ -55,7 +55,6 @@ QUnit.module('gcd_client', {
});
};
remoting.identity = new remoting.Identity();
- chromeMocks.activate(['identity']);
chromeMocks.identity.mock$setToken('fake_token');
client = new remoting.gcd.Client({
apiBaseUrl: 'https://fake.api',
@@ -63,7 +62,6 @@ QUnit.module('gcd_client', {
});
},
teardown: function() {
- chromeMocks.restore();
fakeXhr = null;
queuedResponse = null;
remoting.identity = null;
diff --git a/remoting/webapp/crd/js/gcd_client_with_mock_xhr_unittest.js b/remoting/webapp/crd/js/gcd_client_with_mock_xhr_unittest.js
index 5865841..bd14539 100644
--- a/remoting/webapp/crd/js/gcd_client_with_mock_xhr_unittest.js
+++ b/remoting/webapp/crd/js/gcd_client_with_mock_xhr_unittest.js
@@ -41,7 +41,6 @@ QUnit.module('gcd_client with mock_xhr', {
beforeEach: function() {
remoting.MockXhr.activate();
remoting.identity = new remoting.Identity();
- chromeMocks.activate(['identity']);
chromeMocks.identity.mock$setToken('fake_token');
client = new remoting.gcd.Client({
apiBaseUrl: 'https://fake.api',
@@ -49,7 +48,6 @@ QUnit.module('gcd_client with mock_xhr', {
});
},
afterEach: function() {
- chromeMocks.restore();
remoting.identity = null;
remoting.MockXhr.restore();
}
diff --git a/remoting/webapp/crd/js/host_controller_unittest.js b/remoting/webapp/crd/js/host_controller_unittest.js
index b5b55be..9b4aa77 100644
--- a/remoting/webapp/crd/js/host_controller_unittest.js
+++ b/remoting/webapp/crd/js/host_controller_unittest.js
@@ -76,7 +76,6 @@ var mockHostListApi;
QUnit.module('host_controller', {
beforeEach: function(/** QUnit.Assert */ assert) {
- chromeMocks.activate(['identity', 'runtime']);
chromeMocks.identity.mock$setToken(FAKE_IDENTITY_TOKEN);
remoting.settings = new remoting.Settings();
remoting.identity = new remoting.Identity();
@@ -173,7 +172,6 @@ QUnit.module('host_controller', {
signalStrategyCreateStub.restore();
remoting.hostList = null;
remoting.oauth2 = null;
- chromeMocks.restore();
remoting.HostListApi.setInstance(null);
remoting.identity = null;
}
diff --git a/remoting/webapp/crd/js/host_daemon_facade_unittest.js b/remoting/webapp/crd/js/host_daemon_facade_unittest.js
index f7f6ad2..0bdfbd3 100644
--- a/remoting/webapp/crd/js/host_daemon_facade_unittest.js
+++ b/remoting/webapp/crd/js/host_daemon_facade_unittest.js
@@ -24,7 +24,6 @@ var it;
QUnit.module('host_daemon_facade', {
beforeEach: function(/** QUnit.Assert */ assert) {
- chromeMocks.activate(['runtime']);
chromeMocks.identity.mock$setToken('my_token');
nativePortMock =
chromeMocks.runtime.connectNative('com.google.chrome.remote_desktop');
@@ -38,7 +37,6 @@ QUnit.module('host_daemon_facade', {
}
mockHostResponses = null;
postMessageStub.restore();
- chromeMocks.restore();
it = null;
}
});
diff --git a/remoting/webapp/files.gni b/remoting/webapp/files.gni
index 10b9976..dde5fa6 100644
--- a/remoting/webapp/files.gni
+++ b/remoting/webapp/files.gni
@@ -104,11 +104,8 @@ remoting_webapp_unittests_js_files = [
"crd/js/mock_xhr_unittest.js",
]
remoting_webapp_unittests_js_mock_files = [
- # Some proto files can be repurposed as simple mocks for the unittests.
- # Note that some defs in chrome_proto are overwritten by chrome_mocks.
"crd/js/mock_host_daemon_facade.js",
"crd/js/mock_signal_strategy.js",
- "js_proto/chrome_proto.js",
"js_proto/chrome_mocks.js",
"unittests/sinon_helpers.js",
"crd/js/mock_xhr.js",
@@ -117,6 +114,7 @@ remoting_webapp_unittests_js_mock_files = [
# Prototypes for objects that are not mocked.
remoting_webapp_unittests_js_proto_files = [
"js_proto/chrome_cast_proto.js",
+ "js_proto/chrome_proto.js",
"js_proto/dom_proto.js",
"js_proto/remoting_proto.js",
"js_proto/qunit_proto.js",
@@ -125,6 +123,7 @@ remoting_webapp_unittests_js_proto_files = [
remoting_webapp_unittests_all_js_files = [
"<@(remoting_webapp_unittests_js_files)",
"<@(remoting_webapp_unittests_js_mock_files)",
+ "unittests/qunit_callbacks.js",
]
# All the files needed to run the unittests.
diff --git a/remoting/webapp/js_proto/chrome_mocks.js b/remoting/webapp/js_proto/chrome_mocks.js
index d18e804..7d76d3c 100644
--- a/remoting/webapp/js_proto/chrome_mocks.js
+++ b/remoting/webapp/js_proto/chrome_mocks.js
@@ -5,8 +5,6 @@
// This file contains various mock objects for the chrome platform to make
// unit testing easier.
-Entry = function() {};
-
var chromeMocks = {};
/** @constructor */
@@ -21,6 +19,8 @@ chrome.Event.prototype.removeListener = function(callback) {};
(function(){
+'use strict'
+
/**
* @constructor
* @extends {chrome.Event}
@@ -232,28 +232,59 @@ chromeMocks.Identity.prototype.mock$clearToken = function() {
};
/** @type {chromeMocks.Identity} */
-chromeMocks.identity = new chromeMocks.Identity();
+chromeMocks.identity;
+
+/** @constructor */
+chromeMocks.I18n = function() {};
+
+/**
+ * @param {string} messageName
+ * @param {(string|Array<string>)=} opt_args
+ * @return {string}
+ */
+chromeMocks.I18n.prototype.getMessage = function(messageName, opt_args) {};
+
+/**
+ * @return {string}
+ */
+chromeMocks.I18n.prototype.getUILanguage = function() {};
+
+/** @constructor */
+chromeMocks.WindowManager = function() {};
+
+chromeMocks.WindowManager.prototype.current = function() {
+ return new chromeMocks.AppWindow();
+};
+
+/** @constructor */
+chromeMocks.AppWindow = function() {};
var originals_ = null;
/**
* Activates a list of Chrome components to mock
- * @param {Array<string>} components
*/
-chromeMocks.activate = function(components) {
+chromeMocks.activate = function() {
if (originals_) {
throw new Error('chromeMocks.activate() can only be called once.');
}
originals_ = {};
nativePorts = {};
- components.forEach(function(component) {
- if (!chromeMocks[component]) {
- throw new Error('No mocks defined for chrome.' + component);
- }
- originals_[component] = chrome[component];
- chrome[component] = chromeMocks[component];
- });
+
+ chromeMocks.i18n = new chromeMocks.I18n();
+ chromeMocks.identity = new chromeMocks.Identity();
+
+ ['identity', 'i18n', 'runtime', 'storage'].forEach(
+ function(/** string */ component) {
+ if (!chromeMocks[component]) {
+ throw new Error('No mocks defined for chrome.' + component);
+ }
+ originals_[component] = chrome[component];
+ chrome[component] = chromeMocks[component];
+ });
+
+ chrome.app.window = new chromeMocks.WindowManager();
};
chromeMocks.restore = function() {
diff --git a/remoting/webapp/js_proto/qunit_proto.js b/remoting/webapp/js_proto/qunit_proto.js
index ff289ca..ee53516 100644
--- a/remoting/webapp/js_proto/qunit_proto.js
+++ b/remoting/webapp/js_proto/qunit_proto.js
@@ -25,6 +25,8 @@ QUnit.Clock.prototype.tick = function(ticks) {};
/** @param {Function} f */
QUnit.testStart = function(f) {};
+/** @param {Function} f */
+QUnit.testDone = function(f) {};
/**
* @interface
*/
@@ -101,3 +103,9 @@ QUnit.module = function(desc, opt_args) {};
* @param {function(!QUnit.Assert)} f
*/
QUnit.test = function(desc, f) {};
+
+/**
+ * @param {string} desc
+ * @param {function(!QUnit.Assert)} f
+ */
+QUnit.skip = function(desc, f) {}; \ No newline at end of file
diff --git a/remoting/webapp/unittests/qunit_callbacks.js b/remoting/webapp/unittests/qunit_callbacks.js
new file mode 100644
index 0000000..f757e9a
--- /dev/null
+++ b/remoting/webapp/unittests/qunit_callbacks.js
@@ -0,0 +1,17 @@
+// Copyright 2015 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';
+
+QUnit.testStart(function(){
+ chromeMocks.activate();
+});
+
+QUnit.testDone(function(){
+ chromeMocks.restore();
+});
+
+})();