123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- goog.setTestOnly('goog.testing');
- goog.provide('goog.testing');
- goog.provide('goog.testing.FunctionMock');
- goog.provide('goog.testing.GlobalFunctionMock');
- goog.provide('goog.testing.MethodMock');
- goog.require('goog.object');
- goog.require('goog.testing.LooseMock');
- goog.require('goog.testing.Mock');
- goog.require('goog.testing.PropertyReplacer');
- goog.require('goog.testing.StrictMock');
- goog.testing.FunctionMock = function(opt_functionName, opt_strictness) {
- var fn = function() {
- var args = Array.prototype.slice.call(arguments);
- args.splice(0, 0, opt_functionName || '[anonymous mocked function]');
- return fn.$mockMethod.apply(fn, args);
- };
- var base = opt_strictness === goog.testing.Mock.LOOSE ?
- goog.testing.LooseMock :
- goog.testing.StrictMock;
- goog.object.extend(fn, new base({}));
- return (fn);
- };
- goog.testing.MethodMock = function(scope, functionName, opt_strictness) {
- if (!(functionName in scope)) {
- throw Error(functionName + ' is not a property of the given scope.');
- }
- var fn = goog.testing.FunctionMock(functionName, opt_strictness);
- fn.$propertyReplacer_ = new goog.testing.PropertyReplacer();
- fn.$propertyReplacer_.set(scope, functionName, fn);
- fn.$tearDown = goog.testing.MethodMock.$tearDown;
- return fn;
- };
- goog.testing.MethodMock.fromObjectPropertyString = function(
- scopeFunctionName, opt_strictness) {
- return goog.testing.MethodMock(
- scopeFunctionName.getObject(), scopeFunctionName.getPropertyString(),
- opt_strictness);
- };
- goog.testing.MethodMock.MockInternalInterface_ = function() {};
- goog.testing.MethodMock.MockInternalInterface_.prototype.$propertyReplacer_;
- goog.testing.MethodMock.$tearDown = function() {
- (this)
- .$propertyReplacer_.reset();
- };
- goog.testing.GlobalFunctionMock = function(functionName, opt_strictness) {
- return goog.testing.MethodMock(goog.global, functionName, opt_strictness);
- };
- goog.testing.createFunctionMock = function(opt_functionName, opt_strictness) {
- return goog.testing.FunctionMock(opt_functionName, opt_strictness);
- };
- goog.testing.createMethodMock = function(scope, functionName, opt_strictness) {
- return goog.testing.MethodMock(scope, functionName, opt_strictness);
- };
- goog.testing.createConstructorMock = function(
- scope, constructorName, opt_strictness) {
- var realConstructor = scope[constructorName];
- var constructorMock =
- goog.testing.MethodMock(scope, constructorName, opt_strictness);
-
-
-
- for (var property in realConstructor) {
- if (property != 'superClass_' && property != 'prototype' &&
- realConstructor.hasOwnProperty(property)) {
- constructorMock[property] = realConstructor[property];
- }
- }
- return constructorMock;
- };
- goog.testing.createGlobalFunctionMock = function(functionName, opt_strictness) {
- return goog.testing.GlobalFunctionMock(functionName, opt_strictness);
- };
|