Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Commit

Permalink
Added a failing test for FileUriExposedException on Nougat
Browse files Browse the repository at this point in the history
  • Loading branch information
spacecowboy committed Oct 22, 2016
1 parent 9187962 commit 8fb5579
Showing 1 changed file with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.nononsenseapps.filepicker.sample;


import android.support.test.espresso.ViewInteraction;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withParent;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static com.nononsenseapps.filepicker.sample.PermissionGranter.allowPermissionsIfNeeded;
import static org.hamcrest.Matchers.allOf;

@LargeTest
@RunWith(AndroidJUnit4.class)
public class SelectMultipleFiles {

@Rule
public ActivityTestRule<NoNonsenseFilePickerTest> mActivityTestRule =
new ActivityTestRule<>(NoNonsenseFilePickerTest.class);

@Before
public void allowPermissions() {
allowPermissionsIfNeeded(mActivityTestRule.getActivity());
}

/**
* Should not throw on Android 24
*/
@Test
public void selectTwoFilesDoesNotThrow() {
ViewInteraction radioButton = onView(
allOf(withId(R.id.radioFile), withText("Select file"),
withParent(withId(R.id.radioGroup)),
isDisplayed()));
radioButton.perform(click());

ViewInteraction checkBox = onView(
allOf(withId(R.id.checkAllowMultiple), withText("Multiple items"), isDisplayed()));
checkBox.perform(click());

ViewInteraction button = onView(
allOf(withId(R.id.button_sd), withText("Pick SD-card"), isDisplayed()));
button.perform(click());

ViewInteraction recyclerView = onView(
allOf(withId(android.R.id.list), isDisplayed()));

// Refresh view (into dir, and out again)
recyclerView.perform(actionOnItemAtPosition(1, click()));
recyclerView.perform(actionOnItemAtPosition(0, click()));

// Click on test dir
recyclerView.perform(actionOnItemAtPosition(1, click()));
// sub dir
recyclerView.perform(actionOnItemAtPosition(1, click()));
// Select first two
recyclerView.perform(actionOnItemAtPosition(1, click()));
recyclerView.perform(actionOnItemAtPosition(2, click()));

// Click OK
ViewInteraction okButton = onView(
allOf(withId(R.id.nnf_button_ok),
withParent(allOf(withId(R.id.nnf_button_container),
withParent(withId(R.id.nnf_buttons_container)))),
isDisplayed()));
okButton.perform(click());

ViewInteraction textView = onView(withId(R.id.text));
textView.check(matches(
withText("file:///storage/emulated/0/000000_nonsense-tests/A-dir/file-1.txt\n" +
"file:///storage/emulated/0/000000_nonsense-tests/A-dir/file-0.txt")));
}
}

0 comments on commit 8fb5579

Please sign in to comment.