aboutsummaryrefslogtreecommitdiff
path: root/contexts/data/lib/closure-library/closure/goog/result/simpleresult_test.html
diff options
context:
space:
mode:
Diffstat (limited to 'contexts/data/lib/closure-library/closure/goog/result/simpleresult_test.html')
-rw-r--r--contexts/data/lib/closure-library/closure/goog/result/simpleresult_test.html254
1 files changed, 0 insertions, 254 deletions
diff --git a/contexts/data/lib/closure-library/closure/goog/result/simpleresult_test.html b/contexts/data/lib/closure-library/closure/goog/result/simpleresult_test.html
deleted file mode 100644
index df52c9c..0000000
--- a/contexts/data/lib/closure-library/closure/goog/result/simpleresult_test.html
+++ /dev/null
@@ -1,254 +0,0 @@
-<!DOCTYPE html>
-<html>
-<!--
-Copyright 2012 The Closure Library Authors. All Rights Reserved.
-
-Use of this source code is governed by the Apache License, Version 2.0.
-See the COPYING file for details.
--->
-<head>
-<title>Closure Unit Tests - goog.result.SimpleResult</title>
-<script src="../base.js"></script>
-<script>
-
-goog.require('goog.Timer');
-goog.require('goog.result');
-goog.require('goog.testing.MockClock');
-goog.require('goog.testing.recordFunction');
-goog.require('goog.testing.jsunit');
-
-</script>
-</head>
-<body>
-<script>
-
-var result, mockClock, resultCallback;
-
-function setUpPage() {
- mockClock = new goog.testing.MockClock();
- mockClock.install();
-}
-
-function setUp() {
- mockClock.reset();
- resultCallback = new goog.testing.recordFunction();
- resultCallback1 = new goog.testing.recordFunction();
- resultCallback2 = new goog.testing.recordFunction();
- result = new goog.result.SimpleResult();
-}
-
-function tearDown() {
- resultCallback = resultCallback1 = resultCallback2 = result = null;
-}
-
-function tearDownPage() {
- mockClock.uninstall();
- goog.dispose(mockClock);
-}
-
-function testHandlersCalledOnSuccess() {
- result.wait(resultCallback1);
- result.wait(resultCallback2);
-
- assertEquals(goog.result.Result.State.PENDING, result.getState());
- assertEquals(0, resultCallback1.getCallCount());
- assertEquals(0, resultCallback2.getCallCount());
-
- result.setValue(2);
-
- assertEquals(goog.result.Result.State.SUCCESS, result.getState());
- assertEquals(2, result.getValue());
- assertEquals(1, resultCallback1.getCallCount());
- assertEquals(1, resultCallback2.getCallCount());
-
- var res1 = resultCallback1.popLastCall().getArgument(0);
- assertObjectEquals(result, res1);
-
- var res2 = resultCallback2.popLastCall().getArgument(0);
- assertObjectEquals(result, res2);
-}
-
-function testHandlersCalledOnError() {
- result.wait(resultCallback1);
- result.wait(resultCallback2);
- assertEquals(goog.result.Result.State.PENDING, result.getState());
-
- var error = "Network Error";
- result.setError(error);
-
- assertEquals(goog.result.Result.State.ERROR, result.getState());
- assertEquals(error, result.getError());
- assertEquals(1, resultCallback1.getCallCount());
- assertEquals(1, resultCallback2.getCallCount());
-
- var res1 = resultCallback1.popLastCall().getArgument(0);
- assertObjectEquals(result, res1);
- var res2 = resultCallback2.popLastCall().getArgument(0);
- assertObjectEquals(result, res2);
-}
-
-function testAttachingHandlerOnSuccessfulResult() {
- result.setValue(2);
- assertEquals(goog.result.Result.State.SUCCESS, result.getState());
- assertEquals(2, result.getValue());
- // resultCallback should be called immediately on a resolved Result
- assertEquals(0, resultCallback.getCallCount());
-
- result.wait(resultCallback);
-
- assertEquals(1, resultCallback.getCallCount());
- var res = resultCallback.popLastCall().getArgument(0);
- assertEquals(result, res);
-}
-
-function testAttachingHandlerOnErrorResult() {
- var error = { code: -1, errorString: "Invalid JSON" };
- result.setError(error);
- assertEquals(goog.result.Result.State.ERROR, result.getState());
- assertEquals(error, result.getError());
- // resultCallback should be called immediately on a resolved Result
- assertEquals(0, resultCallback.getCallCount());
-
- result.wait(resultCallback);
-
- assertEquals(1, resultCallback.getCallCount());
- var res = resultCallback.popLastCall().getArgument(0);
- assertEquals(result, res);
-}
-
-function testExceptionThrownOnMultipleSuccessfulResolutionAttempts() {
- result.setValue(1);
- assertEquals(goog.result.Result.State.SUCCESS, result.getState());
- assertEquals(1, result.getValue());
-
- // Try to set the value again
- var e = assertThrows(goog.bind(result.setValue, result, 3));
- assertTrue(e instanceof goog.result.SimpleResult.StateError);
-}
-
-function testExceptionThrownOnMultipleErrorResolutionAttempts() {
- assertEquals(goog.result.Result.State.PENDING, result.getState());
-
- result.setError(5);
-
- assertEquals(goog.result.Result.State.ERROR, result.getState());
- assertEquals(5, result.getError());
- // Try to set error again
- var e = assertThrows(goog.bind(result.setError, result, 4));
- assertTrue(e instanceof goog.result.SimpleResult.StateError);
-}
-
-function testExceptionThrownOnSuccessThenErrorResolutionAttempt() {
- assertEquals(goog.result.Result.State.PENDING, result.getState());
-
- result.setValue(1);
-
- assertEquals(goog.result.Result.State.SUCCESS, result.getState());
- assertEquals(1, result.getValue());
-
- // Try to set error after setting value
- var e = assertThrows(goog.bind(result.setError, result, 3));
- assertTrue(e instanceof goog.result.SimpleResult.StateError);
-}
-
-function testExceptionThrownOnErrorThenSuccessResolutionAttempt() {
- assertEquals(goog.result.Result.State.PENDING, result.getState());
-
- var error = "fail";
- result.setError(error);
-
- assertEquals(goog.result.Result.State.ERROR, result.getState());
- assertEquals(error, result.getError());
- // Try to set value after setting error
- var e = assertThrows(goog.bind(result.setValue, result, 1));
- assertTrue(e instanceof goog.result.SimpleResult.StateError);
-}
-
-function testSuccessfulAsyncResolution() {
- result.wait(resultCallback);
- assertEquals(goog.result.Result.State.PENDING, result.getState());
-
- goog.Timer.callOnce(function() {
- result.setValue(1);
- });
- mockClock.tick();
-
- assertEquals(1, resultCallback.getCallCount());
-
- var res = resultCallback.popLastCall().getArgument(0);
- assertEquals(goog.result.Result.State.SUCCESS, res.getState());
- assertEquals(1, res.getValue());
-}
-
-function testErrorAsyncResolution() {
- result.wait(resultCallback);
- assertEquals(goog.result.Result.State.PENDING, result.getState());
-
- var error = 'Network failure';
- goog.Timer.callOnce(function() {
- result.setError(error);
- });
- mockClock.tick();
-
- assertEquals(1, resultCallback.getCallCount());
- var res = resultCallback.popLastCall().getArgument(0);
- assertEquals(goog.result.Result.State.ERROR, res.getState());
- assertEquals(error, res.getError());
-}
-
-function testCancelStateAndReturn() {
- assertFalse(result.isCanceled());
- var canceled = result.cancel();
- assertTrue(result.isCanceled());
- assertEquals(goog.result.Result.State.ERROR, result.getState());
- assertTrue(result.getError() instanceof goog.result.Result.CancelError);
- assertTrue(canceled);
-}
-
-function testErrorHandlersFireOnCancel() {
- result.wait(resultCallback);
- result.cancel();
-
- assertEquals(1, resultCallback.getCallCount());
- var lastCall = resultCallback.popLastCall();
- var res = lastCall.getArgument(0);
- assertEquals(goog.result.Result.State.ERROR, res.getState());
- assertTrue(res.getError() instanceof goog.result.Result.CancelError);
-}
-
-function testCancelAfterSetValue() {
- // cancel after setValue/setError => no-op
- result.wait(resultCallback);
- result.setValue(1);
-
- assertEquals(goog.result.Result.State.SUCCESS, result.getState());
- assertEquals(1, result.getValue());
- assertEquals(1, resultCallback.getCallCount());
-
- result.cancel();
-
- assertEquals(goog.result.Result.State.SUCCESS, result.getState());
- assertEquals(1, result.getValue());
- assertEquals(1, resultCallback.getCallCount());
-}
-
-function testSetValueAfterCancel() {
- // setValue/setError after cancel => no-op
- result.wait(resultCallback);
-
- result.cancel();
- assertTrue(result.isCanceled());
- assertTrue(result.getError() instanceof goog.result.Result.CancelError);
-
- result.setValue(1);
- assertTrue(result.isCanceled());
- assertTrue(result.getError() instanceof goog.result.Result.CancelError);
-
- result.setError(3);
- assertTrue(result.isCanceled());
- assertTrue(result.getError() instanceof goog.result.Result.CancelError);
-}
-
-</script>
-</body>
-</html>