This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from spacecowboy/4-nougat
Fixed `FileUriExposed` error on Nougat properly
- Loading branch information
Showing
14 changed files
with
470 additions
and
283 deletions.
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
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
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
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,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<paths xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<root-path | ||
name="root" | ||
path="." /> | ||
</paths> |
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
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
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
117 changes: 117 additions & 0 deletions
117
...src/androidTestUitests/java/com/nononsenseapps/filepicker/sample/SelectMultipleFiles.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,117 @@ | ||
package com.nononsenseapps.filepicker.sample; | ||
|
||
|
||
import android.net.Uri; | ||
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 com.nononsenseapps.filepicker.Utils; | ||
|
||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import java.io.File; | ||
|
||
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; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
@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 selectTwoFilesDoesNotThrowWithClipData() { | ||
NoNonsenseFilePicker.useClipData = true; | ||
|
||
selectTwoFilesDoesNotThrow(); | ||
} | ||
|
||
/** | ||
* Should not throw on Android 24 | ||
*/ | ||
@Test | ||
public void selectTwoFilesDoesNotThrowWithStringExtras() { | ||
NoNonsenseFilePicker.useClipData = false; | ||
|
||
selectTwoFilesDoesNotThrow(); | ||
} | ||
|
||
private 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("/storage/emulated/0/000000_nonsense-tests/A-dir/file-1.txt\n" + | ||
"/storage/emulated/0/000000_nonsense-tests/A-dir/file-0.txt"))); | ||
|
||
// Make sure we can read one | ||
File file = | ||
Utils.getFileForUri( | ||
Uri.parse("content://com.nononsenseapps.filepicker.sample.provider/root/storage/emulated/0/000000_nonsense-tests/A-dir/file-1.txt")); | ||
assertEquals("/storage/emulated/0/000000_nonsense-tests/A-dir/file-1.txt", file.toString()); | ||
assertTrue(file.isFile()); | ||
assertTrue(file.canRead()); | ||
assertTrue(file.canWrite()); | ||
} | ||
} |
Oops, something went wrong.