Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2012 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 package android.ui.cts;
     17 
     18 import android.test.ActivityInstrumentationTestCase2;
     19 
     20 import com.android.compatibility.common.util.DeviceReportLog;
     21 import com.android.compatibility.common.util.MeasureRun;
     22 import com.android.compatibility.common.util.MeasureTime;
     23 import com.android.compatibility.common.util.ResultType;
     24 import com.android.compatibility.common.util.ResultUnit;
     25 import com.android.compatibility.common.util.Stat;
     26 
     27 import java.io.IOException;
     28 
     29 public class ScrollingTest extends ActivityInstrumentationTestCase2<ScrollingActivity> {
     30 
     31     private static final String REPORT_LOG_NAME = "CtsUiDeviceTestCases";
     32 
     33     private ScrollingActivity mActivity;
     34 
     35     public ScrollingTest() {
     36         super(ScrollingActivity.class);
     37     }
     38 
     39     @Override
     40     protected void setUp() throws Exception {
     41         super.setUp();
     42         mActivity = getActivity();
     43         getInstrumentation().waitForIdleSync();
     44         try {
     45             runTestOnUiThread(new Runnable() {
     46                 @Override
     47                 public void run() {
     48                 }
     49             });
     50         } catch (Throwable e) {
     51             e.printStackTrace();
     52             fail();
     53         }
     54     }
     55 
     56     @Override
     57     protected void tearDown() throws Exception {
     58         mActivity = null;
     59         super.tearDown();
     60     }
     61 
     62     public void testFullScrolling() throws Exception {
     63         final int NUMBER_REPEAT = 10;
     64         final ScrollingActivity activity = mActivity;
     65         double[] results = MeasureTime.measure(NUMBER_REPEAT, new MeasureRun() {
     66 
     67             @Override
     68             public void run(int i) throws IOException {
     69                 assertTrue(activity.scrollToBottom());
     70                 assertTrue(activity.scrollToTop());
     71             }
     72         });
     73         String streamName = "test_full_scrolling";
     74         DeviceReportLog report = new DeviceReportLog(REPORT_LOG_NAME, streamName);
     75         report.addValues("scrolling_time", results, ResultType.LOWER_BETTER,ResultUnit.MS);
     76         Stat.StatResult stat = Stat.getStat(results);
     77         report.setSummary("scrolling_time_average", stat.mAverage,
     78                 ResultType.LOWER_BETTER,ResultUnit.MS);
     79         report.submit(getInstrumentation());
     80     }
     81 }
     82