mobile/android/base/tests/testNewTab.java

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial