モックを使ってテスト
git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@7152 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
parent
426d5dca35
commit
db5de24de9
@ -2207,7 +2207,4 @@ catch(e) {
|
||||
TreeStyleTabService.__proto__ = TreeStyleTabService.utils = namespace.TreeStyleTabUtils;
|
||||
TreeStyleTabService.utils.init();
|
||||
})();
|
||||
window.addEventListener('DOMContentLoaded', TreeStyleTabService, true);
|
||||
window.addEventListener('load', TreeStyleTabService, false);
|
||||
TreeStyleTabService.ObserverService.addObserver(TreeStyleTabService, 'sessionstore-windows-restored', false);
|
||||
|
||||
|
@ -11,6 +11,11 @@
|
||||
<script src="res/UninstallationListener.js" type="application/javascript"/>
|
||||
|
||||
<script src="treestyletab.js" type="application/javascript"/>
|
||||
<script type="application/javascript"><![CDATA[
|
||||
window.addEventListener('DOMContentLoaded', TreeStyleTabService, true);
|
||||
window.addEventListener('load', TreeStyleTabService, false);
|
||||
TreeStyleTabService.ObserverService.addObserver(TreeStyleTabService, 'sessionstore-windows-restored', false);
|
||||
]]></script>
|
||||
<script src="treestyletabbrowser.js" type="application/javascript"/>
|
||||
<script src="treestyletabbrowser_autoHide.js" type="application/javascript"/>
|
||||
<script src="treestyletabbrowser_tabbarDNDObserver.js" type="application/javascript"/>
|
||||
|
@ -1,11 +1,16 @@
|
||||
var autoHideFile = baseURL+'../../content/treestyletab/treestyletabbrowser_autoHide.js';
|
||||
|
||||
utils.include(baseURL+'../../content/treestyletab/treestyletab.js');
|
||||
utils.include(baseURL+'../../content/treestyletab/treestyletabbrowser_autoHide.js');
|
||||
utils.include(autoHideFile);
|
||||
var TSTBAutoHide = TreeStyleTabBrowserAutoHide;
|
||||
|
||||
var autoHide;
|
||||
var owner;
|
||||
|
||||
function setUp()
|
||||
{
|
||||
utils.include(autoHideFile);
|
||||
|
||||
owner = new Mock('owner mock');
|
||||
Mock.expect(TreeStyleTabBrowserAutoHide.prototype, 'init', []);
|
||||
autoHide = new TreeStyleTabBrowserAutoHide(owner);
|
||||
@ -13,24 +18,33 @@ function setUp()
|
||||
|
||||
function tearDown()
|
||||
{
|
||||
owner = null;
|
||||
}
|
||||
|
||||
|
||||
function test_fireStateChangingEvent()
|
||||
test_fireStateChangingEvent.parameters = {
|
||||
expanded : {
|
||||
state : TSTBAutoHide.prototype.kSTATE_EXPANDED,
|
||||
shown : true
|
||||
},
|
||||
shrunken : {
|
||||
state : TSTBAutoHide.prototype.kSTATE_SHRUNKEN,
|
||||
shown : false
|
||||
},
|
||||
hidden : {
|
||||
state : TSTBAutoHide.prototype.kSTATE_HIDDEN,
|
||||
shown : false
|
||||
}
|
||||
};
|
||||
function test_fireStateChangingEvent(aParameter)
|
||||
{
|
||||
var expanded = Math.random() + Date.now() + 'expanded';
|
||||
var state = Math.random() + Date.now() + 'state';
|
||||
|
||||
owner.browser = new Mock('browser');
|
||||
owner.browser.expect('dispatchEvent', TypeOf(Ci.nsIDOMEvent))
|
||||
.then(function(aEvent) {
|
||||
assert.equals(expanded, aEvent.shown);
|
||||
assert.equals(state, aEvent.state);
|
||||
assert.equals('TreeStyleTabAutoHideStateChanging', aEvent.type);
|
||||
assert.strictlyEquals(aParameter.shown, aEvent.shown);
|
||||
assert.equals(aParameter.state, aEvent.state);
|
||||
});
|
||||
Mock.expectGet(autoHide, 'expanded', expanded);
|
||||
Mock.expectGet(autoHide, 'state', state);
|
||||
Mock.expectGet(autoHide, 'state', aParameter.state).times(2);
|
||||
|
||||
autoHide.fireStateChangingEvent();
|
||||
}
|
||||
|
||||
|
||||
|
56
tests/unit/TreeStyleTabBrowserAutoHide_withoutMock.test.js
Normal file
56
tests/unit/TreeStyleTabBrowserAutoHide_withoutMock.test.js
Normal file
@ -0,0 +1,56 @@
|
||||
var autoHideFile = baseURL+'../../content/treestyletab/treestyletabbrowser_autoHide.js';
|
||||
|
||||
utils.include(baseURL+'../../content/treestyletab/treestyletab.js');
|
||||
utils.include(autoHideFile);
|
||||
var TSTBAutoHide = TreeStyleTabBrowserAutoHide;
|
||||
|
||||
var autoHide;
|
||||
var owner;
|
||||
|
||||
function setUp()
|
||||
{
|
||||
utils.include(autoHideFile);
|
||||
|
||||
utils.setUpTestWindow();
|
||||
|
||||
var w = utils.getTestWindow();
|
||||
owner = { browser : w.gBrowser };
|
||||
TreeStyleTabBrowserAutoHide.prototype.init = function() {};
|
||||
autoHide = new TreeStyleTabBrowserAutoHide(owner);
|
||||
}
|
||||
|
||||
function tearDown()
|
||||
{
|
||||
utils.tearDownTestWindow();
|
||||
owner = null;
|
||||
}
|
||||
|
||||
test_fireStateChangingEvent.parameters = {
|
||||
expanded : {
|
||||
state : TSTBAutoHide.prototype.kSTATE_EXPANDED,
|
||||
shown : true
|
||||
},
|
||||
shrunken : {
|
||||
state : TSTBAutoHide.prototype.kSTATE_SHRUNKEN,
|
||||
shown : false
|
||||
},
|
||||
hidden : {
|
||||
state : TSTBAutoHide.prototype.kSTATE_HIDDEN,
|
||||
shown : false
|
||||
}
|
||||
};
|
||||
test_fireStateChangingEvent.assertions = 2;
|
||||
function test_fireStateChangingEvent(aParamter)
|
||||
{
|
||||
var w = utils.getTestWindow();
|
||||
|
||||
w.gBrowser.setAttribute(TSTBAutoHide.prototype.kSTATE, aParamter.state);
|
||||
|
||||
w.addEventListener('TreeStyleTabAutoHideStateChanging', function(aEvent) {
|
||||
w.removeEventListener('TreeStyleTabAutoHideStateChanging', arguments.callee, false);
|
||||
assert.equals(aParamter.shown, aEvent.shown);
|
||||
assert.equals(aParamter.state, aEvent.state);
|
||||
}, false);
|
||||
|
||||
autoHide.fireStateChangingEvent();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user