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

Unified Diff: remoting/webapp/unittests/ipc_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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/webapp/unittests/host_table_entry_unittest.js ('k') | remoting/webapp/unittests/l10n_unittest.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/webapp/unittests/ipc_unittest.js
diff --git a/remoting/webapp/unittests/ipc_unittest.js b/remoting/webapp/unittests/ipc_unittest.js
deleted file mode 100644
index e786147e50933e2f64e4e70155cbb72b0d6f3644..0000000000000000000000000000000000000000
--- a/remoting/webapp/unittests/ipc_unittest.js
+++ /dev/null
@@ -1,140 +0,0 @@
-// 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';
-
-/** @type {base.Ipc} */
-var ipc_;
-
-function pass() {
- ok(true);
- QUnit.start();
-}
-
-function fail() {
- ok(false);
- QUnit.start();
-}
-
-module('base.Ipc', {
- setup: function() {
- chromeMocks.activate(['runtime']);
- ipc_ = base.Ipc.getInstance();
- },
- teardown: function() {
- base.Ipc.deleteInstance();
- ipc_ = null;
- chromeMocks.restore();
- }
-});
-
-QUnit.test(
- 'register() should return false if the request type was already registered',
- function() {
- var handler1 = function() {};
- var handler2 = function() {};
- QUnit.equal(true, ipc_.register('foo', handler1));
- QUnit.equal(false, ipc_.register('foo', handler2));
-});
-
-QUnit.asyncTest(
- 'send() should invoke a registered handler with the correct arguments',
- function() {
- var handler = sinon.spy();
- var argArray = [1, 2, 3];
- var argDict = {
- key1: 'value1',
- key2: false
- };
-
- ipc_.register('foo', handler);
- base.Ipc.invoke('foo', 1, false, 'string', argArray, argDict).then(
- function() {
- sinon.assert.calledWith(handler, 1, false, 'string', argArray, argDict);
- pass();
- }, fail);
-});
-
-QUnit.asyncTest(
- 'send() should not invoke a handler that is unregistered',
- function() {
- var handler = sinon.spy();
- ipc_.register('foo', handler);
- ipc_.unregister('foo');
- base.Ipc.invoke('foo', 'hello', 'world').then(fail, function(error) {
- sinon.assert.notCalled(handler);
- QUnit.equal(error, base.Ipc.Error.UNSUPPORTED_REQUEST_TYPE);
- pass();
- });
-});
-
-QUnit.asyncTest(
- 'send() should raise exceptions on unknown request types',
- function() {
- var handler = sinon.spy();
- ipc_.register('foo', handler);
- base.Ipc.invoke('bar', 'hello', 'world').then(fail, function(error) {
- QUnit.equal(error, base.Ipc.Error.UNSUPPORTED_REQUEST_TYPE);
- pass();
- });
-});
-
-QUnit.asyncTest(
- 'send() should raise exceptions on request from another extension',
- function() {
- var handler = sinon.spy();
- var oldId = chrome.runtime.id;
- ipc_.register('foo', handler);
- chrome.runtime.id = 'foreign-extension';
- base.Ipc.invoke('foo', 'hello', 'world').then(fail, function(error) {
- QUnit.equal(error, base.Ipc.Error.INVALID_REQUEST_ORIGIN);
- pass();
- });
- chrome.runtime.id = oldId;
-});
-
-
-QUnit.asyncTest(
- 'send() should pass exceptions raised by the handler to the caller',
- function() {
- var handler = function() {
- throw new Error('Whatever can go wrong, will go wrong.');
- };
- ipc_.register('foo', handler);
- base.Ipc.invoke('foo').then(fail, function(error) {
- QUnit.equal(error, 'Whatever can go wrong, will go wrong.');
- pass();
- });
-});
-
-QUnit.asyncTest(
- 'send() should pass the return value of the handler to the caller',
- function() {
- var handlers = {
- 'boolean': function() { return false; },
- 'number': function() { return 12; },
- 'string': function() { return 'string'; },
- 'array': function() { return [1, 2]; },
- 'dict': function() { return {key1: 'value1', key2: 'value2'}; }
- };
-
- var testCases = [];
- for (var ipcName in handlers) {
- ipc_.register(ipcName, handlers[ipcName]);
- testCases.push(base.Ipc.invoke(ipcName));
- }
-
- Promise.all(testCases).then(function(results){
- QUnit.equal(results[0], false);
- QUnit.equal(results[1], 12);
- QUnit.equal(results[2], 'string');
- QUnit.deepEqual(results[3], [1,2]);
- QUnit.deepEqual(results[4], {key1: 'value1', key2: 'value2'});
- pass();
- }, fail);
-});
-
-})();
« no previous file with comments | « remoting/webapp/unittests/host_table_entry_unittest.js ('k') | remoting/webapp/unittests/l10n_unittest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698