// Licensed to the Software Freedom Conservancy (SFC) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information // regarding copyright ownership. The SFC licenses this file // to you 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. goog.provide('webdriver.test.testutil'); goog.provide('webdriver.test.testutil.StubError'); goog.require('goog.array'); goog.require('goog.debug.Error'); goog.require('goog.string'); goog.require('goog.testing.recordFunction'); goog.require('webdriver.stacktrace'); /** * A custom error used for testing. * @param {string=} opt_msg The error message to use. * @constructor * @extends {goog.debug.Error} * @final */ webdriver.test.testutil.StubError = function(opt_msg) { webdriver.test.testutil.StubError.base(this, 'constructor', opt_msg); }; goog.inherits(webdriver.test.testutil.StubError, goog.debug.Error); /** @override */ webdriver.test.testutil.StubError.prototype.name = 'StubError'; /** @type {Array.} */ webdriver.test.testutil.messages = []; webdriver.test.testutil.getStackTrace = function() { return webdriver.stacktrace.get(); }; webdriver.test.testutil.throwStubError = function() { throw new webdriver.test.testutil.StubError; }; webdriver.test.testutil.assertIsStubError = function(error) { assertTrue(error + ' is not an instanceof StubError', error instanceof webdriver.test.testutil.StubError); }; /** * Asserts the contents of the {@link webdriver.test.testutil.messages} array * are as expected. * @param {...*} var_args The expected contents. */ webdriver.test.testutil.assertMessages = function(var_args) { var args = Array.prototype.slice.call(arguments, 0); assertArrayEquals(args, webdriver.test.testutil.messages); }; /** * Wraps a call to {@link webdriver.test.testutil.assertMessages} so it can * be passed as a callback. * @param {...*} var_args The expected contents. * @return {!Function} The wrapped function. */ webdriver.test.testutil.assertingMessages = function(var_args) { var args = goog.array.slice(arguments, 0); return function() { return webdriver.test.testutil.assertMessages.apply(null, args); }; }; /** * Asserts an object is a promise. * @param {*} obj The object to check. */ webdriver.test.testutil.assertIsPromise = function(obj) { assertTrue('Value is not a promise: ' + goog.typeOf(obj), webdriver.promise.isPromise(obj)); }; /** * Asserts an object is not a promise. * @param {*} obj The object to check. */ webdriver.test.testutil.assertNotPromise = function(obj) { assertFalse(webdriver.promise.isPromise(obj)); }; /** * Wraps a function. The wrapped function will have several utility functions: *