Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Side by Side Diff: remoting/webapp/crd/js/error_unittest.js

Issue 1003433002: Updated remoting.xhr API to use promises. Removed access to the native (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@spy-promise
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 setup: function() {
11 },
12 teardown: function() {
13 }
14 });
15
16 QUnit.test('error constructor 1', function() {
17 var error = new remoting.Error(remoting.Error.Tag.HOST_OVERLOAD);
18 QUnit.equal(error.getTag(), remoting.Error.Tag.HOST_OVERLOAD);
19 QUnit.equal(error.toString(), remoting.Error.Tag.HOST_OVERLOAD);
20 });
21
22 QUnit.test('error constructor 2', function() {
23 var error = new remoting.Error(
24 remoting.Error.Tag.HOST_IS_OFFLINE,
25 'detail');
26 QUnit.equal(error.getTag(), remoting.Error.Tag.HOST_IS_OFFLINE);
27 QUnit.ok(error.toString().indexOf(remoting.Error.Tag.HOST_IS_OFFLINE) != -1);
28 QUnit.ok(error.toString().indexOf('detail') != -1);
29 });
30
31 QUnit.test('hasTag', function() {
32 var error = new remoting.Error(remoting.Error.Tag.HOST_OVERLOAD);
33 QUnit.ok(error.hasTag(remoting.Error.Tag.HOST_OVERLOAD));
34 QUnit.ok(error.hasTag(
35 remoting.Error.Tag.HOST_OVERLOAD,
36 remoting.Error.Tag.HOST_IS_OFFLINE));
37 QUnit.ok(!error.hasTag(remoting.Error.Tag.HOST_IS_OFFLINE));
38 });
39
40 QUnit.test('constructor methods', function() {
41 QUnit.ok(remoting.Error.none().hasTag(remoting.Error.Tag.NONE));
42 QUnit.ok(remoting.Error.unexpected().hasTag(remoting.Error.Tag.UNEXPECTED));
43 });
44
45 QUnit.test('isNone', function() {
46 QUnit.ok(remoting.Error.none().isNone());
47 QUnit.ok(!remoting.Error.unexpected().isNone());
48 QUnit.ok(!new remoting.Error(remoting.Error.Tag.CANCELLED).isNone());
49 });
50
51
52 QUnit.test('fromHttpStatus', function() {
53 QUnit.ok(remoting.Error.fromHttpStatus(200).isNone());
54 QUnit.ok(remoting.Error.fromHttpStatus(201).isNone());
55 QUnit.ok(!remoting.Error.fromHttpStatus(500).isNone());
56 QUnit.equal(
57 remoting.Error.fromHttpStatus(0).getTag(),
58 remoting.Error.Tag.NETWORK_FAILURE);
59 QUnit.equal(
60 remoting.Error.fromHttpStatus(100).getTag(),
61 remoting.Error.Tag.UNEXPECTED);
62 QUnit.equal(
63 remoting.Error.fromHttpStatus(200).getTag(),
64 remoting.Error.Tag.NONE);
65 QUnit.equal(
66 remoting.Error.fromHttpStatus(201).getTag(),
67 remoting.Error.Tag.NONE);
68 QUnit.equal(
69 remoting.Error.fromHttpStatus(400).getTag(),
70 remoting.Error.Tag.AUTHENTICATION_FAILED);
71 QUnit.equal(
72 remoting.Error.fromHttpStatus(401).getTag(),
73 remoting.Error.Tag.AUTHENTICATION_FAILED);
74 QUnit.equal(
75 remoting.Error.fromHttpStatus(402).getTag(),
76 remoting.Error.Tag.UNEXPECTED);
77 QUnit.equal(
78 remoting.Error.fromHttpStatus(403).getTag(),
79 remoting.Error.Tag.NOT_AUTHORIZED);
80 QUnit.equal(
81 remoting.Error.fromHttpStatus(404).getTag(),
82 remoting.Error.Tag.NOT_FOUND);
83 QUnit.equal(
84 remoting.Error.fromHttpStatus(500).getTag(),
85 remoting.Error.Tag.SERVICE_UNAVAILABLE);
86 QUnit.equal(
87 remoting.Error.fromHttpStatus(501).getTag(),
88 remoting.Error.Tag.SERVICE_UNAVAILABLE);
89 QUnit.equal(
90 remoting.Error.fromHttpStatus(600).getTag(),
91 remoting.Error.Tag.UNEXPECTED);
92 });
93
94 QUnit.test('handler 1', function() {
95 /** @type {!remoting.Error} */
96 var reportedError;
97 var onError = function(/** !remoting.Error */ arg) {
98 reportedError = arg;
99 };
100 remoting.Error.handler(onError)('not a real tag');
101 QUnit.ok(reportedError instanceof remoting.Error);
102 QUnit.equal(reportedError.getTag(), remoting.Error.Tag.UNEXPECTED);
103 });
104
105
106 QUnit.test('handler 2', function() {
107 /** @type {!remoting.Error} */
108 var reportedError;
109 var onError = function(/** !remoting.Error */ arg) {
110 reportedError = arg;
111 };
112 var origError = new remoting.Error(remoting.Error.Tag.HOST_IS_OFFLINE);
113 remoting.Error.handler(onError)(origError);
114 QUnit.equal(reportedError, origError);
115 });
116
117 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698