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

Unified Diff: remoting/webapp/unittests/error_unittest.js

Issue 955283002: Converted remoting.Error from an enum to a class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/webapp/crd/js/xmpp_login_handler.js ('k') | remoting/webapp/unittests/mock_signal_strategy.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/webapp/unittests/error_unittest.js
diff --git a/remoting/webapp/unittests/error_unittest.js b/remoting/webapp/unittests/error_unittest.js
new file mode 100644
index 0000000000000000000000000000000000000000..21547e4034579696335811e1f5bd5af88acba476
--- /dev/null
+++ b/remoting/webapp/unittests/error_unittest.js
@@ -0,0 +1,115 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @fileoverview
+ * @suppress {checkTypes|checkVars|reportUnknownTypes}
+ */
+
+(function() {
+
+'use strict';
+
+QUnit.module('error', {
+ setup: function() {
+ },
+ teardown: function() {
+ }
+});
+
+QUnit.test('error constructor 1', function() {
+ var error = new remoting.Error(remoting.Error.Tag.HOST_OVERLOAD);
+ QUnit.strictEqual(error.tag, remoting.Error.Tag.HOST_OVERLOAD);
+ QUnit.strictEqual(error.message, null);
+});
+
+QUnit.test('error constructor 2', function() {
+ var error = new remoting.Error(
+ remoting.Error.Tag.HOST_IS_OFFLINE,
+ 'detail');
+ QUnit.strictEqual(error.tag, remoting.Error.Tag.HOST_IS_OFFLINE);
+ QUnit.strictEqual(error.message, 'detail');
+});
+
+QUnit.test('hasTag', function() {
+ var error = new remoting.Error(remoting.Error.Tag.HOST_OVERLOAD);
+ QUnit.ok(error.hasTag(remoting.Error.Tag.HOST_OVERLOAD));
+ QUnit.ok(!error.hasTag(remoting.Error.Tag.HOST_IS_OFFLINE));
+});
+
+QUnit.test('constructor methods', function() {
+ QUnit.ok(remoting.Error.none().hasTag(remoting.Error.Tag.NONE));
+ QUnit.ok(remoting.Error.unexpected().hasTag(remoting.Error.Tag.UNEXPECTED));
+});
+
+QUnit.test('isError', function() {
+ QUnit.ok(!remoting.Error.none().isError());
+ QUnit.ok(remoting.Error.unexpected().isError());
+});
+
+
+QUnit.test('fromHttpStatus', function() {
+ QUnit.ok(!remoting.Error.fromHttpStatus(200).isError());
+ QUnit.ok(!remoting.Error.fromHttpStatus(201).isError());
+ QUnit.ok(remoting.Error.fromHttpStatus(500).isError());
+ QUnit.strictEqual(
+ remoting.Error.fromHttpStatus(0).tag,
+ remoting.Error.Tag.NETWORK_FAILURE);
+ QUnit.strictEqual(
+ remoting.Error.fromHttpStatus(100).tag,
+ remoting.Error.Tag.UNEXPECTED);
+ QUnit.strictEqual(
+ remoting.Error.fromHttpStatus(200).tag,
+ remoting.Error.Tag.NONE);
+ QUnit.strictEqual(
+ remoting.Error.fromHttpStatus(201).tag,
+ remoting.Error.Tag.NONE);
+ QUnit.strictEqual(
+ remoting.Error.fromHttpStatus(400).tag,
+ remoting.Error.Tag.AUTHENTICATION_FAILED);
+ QUnit.strictEqual(
+ remoting.Error.fromHttpStatus(401).tag,
+ remoting.Error.Tag.AUTHENTICATION_FAILED);
+ QUnit.strictEqual(
+ remoting.Error.fromHttpStatus(402).tag,
+ remoting.Error.Tag.UNEXPECTED);
+ QUnit.strictEqual(
+ remoting.Error.fromHttpStatus(403).tag,
+ remoting.Error.Tag.NOT_AUTHORIZED);
+ QUnit.strictEqual(
+ remoting.Error.fromHttpStatus(404).tag,
+ remoting.Error.Tag.NOT_FOUND);
+ QUnit.strictEqual(
+ remoting.Error.fromHttpStatus(500).tag,
+ remoting.Error.Tag.SERVICE_UNAVAILABLE);
+ QUnit.strictEqual(
+ remoting.Error.fromHttpStatus(501).tag,
+ remoting.Error.Tag.SERVICE_UNAVAILABLE);
+ QUnit.strictEqual(
+ remoting.Error.fromHttpStatus(600).tag,
+ remoting.Error.Tag.UNEXPECTED);
+});
+
+QUnit.test('handler 1', function() {
+ var reportedError;
+ var onError = function(arg) {
+ reportedError = arg;
+ };
+ remoting.Error.handler(onError)('???');
+ QUnit.ok(reportedError instanceof remoting.Error);
+ QUnit.strictEqual(reportedError.tag, remoting.Error.Tag.UNEXPECTED);
+});
+
+
+QUnit.test('handler 2', function() {
+ var reportedError;
+ var onError = function(arg) {
+ reportedError = arg;
+ };
+ var origError = new remoting.Error(remoting.Error.Tag.HOST_IS_OFFLINE);
+ remoting.Error.handler(onError)(origError);
+ QUnit.strictEqual(reportedError, origError);
+});
+
+})();
« no previous file with comments | « remoting/webapp/crd/js/xmpp_login_handler.js ('k') | remoting/webapp/unittests/mock_signal_strategy.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698