diff options
Diffstat (limited to 'contexts/data/lib/closure-library/closure/goog/testing/async/.svn')
6 files changed, 0 insertions, 520 deletions
diff --git a/contexts/data/lib/closure-library/closure/goog/testing/async/.svn/all-wcprops b/contexts/data/lib/closure-library/closure/goog/testing/async/.svn/all-wcprops deleted file mode 100644 index a34ad80..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/async/.svn/all-wcprops +++ /dev/null @@ -1,17 +0,0 @@ -K 25 -svn:wc:ra_dav:version-url -V 51 -/svn/!svn/ver/1434/trunk/closure/goog/testing/async -END -mockcontrol.js -K 25 -svn:wc:ra_dav:version-url -V 65 -/svn/!svn/ver/850/trunk/closure/goog/testing/async/mockcontrol.js -END -mockcontrol_test.html -K 25 -svn:wc:ra_dav:version-url -V 73 -/svn/!svn/ver/1434/trunk/closure/goog/testing/async/mockcontrol_test.html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/async/.svn/entries b/contexts/data/lib/closure-library/closure/goog/testing/async/.svn/entries deleted file mode 100644 index 9043113..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/async/.svn/entries +++ /dev/null @@ -1,96 +0,0 @@ -10 - -dir -1494 -http://closure-library.googlecode.com/svn/trunk/closure/goog/testing/async -http://closure-library.googlecode.com/svn - - - -2011-11-30T22:16:21.000000Z -1434 -chrishenry@google.com - - - - - - - - - - - - - - -0b95b8e8-c90f-11de-9d4f-f947ee5921c8 - -mockcontrol.js -file - - - - -2011-12-23T22:42:26.940311Z -008c591a7303cb0978222f1c9d0f0d36 -2011-04-12T20:35:47.000000Z -850 -diegosalas@google.com -has-props - - - - - - - - - - - - - - - - - - - - -6338 - -mockcontrol_test.html -file - - - - -2011-12-23T22:42:26.941311Z -2d8cd4667fc5ca6aafc4bfd1e0d6811f -2011-11-30T22:16:21.000000Z -1434 -chrishenry@google.com -has-props - - - - - - - - - - - - - - - - - - - - -7058 - diff --git a/contexts/data/lib/closure-library/closure/goog/testing/async/.svn/prop-base/mockcontrol.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/async/.svn/prop-base/mockcontrol.js.svn-base deleted file mode 100644 index 7febff5..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/async/.svn/prop-base/mockcontrol.js.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 22 -application/javascript -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/async/.svn/prop-base/mockcontrol_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/async/.svn/prop-base/mockcontrol_test.html.svn-base deleted file mode 100644 index d356868..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/async/.svn/prop-base/mockcontrol_test.html.svn-base +++ /dev/null @@ -1,5 +0,0 @@ -K 13 -svn:mime-type -V 9 -text/html -END diff --git a/contexts/data/lib/closure-library/closure/goog/testing/async/.svn/text-base/mockcontrol.js.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/async/.svn/text-base/mockcontrol.js.svn-base deleted file mode 100644 index 7505812..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/async/.svn/text-base/mockcontrol.js.svn-base +++ /dev/null @@ -1,174 +0,0 @@ -// Copyright 2010 The Closure Library Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS-IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** - * @fileoverview A wrapper for MockControl that provides mocks and assertions - * for testing asynchronous code. All assertions will only be verified when - * $verifyAll is called on the wrapped MockControl. - * - * This class is meant primarily for testing code that exposes asynchronous APIs - * without being truly asynchronous (using asynchronous primitives like browser - * events or timeouts). This is often the case when true asynchronous - * depedencies have been mocked out. This means that it doesn't rely on - * AsyncTestCase or DeferredTestCase, although it can be used with those as - * well. - * - * Example usage: - * - * <pre> - * var mockControl = new goog.testing.MockControl(); - * var asyncMockControl = new goog.testing.async.MockControl(mockControl); - * - * myAsyncObject.onSuccess(asyncMockControl.asyncAssertEquals( - * 'callback should run and pass the correct value', - * 'http://someurl.com'); - * asyncMockControl.assertDeferredEquals( - * 'deferred object should be resolved with the correct value', - * 'http://someurl.com', - * myAsyncObject.getDeferredUrl()); - * asyncMockControl.run(); - * mockControl.$verifyAll(); - * </pre> - * - */ - - -goog.provide('goog.testing.async.MockControl'); - -goog.require('goog.asserts'); -goog.require('goog.async.Deferred'); -goog.require('goog.debug'); -goog.require('goog.testing.asserts'); -goog.require('goog.testing.mockmatchers.IgnoreArgument'); - - - -/** - * Provides asynchronous mocks and assertions controlled by a parent - * MockControl. - * - * @param {goog.testing.MockControl} mockControl The parent MockControl. - * @constructor - */ -goog.testing.async.MockControl = function(mockControl) { - /** - * The parent MockControl. - * @type {goog.testing.MockControl} - * @private - */ - this.mockControl_ = mockControl; -}; - - -/** - * Returns a function that will assert that it will be called, and run the given - * callback when it is. - * - * @param {string} name The name of the callback mock. - * @param {function(...[*]) : *} callback The wrapped callback. This will be - * called when the returned function is called. - * @param {Object=} opt_selfObj The object which this should point to when the - * callback is run. - * @return {!Function} The mock callback. - * @suppress {missingProperties} Mocks do not fit in the type system well. - */ -goog.testing.async.MockControl.prototype.createCallbackMock = function( - name, callback, opt_selfObj) { - goog.asserts.assert( - goog.isString(name), - 'name parameter ' + goog.debug.deepExpose(name) + ' should be a string'); - - var ignored = new goog.testing.mockmatchers.IgnoreArgument(); - - // Use everyone's favorite "double-cast" trick to subvert the type system. - var obj = /** @type {Object} */ (this.mockControl_.createFunctionMock(name)); - var fn = /** @type {Function} */ (obj); - - fn(ignored).$does(function(args) { - if (opt_selfObj) { - callback = goog.bind(callback, opt_selfObj); - } - return callback.apply(this, args); - }); - fn.$replay(); - return function() { return fn(arguments); }; -}; - - -/** - * Returns a function that will assert that its arguments are equal to the - * arguments given to asyncAssertEquals. In addition, the function also asserts - * that it will be called. - * - * @param {string} message A message to print if the arguments are wrong. - * @param {...*} var_args The arguments to assert. - * @return {function(...[*]) : void} The mock callback. - */ -goog.testing.async.MockControl.prototype.asyncAssertEquals = function( - message, var_args) { - var expectedArgs = Array.prototype.slice.call(arguments, 1); - return this.createCallbackMock('asyncAssertEquals', function() { - assertObjectEquals( - message, expectedArgs, Array.prototype.slice.call(arguments)); - }); -}; - - -/** - * Asserts that a deferred object will have an error and call its errback - * function. - * @param {goog.async.Deferred} deferred The deferred object. - * @param {function() : void} fn A function wrapping the code in which the error - * will occur. - */ -goog.testing.async.MockControl.prototype.assertDeferredError = function( - deferred, fn) { - deferred.addErrback(this.createCallbackMock( - 'assertDeferredError', function() {})); - goog.testing.asserts.callWithoutLogging(fn); -}; - - -/** - * Asserts that a deferred object will call its callback with the given value. - * - * @param {string} message A message to print if the arguments are wrong. - * @param {goog.async.Deferred|*} expected The expected value. If this is a - * deferred object, then the expected value is the deferred value. - * @param {goog.async.Deferred|*} actual The actual value. If this is a deferred - * object, then the actual value is the deferred value. Either this or - * 'expected' must be deferred. - */ -goog.testing.async.MockControl.prototype.assertDeferredEquals = function( - message, expected, actual) { - if (expected instanceof goog.async.Deferred && - actual instanceof goog.async.Deferred) { - // Assert that the first deferred is resolved. - expected.addCallback(this.createCallbackMock( - 'assertDeferredEquals', function(exp) { - // Assert that the second deferred is resolved, and that the value is - // as expected. - actual.addCallback(this.asyncAssertEquals(message, exp)); - }, this)); - } else if (expected instanceof goog.async.Deferred) { - expected.addCallback(this.createCallbackMock( - 'assertDeferredEquals', function(exp) { - assertObjectEquals(message, exp, actual); - })); - } else if (actual instanceof goog.async.Deferred) { - actual.addCallback(this.asyncAssertEquals(message, expected)); - } else { - throw Error('Either expected or actual must be deferred'); - } -}; diff --git a/contexts/data/lib/closure-library/closure/goog/testing/async/.svn/text-base/mockcontrol_test.html.svn-base b/contexts/data/lib/closure-library/closure/goog/testing/async/.svn/text-base/mockcontrol_test.html.svn-base deleted file mode 100644 index 83c4797..0000000 --- a/contexts/data/lib/closure-library/closure/goog/testing/async/.svn/text-base/mockcontrol_test.html.svn-base +++ /dev/null @@ -1,223 +0,0 @@ -<!DOCTYPE html> -<html> -<!-- -Copyright 2010 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.testing.async.MockControl; -</title> -<script type="text/javascript" src="../../base.js"></script> -<script type="text/javascript"> -goog.require('goog.async.Deferred'); -goog.require('goog.testing.MockControl'); -goog.require('goog.testing.async.MockControl'); -goog.require('goog.testing.jsunit'); -goog.require('goog.testing.asserts'); -</script> -</head> -<body> -<script type="text/javascript"> -var mockControl; -var asyncMockControl; - -var mockControl2; -var asyncMockControl2; - -function setUp() { - mockControl = new goog.testing.MockControl(); - asyncMockControl = new goog.testing.async.MockControl(mockControl); - - // We need two of these for the tests where we need to verify our meta-test - // assertions without verifying our tested assertions. - mockControl2 = new goog.testing.MockControl(); - asyncMockControl2 = new goog.testing.async.MockControl(mockControl2); -} - -function assertVerifyFails() { - assertThrowsJsUnitException(function() { mockControl.$verifyAll(); }); -} - -function testCreateCallbackMockFailure() { - asyncMockControl.createCallbackMock('failingCallbackMock', function() {}); - assertVerifyFails(); -} - -function testCreateCallbackMockSuccess() { - var callback = asyncMockControl.createCallbackMock( - 'succeedingCallbackMock', function() {}); - callback(); - mockControl.$verifyAll(); -} - -function testCreateCallbackMockSuccessWithArg() { - var callback = asyncMockControl.createCallbackMock( - 'succeedingCallbackMockWithArg', - asyncMockControl.createCallbackMock( - 'metaCallbackMock', - function(val) { assertEquals(10, val); })); - callback(10); - mockControl.$verifyAll(); -} - -function testCreateCallbackMockSuccessWithArgs() { - var callback = asyncMockControl.createCallbackMock( - 'succeedingCallbackMockWithArgs', - asyncMockControl.createCallbackMock( - 'metaCallbackMock', function(val1, val2, val3) { - assertEquals(10, val1); - assertEquals('foo', val2); - assertObjectEquals({foo: 'bar'}, val3); - })); - callback(10, 'foo', {foo: 'bar'}); - mockControl.$verifyAll(); -} - -function testAsyncAssertEqualsFailureNeverCalled() { - asyncMockControl.asyncAssertEquals('never called', 12); - assertVerifyFails(); -} - -function testAsyncAssertEqualsFailureNumberOfArgs() { - assertThrowsJsUnitException(function() { - asyncMockControl.asyncAssertEquals('wrong number of args', 12)(); - }); -} - -function testAsyncAssertEqualsFailureOneArg() { - assertThrowsJsUnitException(function() { - asyncMockControl.asyncAssertEquals('wrong arg value', 12)(13); - }); -} - -function testAsyncAssertEqualsFailureThreeArgs() { - assertThrowsJsUnitException(function() { - asyncMockControl.asyncAssertEquals('wrong arg values', 1, 2, 15)(2, 2, 15); - }); -} - -function testAsyncAssertEqualsSuccessNoArgs() { - asyncMockControl.asyncAssertEquals('should be called')(); - mockControl.$verifyAll(); -} - -function testAsyncAssertEqualsSuccessThreeArgs() { - asyncMockControl.asyncAssertEquals('should have args', 1, 2, 3)(1, 2, 3); - mockControl.$verifyAll(); -} - -function testAssertDeferredErrorFailureNoError() { - var deferred = new goog.async.Deferred(); - asyncMockControl.assertDeferredError(deferred, function() {}); - assertVerifyFails(); -} - -function testAssertDeferredErrorSuccess() { - var deferred = new goog.async.Deferred(); - asyncMockControl.assertDeferredError(deferred, function() { - deferred.errback(new Error('FAIL')); - }); - mockControl.$verifyAll(); -} - -function testAssertDeferredEqualsFailureActualDeferredNeverResolves() { - var actual = new goog.async.Deferred(); - asyncMockControl.assertDeferredEquals('doesn\'t resolve', 12, actual); - assertVerifyFails(); -} - -function testAssertDeferredEqualsFailureActualDeferredNeverResolvesBoth() { - var actualDeferred = new goog.async.Deferred(); - var expectedDeferred = new goog.async.Deferred(); - expectedDeferred.callback(12); - asyncMockControl.assertDeferredEquals( - 'doesn\'t resolve', expectedDeferred, actualDeferred); - assertVerifyFails(); -} - -function testAssertDeferredEqualsFailureExpectedDeferredNeverResolves() { - var expected = new goog.async.Deferred(); - asyncMockControl.assertDeferredEquals('doesn\'t resolve', expected, 12); - assertVerifyFails(); -} - -function testAssertDeferredEqualsFailureExpectedDeferredNeverResolvesBoth() { - var actualDeferred = new goog.async.Deferred(); - var expectedDeferred = new goog.async.Deferred(); - actualDeferred.callback(12); - asyncMockControl.assertDeferredEquals( - 'doesn\'t resolve', expectedDeferred, actualDeferred); - assertVerifyFails(); -} - -function testAssertDeferredEqualsFailureWrongValueActualDeferred() { - var actual = new goog.async.Deferred(); - asyncMockControl.assertDeferredEquals('doesn\'t resolve', 12, actual); - asyncMockControl2.assertDeferredError(actual, function() { - actual.callback(13); - }); - mockControl2.$verifyAll(); -} - -function testAssertDeferredEqualsFailureWrongValueExpectedDeferred() { - var expected = new goog.async.Deferred(); - asyncMockControl.assertDeferredEquals('doesn\'t resolve', expected, 12); - asyncMockControl2.assertDeferredError(expected, function() { - expected.callback(13); - }); - mockControl2.$verifyAll(); -} - -function testAssertDeferredEqualsFailureWongValueBothDeferred() { - var actualDeferred = new goog.async.Deferred(); - var expectedDeferred = new goog.async.Deferred(); - asyncMockControl.assertDeferredEquals( - 'different values', expectedDeferred, actualDeferred); - expectedDeferred.callback(12); - asyncMockControl2.assertDeferredError(actualDeferred, function() { - actualDeferred.callback(13); - }); - assertVerifyFails(); - mockControl2.$verifyAll(); -} - -function testAssertDeferredEqualsFailureNeitherDeferredEverResolves() { - var actualDeferred = new goog.async.Deferred(); - var expectedDeferred = new goog.async.Deferred(); - asyncMockControl.assertDeferredEquals( - 'doesn\'t resolve', expectedDeferred, actualDeferred); - assertVerifyFails(); -} - -function testAssertDeferredEqualsSuccessActualDeferred() { - var actual = new goog.async.Deferred(); - asyncMockControl.assertDeferredEquals('should succeed', 12, actual); - actual.callback(12); - mockControl.$verifyAll(); -} - -function testAssertDeferredEqualsSuccessExpectedDeferred() { - var expected = new goog.async.Deferred(); - asyncMockControl.assertDeferredEquals('should succeed', expected, 12); - expected.callback(12); - mockControl.$verifyAll(); -} - -function testAssertDeferredEqualsSuccessBothDeferred() { - var actualDeferred = new goog.async.Deferred(); - var expectedDeferred = new goog.async.Deferred(); - asyncMockControl.assertDeferredEquals( - 'should succeed', expectedDeferred, actualDeferred); - expectedDeferred.callback(12); - actualDeferred.callback(12); - mockControl.$verifyAll(); -} - -</script> -</body> -</html> |