blob: a20eb5ff6d5e517ed9a08d3e028058a91dc1547c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview Tests to ensure that chrome.send mocking works as expected.
* @author scr@chromium.org (Sheridan Rawlins)
* @see test_api.js
*/
GEN('#include "chrome/test/data/webui/chrome_send_browsertest.h"');
/**
* Test fixture for chrome send WebUI testing.
* @constructor
* @extends {testing.Test}
*/
function ChromeSendWebUITest() {}
ChromeSendWebUITest.prototype = {
__proto__: testing.Test.prototype,
/**
* Generate a real C++ class; don't typedef.
* @type {?string}
* @override
*/
typedefCppFixture: null,
/** @inheritDoc */
browsePreload: DUMMY_URL,
/** @inheritDoc */
setUp: function() {
// Set up a mock handler class to catch the 'checkSend' message.
function MockHandler() {}
MockHandler.prototype = {
checkSend: function() {},
};
this.mockHandler = mock(MockHandler);
registerMockMessageCallbacks(this.mockHandler, MockHandler);
}
};
// Test that chrome.send can be mocked outside the preLoad method.
TEST_F('ChromeSendWebUITest', 'NotInPreload', function() {
this.mockHandler.expects(once()).checkSend();
chrome.send('checkSend');
});
/**
* Test fixture for chrome send WebUI testing with passthrough.
* @constructor
* @extends {ChromeSendWebUITest}
*/
function ChromeSendPassthroughWebUITest() {}
ChromeSendPassthroughWebUITest.prototype = {
__proto__: ChromeSendWebUITest.prototype,
};
// Test that the mocked chrome.send can call the original.
TEST_F('ChromeSendPassthroughWebUITest', 'CanCallOriginal', function() {
chrome.send('expectCheckSend');
this.mockHandler.expects(once()).checkSend().
will(callFunction(function() {
chrome.originalSend('checkSend');
}));
chrome.send('checkSend');
});
|