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