テスト追加

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@5275 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2009-10-26 16:49:02 +00:00
parent 91e0cbbf59
commit 088ca43386
2 changed files with 128 additions and 27 deletions

View File

@ -648,16 +648,19 @@ var TreeStyleTabService = {
).singleNodeValue; ).singleNodeValue;
}, },
getTabBrowserFromChild : function(aTab) getTabBrowserFromChild : function(aTabBrowserChild)
{ {
if (!aTab) return null; if (!aTabBrowserChild) return null;
if (aTab.__treestyletab__linkedTabBrowser) if (aTabBrowserChild.__treestyletab__linkedTabBrowser)
return aTab.__treestyletab__linkedTabBrowser; return aTabBrowserChild.__treestyletab__linkedTabBrowser;
if (aTabBrowserChild.localName == 'tabbrowser')
return aTabBrowserChild;
return this.evaluateXPath( return this.evaluateXPath(
'ancestor-or-self::xul:tabbrowser', 'ancestor::xul:tabbrowser[1]',
aTab, aTabBrowserChild,
XPathResult.FIRST_ORDERED_NODE_TYPE XPathResult.FIRST_ORDERED_NODE_TYPE
).singleNodeValue; ).singleNodeValue;
}, },
@ -751,17 +754,18 @@ var TreeStyleTabService = {
).booleanValue; ).booleanValue;
}, },
getTabs : function(aTabBrowser) getTabs : function(aTabBrowserChild)
{ {
var b = this.getTabBrowserFromChild(aTabBrowserChild);
return this.evaluateXPath( return this.evaluateXPath(
'descendant::xul:tab', 'descendant::xul:tab',
aTabBrowser.mTabContainer b.mTabContainer
); );
}, },
getTabsArray : function(aTabBrowser) getTabsArray : function(aTabBrowserChild)
{ {
var tabs = this.getTabs(aTabBrowser); var tabs = this.getTabs(aTabBrowserChild);
var array = []; var array = [];
for (var i = 0, maxi = tabs.snapshotLength; i < maxi; i++) for (var i = 0, maxi = tabs.snapshotLength; i < maxi; i++)
{ {
@ -770,20 +774,22 @@ var TreeStyleTabService = {
return array; return array;
}, },
getFirstTab : function(aTabBrowser) getFirstTab : function(aTabBrowserChild)
{ {
var b = this.getTabBrowserFromChild(aTabBrowserChild);
return this.evaluateXPath( return this.evaluateXPath(
'descendant::xul:tab[1]', 'child::xul:tab[1]',
aTabBrowser.mTabContainer, b.mTabContainer,
XPathResult.FIRST_ORDERED_NODE_TYPE XPathResult.FIRST_ORDERED_NODE_TYPE
).singleNodeValue; ).singleNodeValue;
}, },
getLastTab : function(aTabBrowser) getLastTab : function(aTabBrowserChild)
{ {
var b = this.getTabBrowserFromChild(aTabBrowserChild);
return this.evaluateXPath( return this.evaluateXPath(
'descendant::xul:tab[last()]', 'child::xul:tab[last()]',
aTabBrowser.mTabContainer, b.mTabContainer,
XPathResult.FIRST_ORDERED_NODE_TYPE XPathResult.FIRST_ORDERED_NODE_TYPE
).singleNodeValue; ).singleNodeValue;
}, },
@ -846,28 +852,30 @@ var TreeStyleTabService = {
).singleNodeValue; ).singleNodeValue;
}, },
getLastVisibleTab : function(aTab) getLastVisibleTab : function(aTabBrowserChild)
{ {
if (!aTab) return null; var b = this.getTabBrowserFromChild(aTabBrowserChild);
if (!b) return null;
if (!this.canCollapseSubtree(aTab)) if (!this.canCollapseSubtree(b))
return this.getLastTab(aTab); return this.getLastTab(b);
return this.evaluateXPath( return this.evaluateXPath(
'child::xul:tab[not(@'+this.kCOLLAPSED+'="true")][last()]', 'child::xul:tab[not(@'+this.kCOLLAPSED+'="true")][last()]',
aTab.parentNode, b.mTabContainer,
XPathResult.FIRST_ORDERED_NODE_TYPE XPathResult.FIRST_ORDERED_NODE_TYPE
).singleNodeValue; ).singleNodeValue;
}, },
getVisibleTabs : function(aTab) getVisibleTabs : function(aTabBrowserChild)
{ {
if (!this.canCollapseSubtree(aTab)) var b = this.getTabBrowserFromChild(aTabBrowserChild);
if (!this.canCollapseSubtree(b))
return this.getTabs(b); return this.getTabs(b);
var xpathResult = this.evaluateXPath( var xpathResult = this.evaluateXPath(
'child::xul:tab[not(@'+this.kCOLLAPSED+'="true")]', 'child::xul:tab[not(@'+this.kCOLLAPSED+'="true")]',
aTab.parentNode b.mTabContainer
); );
return xpathResult; return xpathResult;
}, },

