1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/tests/testNewTab.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,111 @@ 1.4 +package org.mozilla.gecko.tests; 1.5 + 1.6 +import org.mozilla.gecko.Element; 1.7 +import org.mozilla.gecko.R; 1.8 + 1.9 +import android.app.Activity; 1.10 +import android.view.View; 1.11 + 1.12 +import com.jayway.android.robotium.solo.Condition; 1.13 + 1.14 +/* A simple test that creates 2 new tabs and checks that the tab count increases. */ 1.15 +public class testNewTab extends BaseTest { 1.16 + private Element tabCount = null; 1.17 + private Element tabs = null; 1.18 + private Element closeTab = null; 1.19 + private int tabCountInt = 0; 1.20 + 1.21 + public void testNewTab() { 1.22 + String url = getAbsoluteUrl("/robocop/robocop_blank_01.html"); 1.23 + String url2 = getAbsoluteUrl("/robocop/robocop_blank_02.html"); 1.24 + 1.25 + blockForGeckoReady(); 1.26 + 1.27 + Activity activity = getActivity(); 1.28 + tabCount = mDriver.findElement(activity, R.id.tabs_counter); 1.29 + tabs = mDriver.findElement(activity, R.id.tabs); 1.30 + mAsserter.ok(tabCount != null && tabs != null, 1.31 + "Checking elements", "all elements present"); 1.32 + 1.33 + int expectedTabCount = 1; 1.34 + getTabCount(expectedTabCount); 1.35 + mAsserter.is(tabCountInt, expectedTabCount, "Initial number of tabs correct"); 1.36 + 1.37 + addTab(url); 1.38 + expectedTabCount++; 1.39 + getTabCount(expectedTabCount); 1.40 + mAsserter.is(tabCountInt, expectedTabCount, "Number of tabs increased"); 1.41 + 1.42 + addTab(url2); 1.43 + expectedTabCount++; 1.44 + getTabCount(expectedTabCount); 1.45 + mAsserter.is(tabCountInt, expectedTabCount, "Number of tabs increased"); 1.46 + 1.47 + // cleanup: close all opened tabs 1.48 + //closeTabs(); 1.49 + } 1.50 + 1.51 + private void closeTabs() { 1.52 + final int closeTabId = closeTab.getId(); 1.53 + String tabCountText = null; 1.54 + 1.55 + // open tabs panel 1.56 + boolean clicked = tabs.click(); 1.57 + if (!clicked) { 1.58 + mAsserter.ok(clicked != false, "checking that tabs clicked", "tabs element clicked"); 1.59 + } 1.60 + 1.61 + // wait for closeTab to appear (this is usually immediate) 1.62 + boolean success = waitForTest(new BooleanTest() { 1.63 + @Override 1.64 + public boolean test() { 1.65 + View closeTabView = getActivity().findViewById(closeTabId); 1.66 + if (closeTabView == null) { 1.67 + return false; 1.68 + } 1.69 + return true; 1.70 + } 1.71 + }, MAX_WAIT_MS); 1.72 + if (!success) { 1.73 + mAsserter.ok(success != false, "waiting for close tab view", "close tab view available"); 1.74 + } 1.75 + 1.76 + // close tabs until only one remains 1.77 + tabCountText = tabCount.getText(); 1.78 + tabCountInt = Integer.parseInt(tabCountText); 1.79 + while (tabCountInt > 1) { 1.80 + clicked = closeTab.click(); 1.81 + if (!clicked) { 1.82 + mAsserter.ok(clicked != false, "checking that close_tab clicked", "close_tab element clicked"); 1.83 + } 1.84 + 1.85 + success = waitForCondition(new Condition() { 1.86 + @Override 1.87 + public boolean isSatisfied() { 1.88 + String newTabCountText = tabCount.getText(); 1.89 + int newTabCount = Integer.parseInt(newTabCountText); 1.90 + if (newTabCount < tabCountInt) { 1.91 + tabCountInt = newTabCount; 1.92 + return true; 1.93 + } 1.94 + return false; 1.95 + } 1.96 + }, MAX_WAIT_MS); 1.97 + mAsserter.ok(success, "Checking tab closed", "number of tabs now "+tabCountInt); 1.98 + } 1.99 + } 1.100 + 1.101 + private void getTabCount(final int expected) { 1.102 + waitForCondition(new Condition() { 1.103 + @Override 1.104 + public boolean isSatisfied() { 1.105 + String newTabCountText = tabCount.getText(); 1.106 + tabCountInt = Integer.parseInt(newTabCountText); 1.107 + if (tabCountInt == expected) { 1.108 + return true; 1.109 + } 1.110 + return false; 1.111 + } 1.112 + }, MAX_WAIT_MS); 1.113 + } 1.114 +}