Home | History | Annotate | Download | only in stress
      1 /*
      2  * Copyright (C) 2008 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 com.android.music.tests.stress;
     17 
     18 import android.app.Activity;
     19 import android.app.ActivityManager;
     20 import android.app.Instrumentation;
     21 import android.app.Instrumentation.ActivityMonitor;
     22 import android.content.Context;
     23 import android.content.Intent;
     24 import android.os.Bundle;
     25 import android.os.SystemClock;
     26 import android.test.ActivityInstrumentationTestCase;
     27 import android.test.suitebuilder.annotation.LargeTest;
     28 import android.view.KeyEvent;
     29 import android.util.Log;
     30 
     31 import com.android.music.AlbumBrowserActivity;
     32 import com.android.music.tests.MusicPlayerNames;
     33 
     34 public class AlbumsPlaybackStress extends ActivityInstrumentationTestCase <AlbumBrowserActivity>{
     35 
     36   private Activity browseActivity;
     37   private String[] testing;
     38   private String TAG = "AlbumsPlaybackStress";
     39 
     40   public AlbumsPlaybackStress() {
     41       super("com.android.music",AlbumBrowserActivity.class);
     42   }
     43 
     44   @Override
     45   protected void setUp() throws Exception {
     46       super.setUp();
     47   }
     48 
     49   @Override
     50   protected void tearDown() throws Exception {
     51       super.tearDown();
     52   }
     53 
     54   /*
     55    * Test case: Keeps launching music playback from Albums and then go
     56    * back to the album screen
     57    * Verification: Check if it is in low memory
     58    * The test depends on the test media in the sdcard
     59    */
     60     @LargeTest
     61     public void testAlbumPlay() {
     62       Instrumentation inst = getInstrumentation();
     63       try{
     64         inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_RIGHT);
     65         inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_RIGHT);
     66         inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
     67         inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
     68         inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
     69         Thread.sleep(MusicPlayerNames.WAIT_LONG_TIME);
     70         inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
     71         inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
     72         for(int i=0; i< MusicPlayerNames.NO_ALBUMS_TOBE_PLAYED; i++){
     73           inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_DOWN);
     74           inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
     75           inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
     76           Thread.sleep(MusicPlayerNames.WAIT_LONG_TIME);
     77           inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
     78           inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
     79         }
     80       }catch (Exception e){
     81           Log.v(TAG, e.toString());
     82       }
     83       inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
     84 
     85       //Verification: check if it is in low memory
     86       ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
     87       ((ActivityManager)getActivity().getSystemService(Context.ACTIVITY_SERVICE)).getMemoryInfo(mi);
     88       assertFalse(TAG, mi.lowMemory);
     89 
     90 
     91   }
     92 }
     93