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.
11 QUnit.test('error constructor 1', function(assert) {
12 var error = new remoting.Error(remoting.Error.Tag.HOST_OVERLOAD);
13 assert.equal(error.getTag(), remoting.Error.Tag.HOST_OVERLOAD);
14 assert.equal(error.toString(), remoting.Error.Tag.HOST_OVERLOAD);
17 QUnit.test('error constructor 2', function(assert) {
18 var error = new remoting.Error(
19 remoting.Error.Tag.HOST_IS_OFFLINE,
21 assert.equal(error.getTag(), remoting.Error.Tag.HOST_IS_OFFLINE);
22 assert.ok(error.toString().indexOf(remoting.Error.Tag.HOST_IS_OFFLINE) != -1);
23 assert.ok(error.toString().indexOf('detail') != -1);
26 QUnit.test('hasTag', function(assert) {
27 var error = new remoting.Error(remoting.Error.Tag.HOST_OVERLOAD);
28 assert.ok(error.hasTag(remoting.Error.Tag.HOST_OVERLOAD));
29 assert.ok(error.hasTag(
30 remoting.Error.Tag.HOST_OVERLOAD,
31 remoting.Error.Tag.HOST_IS_OFFLINE));
32 assert.ok(!error.hasTag(remoting.Error.Tag.HOST_IS_OFFLINE));
35 QUnit.test('constructor methods', function(assert) {
36 assert.ok(remoting.Error.none().hasTag(remoting.Error.Tag.NONE));
37 assert.ok(remoting.Error.unexpected().hasTag(remoting.Error.Tag.UNEXPECTED));
40 QUnit.test('isNone', function(assert) {
41 assert.ok(remoting.Error.none().isNone());
42 assert.ok(!remoting.Error.unexpected().isNone());
43 assert.ok(!new remoting.Error(remoting.Error.Tag.CANCELLED).isNone());
47 QUnit.test('fromHttpStatus', function(assert) {
48 assert.ok(remoting.Error.fromHttpStatus(200).isNone());
49 assert.ok(remoting.Error.fromHttpStatus(201).isNone());
50 assert.ok(!remoting.Error.fromHttpStatus(500).isNone());
52 remoting.Error.fromHttpStatus(0).getTag(),
53 remoting.Error.Tag.NETWORK_FAILURE);
55 remoting.Error.fromHttpStatus(100).getTag(),
56 remoting.Error.Tag.UNEXPECTED);
58 remoting.Error.fromHttpStatus(200).getTag(),
59 remoting.Error.Tag.NONE);
61 remoting.Error.fromHttpStatus(201).getTag(),
62 remoting.Error.Tag.NONE);
64 remoting.Error.fromHttpStatus(400).getTag(),
65 remoting.Error.Tag.AUTHENTICATION_FAILED);
67 remoting.Error.fromHttpStatus(401).getTag(),
68 remoting.Error.Tag.AUTHENTICATION_FAILED);
70 remoting.Error.fromHttpStatus(402).getTag(),
71 remoting.Error.Tag.UNEXPECTED);
73 remoting.Error.fromHttpStatus(403).getTag(),
74 remoting.Error.Tag.NOT_AUTHORIZED);
76 remoting.Error.fromHttpStatus(404).getTag(),
77 remoting.Error.Tag.NOT_FOUND);
79 remoting.Error.fromHttpStatus(500).getTag(),
80 remoting.Error.Tag.SERVICE_UNAVAILABLE);
82 remoting.Error.fromHttpStatus(501).getTag(),
83 remoting.Error.Tag.SERVICE_UNAVAILABLE);
85 remoting.Error.fromHttpStatus(600).getTag(),
86 remoting.Error.Tag.UNEXPECTED);
89 QUnit.test('handler 1', function(assert) {
90 /** @type {!remoting.Error} */
92 var onError = function(/** !remoting.Error */ arg) {
95 remoting.Error.handler(onError)('not a real tag');
96 assert.ok(reportedError instanceof remoting.Error);
97 assert.equal(reportedError.getTag(), remoting.Error.Tag.UNEXPECTED);
101 QUnit.test('handler 2', function(assert) {
102 /** @type {!remoting.Error} */
104 var onError = function(/** !remoting.Error */ arg) {
107 var origError = new remoting.Error(remoting.Error.Tag.HOST_IS_OFFLINE);
108 remoting.Error.handler(onError)(origError);
109 assert.equal(reportedError, origError);