-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change snackbar duration timeout for a11y
PiperOrigin-RevId: 255456517
- Loading branch information
1 parent
0e4142e
commit 469c126
Showing
2 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
lib/javatests/com/google/android/material/snackbar/SnackbarTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright 2019 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.android.material.snackbar; | ||
|
||
import com.google.android.material.R; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import android.content.Context; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
import androidx.coordinatorlayout.widget.CoordinatorLayout; | ||
import androidx.test.core.app.ApplicationProvider; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.Robolectric; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.annotation.internal.DoNotInstrument; | ||
import org.robolectric.shadow.api.Shadow; | ||
import org.robolectric.shadows.ShadowAccessibilityManager; | ||
|
||
|
||
/** | ||
* Tests for {@link com.google.android.material.snackbar.Snackbar}. | ||
*/ | ||
@RunWith(RobolectricTestRunner.class) | ||
@DoNotInstrument | ||
public class SnackbarTest { | ||
|
||
private Snackbar snackbar; | ||
private Context activity; | ||
private ShadowAccessibilityManager accessibilityManager; | ||
|
||
@Before | ||
public void createActivityAndShadow() { | ||
ApplicationProvider.getApplicationContext() | ||
.setTheme(R.style.Theme_MaterialComponents_Light_NoActionBar); | ||
activity = Robolectric.buildActivity(AppCompatActivity.class).create().get(); | ||
accessibilityManager = Shadow. | ||
extract(activity.getSystemService(Context.ACCESSIBILITY_SERVICE)); | ||
} | ||
|
||
@Test | ||
public void testGetDuration_whenTouchExplorationEnabled_isIndefinite() { | ||
accessibilityManager.setTouchExplorationEnabled(true); | ||
|
||
CoordinatorLayout view = new CoordinatorLayout(activity); | ||
snackbar = Snackbar.make(view, "Test text", Snackbar.LENGTH_LONG).setAction("STUFF!", v -> {}); | ||
|
||
assertThat(snackbar.getDuration()).isEqualTo(Snackbar.LENGTH_INDEFINITE); | ||
} | ||
|
||
@Test | ||
public void testGetDuration_whenTouchExplorationDisabled_isProvidedValue() { | ||
accessibilityManager.setTouchExplorationEnabled(false); | ||
|
||
CoordinatorLayout view = new CoordinatorLayout(activity); | ||
snackbar = Snackbar.make(view, "Test text", 300).setAction("STUFF!", v -> {}); | ||
|
||
assertThat(snackbar.getDuration()).isEqualTo(300); | ||
} | ||
} |