OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 /** |
| 6 * @fileoverview |
| 7 * @suppress {checkTypes|checkVars|reportUnknownTypes} |
| 8 */ |
| 9 |
| 10 (function() { |
| 11 |
| 12 'use strict'; |
| 13 |
| 14 QUnit.module('error', { |
| 15 setup: function() { |
| 16 }, |
| 17 teardown: function() { |
| 18 } |
| 19 }); |
| 20 |
| 21 QUnit.test('error constructor 1', function() { |
| 22 var error = new remoting.Error(remoting.Error.Tag.HOST_OVERLOAD); |
| 23 QUnit.strictEqual(error.tag, remoting.Error.Tag.HOST_OVERLOAD); |
| 24 QUnit.strictEqual(error.message, null); |
| 25 }); |
| 26 |
| 27 QUnit.test('error constructor 2', function() { |
| 28 var error = new remoting.Error( |
| 29 remoting.Error.Tag.HOST_IS_OFFLINE, |
| 30 'detail'); |
| 31 QUnit.strictEqual(error.tag, remoting.Error.Tag.HOST_IS_OFFLINE); |
| 32 QUnit.strictEqual(error.message, 'detail'); |
| 33 }); |
| 34 |
| 35 QUnit.test('hasTag', function() { |
| 36 var error = new remoting.Error(remoting.Error.Tag.HOST_OVERLOAD); |
| 37 QUnit.ok(error.hasTag(remoting.Error.Tag.HOST_OVERLOAD)); |
| 38 QUnit.ok(!error.hasTag(remoting.Error.Tag.HOST_IS_OFFLINE)); |
| 39 }); |
| 40 |
| 41 QUnit.test('constructor methods', function() { |
| 42 QUnit.ok(remoting.Error.none().hasTag(remoting.Error.Tag.NONE)); |
| 43 QUnit.ok(remoting.Error.unexpected().hasTag(remoting.Error.Tag.UNEXPECTED)); |
| 44 }); |
| 45 |
| 46 QUnit.test('isError', function() { |
| 47 QUnit.ok(!remoting.Error.none().isError()); |
| 48 QUnit.ok(remoting.Error.unexpected().isError()); |
| 49 }); |
| 50 |
| 51 |
| 52 QUnit.test('fromHttpStatus', function() { |
| 53 QUnit.ok(!remoting.Error.fromHttpStatus(200).isError()); |
| 54 QUnit.ok(!remoting.Error.fromHttpStatus(201).isError()); |
| 55 QUnit.ok(remoting.Error.fromHttpStatus(500).isError()); |
| 56 QUnit.strictEqual( |
| 57 remoting.Error.fromHttpStatus(0).tag, |
| 58 remoting.Error.Tag.NETWORK_FAILURE); |
| 59 QUnit.strictEqual( |
| 60 remoting.Error.fromHttpStatus(100).tag, |
| 61 remoting.Error.Tag.UNEXPECTED); |
| 62 QUnit.strictEqual( |
| 63 remoting.Error.fromHttpStatus(200).tag, |
| 64 remoting.Error.Tag.NONE); |
| 65 QUnit.strictEqual( |
| 66 remoting.Error.fromHttpStatus(201).tag, |
| 67 remoting.Error.Tag.NONE); |
| 68 QUnit.strictEqual( |
| 69 remoting.Error.fromHttpStatus(400).tag, |
| 70 remoting.Error.Tag.AUTHENTICATION_FAILED); |
| 71 QUnit.strictEqual( |
| 72 remoting.Error.fromHttpStatus(401).tag, |
| 73 remoting.Error.Tag.AUTHENTICATION_FAILED); |
| 74 QUnit.strictEqual( |
| 75 remoting.Error.fromHttpStatus(402).tag, |
| 76 remoting.Error.Tag.UNEXPECTED); |
| 77 QUnit.strictEqual( |
| 78 remoting.Error.fromHttpStatus(403).tag, |
| 79 remoting.Error.Tag.NOT_AUTHORIZED); |
| 80 QUnit.strictEqual( |
| 81 remoting.Error.fromHttpStatus(404).tag, |
| 82 remoting.Error.Tag.NOT_FOUND); |
| 83 QUnit.strictEqual( |
| 84 remoting.Error.fromHttpStatus(500).tag, |
| 85 remoting.Error.Tag.SERVICE_UNAVAILABLE); |
| 86 QUnit.strictEqual( |
| 87 remoting.Error.fromHttpStatus(501).tag, |
| 88 remoting.Error.Tag.SERVICE_UNAVAILABLE); |
| 89 QUnit.strictEqual( |
| 90 remoting.Error.fromHttpStatus(600).tag, |
| 91 remoting.Error.Tag.UNEXPECTED); |
| 92 }); |
| 93 |
| 94 QUnit.test('handler 1', function() { |
| 95 var reportedError; |
| 96 var onError = function(arg) { |
| 97 reportedError = arg; |
| 98 }; |
| 99 remoting.Error.handler(onError)('???'); |
| 100 QUnit.ok(reportedError instanceof remoting.Error); |
| 101 QUnit.strictEqual(reportedError.tag, remoting.Error.Tag.UNEXPECTED); |
| 102 }); |
| 103 |
| 104 |
| 105 QUnit.test('handler 2', function() { |
| 106 var reportedError; |
| 107 var onError = function(arg) { |
| 108 reportedError = arg; |
| 109 }; |
| 110 var origError = new remoting.Error(remoting.Error.Tag.HOST_IS_OFFLINE); |
| 111 remoting.Error.handler(onError)(origError); |
| 112 QUnit.strictEqual(reportedError, origError); |
| 113 }); |
| 114 |
| 115 })(); |
OLD | NEW |