michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: ok(!TabView.isVisible(), 'TabView is hidden'); michael@0: let tab = gBrowser.loadOneTab('about:blank#other', {inBackground: true}); michael@0: michael@0: TabView._initFrame(function () { michael@0: newWindowWithTabView(function (win) { michael@0: onTabViewWindowLoaded(win, tab); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function onTabViewWindowLoaded(win, tab) { michael@0: let contentWindow = win.TabView.getContentWindow(); michael@0: let search = contentWindow.document.getElementById('search'); michael@0: let searchbox = contentWindow.document.getElementById('searchbox'); michael@0: let searchButton = contentWindow.document.getElementById('searchbutton'); michael@0: let results = contentWindow.document.getElementById('results'); michael@0: michael@0: let isSearchEnabled = function () { michael@0: return 'none' != search.style.display; michael@0: } michael@0: michael@0: let assertSearchIsEnabled = function () { michael@0: ok(isSearchEnabled(), 'search is enabled'); michael@0: } michael@0: michael@0: let assertSearchIsDisabled = function () { michael@0: ok(!isSearchEnabled(), 'search is disabled'); michael@0: } michael@0: michael@0: let enableSearch = function () { michael@0: assertSearchIsDisabled(); michael@0: EventUtils.sendMouseEvent({type: 'mousedown'}, searchButton, contentWindow); michael@0: } michael@0: michael@0: let finishTest = function () { michael@0: win.close(); michael@0: gBrowser.removeTab(tab); michael@0: finish(); michael@0: } michael@0: michael@0: let testClickOnSearchBox = function () { michael@0: EventUtils.synthesizeMouseAtCenter(searchbox, {}, contentWindow); michael@0: assertSearchIsEnabled(); michael@0: } michael@0: michael@0: let testClickOnOtherSearchResult = function () { michael@0: // search for the tab from our main window michael@0: searchbox.setAttribute('value', 'other'); michael@0: contentWindow.Search.perform(); michael@0: michael@0: // prepare to finish when the main window gets focus back michael@0: window.addEventListener('focus', function onFocus() { michael@0: window.removeEventListener('focus', onFocus, true); michael@0: assertSearchIsDisabled(); michael@0: michael@0: // check that the right tab is active michael@0: is(gBrowser.selectedTab, tab, 'search result is the active tab'); michael@0: michael@0: finishTest(); michael@0: }, true); michael@0: michael@0: // click the first result michael@0: ok(results.firstChild, 'search returns one result'); michael@0: EventUtils.synthesizeMouseAtCenter(results.firstChild, {}, contentWindow); michael@0: } michael@0: michael@0: enableSearch(); michael@0: assertSearchIsEnabled(); michael@0: michael@0: testClickOnSearchBox(); michael@0: testClickOnOtherSearchResult(); michael@0: }