/tests/src/com/android/music/stress/AlbumsPlaybackStress.java

https://github.com/yeffel/android_packages_apps_Music · Java · 91 lines · 58 code · 11 blank · 22 comment · 1 complexity · 4e36a64edd2391c92b934a73b2a7fcb5 MD5 · raw file

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