browser/components/tabview/test/browser_tabview_bug618828.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:de485333d66d
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 function test() {
5 waitForExplicitFinish();
6
7 ok(!TabView.isVisible(), 'TabView is hidden');
8 let tab = gBrowser.loadOneTab('about:blank#other', {inBackground: true});
9
10 TabView._initFrame(function () {
11 newWindowWithTabView(function (win) {
12 onTabViewWindowLoaded(win, tab);
13 });
14 });
15 }
16
17 function onTabViewWindowLoaded(win, tab) {
18 let contentWindow = win.TabView.getContentWindow();
19 let search = contentWindow.document.getElementById('search');
20 let searchbox = contentWindow.document.getElementById('searchbox');
21 let searchButton = contentWindow.document.getElementById('searchbutton');
22 let results = contentWindow.document.getElementById('results');
23
24 let isSearchEnabled = function () {
25 return 'none' != search.style.display;
26 }
27
28 let assertSearchIsEnabled = function () {
29 ok(isSearchEnabled(), 'search is enabled');
30 }
31
32 let assertSearchIsDisabled = function () {
33 ok(!isSearchEnabled(), 'search is disabled');
34 }
35
36 let enableSearch = function () {
37 assertSearchIsDisabled();
38 EventUtils.sendMouseEvent({type: 'mousedown'}, searchButton, contentWindow);
39 }
40
41 let finishTest = function () {
42 win.close();
43 gBrowser.removeTab(tab);
44 finish();
45 }
46
47 let testClickOnSearchBox = function () {
48 EventUtils.synthesizeMouseAtCenter(searchbox, {}, contentWindow);
49 assertSearchIsEnabled();
50 }
51
52 let testClickOnOtherSearchResult = function () {
53 // search for the tab from our main window
54 searchbox.setAttribute('value', 'other');
55 contentWindow.Search.perform();
56
57 // prepare to finish when the main window gets focus back
58 window.addEventListener('focus', function onFocus() {
59 window.removeEventListener('focus', onFocus, true);
60 assertSearchIsDisabled();
61
62 // check that the right tab is active
63 is(gBrowser.selectedTab, tab, 'search result is the active tab');
64
65 finishTest();
66 }, true);
67
68 // click the first result
69 ok(results.firstChild, 'search returns one result');
70 EventUtils.synthesizeMouseAtCenter(results.firstChild, {}, contentWindow);
71 }
72
73 enableSearch();
74 assertSearchIsEnabled();
75
76 testClickOnSearchBox();
77 testClickOnOtherSearchResult();
78 }

mercurial