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