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 */
16package com.android.music.tests.stress;
17
18import android.app.Activity;
19import android.app.ActivityManager;
20import android.app.Instrumentation;
21import android.app.Instrumentation.ActivityMonitor;
22import android.content.Intent;
23import android.os.Bundle;
24import android.os.SystemClock;
25import android.test.ActivityInstrumentationTestCase;
26import android.test.suitebuilder.annotation.LargeTest;
27import android.view.KeyEvent;
28import android.util.Log;
29import android.content.Context;
30
31
32import com.android.music.MusicBrowserActivity;
33import com.android.music.MusicUtils;
34import com.android.music.TrackBrowserActivity;
35import com.android.music.tests.MusicPlayerNames;
36
37public class MusicPlaybackStress extends ActivityInstrumentationTestCase <TrackBrowserActivity>{
38    private static String TAG = "mediaplayertests";
39
40    public MusicPlaybackStress() {
41      super("com.android.music",TrackBrowserActivity.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    @LargeTest
55    public void testPlayAllSongs() {
56      Activity mediaPlaybackActivity;
57      try{
58        Instrumentation inst = getInstrumentation();
59        ActivityMonitor mediaPlaybackMon = inst.addMonitor("com.android.music.MediaPlaybackActivity",
60          null, false);
61        inst.invokeMenuActionSync(getActivity(), MusicUtils.Defs.CHILD_MENU_BASE + 3, 0);
62        Thread.sleep(MusicPlayerNames.WAIT_LONG_TIME);
63        mediaPlaybackActivity = mediaPlaybackMon.waitForActivityWithTimeout(2000);
64        for (int i=0;i< MusicPlayerNames.NO_SKIPPING_SONGS;i++){
65          Thread.sleep(MusicPlayerNames.SKIP_WAIT_TIME);
66          if (i==0){
67            //Set the repeat all
68            inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_RIGHT);
69            inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_UP);
70            inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
71
72            //Set focus on the next button
73            inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_DOWN);
74          }
75          inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
76        }
77        mediaPlaybackActivity.finish();
78      }catch (Exception e){
79        Log.e(TAG, e.toString());
80      }
81      //Verification: check if it is in low memory
82      ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
83      ((ActivityManager)getActivity().getSystemService(Context.ACTIVITY_SERVICE)).getMemoryInfo(mi);
84      assertFalse(TAG, mi.lowMemory);
85    }
86}
87