michael@0: package org.mozilla.gecko.tests; michael@0: michael@0: import org.mozilla.gecko.Element; michael@0: import org.mozilla.gecko.R; michael@0: michael@0: import android.app.Activity; michael@0: import android.view.View; michael@0: michael@0: import com.jayway.android.robotium.solo.Condition; michael@0: michael@0: /* A simple test that creates 2 new tabs and checks that the tab count increases. */ michael@0: public class testNewTab extends BaseTest { michael@0: private Element tabCount = null; michael@0: private Element tabs = null; michael@0: private Element closeTab = null; michael@0: private int tabCountInt = 0; michael@0: michael@0: public void testNewTab() { michael@0: String url = getAbsoluteUrl("/robocop/robocop_blank_01.html"); michael@0: String url2 = getAbsoluteUrl("/robocop/robocop_blank_02.html"); michael@0: michael@0: blockForGeckoReady(); michael@0: michael@0: Activity activity = getActivity(); michael@0: tabCount = mDriver.findElement(activity, R.id.tabs_counter); michael@0: tabs = mDriver.findElement(activity, R.id.tabs); michael@0: mAsserter.ok(tabCount != null && tabs != null, michael@0: "Checking elements", "all elements present"); michael@0: michael@0: int expectedTabCount = 1; michael@0: getTabCount(expectedTabCount); michael@0: mAsserter.is(tabCountInt, expectedTabCount, "Initial number of tabs correct"); michael@0: michael@0: addTab(url); michael@0: expectedTabCount++; michael@0: getTabCount(expectedTabCount); michael@0: mAsserter.is(tabCountInt, expectedTabCount, "Number of tabs increased"); michael@0: michael@0: addTab(url2); michael@0: expectedTabCount++; michael@0: getTabCount(expectedTabCount); michael@0: mAsserter.is(tabCountInt, expectedTabCount, "Number of tabs increased"); michael@0: michael@0: // cleanup: close all opened tabs michael@0: //closeTabs(); michael@0: } michael@0: michael@0: private void closeTabs() { michael@0: final int closeTabId = closeTab.getId(); michael@0: String tabCountText = null; michael@0: michael@0: // open tabs panel michael@0: boolean clicked = tabs.click(); michael@0: if (!clicked) { michael@0: mAsserter.ok(clicked != false, "checking that tabs clicked", "tabs element clicked"); michael@0: } michael@0: michael@0: // wait for closeTab to appear (this is usually immediate) michael@0: boolean success = waitForTest(new BooleanTest() { michael@0: @Override michael@0: public boolean test() { michael@0: View closeTabView = getActivity().findViewById(closeTabId); michael@0: if (closeTabView == null) { michael@0: return false; michael@0: } michael@0: return true; michael@0: } michael@0: }, MAX_WAIT_MS); michael@0: if (!success) { michael@0: mAsserter.ok(success != false, "waiting for close tab view", "close tab view available"); michael@0: } michael@0: michael@0: // close tabs until only one remains michael@0: tabCountText = tabCount.getText(); michael@0: tabCountInt = Integer.parseInt(tabCountText); michael@0: while (tabCountInt > 1) { michael@0: clicked = closeTab.click(); michael@0: if (!clicked) { michael@0: mAsserter.ok(clicked != false, "checking that close_tab clicked", "close_tab element clicked"); michael@0: } michael@0: michael@0: success = waitForCondition(new Condition() { michael@0: @Override michael@0: public boolean isSatisfied() { michael@0: String newTabCountText = tabCount.getText(); michael@0: int newTabCount = Integer.parseInt(newTabCountText); michael@0: if (newTabCount < tabCountInt) { michael@0: tabCountInt = newTabCount; michael@0: return true; michael@0: } michael@0: return false; michael@0: } michael@0: }, MAX_WAIT_MS); michael@0: mAsserter.ok(success, "Checking tab closed", "number of tabs now "+tabCountInt); michael@0: } michael@0: } michael@0: michael@0: private void getTabCount(final int expected) { michael@0: waitForCondition(new Condition() { michael@0: @Override michael@0: public boolean isSatisfied() { michael@0: String newTabCountText = tabCount.getText(); michael@0: tabCountInt = Integer.parseInt(newTabCountText); michael@0: if (tabCountInt == expected) { michael@0: return true; michael@0: } michael@0: return false; michael@0: } michael@0: }, MAX_WAIT_MS); michael@0: } michael@0: }