-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(android): add a heap growth detection test
- Loading branch information
Showing
4 changed files
with
85 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- | ||
Check warning Code scanning / mobsfscan The flag [android:allowBackup] should be set to false. By default it is set to true and allows anyone to backup your application data via adb. It allows users who have enabled USB debugging to copy application data off of the device. Warning
The flag [android:allowBackup] should be set to false. By default it is set to true and allows anyone to backup your application data via adb. It allows users who have enabled USB debugging to copy application data off of the device.
|
||
~ Copyright © 2021-2024 Harsh Shandilya. | ||
~ Use of this source code is governed by an MIT-style | ||
~ license that can be found in the LICENSE file or at | ||
~ https://opensource.org/licenses/MIT. | ||
--> | ||
<manifest | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<!-- Performing the heap growth analysis in process requires more heap. --> | ||
<application | ||
android:largeHeap="true"/> | ||
</manifest> |
59 changes: 59 additions & 0 deletions
59
android/src/androidTest/kotlin/dev/msfjarvis/claw/android/HeapGrowthCheck.kt
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,59 @@ | ||
/* | ||
* Copyright © 2024 Harsh Shandilya. | ||
* Use of this source code is governed by an MIT-style | ||
* license that can be found in the LICENSE file or at | ||
* https://opensource.org/licenses/MIT. | ||
*/ | ||
package dev.msfjarvis.claw.android | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.uiautomator.By | ||
import androidx.test.uiautomator.BySelector | ||
import androidx.test.uiautomator.UiDevice | ||
import androidx.test.uiautomator.UiObject2 | ||
import androidx.test.uiautomator.Until | ||
import com.google.common.truth.Truth.assertThat | ||
import de.mannodermaus.junit5.ActivityScenarioExtension | ||
import leakcanary.repeatingAndroidInProcessScenario | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.RegisterExtension | ||
import shark.ObjectGrowthDetector | ||
import shark.forAndroidHeap | ||
|
||
class HeapGrowthCheck { | ||
@JvmField | ||
@RegisterExtension | ||
val scenarioExtension = ActivityScenarioExtension.launch<MainActivity>() | ||
private val detector = ObjectGrowthDetector.forAndroidHeap().repeatingAndroidInProcessScenario() | ||
private lateinit var device: UiDevice | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
val instrumentation = InstrumentationRegistry.getInstrumentation() | ||
device = UiDevice.getInstance(instrumentation) | ||
} | ||
|
||
@Test | ||
fun verify_heap_growth() { | ||
val heapGrowth = detector.findRepeatedlyGrowingObjects { device.exploreScreens() } | ||
assertThat(heapGrowth.growingObjects).isEmpty() | ||
} | ||
|
||
private companion object { | ||
fun UiDevice.exploreScreens() { | ||
listOf("HOTTEST", "NEWEST", "SAVED").forEach { tag -> | ||
waitForObject(By.res(tag)).click() | ||
waitForIdle() | ||
} | ||
} | ||
|
||
private fun UiDevice.waitForObject(selector: BySelector, timeout: Long = 10_000L): UiObject2 { | ||
if (wait(Until.hasObject(selector), timeout)) { | ||
return findObject(selector) | ||
} | ||
|
||
error("Object with selector [$selector] not found") | ||
} | ||
} | ||
} |
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