-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
41506ff
commit 17233ad
Showing
28 changed files
with
746 additions
and
102 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
~ Copyright (C) 2018 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. | ||
--> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="androidx.test.eventto" > | ||
|
||
|
||
<uses-sdk | ||
android:minSdkVersion="21" | ||
android:targetSdkVersion="34" /> | ||
|
||
</manifest> |
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
61 changes: 61 additions & 0 deletions
61
eventto/java/androidx/test/eventto/EventtoUiControlller.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,61 @@ | ||
package androidx.test.eventto; | ||
|
||
import androidx.test.espresso.UiController; | ||
import androidx.test.espresso.InjectEventSecurityException; | ||
import android.view.KeyCharacterMap; | ||
import android.view.KeyEvent; | ||
import android.view.MotionEvent; | ||
import android.os.Handler; | ||
import static android.os.Looper.getMainLooper; | ||
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; | ||
import android.util.Log; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import androidx.test.espresso.base.Interrogator; | ||
import androidx.test.espresso.base.EventInjector; | ||
|
||
class EventtoUiController { | ||
// implements UiController { | ||
// private final Handler mainHandler; | ||
// private final QueueIdler queueIdler; | ||
// private final ExecutorService keyEventExecutor = | ||
// Executors.newSingleThreadExecutor( | ||
// new ThreadFactoryBuilder().setNameFormat("Eventto Key Event #%d").build()); | ||
// private final EventInjector eventInjector; | ||
// | ||
// EventtoUiController() { | ||
// this.mainHandler = new Handler(getMainLooper()); | ||
// this.queueIdler = new QueueIdler(); | ||
// this.eventInjector = new EventInjector(new InputManagerEventInjectionStrategy()); | ||
// } | ||
// | ||
// @Override | ||
// public boolean injectMotionEvent(MotionEvent event) throws InjectEventSecurityException { | ||
// Log.i("EventtoUiController", "injectMotionEvent using ui automation"); | ||
// | ||
// getInstrumentation().getUiAutomation().injectInputEvent(event, false); | ||
// return true; | ||
// } | ||
// | ||
// @Override | ||
// public boolean injectKeyEvent(KeyEvent event) { | ||
// throw new UnsupportedOperationException(); | ||
// } | ||
// | ||
// @Override | ||
// public boolean injectString(String str) throws InjectEventSecurityException { | ||
// throw new UnsupportedOperationException(); | ||
// } | ||
// | ||
// @Override | ||
// public void loopMainThreadUntilIdle() { | ||
// queueIdler.idle(); | ||
// } | ||
// | ||
// @Override | ||
// public void loopMainThreadForAtLeast(long millisDelay) { | ||
// AtomicBoolean elapsedTimeReached = new AtomicBoolean(false); | ||
// mainHandler.postDelayed(() -> elapsedTimeReached.set(true), millisDelay); | ||
// queueIdler.idleUntil(() -> elapsedTimeReached.get()) ; | ||
// loopMainThreadUntilIdle(); | ||
// } | ||
} |
102 changes: 102 additions & 0 deletions
102
eventto/java/androidx/test/eventto/EventtoViewFinderImpl.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,102 @@ | ||
/* | ||
* Copyright (C) 2014 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 androidx.test.eventto; | ||
|
||
import static androidx.test.espresso.util.TreeIterables.breadthFirstViewTraversal; | ||
import static androidx.test.internal.util.Checks.checkMainThread; | ||
import static androidx.test.internal.util.Checks.checkNotNull; | ||
|
||
import android.view.View; | ||
import android.widget.AdapterView; | ||
import androidx.test.espresso.AmbiguousViewMatcherException; | ||
import androidx.test.espresso.NoMatchingViewException; | ||
import androidx.test.espresso.ViewFinder; | ||
import androidx.test.espresso.matcher.ViewMatchers; | ||
import androidx.test.espresso.util.IterablesKt; | ||
import androidx.test.espresso.util.Iterators; | ||
import androidx.test.espresso.util.StringJoinerKt; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import javax.inject.Inject; | ||
import javax.inject.Provider; | ||
import org.hamcrest.Matcher; | ||
|
||
/** Implementation of {@link ViewFinder}. */ | ||
// TODO: in the future we may want to collect stats here about the size of the view | ||
// hierarchy, average matcher execution time, warn when matchers take too long to execute, etc. | ||
public final class EventtoViewFinderImpl { | ||
|
||
private final Matcher<View> viewMatcher; | ||
|
||
@Inject | ||
public EventtoViewFinderImpl(Matcher<View> viewMatcher) { | ||
this.viewMatcher = viewMatcher; | ||
} | ||
|
||
public View getView(View root) throws AmbiguousViewMatcherException, NoMatchingViewException { | ||
checkMainThread(); | ||
checkNotNull(viewMatcher); | ||
|
||
Iterator<View> matchedViewIterator = | ||
IterablesKt.filter(breadthFirstViewTraversal(root), viewMatcher).iterator(); | ||
View matchedView = null; | ||
|
||
while (matchedViewIterator.hasNext()) { | ||
if (matchedView != null) { | ||
// Ambiguous! | ||
throw new AmbiguousViewMatcherException.Builder() | ||
.withViewMatcher(viewMatcher) | ||
.withRootView(root) | ||
.withView1(matchedView) | ||
.withView2(matchedViewIterator.next()) | ||
.withOtherAmbiguousViews(Iterators.toArray(matchedViewIterator, View.class)) | ||
.build(); | ||
} else { | ||
matchedView = matchedViewIterator.next(); | ||
} | ||
} | ||
if (null == matchedView) { | ||
List<View> adapterViews = | ||
IterablesKt.filterToList( | ||
breadthFirstViewTraversal(root), ViewMatchers.isAssignableFrom(AdapterView.class)); | ||
|
||
if (adapterViews.isEmpty()) { | ||
throw new NoMatchingViewException.Builder() | ||
.withViewMatcher(viewMatcher) | ||
.withRootView(root) | ||
.build(); | ||
} | ||
|
||
String warning = | ||
String.format( | ||
Locale.ROOT, | ||
"\n" | ||
+ "If the target view is not part of the view hierarchy, you may need to use" | ||
+ " Espresso.onData to load it from one of the following AdapterViews:%s", | ||
StringJoinerKt.joinToString(adapterViews, "\n- ")); | ||
throw new NoMatchingViewException.Builder() | ||
.withViewMatcher(viewMatcher) | ||
.withRootView(root) | ||
.withAdapterViews(adapterViews) | ||
.withAdapterViewWarning(warning) | ||
.build(); | ||
} else { | ||
return matchedView; | ||
} | ||
} | ||
} |
Oops, something went wrong.