選択範囲のリンクを開く機能のテスト

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@3622 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2009-02-11 16:52:47 +00:00
parent 210a082b62
commit 02aacb8fed
6 changed files with 254 additions and 3 deletions

View File

@ -1965,7 +1965,7 @@ catch(e) {
if (startCount < allLinksCount) {
var firstNode = this.evaluateXPath(
'descendant-or-self::node()[not(child::node()) and not(preceding-sibling::node())]',
linksResult.snapshotItem(startCount),
linksResult.snapshotItem(allLinksCount-1),
XPathResult.FIRST_ORDERED_NODE_TYPE
).singleNodeValue;
contentRange.selectNodeContents(firstNode);

View File

@ -4,8 +4,9 @@
<meta http-equiv="Content-Type" content="text/html;charset=Shift_JIS" />
<title>テスト</title>
</head>
<frameset rows="*,*">
<frameset rows="*,*,*">
<frame src="about:logo"/>
<frame src="about:logo"/>
<frame src="links.html"/>
</frames>
</html>

View File

@ -6,6 +6,7 @@
</head>
<body>
<p>テスト</p>
<iframe src="about:logo"/>
<iframe src="about:logo"></iframe>
<iframe src="links.html"></iframe>
</body>
</html>

26
tests/fixtures/links.html vendored Normal file
View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="Sfhit_JIS"?>
<html xml:lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=Shift_JIS" />
<title>テスト</title>
</head>
<body>
<ul>
<li id="item1"><a id="link1" href="about:blank#1"><em id="em1">リンク1</em></a></li>
<li id="item2"><a id="link2" href="about:blank#2"><em id="em2">リンク2</em></a></li>
<li id="item3"><a id="link3" href="about:blank#3"><em id="em3">リンク3</em></a></li>
<li id="item4"><a id="link4" href="about:blank#4"><em id="em4">リンク4</em></a></li>
<li id="item5"><a id="link5" href="about:blank#5"><em id="em5">リンク5</em></a></li>
<li id="item6"><a id="link6" href="about:blank#6"><em id="em6">リンク6</em></a></li>
<li id="item7"><a id="link7" href="about:blank#7"><em id="em7">リンク7</em></a></li>
<li id="item8"><a id="link8" href="about:blank#8"><em id="em8">リンク8</em></a></li>
<li id="item9"><a id="link9" href="about:blank#9"><em id="em9">リンク9</em></a></li>
<li id="item10"><a id="link10" href="about:blank#10"><em id="em10">リンク10</em></a></li>
<li id="item11"><a id="link11" href="about:blank#11"><em id="em11">リンク11</em></a></li>
<li id="item12"><a id="link12" href="about:blank#12"><em id="em12">リンク12</em></a></li>
<li id="item13"><a id="link13" href="about:blank#13"><em id="em13">リンク13</em></a></li>
<li id="item14"><a id="link14" href="about:blank#14"><em id="em14">リンク14</em></a></li>
<li id="item15"><a id="link15" href="about:blank#15"><em id="em15">リンク15</em></a></li>
</ul>
</body>
</html>

View File

@ -0,0 +1,202 @@
var win;
var sv;
function setUp()
{
utils.setPref('browser.tabs.warnOnClose', false);
yield utils.setUpTestWindow();
win = utils.getTestWindow();
sv = win.TreeStyleTabService;
yield Do(utils.addTab('../fixtures/links.html'));
var tabs = gBrowser.mTabs;
gBrowser.removeAllTabsBut(tabs[tabs.length-1]);
assert.equals(1, tabs.length);
}
function tearDown()
{
win = null;
utils.tearDownTestWindow();
}
function $(aId)
{
return content.document.getElementById(aId);
}
function test_getCurrentFrame()
{
yield Do(utils.addTab('../fixtures/frameTest.html'));
yield Do(utils.addTab('../fixtures/frameTestInline.html'));
var tabs = gBrowser.mTabs;
assert.equals(3, tabs.length);
var frame;
frame = gBrowser.contentWindow;
assert.equals(frame, sv.getCurrentFrame());
assert.equals(frame, sv.getCurrentFrame(frame));
frame = tabs[1].linkedBrowser.contentWindow.frames[1];
assert.equals(frame, sv.getCurrentFrame(frame));
frame = tabs[2].linkedBrowser.contentWindow.frames[0];
assert.equals(frame, sv.getCurrentFrame(frame));
}
function test_getLinksInRange()
{
var range = content.document.createRange();
range.setStartBefore($('item2'));
range.setEndAfter($('item4'));
assert.equals(
[$('link2'), $('link3'), $('link4')],
sv.getLinksInRange(range)
);
range.setStartBefore($('link2'));
range.setEndAfter($('link4'));
assert.equals(
[$('link2'), $('link3'), $('link4')],
sv.getLinksInRange(range)
);
range.setStartBefore($('em2'));
range.setEndAfter($('em4'));
assert.equals(
[$('link2'), $('link3'), $('link4')],
sv.getLinksInRange(range)
);
range.setStart($('em2').firstChild, 2);
range.setEnd($('em4').firstChild, 2);
assert.equals(
[$('link2'), $('link3'), $('link4')],
sv.getLinksInRange(range)
);
range.setStartAfter($('em1'));
range.setEndBefore($('em5'));
assert.equals(
[$('link2'), $('link3'), $('link4')],
sv.getLinksInRange(range)
);
range.setStartAfter($('em1').firstChild);
range.setEndBefore($('em5').firstChild);
assert.equals(
[$('link2'), $('link3'), $('link4')],
sv.getLinksInRange(range)
);
}
function test_getSelectionLinks()
{
var selection = content.getSelection();
assert.equals(0, selection.rangeCount);
var range1 = content.document.createRange();
range1.setStartBefore($('link2'));
range1.setEndAfter($('link4'));
selection.addRange(range1);
assert.equals(1, selection.rangeCount);
assert.equals(
[$('link2'), $('link3'), $('link4')],
sv.getSelectionLinks(content)
);
var range2 = content.document.createRange();
range2.setStartBefore($('link6'));
range2.setEndAfter($('link8'));
selection.addRange(range2);
var range3 = content.document.createRange();
range3.setStartBefore($('link12'));
range3.setEndAfter($('link14'));
selection.addRange(range3);
assert.equals(3, selection.rangeCount);
assert.equals(
[$('link2'), $('link3'), $('link4'),
$('link6'), $('link7'), $('link8'),
$('link12'), $('link13'), $('link14')],
sv.getSelectionLinks(content)
);
selection.removeAllRanges();
range1.detach();
range2.detach();
range3.detach();
}
function test_openSelectionLinks()
{
function assert_openSelectionLinksInFrame(aFrame)
{
function $(aId)
{
return aFrame.document.getElementById(aId);
}
gBrowser.removeAllTabsBut(gBrowser.selectedTab);
assert.equals(1, gBrowser.mTabs.length);
var selection = aFrame.getSelection();
assert.equals(0, selection.rangeCount);
var range1 = aFrame.document.createRange();
range1.setStartBefore($('link2'));
range1.setEndAfter($('link4'));
selection.addRange(range1);
assert.equals(1, selection.rangeCount);
var tabs = gBrowser.mTabs;
assert.equals(1, tabs.length);
sv.openSelectionLinks(aFrame);
assert.equals(4, tabs.length);
assert.equals(
[tabs[1], tabs[2], tabs[3]],
sv.getChildTabs(tabs[0])
);
gBrowser.removeAllTabsBut(tabs[0]);
assert.equals(1, tabs.length);
var range2 = aFrame.document.createRange();
range2.setStartBefore($('link6'));
range2.setEndAfter($('link8'));
selection.addRange(range2);
var range3 = aFrame.document.createRange();
range3.setStartBefore($('link12'));
range3.setEndAfter($('link14'));
selection.addRange(range3);
sv.openSelectionLinks(aFrame);
assert.equals(10, tabs.length);
assert.equals(
[tabs[1], tabs[2], tabs[3],
tabs[4], tabs[5], tabs[6],
tabs[7], tabs[8], tabs[9]],
sv.getChildTabs(tabs[0])
);
selection.removeAllRanges();
range1.detach();
range2.detach();
range3.detach();
}
assert_openSelectionLinksInFrame(content);
yield Do(utils.addTab('../fixtures/frameTest.html', { selected : true }));
assert_openSelectionLinksInFrame(content.frames[2]);
yield Do(utils.addTab('../fixtures/frameTestInline.html', { selected : true }));
assert_openSelectionLinksInFrame(content.frames[1]);
}

View File

@ -0,0 +1,21 @@
/*
sv.rootTabs
sv.getParentTab(tab)
sv.getRootTab(tab)
sv.getNextSiblingTab(tab)
sv.getPreviousSiblingTab(tab)
sv.getChildTabs(tab, array)
sv.hasChildTabs(tab)
sv.getDescendantTabs(tab)
sv.getFirstChildTab(tab)
sv.getLastChildTab(tab)
sv.getChildIndex(tab, parent)
sv.removeTabSubTree(tabs, onlychildren)
sv.collapseExpandAllSubtree(collapse)
sv.registerCollapseExpandPostProcess(func)
*/