| Index: remoting/webapp/crd/js/error_unittest.js
|
| diff --git a/remoting/webapp/crd/js/error_unittest.js b/remoting/webapp/crd/js/error_unittest.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..5b90773942532154f4aecb2b87ffd61be10bcdf6
|
| --- /dev/null
|
| +++ b/remoting/webapp/crd/js/error_unittest.js
|
| @@ -0,0 +1,129 @@
|
| +// 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.
|
| +
|
| +/**
|
| + * @suppress {accessControls}
|
| + */
|
| +
|
| +(function() {
|
| +
|
| +'use strict';
|
| +
|
| +QUnit.module('error', {
|
| + setup: function() {
|
| + },
|
| + teardown: function() {
|
| + }
|
| +});
|
| +
|
| +QUnit.test('error constructor 1', function() {
|
| + var error = new remoting.Error(remoting.Error.Tag.HOST_OVERLOAD);
|
| + QUnit.equal(error.tag_, remoting.Error.Tag.HOST_OVERLOAD);
|
| + QUnit.equal(error.message, null);
|
| +});
|
| +
|
| +QUnit.test('error constructor 2', function() {
|
| + var error = new remoting.Error(
|
| + remoting.Error.Tag.HOST_IS_OFFLINE,
|
| + 'detail');
|
| + QUnit.equal(error.tag_, remoting.Error.Tag.HOST_IS_OFFLINE);
|
| + QUnit.equal(error.message, 'detail');
|
| +});
|
| +
|
| +QUnit.test('hasTag', function() {
|
| + var error = new remoting.Error(remoting.Error.Tag.HOST_OVERLOAD);
|
| + QUnit.ok(error.hasTag(remoting.Error.Tag.HOST_OVERLOAD));
|
| + QUnit.ok(!error.hasTag(remoting.Error.Tag.HOST_IS_OFFLINE));
|
| +});
|
| +
|
| +
|
| +QUnit.test('hasAnyTag', function() {
|
| + var error = new remoting.Error(remoting.Error.Tag.HOST_OVERLOAD);
|
| + QUnit.ok(error.hasAnyTag([
|
| + remoting.Error.Tag.HOST_OVERLOAD,
|
| + remoting.Error.Tag.HOST_IS_OFFLINE]));
|
| + QUnit.ok(!error.hasAnyTag([
|
| + remoting.Error.Tag.HOST_IS_OFFLINE
|
| + ]));
|
| + QUnit.ok(!error.hasAnyTag([]));
|
| +});
|
| +
|
| +QUnit.test('constructor methods', function() {
|
| + QUnit.ok(remoting.Error.none().hasTag(remoting.Error.Tag.NONE));
|
| + QUnit.ok(remoting.Error.unexpected().hasTag(remoting.Error.Tag.UNEXPECTED));
|
| +});
|
| +
|
| +QUnit.test('isNone', function() {
|
| + QUnit.ok(remoting.Error.none().isNone());
|
| + QUnit.ok(!remoting.Error.unexpected().isNone());
|
| + QUnit.ok(!new remoting.Error(remoting.Error.Tag.CANCELLED).isNone());
|
| +});
|
| +
|
| +
|
| +QUnit.test('fromHttpStatus', function() {
|
| + QUnit.ok(remoting.Error.fromHttpStatus(200).isNone());
|
| + QUnit.ok(remoting.Error.fromHttpStatus(201).isNone());
|
| + QUnit.ok(!remoting.Error.fromHttpStatus(500).isNone());
|
| + QUnit.equal(
|
| + remoting.Error.fromHttpStatus(0).tag_,
|
| + remoting.Error.Tag.NETWORK_FAILURE);
|
| + QUnit.equal(
|
| + remoting.Error.fromHttpStatus(100).tag_,
|
| + remoting.Error.Tag.UNEXPECTED);
|
| + QUnit.equal(
|
| + remoting.Error.fromHttpStatus(200).tag_,
|
| + remoting.Error.Tag.NONE);
|
| + QUnit.equal(
|
| + remoting.Error.fromHttpStatus(201).tag_,
|
| + remoting.Error.Tag.NONE);
|
| + QUnit.equal(
|
| + remoting.Error.fromHttpStatus(400).tag_,
|
| + remoting.Error.Tag.AUTHENTICATION_FAILED);
|
| + QUnit.equal(
|
| + remoting.Error.fromHttpStatus(401).tag_,
|
| + remoting.Error.Tag.AUTHENTICATION_FAILED);
|
| + QUnit.equal(
|
| + remoting.Error.fromHttpStatus(402).tag_,
|
| + remoting.Error.Tag.UNEXPECTED);
|
| + QUnit.equal(
|
| + remoting.Error.fromHttpStatus(403).tag_,
|
| + remoting.Error.Tag.NOT_AUTHORIZED);
|
| + QUnit.equal(
|
| + remoting.Error.fromHttpStatus(404).tag_,
|
| + remoting.Error.Tag.NOT_FOUND);
|
| + QUnit.equal(
|
| + remoting.Error.fromHttpStatus(500).tag_,
|
| + remoting.Error.Tag.SERVICE_UNAVAILABLE);
|
| + QUnit.equal(
|
| + remoting.Error.fromHttpStatus(501).tag_,
|
| + remoting.Error.Tag.SERVICE_UNAVAILABLE);
|
| + QUnit.equal(
|
| + remoting.Error.fromHttpStatus(600).tag_,
|
| + remoting.Error.Tag.UNEXPECTED);
|
| +});
|
| +
|
| +QUnit.test('handler 1', function() {
|
| + /** @type {!remoting.Error} */
|
| + var reportedError;
|
| + var onError = function(/** !remoting.Error */ arg) {
|
| + reportedError = arg;
|
| + };
|
| + remoting.Error.handler(onError)('???');
|
| + QUnit.ok(reportedError instanceof remoting.Error);
|
| + QUnit.equal(reportedError.tag_, remoting.Error.Tag.UNEXPECTED);
|
| +});
|
| +
|
| +
|
| +QUnit.test('handler 2', function() {
|
| + /** @type {!remoting.Error} */
|
| + var reportedError;
|
| + var onError = function(/** !remoting.Error */ arg) {
|
| + reportedError = arg;
|
| + };
|
| + var origError = new remoting.Error(remoting.Error.Tag.HOST_IS_OFFLINE);
|
| + remoting.Error.handler(onError)(origError);
|
| + QUnit.equal(reportedError, origError);
|
| +});
|
| +
|
| +})();
|
|
|