|
|
|
@ -16,6 +16,7 @@
|
|
|
|
|
|
|
|
|
|
package com.google.samples.apps.nowinandroid.foryou
|
|
|
|
|
|
|
|
|
|
import android.util.Log
|
|
|
|
|
import androidx.benchmark.macro.MacrobenchmarkScope
|
|
|
|
|
import androidx.test.uiautomator.By
|
|
|
|
|
import androidx.test.uiautomator.Until
|
|
|
|
@ -23,7 +24,8 @@ import androidx.test.uiautomator.untilHasChildren
|
|
|
|
|
import com.google.samples.apps.nowinandroid.flingElementDownUp
|
|
|
|
|
import com.google.samples.apps.nowinandroid.waitAndFindObject
|
|
|
|
|
import com.google.samples.apps.nowinandroid.waitForObjectOnTopAppBar
|
|
|
|
|
import org.junit.Assert.fail
|
|
|
|
|
|
|
|
|
|
private const val TAG = "ForYouActions"
|
|
|
|
|
|
|
|
|
|
fun MacrobenchmarkScope.forYouWaitForContent() {
|
|
|
|
|
// Wait until content is loaded by checking if topics are loaded
|
|
|
|
@ -41,6 +43,12 @@ fun MacrobenchmarkScope.forYouWaitForContent() {
|
|
|
|
|
*/
|
|
|
|
|
fun MacrobenchmarkScope.forYouSelectTopics(recheckTopicsIfChecked: Boolean = false) {
|
|
|
|
|
val topics = device.findObject(By.res("forYou:topicSelection"))
|
|
|
|
|
val withChildren = topics.childCount != 0
|
|
|
|
|
if (!withChildren) {
|
|
|
|
|
// TODO: Ensure ForYou has topics.
|
|
|
|
|
Log.w(TAG, "no topics found, can't scroll for baseline profile generation.")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set gesture margin from sides not to trigger system gesture navigation
|
|
|
|
|
val horizontalMargin = 10 * topics.visibleBounds.width() / 100
|
|
|
|
@ -51,9 +59,6 @@ fun MacrobenchmarkScope.forYouSelectTopics(recheckTopicsIfChecked: Boolean = fal
|
|
|
|
|
var visited = 0
|
|
|
|
|
|
|
|
|
|
while (visited < 3) {
|
|
|
|
|
if (topics.childCount == 0) {
|
|
|
|
|
fail("No topics found, can't generate profile for ForYou page.")
|
|
|
|
|
}
|
|
|
|
|
// Selecting some topics, which will populate items in the feed.
|
|
|
|
|
val topic = topics.children[index % topics.childCount]
|
|
|
|
|
// Find the checkable element to figure out whether it's checked or not
|
|
|
|
|