1 /*
2  * Copyright (C) 2009 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.android.music.tests;
18 
19 import android.app.Instrumentation;
20 import com.android.music.TrackBrowserActivity;
21 import android.view.KeyEvent;
22 import android.widget.ListView;
23 
24 import android.test.ActivityInstrumentationTestCase2;
25 import android.test.suitebuilder.annotation.LargeTest;
26 
27 /**
28  * Junit / Instrumentation test case for the Music Player
29  */
30 
31 public class MusicPlayerStability extends ActivityInstrumentationTestCase2 <TrackBrowserActivity>{
32     private static String TAG = "musicplayerstability";
33     private static int PLAY_TIME = 30000;
34     private ListView mTrackList;
35 
MusicPlayerStability()36     public MusicPlayerStability() {
37         super("com.android.music",TrackBrowserActivity.class);
38     }
39 
40     @Override
setUp()41     protected void setUp() throws Exception {
42         getActivity();
43         super.setUp();
44     }
45 
46     @Override
tearDown()47     protected void tearDown() throws Exception {
48         super.tearDown();
49     }
50 
51     /**
52      * Test case 1: This test case is for the power and general stability
53      * measurment. We don't need to do the validation. This test case simply
54      * play the mp3 for 30 seconds then stop.
55      * The sdcard should have the target mp3 files.
56      */
57     @LargeTest
testPlay30sMP3()58     public void testPlay30sMP3() throws Exception {
59         // Launch the songs list. Pick the fisrt song and play
60         try {
61             Instrumentation inst = getInstrumentation();
62             //Make sure the song list shown up
63             Thread.sleep(2000);
64             inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_DOWN);
65             mTrackList = getActivity().getListView();
66             int scrollCount = mTrackList.getMaxScrollAmount();
67             //Make sure there is at least one song in the sdcard
68             if (scrollCount != -1) {
69                 inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_CENTER);
70             } else {
71                 assertTrue("testPlayMP3", false);
72             }
73             Thread.sleep(PLAY_TIME);
74         } catch (Exception e) {
75             assertTrue("testPlayMP3", false);
76         }
77     }
78 
79     @LargeTest
testLaunchMusicPlayer()80     public void testLaunchMusicPlayer() throws Exception {
81         // Launch music player and sleep for 30 seconds to capture
82         // the music player power usage base line.
83         try {
84             Thread.sleep(PLAY_TIME);
85         } catch (Exception e) {
86             assertTrue("MusicPlayer Do Nothing", false);
87         }
88         assertTrue("MusicPlayer Do Nothing", true);
89     }
90 }
91