• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.settings.notification;
17 
18 import static android.support.test.espresso.Espresso.onView;
19 import static android.support.test.espresso.assertion.ViewAssertions.matches;
20 import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant;
21 import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
22 import static android.support.test.espresso.matcher.ViewMatchers.withId;
23 import static android.support.test.espresso.matcher.ViewMatchers.withText;
24 import static org.hamcrest.Matchers.allOf;
25 import static org.hamcrest.Matchers.containsString;
26 
27 import android.content.Context;
28 import android.media.AudioManager;
29 import android.support.test.espresso.contrib.RecyclerViewActions;
30 import android.support.test.filters.SmallTest;
31 import android.support.test.rule.ActivityTestRule;
32 import android.support.test.runner.AndroidJUnit4;
33 import com.android.settings.R;
34 import com.android.settings.Settings;
35 import org.junit.Rule;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 
39 @RunWith(AndroidJUnit4.class)
40 @SmallTest
41 public class SoundSettingsIntegrationTest {
42 
43     private AudioManager mAudioManager;
44     private final String TRUNCATED_SUMMARY = "Ring volume at";
45 
46     @Rule
47     public ActivityTestRule<Settings> mActivityRule =
48             new ActivityTestRule<>(Settings.class, true);
49 
50     @Test
soundPreferenceShowsCorrectSummaryOnSilentMode()51     public void soundPreferenceShowsCorrectSummaryOnSilentMode() {
52         mAudioManager = (AudioManager) mActivityRule.getActivity().getApplicationContext()
53                 .getSystemService(Context.AUDIO_SERVICE);
54         mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
55         onView(withId(R.id.dashboard_container))
56                 .perform(RecyclerViewActions.scrollTo(
57                         hasDescendant(withText(R.string.sound_settings))));
58         onView(withText(R.string.sound_settings_summary_silent)).check(matches(isDisplayed()));
59     }
60 
61     @Test
soundPreferenceShowsCorrectSummaryOnVibrateMode()62     public void soundPreferenceShowsCorrectSummaryOnVibrateMode() {
63         mAudioManager = (AudioManager) mActivityRule.getActivity().getApplicationContext()
64                 .getSystemService(Context.AUDIO_SERVICE);
65         mAudioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
66         onView(withId(R.id.dashboard_container)).perform(RecyclerViewActions
67                 .scrollTo(hasDescendant(withText(R.string.sound_settings))));
68         onView(withText(R.string.sound_settings_summary_vibrate)).check(matches(isDisplayed()));
69     }
70 
71     @Test
soundPreferenceShowsCorrectSummaryOnMaxVolume()72     public void soundPreferenceShowsCorrectSummaryOnMaxVolume() {
73         mAudioManager = (AudioManager) mActivityRule.getActivity().getApplicationContext()
74                 .getSystemService(Context.AUDIO_SERVICE);
75         mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
76         mAudioManager.setStreamVolume(AudioManager.STREAM_RING,
77                 mAudioManager.getStreamMaxVolume(AudioManager.STREAM_RING), 0);
78         onView(withId(R.id.dashboard_container))
79                 .perform(RecyclerViewActions.scrollTo(
80                         hasDescendant(withText(R.string.sound_settings))));
81         onView(withText(containsString(TRUNCATED_SUMMARY))).check(matches(isDisplayed()));
82     }
83 }