summaryrefslogtreecommitdiffstats
path: root/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ProfileLockedTest.kt
blob: 7c47ade0f72a540ba00fdfeca1f86d11d1706a0e (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
46
47
48
49
50
51
52
package org.mozilla.geckoview.test

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import androidx.test.platform.app.InstrumentationRegistry
import org.hamcrest.CoreMatchers.equalTo
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.geckoview.test.TestRuntimeService.RuntimeInstance
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.ClosedSessionAtStart

@RunWith(AndroidJUnit4::class)
@MediumTest
class ProfileLockedTest : BaseSessionTest() {
    private val targetContext
        get() = InstrumentationRegistry.getInstrumentation().targetContext

    @Test
    @ClosedSessionAtStart
    fun profileLocked() {
        val runtime0 = RuntimeInstance.start(
            targetContext,
            TestRuntimeService.instance0::class.java,
            temporaryProfile.get(),
        )

        // Start the first runtime and wait until it's ready
        sessionRule.waitForResult(runtime0.started)

        assertThat("The service should be connected now", runtime0.isConnected, equalTo(true))

        // Now start a _second_ runtime with the same profile folder, this will kill the first
        // runtime
        val runtime1 = RuntimeInstance.start(
            targetContext,
            TestRuntimeService.instance1::class.java,
            temporaryProfile.get(),
        )

        // Wait for the first runtime to disconnect
        sessionRule.waitForResult(runtime0.disconnected)

        // GeckoRuntime will quit after killing the offending process
        sessionRule.waitForResult(runtime1.quitted)

        assertThat(
            "The service shouldn't be connected anymore",
            runtime0.isConnected,
            equalTo(false),
        )
    }
}