1
0
Fork 0

Add license header to ext tests (#8130)

master
Tiger Oakes 2020-02-05 20:37:49 -08:00 committed by GitHub
parent 1acde42df9
commit 453e7955bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 77 additions and 53 deletions

View File

@ -1,35 +1,38 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.ext
import org.mozilla.fenix.TestApplication
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.assertTrue
import org.junit.Assert.assertEquals
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import android.app.Activity
import android.view.View
import android.view.WindowManager
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.TestApplication
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.Shadows.shadowOf
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(application = TestApplication::class)
class ActivityTest {
@Test
fun testEnterImmersiveMode() {
val activity = Robolectric.buildActivity(Activity::class.java).create().get()
val window = activity.getWindow()
val window = activity.window
// Turn off Keep Screen on Flag if it is on
if (shadowOf(window).getFlag(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)) window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
// Make sure that System UI flags are not set before the test
val flags = arrayOf(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION, View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN, View.SYSTEM_UI_FLAG_HIDE_NAVIGATION, View.SYSTEM_UI_FLAG_FULLSCREEN, View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
if (flags.any { f -> (window.getDecorView().getSystemUiVisibility() and f) == f }) {
window.getDecorView().setSystemUiVisibility(0)
if (flags.any { f -> (window.decorView.systemUiVisibility and f) == f }) {
window.decorView.systemUiVisibility = 0
}
// Run

View File

@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.ext
import android.widget.ImageView
@ -15,7 +19,6 @@ import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(application = TestApplication::class)
class BrowserIconsTest {
@Test
fun loadIntoViewTest() {

View File

@ -1,28 +1,33 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.ext
import org.mozilla.fenix.TestApplication
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import android.graphics.drawable.Drawable
import android.graphics.Rect
import android.graphics.Canvas
import android.graphics.ColorFilter
import android.graphics.Rect
import android.graphics.drawable.Drawable
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.TestApplication
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(application = TestApplication::class)
class DrawableTest {
@Test
fun testSetBounds() {
val drawable = TestDrawable()
assertFalse(drawable.boundsChanged)
val size = 10
drawable.setBounds(size)
assertTrue(drawable.boundsChanged)
val returnRec = drawable.copyBounds()
assertTrue(returnRec.contains(0, 0, -10, 10))
}

View File

@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.ext
import androidx.fragment.app.Fragment
@ -25,25 +29,24 @@ import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(application = TestApplication::class)
class FragmentTest {
val navDirections: NavDirections = mockk(relaxed = true)
val mockDestination = spyk(NavDestination("hi"))
val mockExtras: Extras = mockk(relaxed = true)
val mockId = 4
val navController = spyk(NavController(testContext))
val mockFragment: Fragment = mockk(relaxed = true)
val mockOptions: NavOptions = mockk(relaxed = true)
private val navDirections: NavDirections = mockk(relaxed = true)
private val mockDestination = spyk(NavDestination("hi"))
private val mockExtras: Extras = mockk(relaxed = true)
private val mockId = 4
private val navController = spyk(NavController(testContext))
private val mockFragment: Fragment = mockk(relaxed = true)
private val mockOptions: NavOptions = mockk(relaxed = true)
@Before
fun setup() {
mockkStatic(NavHostFragment::class)
every { (NavHostFragment.findNavController(mockFragment)) } returns navController
every { (NavHostFragment.findNavController(mockFragment).getCurrentDestination()) } returns mockDestination
every { (mockDestination.getId()) } returns mockId
every { (navController.getCurrentDestination()) } returns mockDestination
every { (NavHostFragment.findNavController(mockFragment).getCurrentDestination()?.getId()) } answers { (mockDestination.getId()) }
every { (NavHostFragment.findNavController(mockFragment).currentDestination) } returns mockDestination
every { (mockDestination.id) } returns mockId
every { (navController.currentDestination) } returns mockDestination
every { (NavHostFragment.findNavController(mockFragment).currentDestination?.id) } answers { (mockDestination.id) }
}
@Test
@ -51,7 +54,7 @@ class FragmentTest {
every { (NavHostFragment.findNavController(mockFragment).navigate(navDirections, null)) } just Runs
mockFragment.nav(mockId, navDirections)
verify { (NavHostFragment.findNavController(mockFragment).getCurrentDestination()) }
verify { (NavHostFragment.findNavController(mockFragment).currentDestination) }
verify { (NavHostFragment.findNavController(mockFragment).navigate(navDirections, null)) }
confirmVerified(mockFragment)
}
@ -61,7 +64,7 @@ class FragmentTest {
every { (NavHostFragment.findNavController(mockFragment).navigate(navDirections, mockExtras)) } just Runs
mockFragment.nav(mockId, navDirections, mockExtras)
verify { (NavHostFragment.findNavController(mockFragment).getCurrentDestination()) }
verify { (NavHostFragment.findNavController(mockFragment).currentDestination) }
verify { (NavHostFragment.findNavController(mockFragment).navigate(navDirections, mockExtras)) }
confirmVerified(mockFragment)
}
@ -71,7 +74,7 @@ class FragmentTest {
every { (NavHostFragment.findNavController(mockFragment).navigate(navDirections, mockOptions)) } just Runs
mockFragment.nav(mockId, navDirections, mockOptions)
verify { (NavHostFragment.findNavController(mockFragment).getCurrentDestination()) }
verify { (NavHostFragment.findNavController(mockFragment).currentDestination) }
verify { (NavHostFragment.findNavController(mockFragment).navigate(navDirections, mockOptions)) }
confirmVerified(mockFragment)
}

View File

@ -1,6 +1,10 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.ext
import kotlinx.coroutines.ObsoleteCoroutinesApi
import android.view.View
import mozilla.components.support.test.robolectric.testContext
import org.mozilla.fenix.TestApplication
import org.junit.Test
@ -12,23 +16,22 @@ import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import android.widget.ImageButton
@ObsoleteCoroutinesApi
@RunWith(RobolectricTestRunner::class)
@Config(application = TestApplication::class)
class ImageButtonTest {
val imageButton = ImageButton(testContext)
private val imageButton = ImageButton(testContext)
@Test
fun `Hide and disable`() {
imageButton.hideAndDisable()
assertFalse(imageButton.isEnabled)
assertEquals(4, imageButton.visibility)
assertEquals(View.INVISIBLE, imageButton.visibility)
}
@Test
fun `Show and enable`() {
imageButton.showAndEnable()
assertTrue(imageButton.isEnabled)
assertEquals(0, imageButton.visibility)
assertEquals(View.VISIBLE, imageButton.visibility)
}
}

View File

@ -4,23 +4,23 @@
package org.mozilla.fenix.ext
import org.mozilla.fenix.TestApplication
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import android.util.Log
import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.verify
import android.util.Log
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.TestApplication
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(application = TestApplication::class)
class LogTest {
val numCalls = if (org.mozilla.fenix.Config.channel.isDebug) 1 else 0
private val numCalls = if (org.mozilla.fenix.Config.channel.isDebug) 1 else 0
@Before
fun setup() {

View File

@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.ext
import android.os.Bundle
@ -18,7 +22,6 @@ import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(application = TestApplication::class)
class NavControllerTest {
private val navController: NavController = mockk(relaxed = true)

View File

@ -1,3 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.ext
import assertk.assertThat

View File

@ -1,9 +1,9 @@
package org.mozilla.fenix.whatsnew
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.whatsnew
import androidx.test.ext.junit.runners.AndroidJUnit4
import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert