OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 /** | |
6 * @fileoverview Tests for Mock4JS to ensure that expectations pass or fail as | |
7 * expected using the test framework. | |
8 * @author scr@chromium.org (Sheridan Rawlins) | |
9 * @see test_api.js | |
10 */ | |
11 | |
12 /** | |
13 * Test fixture for Mock4JS testing. | |
14 * @constructor | |
15 * @extends {testing.Test} | |
16 */ | |
17 function Mock4JSWebUITest() {} | |
18 | |
19 Mock4JSWebUITest.prototype = { | |
20 __proto__: testing.Test.prototype, | |
21 | |
22 /** @inheritDoc */ | |
23 browsePreload: DUMMY_URL, | |
24 | |
25 /** @inheritDoc */ | |
26 setUp: function() { | |
27 function MockHandler() {} | |
28 MockHandler.prototype = { | |
29 callMe: function() {}, | |
30 }; | |
31 this.mockHandler = mock(MockHandler); | |
32 }, | |
33 }; | |
34 | |
35 TEST_F('Mock4JSWebUITest', 'CalledExpectPasses', function() { | |
36 this.mockHandler.expects(once()).callMe(); | |
37 this.mockHandler.proxy().callMe(); | |
38 }); | |
39 | |
40 TEST_F('Mock4JSWebUITest', 'CalledTwiceExpectTwice', function() { | |
41 this.mockHandler.expects(exactly(2)).callMe(); | |
42 var proxy = this.mockHandler.proxy(); | |
43 proxy.callMe(); | |
44 proxy.callMe(); | |
45 }); | |
46 | |
47 /** | |
48 * Test fixture for Mock4JS testing which is expected to fail. | |
49 * @constructor | |
50 * @extends {Mock4JSWebUITest} | |
51 */ | |
52 function Mock4JSWebUITestFails() {} | |
53 | |
54 Mock4JSWebUITestFails.prototype = { | |
55 __proto__: Mock4JSWebUITest.prototype, | |
56 | |
57 /** @inheritDoc */ | |
58 testShouldFail: true, | |
59 }; | |
60 | |
61 TEST_F('Mock4JSWebUITestFails', 'NotCalledExpectFails', function() { | |
62 this.mockHandler.expects(once()).callMe(); | |
63 }); | |
64 | |
65 TEST_F('Mock4JSWebUITestFails', 'CalledTwiceExpectOnceFails', function() { | |
66 this.mockHandler.expects(once()).callMe(); | |
67 var proxy = this.mockHandler.proxy(); | |
68 proxy.callMe(); | |
69 proxy.callMe(); | |
70 }); | |
71 | |
72 TEST_F('Mock4JSWebUITestFails', 'CalledOnceExpectTwiceFails', function() { | |
73 this.mockHandler.expects(exactly(2)).callMe(); | |
74 var proxy = this.mockHandler.proxy(); | |
75 proxy.callMe(); | |
76 }); | |
OLD | NEW |