This repository has been archived by the owner on Jul 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 670
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix issue where Lopper.loop() is called even if a looper already exists * Force Precise machine in travis configuration because Trusty environments have a potential bug with android builds preventing jobs from ending.
- Loading branch information
1 parent
0694397
commit e859eb0
Showing
9 changed files
with
151 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,32 @@ | ||
language: android | ||
jdk: oraclejdk8 | ||
dist: precise | ||
env: | ||
global: | ||
- ADB_INSTALL_TIMEOUT=8 # 8 minutes (2 minutes by default) | ||
|
||
android: | ||
components: | ||
- tools | ||
- build-tools-25.0.0 | ||
- platform-tools | ||
- android-24 | ||
- android-25 | ||
- extra-android-support | ||
- extra-google-m2repository | ||
- extra-android-m2repository | ||
- sys-img-armeabi-v7a-android-24 | ||
- sys-img-armeabi-v7a-android-25 | ||
|
||
before_script: | ||
- echo no | android create avd --force -n test -t android-24 --abi armeabi-v7a | ||
- emulator -avd test -no-audio -no-window & | ||
- android-wait-for-emulator | ||
- adb shell settings put global window_animation_scale 0 & | ||
- adb shell settings put global transition_animation_scale 0 & | ||
- adb shell settings put global animator_duration_scale 0 & | ||
- adb shell input keyevent 82 & | ||
|
||
script: | ||
./gradlew checkstyle build test && ./gradlew assembleRelease | ||
./gradlew checkstyle build test connectedDebugAndroidTest && ./gradlew assembleRelease | ||
|
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
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
105 changes: 105 additions & 0 deletions
105
sample/src/androidTest/java/com/karumi/dexter/sample/DexterTest.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,105 @@ | ||
package com.karumi.dexter.sample; | ||
|
||
import android.Manifest; | ||
import android.os.Handler; | ||
import android.os.HandlerThread; | ||
import android.support.test.rule.ActivityTestRule; | ||
import android.support.test.rule.GrantPermissionRule; | ||
import android.support.test.runner.AndroidJUnit4; | ||
import android.util.Log; | ||
import com.karumi.dexter.Dexter; | ||
import com.karumi.dexter.listener.DexterError; | ||
import com.karumi.dexter.listener.PermissionDeniedResponse; | ||
import com.karumi.dexter.listener.PermissionGrantedResponse; | ||
import com.karumi.dexter.listener.PermissionRequestErrorListener; | ||
import com.karumi.dexter.listener.single.BasePermissionListener; | ||
import com.karumi.dexter.listener.single.PermissionListener; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.awaitility.Awaitility.await; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
@RunWith(AndroidJUnit4.class) public class DexterTest { | ||
|
||
private static final String TAG = "DexterTest"; | ||
private final AtomicBoolean unblock = new AtomicBoolean(false); | ||
|
||
private final PermissionListener permissionListener = new BasePermissionListener() { | ||
@Override public void onPermissionGranted(PermissionGrantedResponse response) { | ||
unblock(); | ||
} | ||
|
||
@Override public void onPermissionDenied(PermissionDeniedResponse response) { | ||
unblock(); | ||
} | ||
}; | ||
private final PermissionRequestErrorListener errorListener = | ||
new PermissionRequestErrorListener() { | ||
@Override public void onError(DexterError error) { | ||
Log.i(TAG, error.toString()); | ||
unblock(); | ||
} | ||
}; | ||
|
||
@Rule public ActivityTestRule<SampleActivity> activityTestRule = | ||
new ActivityTestRule<>(SampleActivity.class); | ||
@Rule public GrantPermissionRule grantPermissionRule = | ||
GrantPermissionRule.grant(Manifest.permission.CAMERA); | ||
|
||
private Handler handler; | ||
private HandlerThread handlerThread; | ||
|
||
@Before public void setUp() throws Exception { | ||
handlerThread = new HandlerThread(TAG); | ||
handlerThread.start(); | ||
handler = new Handler(handlerThread.getLooper()); | ||
} | ||
|
||
@After public void tearDown() throws Exception { | ||
handlerThread.quit(); | ||
} | ||
|
||
@Test public void testWithLooper() { | ||
AtomicBoolean milestone = new AtomicBoolean(false); | ||
|
||
requestAndAcceptPermissionOnHandlerThread(milestone, Manifest.permission.CAMERA); | ||
|
||
block(); | ||
assertThat(milestone.get(), is(true)); | ||
} | ||
|
||
private void getPermission(String permission) { | ||
Dexter.withActivity(activityTestRule.getActivity()) | ||
.withPermission(permission) | ||
.withListener(permissionListener) | ||
.withErrorListener(errorListener) | ||
.onSameThread() | ||
.check(); | ||
} | ||
|
||
private void requestAndAcceptPermissionOnHandlerThread(final AtomicBoolean milestone, | ||
final String permission) { | ||
handler.post(new Runnable() { | ||
@Override public void run() { | ||
getPermission(permission); | ||
milestone.set(true); | ||
} | ||
}); | ||
} | ||
|
||
private void unblock() { | ||
unblock.set(true); | ||
} | ||
|
||
private void block() { | ||
await().atMost(20, TimeUnit.SECONDS).untilTrue(unblock); | ||
unblock.set(false); | ||
} | ||
} |