View File

@ -139,43 +139,136 @@ function test_getTabs()
assert.isNull(sv.getNextTab(tabs[3])); assert.isNull(sv.getNextTab(tabs[3]));
assert.equals(tabs[1], sv.getPreviousTab(tabs[2])); assert.equals(tabs[1], sv.getPreviousTab(tabs[2]));
assert.isNull(sv.getPreviousTab(tabs[0])); assert.isNull(sv.getPreviousTab(tabs[0]));
assert.equals(0, sv.getTabIndex(tabs[0]));
assert.equals(1, sv.getTabIndex(tabs[1]));
assert.equals(2, sv.getTabIndex(tabs[2]));
assert.equals(3, sv.getTabIndex(tabs[3]));
} }
function test_tabsVisibility() function test_canCollapseSubtree()
{
gBrowser.setAttribute(sv.kALLOW_COLLAPSE, true);
assert.isTrue(sv.canCollapseSubtree(gBrowser));
gBrowser.removeAttribute(sv.kALLOW_COLLAPSE);
assert.isFalse(sv.canCollapseSubtree(gBrowser));
}
function test_isCollapsed()
{ {
tabs[1].setAttribute(sv.kCOLLAPSED, true); tabs[1].setAttribute(sv.kCOLLAPSED, true);
tabs[3].setAttribute(sv.kCOLLAPSED, true); tabs[3].setAttribute(sv.kCOLLAPSED, true);
gBrowser.setAttribute(sv.kALLOW_COLLAPSE, true);
assert.isFalse(sv.isCollapsed(tabs[0]));
assert.isTrue(sv.isCollapsed(tabs[1]));
assert.isFalse(sv.isCollapsed(tabs[2]));
assert.isTrue(sv.isCollapsed(tabs[3]));
gBrowser.removeAttribute(sv.kALLOW_COLLAPSE);
assert.isFalse(sv.isCollapsed(tabs[0]));
assert.isFalse(sv.isCollapsed(tabs[1]));
assert.isFalse(sv.isCollapsed(tabs[2]));
assert.isFalse(sv.isCollapsed(tabs[3]));
}
function test_getNextVisibleTab()
{
tabs[1].setAttribute(sv.kCOLLAPSED, true);
tabs[3].setAttribute(sv.kCOLLAPSED, true);
gBrowser.setAttribute(sv.kALLOW_COLLAPSE, true);
assert.equals(tabs[2], sv.getNextVisibleTab(tabs[0])); assert.equals(tabs[2], sv.getNextVisibleTab(tabs[0]));
assert.equals(tabs[2], sv.getNextVisibleTab(tabs[1])); assert.equals(tabs[2], sv.getNextVisibleTab(tabs[1]));
assert.isNull(sv.getNextVisibleTab(tabs[2])); assert.isNull(sv.getNextVisibleTab(tabs[2]));
assert.isNull(sv.getNextVisibleTab(tabs[3])); assert.isNull(sv.getNextVisibleTab(tabs[3]));
gBrowser.removeAttribute(sv.kALLOW_COLLAPSE);
assert.equals(tabs[1], sv.getNextVisibleTab(tabs[0]));
assert.equals(tabs[2], sv.getNextVisibleTab(tabs[1]));
assert.equals(tabs[3], sv.getNextVisibleTab(tabs[2]));
assert.isNull(sv.getNextVisibleTab(tabs[3]));
}
function test_getPreviousVisibleTab()
{
tabs[1].setAttribute(sv.kCOLLAPSED, true);
tabs[3].setAttribute(sv.kCOLLAPSED, true);
gBrowser.setAttribute(sv.kALLOW_COLLAPSE, true);
assert.isNull(sv.getPreviousVisibleTab(tabs[0])); assert.isNull(sv.getPreviousVisibleTab(tabs[0]));
assert.equals(tabs[0], sv.getPreviousVisibleTab(tabs[1])); assert.equals(tabs[0], sv.getPreviousVisibleTab(tabs[1]));
assert.equals(tabs[0], sv.getPreviousVisibleTab(tabs[2])); assert.equals(tabs[0], sv.getPreviousVisibleTab(tabs[2]));
assert.equals(tabs[2], sv.getPreviousVisibleTab(tabs[3])); assert.equals(tabs[2], sv.getPreviousVisibleTab(tabs[3]));
gBrowser.removeAttribute(sv.kALLOW_COLLAPSE);
assert.equals(tabs[1], sv.getNextVisibleTab(tabs[0]));
assert.equals(tabs[2], sv.getNextVisibleTab(tabs[1]));
assert.equals(tabs[3], sv.getNextVisibleTab(tabs[2]));
assert.isNull(sv.getNextVisibleTab(tabs[3]));
}
function test_getLastVisibleTab()
{
tabs[1].setAttribute(sv.kCOLLAPSED, true);
tabs[3].setAttribute(sv.kCOLLAPSED, true);
gBrowser.setAttribute(sv.kALLOW_COLLAPSE, true);
assert.equals(tabs[2], sv.getLastVisibleTab(tabs[0])); assert.equals(tabs[2], sv.getLastVisibleTab(tabs[0]));
assert.equals(tabs[2], sv.getLastVisibleTab(tabs[1])); assert.equals(tabs[2], sv.getLastVisibleTab(tabs[1]));
assert.equals(tabs[2], sv.getLastVisibleTab(tabs[2])); assert.equals(tabs[2], sv.getLastVisibleTab(tabs[2]));
assert.equals(tabs[2], sv.getLastVisibleTab(tabs[3])); assert.equals(tabs[2], sv.getLastVisibleTab(tabs[3]));
gBrowser.removeAttribute(sv.kALLOW_COLLAPSE);
assert.equals(tabs[3], sv.getLastVisibleTab(tabs[0]));
assert.equals(tabs[3], sv.getLastVisibleTab(tabs[1]));
assert.equals(tabs[3], sv.getLastVisibleTab(tabs[2]));
assert.equals(tabs[3], sv.getLastVisibleTab(tabs[3]));
}
function test_getVisibleTabs()
{
tabs[1].setAttribute(sv.kCOLLAPSED, true);
tabs[3].setAttribute(sv.kCOLLAPSED, true);
gBrowser.setAttribute(sv.kALLOW_COLLAPSE, true);
var visibleResult = sv.getVisibleTabs(tabs[0]); var visibleResult = sv.getVisibleTabs(tabs[0]);
assert.isTrue(visibleResult instanceof XPathResult); assert.implementsInterface(Ci.nsIDOMXPathResult, visibleResult);
assert.equals(2, visibleResult.snapshotLength); assert.equals(2, visibleResult.snapshotLength);
var visibleTabs = []; var visibleTabs = [];
for (var i = 0, maxi = visibleResult.snapshotLength; i < maxi; i++) for (let i = 0, maxi = visibleResult.snapshotLength; i < maxi; i++)
{ {
visibleTabs.push(visibleResult.snapshotItem(i)); visibleTabs.push(visibleResult.snapshotItem(i));
} }
assert.equals(2, visibleTabs.length); assert.equals(2, visibleTabs.length);
assert.equals([tabs[0], tabs[2]], visibleTabs); assert.equals([tabs[0], tabs[2]], visibleTabs);
gBrowser.removeAttribute(sv.kALLOW_COLLAPSE);
visibleResult = sv.getVisibleTabs(tabs[0]);
assert.implementsInterface(Ci.nsIDOMXPathResult, visibleResult);
assert.equals(4, visibleResult.snapshotLength);
}
function test_getVisibleIndex()
{
tabs[1].setAttribute(sv.kCOLLAPSED, true);
tabs[3].setAttribute(sv.kCOLLAPSED, true);
gBrowser.setAttribute(sv.kALLOW_COLLAPSE, true);
assert.equals(0, sv.getVisibleIndex(tabs[0])); assert.equals(0, sv.getVisibleIndex(tabs[0]));
assert.equals(-1, sv.getVisibleIndex(tabs[1])); assert.equals(-1, sv.getVisibleIndex(tabs[1]));
assert.equals(1, sv.getVisibleIndex(tabs[2])); assert.equals(1, sv.getVisibleIndex(tabs[2]));
assert.equals(-1, sv.getVisibleIndex(tabs[3])); assert.equals(-1, sv.getVisibleIndex(tabs[3]));
gBrowser.removeAttribute(sv.kALLOW_COLLAPSE);
assert.equals(0, sv.getVisibleIndex(tabs[0]));
assert.equals(1, sv.getVisibleIndex(tabs[1]));
assert.equals(2, sv.getVisibleIndex(tabs[2]));
assert.equals(3, sv.getVisibleIndex(tabs[3]));
} }
var randomKey = 'key-'+parseInt(Math.random() * 65000); var randomKey = 'key-'+parseInt(Math.random() * 65000);