1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/tabview/test/browser_tabview_bug618828.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,78 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +function test() { 1.8 + waitForExplicitFinish(); 1.9 + 1.10 + ok(!TabView.isVisible(), 'TabView is hidden'); 1.11 + let tab = gBrowser.loadOneTab('about:blank#other', {inBackground: true}); 1.12 + 1.13 + TabView._initFrame(function () { 1.14 + newWindowWithTabView(function (win) { 1.15 + onTabViewWindowLoaded(win, tab); 1.16 + }); 1.17 + }); 1.18 +} 1.19 + 1.20 +function onTabViewWindowLoaded(win, tab) { 1.21 + let contentWindow = win.TabView.getContentWindow(); 1.22 + let search = contentWindow.document.getElementById('search'); 1.23 + let searchbox = contentWindow.document.getElementById('searchbox'); 1.24 + let searchButton = contentWindow.document.getElementById('searchbutton'); 1.25 + let results = contentWindow.document.getElementById('results'); 1.26 + 1.27 + let isSearchEnabled = function () { 1.28 + return 'none' != search.style.display; 1.29 + } 1.30 + 1.31 + let assertSearchIsEnabled = function () { 1.32 + ok(isSearchEnabled(), 'search is enabled'); 1.33 + } 1.34 + 1.35 + let assertSearchIsDisabled = function () { 1.36 + ok(!isSearchEnabled(), 'search is disabled'); 1.37 + } 1.38 + 1.39 + let enableSearch = function () { 1.40 + assertSearchIsDisabled(); 1.41 + EventUtils.sendMouseEvent({type: 'mousedown'}, searchButton, contentWindow); 1.42 + } 1.43 + 1.44 + let finishTest = function () { 1.45 + win.close(); 1.46 + gBrowser.removeTab(tab); 1.47 + finish(); 1.48 + } 1.49 + 1.50 + let testClickOnSearchBox = function () { 1.51 + EventUtils.synthesizeMouseAtCenter(searchbox, {}, contentWindow); 1.52 + assertSearchIsEnabled(); 1.53 + } 1.54 + 1.55 + let testClickOnOtherSearchResult = function () { 1.56 + // search for the tab from our main window 1.57 + searchbox.setAttribute('value', 'other'); 1.58 + contentWindow.Search.perform(); 1.59 + 1.60 + // prepare to finish when the main window gets focus back 1.61 + window.addEventListener('focus', function onFocus() { 1.62 + window.removeEventListener('focus', onFocus, true); 1.63 + assertSearchIsDisabled(); 1.64 + 1.65 + // check that the right tab is active 1.66 + is(gBrowser.selectedTab, tab, 'search result is the active tab'); 1.67 + 1.68 + finishTest(); 1.69 + }, true); 1.70 + 1.71 + // click the first result 1.72 + ok(results.firstChild, 'search returns one result'); 1.73 + EventUtils.synthesizeMouseAtCenter(results.firstChild, {}, contentWindow); 1.74 + } 1.75 + 1.76 + enableSearch(); 1.77 + assertSearchIsEnabled(); 1.78 + 1.79 + testClickOnSearchBox(); 1.80 + testClickOnOtherSearchResult(); 1.81 +}