OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Library providing basic test framework functionality. | 6 * @fileoverview Library providing basic test framework functionality. |
7 */ | 7 */ |
8 | 8 |
9 /** | 9 /** |
10 * Namespace for |Test|. | 10 * Namespace for |Test|. |
(...skipping 1610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1621 savedArgs.arguments[callbackParameter].apply(null, callbackArguments); | 1621 savedArgs.arguments[callbackParameter].apply(null, callbackArguments); |
1622 | 1622 |
1623 // Mock4JS does not clear the saved args after invocation. | 1623 // Mock4JS does not clear the saved args after invocation. |
1624 // To allow reuse of the same SaveMockArguments for multiple | 1624 // To allow reuse of the same SaveMockArguments for multiple |
1625 // invocations with similar arguments, clear them here. | 1625 // invocations with similar arguments, clear them here. |
1626 savedArgs.arguments.splice(0, savedArgs.arguments.length); | 1626 savedArgs.arguments.splice(0, savedArgs.arguments.length); |
1627 }); | 1627 }); |
1628 } | 1628 } |
1629 | 1629 |
1630 /** | 1630 /** |
1631 * Mock4JS matcher object that matches the actual agrument and the expected | 1631 * Mock4JS matcher object that matches the actual argument and the expected |
1632 * value iff their JSON represenations are same. | 1632 * value iff their JSON represenations are same. |
1633 * @param {Object} expectedValue Expected value. | 1633 * @param {Object} expectedValue |
1634 * @constructor | 1634 * @constructor |
1635 */ | 1635 */ |
1636 function MatchJSON(expectedValue) { | 1636 function MatchJSON(expectedValue) { |
1637 this.expectedValue_ = expectedValue; | 1637 this.expectedValue_ = expectedValue; |
1638 } | 1638 } |
1639 | 1639 |
1640 MatchJSON.prototype = { | 1640 MatchJSON.prototype = { |
1641 /** | 1641 /** |
1642 * Checks that JSON represenation of the actual and expected arguments are | 1642 * Checks that JSON represenation of the actual and expected arguments are |
1643 * same. | 1643 * same. |
1644 * @param {Object} actualArgument The argument to match. | 1644 * @param {Object} actualArgument The argument to match. |
1645 * @return {boolean} Result of the comparison. | 1645 * @return {boolean} Result of the comparison. |
1646 */ | 1646 */ |
1647 argumentMatches: function(actualArgument) { | 1647 argumentMatches: function(actualArgument) { |
1648 return JSON.stringify(this.expectedValue_) === | 1648 return JSON.stringify(this.expectedValue_) === |
1649 JSON.stringify(actualArgument); | 1649 JSON.stringify(actualArgument); |
1650 }, | 1650 }, |
1651 | 1651 |
1652 /** | 1652 /** |
1653 * Describes the matcher. | 1653 * Describes the matcher. |
1654 * @return {string} Description of this Mock4JS matcher. | 1654 * @return {string} Description of this Mock4JS matcher. |
1655 */ | 1655 */ |
1656 describe: function() { | 1656 describe: function() { |
1657 return 'eqJSON(' + JSON.stringify(this.expectedValue_) + ')'; | 1657 return 'eqJSON(' + JSON.stringify(this.expectedValue_) + ')'; |
1658 }, | 1658 }, |
1659 }; | 1659 }; |
1660 | 1660 |
1661 /** | 1661 /** |
1662 * Builds a MatchJSON agrument matcher for a given expected value. | 1662 * Builds a MatchJSON argument matcher for a given expected value. |
1663 * @param {Object} expectedValue Expected value. | 1663 * @param {Object} expectedValue |
1664 * @return {MatchJSON} Resulting Mock4JS matcher. | 1664 * @return {MatchJSON} Resulting Mock4JS matcher. |
1665 */ | 1665 */ |
1666 function eqJSON(expectedValue) { | 1666 function eqJSON(expectedValue) { |
1667 return new MatchJSON(expectedValue); | 1667 return new MatchJSON(expectedValue); |
1668 } | 1668 } |
1669 | 1669 |
| 1670 /** |
| 1671 * Mock4JS matcher object that matches the actual argument and the expected |
| 1672 * value iff the the string representation of the actual argument is equal to |
| 1673 * the expected value. |
| 1674 * @param {string} expectedValue |
| 1675 * @constructor |
| 1676 */ |
| 1677 function MatchToString(expectedValue) { |
| 1678 this.expectedValue_ = expectedValue; |
| 1679 } |
| 1680 |
| 1681 MatchToString.prototype = { |
| 1682 /** |
| 1683 * Checks that the the string representation of the actual argument matches |
| 1684 * the expected value. |
| 1685 * @param {*} actualArgument The argument to match. |
| 1686 * @return {boolean} Result of the comparison. |
| 1687 */ |
| 1688 argumentMatches: function(actualArgument) { |
| 1689 return this.expectedValue_ === String(actualArgument); |
| 1690 }, |
| 1691 |
| 1692 /** |
| 1693 * Describes the matcher. |
| 1694 * @return {string} Description of this Mock4JS matcher. |
| 1695 */ |
| 1696 describe: function() { |
| 1697 return 'eqToString("' + this.expectedValue_ + '")'; |
| 1698 }, |
| 1699 }; |
| 1700 |
| 1701 /** |
| 1702 * Builds a MatchToString argument matcher for a given expected value. |
| 1703 * @param {Object} expectedValue |
| 1704 * @return {MatchToString} Resulting Mock4JS matcher. |
| 1705 */ |
| 1706 function eqToString(expectedValue) { |
| 1707 return new MatchToString(expectedValue); |
| 1708 } |
| 1709 |
1670 // Exports. | 1710 // Exports. |
1671 testing.Test = Test; | 1711 testing.Test = Test; |
1672 exports.testDone = testDone; | 1712 exports.testDone = testDone; |
1673 exports.assertTrue = assertTrue; | 1713 exports.assertTrue = assertTrue; |
1674 exports.assertFalse = assertFalse; | 1714 exports.assertFalse = assertFalse; |
1675 exports.assertGE = assertGE; | 1715 exports.assertGE = assertGE; |
1676 exports.assertGT = assertGT; | 1716 exports.assertGT = assertGT; |
1677 exports.assertEquals = assertEquals; | 1717 exports.assertEquals = assertEquals; |
1678 exports.assertLE = assertLE; | 1718 exports.assertLE = assertLE; |
1679 exports.assertLT = assertLT; | 1719 exports.assertLT = assertLT; |
1680 exports.assertNotEquals = assertNotEquals; | 1720 exports.assertNotEquals = assertNotEquals; |
1681 exports.assertNotReached = assertNotReached; | 1721 exports.assertNotReached = assertNotReached; |
1682 exports.assertAccessibilityOk = assertAccessibilityOk; | 1722 exports.assertAccessibilityOk = assertAccessibilityOk; |
1683 exports.callFunction = callFunction; | 1723 exports.callFunction = callFunction; |
1684 exports.callFunctionWithSavedArgs = callFunctionWithSavedArgs; | 1724 exports.callFunctionWithSavedArgs = callFunctionWithSavedArgs; |
1685 exports.callGlobalWithSavedArgs = callGlobalWithSavedArgs; | 1725 exports.callGlobalWithSavedArgs = callGlobalWithSavedArgs; |
1686 exports.eqJSON = eqJSON; | 1726 exports.eqJSON = eqJSON; |
| 1727 exports.eqToString = eqToString; |
1687 exports.expectTrue = createExpect(assertTrue); | 1728 exports.expectTrue = createExpect(assertTrue); |
1688 exports.expectFalse = createExpect(assertFalse); | 1729 exports.expectFalse = createExpect(assertFalse); |
1689 exports.expectGE = createExpect(assertGE); | 1730 exports.expectGE = createExpect(assertGE); |
1690 exports.expectGT = createExpect(assertGT); | 1731 exports.expectGT = createExpect(assertGT); |
1691 exports.expectEquals = createExpect(assertEquals); | 1732 exports.expectEquals = createExpect(assertEquals); |
1692 exports.expectLE = createExpect(assertLE); | 1733 exports.expectLE = createExpect(assertLE); |
1693 exports.expectLT = createExpect(assertLT); | 1734 exports.expectLT = createExpect(assertLT); |
1694 exports.expectNotEquals = createExpect(assertNotEquals); | 1735 exports.expectNotEquals = createExpect(assertNotEquals); |
1695 exports.expectNotReached = createExpect(assertNotReached); | 1736 exports.expectNotReached = createExpect(assertNotReached); |
1696 exports.expectAccessibilityOk = createExpect(assertAccessibilityOk); | 1737 exports.expectAccessibilityOk = createExpect(assertAccessibilityOk); |
(...skipping 13 matching lines...) Expand all Loading... |
1710 exports.TEST = TEST; | 1751 exports.TEST = TEST; |
1711 exports.TEST_F = TEST_F; | 1752 exports.TEST_F = TEST_F; |
1712 exports.RUNTIME_TEST_F = TEST_F; | 1753 exports.RUNTIME_TEST_F = TEST_F; |
1713 exports.GEN = GEN; | 1754 exports.GEN = GEN; |
1714 exports.GEN_INCLUDE = GEN_INCLUDE; | 1755 exports.GEN_INCLUDE = GEN_INCLUDE; |
1715 exports.WhenTestDone = WhenTestDone; | 1756 exports.WhenTestDone = WhenTestDone; |
1716 | 1757 |
1717 // Import the Mock4JS helpers. | 1758 // Import the Mock4JS helpers. |
1718 Mock4JS.addMockSupport(exports); | 1759 Mock4JS.addMockSupport(exports); |
1719 })(this); | 1760 })(this); |
OLD | NEW |