Home | History | Annotate | Download | only in authenticator
      1 /*
      2  * Copyright (C) 2009 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
      5  * use this file except in compliance with the License. You may obtain a copy of
      6  * the License at
      7  *
      8  * http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
     12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
     13  * License for the specific language governing permissions and limitations under
     14  * the License.
     15  */
     16 package com.example.android.samplesync.authenticator;
     17 
     18 import android.app.Activity;
     19 import android.app.Instrumentation;
     20 import android.content.Context;
     21 import android.content.Intent;
     22 import android.test.ActivityInstrumentationTestCase2;
     23 import android.test.suitebuilder.annotation.SmallTest;
     24 import android.view.View;
     25 
     26 /**
     27  * This is a series of unit tests for the {@link AuthenticatorActivity} class.
     28  */
     29 @SmallTest
     30 public class AuthenticatorActivityTests extends
     31     ActivityInstrumentationTestCase2<AuthenticatorActivity> {
     32 
     33     private static final int ACTIVITY_WAIT = 10000;
     34 
     35     private Instrumentation mInstrumentation;
     36 
     37     private Context mContext;
     38 
     39     public AuthenticatorActivityTests() {
     40 
     41         super(AuthenticatorActivity.class);
     42     }
     43 
     44     /**
     45      * Common setup code for all tests. Sets up a default launch intent, which
     46      * some tests will use (others will override).
     47      */
     48     @Override
     49     protected void setUp() throws Exception {
     50 
     51         super.setUp();
     52         mInstrumentation = this.getInstrumentation();
     53         mContext = mInstrumentation.getTargetContext();
     54     }
     55 
     56     @Override
     57     protected void tearDown() throws Exception {
     58 
     59         super.tearDown();
     60     }
     61 
     62     /**
     63      * Confirm that Login is presented.
     64      */
     65     @SmallTest
     66     public void testLoginOffered() {
     67 
     68         Instrumentation.ActivityMonitor monitor =
     69             mInstrumentation.addMonitor(AuthenticatorActivity.class.getName(), null, false);
     70         Intent intent = new Intent(mContext, AuthenticatorActivity.class);
     71         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     72         mInstrumentation.startActivitySync(intent);
     73         Activity activity = mInstrumentation.waitForMonitorWithTimeout(monitor, ACTIVITY_WAIT);
     74         View loginbutton = activity.findViewById(R.id.ok_button);
     75         int expected = View.VISIBLE;
     76         assertEquals(expected, loginbutton.getVisibility());
     77     }
     78 }
     79