blob: 5d7d60ec6d07939c4e4bc66a920b58999d8233dc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
package org.mozilla.geckoview.test
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.hamcrest.Matchers.* // ktlint-disable no-wildcard-imports
import org.json.JSONObject
import org.junit.Test
import org.junit.runner.RunWith
import java.io.BufferedReader
import java.io.ByteArrayInputStream
import java.io.InputStreamReader
import java.util.zip.GZIPInputStream
@RunWith(AndroidJUnit4::class)
class ProfilerControllerTest : BaseSessionTest() {
@Test
fun startAndStopProfiler() {
sessionRule.runtime.profilerController.startProfiler(arrayOf<String>(), arrayOf<String>())
val result = sessionRule.runtime.profilerController.stopProfiler()
val byteArray = sessionRule.waitForResult(result)
val head = (byteArray[0].toInt() and 0xff) or (byteArray[1].toInt() shl 8 and 0xff00)
assertThat(
"Header of byte array should be the same as the GZIP one",
head,
equalTo(GZIPInputStream.GZIP_MAGIC),
)
val profileString = StringBuilder()
val gzipInputStream = GZIPInputStream(ByteArrayInputStream(byteArray))
val bufferedReader = BufferedReader(InputStreamReader(gzipInputStream))
var line = bufferedReader.readLine()
while (line != null) {
profileString.append(line)
line = bufferedReader.readLine()
}
val json = JSONObject(profileString.toString())
assertThat(
"profile JSON object must not be empty",
json.length(),
greaterThan(0),
)
}
}
|