1 package org.mozilla.geckoview.test 2 3 import androidx.test.filters.LargeTest 4 import androidx.test.rule.ActivityTestRule 5 import androidx.test.ext.junit.runners.AndroidJUnit4 6 import androidx.core.view.ViewCompat 7 import android.view.View 8 9 import org.hamcrest.MatcherAssert.assertThat 10 import org.hamcrest.Matchers.equalTo 11 12 import org.junit.After 13 import org.junit.Before 14 import org.junit.Rule 15 import org.junit.Test 16 import org.junit.rules.RuleChain 17 import org.junit.runner.RunWith 18 19 import org.mozilla.geckoview.GeckoSession 20 import org.mozilla.geckoview.test.rule.GeckoSessionTestRule 21 22 @RunWith(AndroidJUnit4::class) 23 @LargeTest 24 class GeckoViewTest { 25 val activityRule = ActivityTestRule<GeckoViewTestActivity>(GeckoViewTestActivity::class.java) 26 var sessionRule = GeckoSessionTestRule() 27 28 val view get() = activityRule.activity.view 29 30 @get:Rule 31 val rules = RuleChain.outerRule(activityRule).around(sessionRule) 32 33 @Before setupnull34 fun setup() { 35 // Attach the default session from the session rule to the GeckoView 36 view.setSession(sessionRule.session) 37 } 38 39 @After cleanupnull40 fun cleanup() { 41 view.releaseSession() 42 } 43 44 @Test setSessionOnClosednull45 fun setSessionOnClosed() { 46 view.session!!.close() 47 view.setSession(GeckoSession()) 48 } 49 50 @Test(expected = IllegalStateException::class) setSessionOnOpenThrowsnull51 fun setSessionOnOpenThrows() { 52 assertThat("Session is open", view.session!!.isOpen, equalTo(true)) 53 view.setSession(GeckoSession()) 54 } 55 56 @Test(expected = java.lang.IllegalStateException::class) displayAlreadyAcquirednull57 fun displayAlreadyAcquired() { 58 assertThat("View should be attached", 59 ViewCompat.isAttachedToWindow(view), equalTo(true)) 60 view.session!!.acquireDisplay() 61 } 62 63 @Test relaseOnDetachnull64 fun relaseOnDetach() { 65 // The GeckoDisplay should be released when the View is detached from the window... 66 view.onDetachedFromWindow() 67 view.session!!.releaseDisplay(view.session!!.acquireDisplay()) 68 } 69 } 70