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