Home | History | Annotate | Download | only in tests
      1 /*
      2 * Copyright (C) 2014 The Android Open Source Project
      3 *
      4 * Licensed under the Apache License, Version 2.0 (the "License");
      5 * you may not use this file except in compliance with the License.
      6 * You may obtain a copy of 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,
     12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 * See the License for the specific language governing permissions and
     14 * limitations under the License.
     15 */
     16 
     17 package com.example.android.documentcentricapps.tests;
     18 
     19 import com.example.android.documentcentricapps.DocumentCentricActivity;
     20 import com.example.android.documentcentricapps.R;
     21 
     22 import android.app.ActivityManager;
     23 import android.content.Context;
     24 import android.test.ActivityInstrumentationTestCase2;
     25 import android.test.TouchUtils;
     26 import android.test.suitebuilder.annotation.LargeTest;
     27 import android.widget.Button;
     28 
     29 import java.util.List;
     30 
     31 /**
     32  * Instrumentation tests for DocumentCentricApps sample.
     33  */
     34 @LargeTest
     35 public class DocumentCentricAppsInstrumentationTest extends
     36         ActivityInstrumentationTestCase2<DocumentCentricActivity> {
     37 
     38     private DocumentCentricActivity mDocumentCentricActivity;
     39 
     40     public DocumentCentricAppsInstrumentationTest() {
     41         super(DocumentCentricActivity.class);
     42     }
     43 
     44     @Override
     45     protected void setUp() throws Exception {
     46         super.setUp();
     47         mDocumentCentricActivity = getActivity();
     48     }
     49 
     50     public void testNewDocument_CreatesOverviewEntry() {
     51         // Given a initialized Activity
     52         assertNotNull("mDocumentCentricActivity is null", mDocumentCentricActivity);
     53         final Button createNewDocumentButton = (Button) mDocumentCentricActivity
     54                 .findViewById(R.id.new_document_button);
     55         assertNotNull(createNewDocumentButton);
     56 
     57         // When "Create new Document" Button is clicked
     58         TouchUtils.clickView(this, createNewDocumentButton);
     59 
     60         // Then a entry in overview app tasks is created.
     61         List<ActivityManager.AppTask> recentAppTasks = getRecentAppTasks();
     62         assertEquals("# of recentAppTasks does not match", 2, recentAppTasks.size());
     63     }
     64 
     65     private List<ActivityManager.AppTask> getRecentAppTasks() {
     66         ActivityManager activityManager = (ActivityManager) getInstrumentation().getTargetContext()
     67                 .getSystemService(Context.ACTIVITY_SERVICE);
     68         List<ActivityManager.AppTask> appTasks = activityManager.getAppTasks();
     69         return appTasks;
     70     }
     71 
     72 }