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 */
16package com.android.settings.notification;
17
18import static android.support.test.espresso.Espresso.onView;
19import static android.support.test.espresso.assertion.ViewAssertions.matches;
20import static android.support.test.espresso.matcher.ViewMatchers.hasDescendant;
21import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
22import static android.support.test.espresso.matcher.ViewMatchers.withId;
23import static android.support.test.espresso.matcher.ViewMatchers.withText;
24import static org.hamcrest.Matchers.allOf;
25import static org.hamcrest.Matchers.containsString;
26
27import android.content.Context;
28import android.media.AudioManager;
29import android.support.test.espresso.contrib.RecyclerViewActions;
30import android.support.test.filters.SmallTest;
31import android.support.test.rule.ActivityTestRule;
32import android.support.test.runner.AndroidJUnit4;
33import com.android.settings.R;
34import com.android.settings.Settings;
35import org.junit.Rule;
36import org.junit.Test;
37import org.junit.runner.RunWith;
38
39@RunWith(AndroidJUnit4.class)
40@SmallTest
41public 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
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
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
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}