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 | package org.mozilla.gecko.tests; |
michael@0 | 2 | |
michael@0 | 3 | import org.mozilla.gecko.Element; |
michael@0 | 4 | import org.mozilla.gecko.R; |
michael@0 | 5 | |
michael@0 | 6 | import android.app.Activity; |
michael@0 | 7 | import android.view.View; |
michael@0 | 8 | |
michael@0 | 9 | import com.jayway.android.robotium.solo.Condition; |
michael@0 | 10 | |
michael@0 | 11 | /* A simple test that creates 2 new tabs and checks that the tab count increases. */ |
michael@0 | 12 | public class testNewTab extends BaseTest { |
michael@0 | 13 | private Element tabCount = null; |
michael@0 | 14 | private Element tabs = null; |
michael@0 | 15 | private Element closeTab = null; |
michael@0 | 16 | private int tabCountInt = 0; |
michael@0 | 17 | |
michael@0 | 18 | public void testNewTab() { |
michael@0 | 19 | String url = getAbsoluteUrl("/robocop/robocop_blank_01.html"); |
michael@0 | 20 | String url2 = getAbsoluteUrl("/robocop/robocop_blank_02.html"); |
michael@0 | 21 | |
michael@0 | 22 | blockForGeckoReady(); |
michael@0 | 23 | |
michael@0 | 24 | Activity activity = getActivity(); |
michael@0 | 25 | tabCount = mDriver.findElement(activity, R.id.tabs_counter); |
michael@0 | 26 | tabs = mDriver.findElement(activity, R.id.tabs); |
michael@0 | 27 | mAsserter.ok(tabCount != null && tabs != null, |
michael@0 | 28 | "Checking elements", "all elements present"); |
michael@0 | 29 | |
michael@0 | 30 | int expectedTabCount = 1; |
michael@0 | 31 | getTabCount(expectedTabCount); |
michael@0 | 32 | mAsserter.is(tabCountInt, expectedTabCount, "Initial number of tabs correct"); |
michael@0 | 33 | |
michael@0 | 34 | addTab(url); |
michael@0 | 35 | expectedTabCount++; |
michael@0 | 36 | getTabCount(expectedTabCount); |
michael@0 | 37 | mAsserter.is(tabCountInt, expectedTabCount, "Number of tabs increased"); |
michael@0 | 38 | |
michael@0 | 39 | addTab(url2); |
michael@0 | 40 | expectedTabCount++; |
michael@0 | 41 | getTabCount(expectedTabCount); |
michael@0 | 42 | mAsserter.is(tabCountInt, expectedTabCount, "Number of tabs increased"); |
michael@0 | 43 | |
michael@0 | 44 | // cleanup: close all opened tabs |
michael@0 | 45 | //closeTabs(); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | private void closeTabs() { |
michael@0 | 49 | final int closeTabId = closeTab.getId(); |
michael@0 | 50 | String tabCountText = null; |
michael@0 | 51 | |
michael@0 | 52 | // open tabs panel |
michael@0 | 53 | boolean clicked = tabs.click(); |
michael@0 | 54 | if (!clicked) { |
michael@0 | 55 | mAsserter.ok(clicked != false, "checking that tabs clicked", "tabs element clicked"); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | // wait for closeTab to appear (this is usually immediate) |
michael@0 | 59 | boolean success = waitForTest(new BooleanTest() { |
michael@0 | 60 | @Override |
michael@0 | 61 | public boolean test() { |
michael@0 | 62 | View closeTabView = getActivity().findViewById(closeTabId); |
michael@0 | 63 | if (closeTabView == null) { |
michael@0 | 64 | return false; |
michael@0 | 65 | } |
michael@0 | 66 | return true; |
michael@0 | 67 | } |
michael@0 | 68 | }, MAX_WAIT_MS); |
michael@0 | 69 | if (!success) { |
michael@0 | 70 | mAsserter.ok(success != false, "waiting for close tab view", "close tab view available"); |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | // close tabs until only one remains |
michael@0 | 74 | tabCountText = tabCount.getText(); |
michael@0 | 75 | tabCountInt = Integer.parseInt(tabCountText); |
michael@0 | 76 | while (tabCountInt > 1) { |
michael@0 | 77 | clicked = closeTab.click(); |
michael@0 | 78 | if (!clicked) { |
michael@0 | 79 | mAsserter.ok(clicked != false, "checking that close_tab clicked", "close_tab element clicked"); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | success = waitForCondition(new Condition() { |
michael@0 | 83 | @Override |
michael@0 | 84 | public boolean isSatisfied() { |
michael@0 | 85 | String newTabCountText = tabCount.getText(); |
michael@0 | 86 | int newTabCount = Integer.parseInt(newTabCountText); |
michael@0 | 87 | if (newTabCount < tabCountInt) { |
michael@0 | 88 | tabCountInt = newTabCount; |
michael@0 | 89 | return true; |
michael@0 | 90 | } |
michael@0 | 91 | return false; |
michael@0 | 92 | } |
michael@0 | 93 | }, MAX_WAIT_MS); |
michael@0 | 94 | mAsserter.ok(success, "Checking tab closed", "number of tabs now "+tabCountInt); |
michael@0 | 95 | } |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | private void getTabCount(final int expected) { |
michael@0 | 99 | waitForCondition(new Condition() { |
michael@0 | 100 | @Override |
michael@0 | 101 | public boolean isSatisfied() { |
michael@0 | 102 | String newTabCountText = tabCount.getText(); |
michael@0 | 103 | tabCountInt = Integer.parseInt(newTabCountText); |
michael@0 | 104 | if (tabCountInt == expected) { |
michael@0 | 105 | return true; |
michael@0 | 106 | } |
michael@0 | 107 | return false; |
michael@0 | 108 | } |
michael@0 | 109 | }, MAX_WAIT_MS); |
michael@0 | 110 | } |
michael@0 | 111 | } |