| 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 (function() { | |
| 6 | |
| 7 'use strict'; | |
| 8 | |
| 9 QUnit.module('error'); | |
| 10 | |
| 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); | |
| 15 }); | |
| 16 | |
| 17 QUnit.test('error constructor 2', function(assert) { | |
| 18 var error = new remoting.Error( | |
| 19 remoting.Error.Tag.HOST_IS_OFFLINE, | |
| 20 'detail'); | |
| 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); | |
| 24 }); | |
| 25 | |
| 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)); | |
| 33 }); | |
| 34 | |
| 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)); | |
| 38 }); | |
| 39 | |
| 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()); | |
| 44 }); | |
| 45 | |
| 46 | |
| 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()); | |
| 51 assert.equal( | |
| 52 remoting.Error.fromHttpStatus(0).getTag(), | |
| 53 remoting.Error.Tag.NETWORK_FAILURE); | |
| 54 assert.equal( | |
| 55 remoting.Error.fromHttpStatus(100).getTag(), | |
| 56 remoting.Error.Tag.UNEXPECTED); | |
| 57 assert.equal( | |
| 58 remoting.Error.fromHttpStatus(200).getTag(), | |
| 59 remoting.Error.Tag.NONE); | |
| 60 assert.equal( | |
| 61 remoting.Error.fromHttpStatus(201).getTag(), | |
| 62 remoting.Error.Tag.NONE); | |
| 63 assert.equal( | |
| 64 remoting.Error.fromHttpStatus(400).getTag(), | |
| 65 remoting.Error.Tag.AUTHENTICATION_FAILED); | |
| 66 assert.equal( | |
| 67 remoting.Error.fromHttpStatus(401).getTag(), | |
| 68 remoting.Error.Tag.AUTHENTICATION_FAILED); | |
| 69 assert.equal( | |
| 70 remoting.Error.fromHttpStatus(402).getTag(), | |
| 71 remoting.Error.Tag.UNEXPECTED); | |
| 72 assert.equal( | |
| 73 remoting.Error.fromHttpStatus(403).getTag(), | |
| 74 remoting.Error.Tag.NOT_AUTHORIZED); | |
| 75 assert.equal( | |
| 76 remoting.Error.fromHttpStatus(404).getTag(), | |
| 77 remoting.Error.Tag.NOT_FOUND); | |
| 78 assert.equal( | |
| 79 remoting.Error.fromHttpStatus(500).getTag(), | |
| 80 remoting.Error.Tag.SERVICE_UNAVAILABLE); | |
| 81 assert.equal( | |
| 82 remoting.Error.fromHttpStatus(501).getTag(), | |
| 83 remoting.Error.Tag.SERVICE_UNAVAILABLE); | |
| 84 assert.equal( | |
| 85 remoting.Error.fromHttpStatus(600).getTag(), | |
| 86 remoting.Error.Tag.UNEXPECTED); | |
| 87 }); | |
| 88 | |
| 89 QUnit.test('handler 1', function(assert) { | |
| 90 /** @type {!remoting.Error} */ | |
| 91 var reportedError; | |
| 92 var onError = function(/** !remoting.Error */ arg) { | |
| 93 reportedError = arg; | |
| 94 }; | |
| 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); | |
| 98 }); | |
| 99 | |
| 100 | |
| 101 QUnit.test('handler 2', function(assert) { | |
| 102 /** @type {!remoting.Error} */ | |
| 103 var reportedError; | |
| 104 var onError = function(/** !remoting.Error */ arg) { | |
| 105 reportedError = arg; | |
| 106 }; | |
| 107 var origError = new remoting.Error(remoting.Error.Tag.HOST_IS_OFFLINE); | |
| 108 remoting.Error.handler(onError)(origError); | |
| 109 assert.equal(reportedError, origError); | |
| 110 }); | |
| 111 | |
| 112 })(); | |
| OLD | NEW |