aboutsummaryrefslogtreecommitdiff
path: root/contexts/data/lib/closure-library/closure/goog/result/wait_test.html
diff options
context:
space:
mode:
Diffstat (limited to 'contexts/data/lib/closure-library/closure/goog/result/wait_test.html')
-rw-r--r--contexts/data/lib/closure-library/closure/goog/result/wait_test.html194
1 files changed, 0 insertions, 194 deletions
diff --git a/contexts/data/lib/closure-library/closure/goog/result/wait_test.html b/contexts/data/lib/closure-library/closure/goog/result/wait_test.html
deleted file mode 100644
index 69b87d4..0000000
--- a/contexts/data/lib/closure-library/closure/goog/result/wait_test.html
+++ /dev/null
@@ -1,194 +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.wait</title>
-<script src="../base.js"></script>
-<script>
-
-goog.require('goog.Timer');
-goog.require('goog.result.SimpleResult');
-goog.require('goog.result');
-goog.require('goog.testing.MockClock');
-goog.require('goog.testing.jsunit');
-goog.require('goog.testing.recordFunction');
-
-</script>
-</head>
-<body>
-<script>
-
-var result, waitCallback, waitOnSuccessCallback, waitOnErrorCallback;
-
-var mockClock, propertyReplacer;
-
-function setUpPage() {
- mockClock = new goog.testing.MockClock();
- mockClock.install();
-}
-
-function setUp() {
- mockClock.reset();
- result = new goog.result.SimpleResult();
- propertyReplacer = new goog.testing.PropertyReplacer();
- waitCallback = new goog.testing.recordFunction();
- waitOnSuccessCallback = new goog.testing.recordFunction();
- waitOnErrorCallback = new goog.testing.recordFunction();
-}
-
-function tearDown() {
- result = waitCallback = waitOnSuccessCallback = waitOnErrorCallback = null;
- propertyReplacer.reset();
-}
-
-function tearDownPage() {
- mockClock.uninstall();
-}
-
-function testSynchronousSuccess() {
- assertEquals(goog.result.Result.State.PENDING, result.getState());
- assertUndefined(result.getValue());
-
- goog.result.wait(result, waitCallback);
- goog.result.waitOnSuccess(result, waitOnSuccessCallback);
- goog.result.waitOnError(result, waitOnErrorCallback);
-
- result.setValue(1);
-
- assertEquals(goog.result.Result.State.SUCCESS, result.getState());
- assertEquals(1, result.getValue());
-
- assertCall(waitCallback, result);
- assertSuccessCall(waitOnSuccessCallback, 1, result);
- assertNoCall(waitOnErrorCallback);
-}
-
-function testAsynchronousSuccess() {
- goog.result.wait(result, waitCallback);
- goog.result.waitOnSuccess(result, waitOnSuccessCallback);
- goog.result.waitOnError(result, waitOnErrorCallback);
-
- goog.Timer.callOnce(function() {
- result.setValue(1);
- });
-
- assertUndefined(result.getValue());
- assertEquals(goog.result.Result.State.PENDING, result.getState());
-
- assertNoCall(waitCallback);
- assertNoCall(waitOnSuccessCallback);
- assertNoCall(waitOnErrorCallback);
-
- mockClock.tick();
-
- assertEquals(goog.result.Result.State.SUCCESS, result.getState());
- assertEquals(1, result.getValue());
-
- assertCall(waitCallback, result);
- assertSuccessCall(waitOnSuccessCallback, 1, result);
- assertNoCall(waitOnErrorCallback);
-}
-
-function testSynchronousError() {
- assertEquals(goog.result.Result.State.PENDING, result.getState());
- assertUndefined(result.getValue());
-
- goog.result.wait(result, waitCallback);
- goog.result.waitOnSuccess(result, waitOnSuccessCallback);
- goog.result.waitOnError(result, waitOnErrorCallback);
-
- result.setError();
-
- assertEquals(goog.result.Result.State.ERROR, result.getState());
- assertUndefined(result.getValue());
-
- assertCall(waitCallback, result);
- assertNoCall(waitOnSuccessCallback);
- assertCall(waitOnErrorCallback, result);
-}
-
-function testAsynchronousError() {
- goog.result.wait(result, waitCallback);
- goog.result.waitOnSuccess(result, waitOnSuccessCallback);
- goog.result.waitOnError(result, waitOnErrorCallback);
-
- goog.Timer.callOnce(function() {
- result.setError();
- });
-
- assertEquals(goog.result.Result.State.PENDING, result.getState());
- assertUndefined(result.getValue());
-
- assertNoCall(waitCallback);
- assertNoCall(waitOnSuccessCallback);
- assertNoCall(waitOnErrorCallback);
-
- mockClock.tick();
-
- assertEquals(goog.result.Result.State.ERROR, result.getState());
- assertUndefined(result.getValue());
-
- assertCall(waitCallback, result);
- assertNoCall(waitOnSuccessCallback);
- assertCall(waitOnErrorCallback, result);
-}
-
-function testCustomScope() {
- var scope = {};
- goog.result.wait(result, waitCallback, scope);
- result.setValue(1);
- assertEquals(scope, waitCallback.popLastCall().getThis());
-}
-
-function testDefaultScope() {
- goog.result.wait(result, waitCallback);
- result.setValue(1);
- assertEquals(goog.global, waitCallback.popLastCall().getThis());
-}
-
-function testOnSuccessScope() {
- var scope = {};
- goog.result.waitOnSuccess(result, waitOnSuccessCallback, scope);
- result.setValue(1);
- assertSuccessCall(waitOnSuccessCallback, 1, result, scope);
-}
-
-function testOnErrorScope() {
- var scope = {};
- goog.result.waitOnError(result, waitOnErrorCallback, scope);
- result.setError();
- assertCall(waitOnErrorCallback, result, scope);
-}
-
-// opt_scope defaults to goog.global
-function assertCall(recordedFunction, result, opt_scope) {
- var scope = opt_scope || goog.global;
- assertEquals(1, recordedFunction.getCallCount());
- var call = recordedFunction.popLastCall();
- assertEquals(1, call.getArguments().length);
- assertEquals(result, call.getArgument(0));
- assertEquals(scope, call.getThis());
-}
-
-// opt_scope defaults to goog.global
-function assertSuccessCall(recordedFunction, value, result, opt_scope) {
- var scope = opt_scope || goog.global;
- assertEquals(1, recordedFunction.getCallCount());
- var call = recordedFunction.popLastCall();
- assertEquals(2, call.getArguments().length);
- assertEquals(value, call.getArgument(0));
- assertEquals(result, call.getArgument(1));
- assertEquals(scope, call.getThis());
-}
-
-function assertNoCall(recordedFunction) {
- assertEquals(0, recordedFunction.getCallCount());
-}
-</script>
-</body>
-</html>