Add license header to ext tests (#8130)
This commit is contained in:
parent
1acde42df9
commit
453e7955bb
|
@ -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
|
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.app.Activity
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.WindowManager
|
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.Shadows.shadowOf
|
||||||
|
import org.robolectric.annotation.Config
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner::class)
|
@RunWith(RobolectricTestRunner::class)
|
||||||
@Config(application = TestApplication::class)
|
@Config(application = TestApplication::class)
|
||||||
|
|
||||||
class ActivityTest {
|
class ActivityTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testEnterImmersiveMode() {
|
fun testEnterImmersiveMode() {
|
||||||
val activity = Robolectric.buildActivity(Activity::class.java).create().get()
|
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
|
// 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)
|
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
|
// 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)
|
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 }) {
|
if (flags.any { f -> (window.decorView.systemUiVisibility and f) == f }) {
|
||||||
window.getDecorView().setSystemUiVisibility(0)
|
window.decorView.systemUiVisibility = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run
|
// Run
|
||||||
|
|
|
@ -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
|
package org.mozilla.fenix.ext
|
||||||
|
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
|
@ -15,7 +19,6 @@ import org.robolectric.annotation.Config
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner::class)
|
@RunWith(RobolectricTestRunner::class)
|
||||||
@Config(application = TestApplication::class)
|
@Config(application = TestApplication::class)
|
||||||
|
|
||||||
class BrowserIconsTest {
|
class BrowserIconsTest {
|
||||||
@Test
|
@Test
|
||||||
fun loadIntoViewTest() {
|
fun loadIntoViewTest() {
|
||||||
|
|
|
@ -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
|
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.Canvas
|
||||||
import android.graphics.ColorFilter
|
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)
|
@RunWith(RobolectricTestRunner::class)
|
||||||
@Config(application = TestApplication::class)
|
@Config(application = TestApplication::class)
|
||||||
|
|
||||||
class DrawableTest {
|
class DrawableTest {
|
||||||
@Test
|
@Test
|
||||||
fun testSetBounds() {
|
fun testSetBounds() {
|
||||||
val drawable = TestDrawable()
|
val drawable = TestDrawable()
|
||||||
assertFalse(drawable.boundsChanged)
|
assertFalse(drawable.boundsChanged)
|
||||||
|
|
||||||
val size = 10
|
val size = 10
|
||||||
drawable.setBounds(size)
|
drawable.setBounds(size)
|
||||||
assertTrue(drawable.boundsChanged)
|
assertTrue(drawable.boundsChanged)
|
||||||
|
|
||||||
val returnRec = drawable.copyBounds()
|
val returnRec = drawable.copyBounds()
|
||||||
assertTrue(returnRec.contains(0, 0, -10, 10))
|
assertTrue(returnRec.contains(0, 0, -10, 10))
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
package org.mozilla.fenix.ext
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
|
@ -25,25 +29,24 @@ import org.robolectric.annotation.Config
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner::class)
|
@RunWith(RobolectricTestRunner::class)
|
||||||
@Config(application = TestApplication::class)
|
@Config(application = TestApplication::class)
|
||||||
|
|
||||||
class FragmentTest {
|
class FragmentTest {
|
||||||
|
|
||||||
val navDirections: NavDirections = mockk(relaxed = true)
|
private val navDirections: NavDirections = mockk(relaxed = true)
|
||||||
val mockDestination = spyk(NavDestination("hi"))
|
private val mockDestination = spyk(NavDestination("hi"))
|
||||||
val mockExtras: Extras = mockk(relaxed = true)
|
private val mockExtras: Extras = mockk(relaxed = true)
|
||||||
val mockId = 4
|
private val mockId = 4
|
||||||
val navController = spyk(NavController(testContext))
|
private val navController = spyk(NavController(testContext))
|
||||||
val mockFragment: Fragment = mockk(relaxed = true)
|
private val mockFragment: Fragment = mockk(relaxed = true)
|
||||||
val mockOptions: NavOptions = mockk(relaxed = true)
|
private val mockOptions: NavOptions = mockk(relaxed = true)
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun setup() {
|
fun setup() {
|
||||||
mockkStatic(NavHostFragment::class)
|
mockkStatic(NavHostFragment::class)
|
||||||
every { (NavHostFragment.findNavController(mockFragment)) } returns navController
|
every { (NavHostFragment.findNavController(mockFragment)) } returns navController
|
||||||
every { (NavHostFragment.findNavController(mockFragment).getCurrentDestination()) } returns mockDestination
|
every { (NavHostFragment.findNavController(mockFragment).currentDestination) } returns mockDestination
|
||||||
every { (mockDestination.getId()) } returns mockId
|
every { (mockDestination.id) } returns mockId
|
||||||
every { (navController.getCurrentDestination()) } returns mockDestination
|
every { (navController.currentDestination) } returns mockDestination
|
||||||
every { (NavHostFragment.findNavController(mockFragment).getCurrentDestination()?.getId()) } answers { (mockDestination.getId()) }
|
every { (NavHostFragment.findNavController(mockFragment).currentDestination?.id) } answers { (mockDestination.id) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -51,7 +54,7 @@ class FragmentTest {
|
||||||
every { (NavHostFragment.findNavController(mockFragment).navigate(navDirections, null)) } just Runs
|
every { (NavHostFragment.findNavController(mockFragment).navigate(navDirections, null)) } just Runs
|
||||||
|
|
||||||
mockFragment.nav(mockId, navDirections)
|
mockFragment.nav(mockId, navDirections)
|
||||||
verify { (NavHostFragment.findNavController(mockFragment).getCurrentDestination()) }
|
verify { (NavHostFragment.findNavController(mockFragment).currentDestination) }
|
||||||
verify { (NavHostFragment.findNavController(mockFragment).navigate(navDirections, null)) }
|
verify { (NavHostFragment.findNavController(mockFragment).navigate(navDirections, null)) }
|
||||||
confirmVerified(mockFragment)
|
confirmVerified(mockFragment)
|
||||||
}
|
}
|
||||||
|
@ -61,7 +64,7 @@ class FragmentTest {
|
||||||
every { (NavHostFragment.findNavController(mockFragment).navigate(navDirections, mockExtras)) } just Runs
|
every { (NavHostFragment.findNavController(mockFragment).navigate(navDirections, mockExtras)) } just Runs
|
||||||
|
|
||||||
mockFragment.nav(mockId, navDirections, mockExtras)
|
mockFragment.nav(mockId, navDirections, mockExtras)
|
||||||
verify { (NavHostFragment.findNavController(mockFragment).getCurrentDestination()) }
|
verify { (NavHostFragment.findNavController(mockFragment).currentDestination) }
|
||||||
verify { (NavHostFragment.findNavController(mockFragment).navigate(navDirections, mockExtras)) }
|
verify { (NavHostFragment.findNavController(mockFragment).navigate(navDirections, mockExtras)) }
|
||||||
confirmVerified(mockFragment)
|
confirmVerified(mockFragment)
|
||||||
}
|
}
|
||||||
|
@ -71,7 +74,7 @@ class FragmentTest {
|
||||||
every { (NavHostFragment.findNavController(mockFragment).navigate(navDirections, mockOptions)) } just Runs
|
every { (NavHostFragment.findNavController(mockFragment).navigate(navDirections, mockOptions)) } just Runs
|
||||||
|
|
||||||
mockFragment.nav(mockId, navDirections, mockOptions)
|
mockFragment.nav(mockId, navDirections, mockOptions)
|
||||||
verify { (NavHostFragment.findNavController(mockFragment).getCurrentDestination()) }
|
verify { (NavHostFragment.findNavController(mockFragment).currentDestination) }
|
||||||
verify { (NavHostFragment.findNavController(mockFragment).navigate(navDirections, mockOptions)) }
|
verify { (NavHostFragment.findNavController(mockFragment).navigate(navDirections, mockOptions)) }
|
||||||
confirmVerified(mockFragment)
|
confirmVerified(mockFragment)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
package org.mozilla.fenix.ext
|
||||||
|
|
||||||
import kotlinx.coroutines.ObsoleteCoroutinesApi
|
import android.view.View
|
||||||
import mozilla.components.support.test.robolectric.testContext
|
import mozilla.components.support.test.robolectric.testContext
|
||||||
import org.mozilla.fenix.TestApplication
|
import org.mozilla.fenix.TestApplication
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
@ -12,23 +16,22 @@ import org.robolectric.RobolectricTestRunner
|
||||||
import org.robolectric.annotation.Config
|
import org.robolectric.annotation.Config
|
||||||
import android.widget.ImageButton
|
import android.widget.ImageButton
|
||||||
|
|
||||||
@ObsoleteCoroutinesApi
|
|
||||||
@RunWith(RobolectricTestRunner::class)
|
@RunWith(RobolectricTestRunner::class)
|
||||||
@Config(application = TestApplication::class)
|
@Config(application = TestApplication::class)
|
||||||
class ImageButtonTest {
|
class ImageButtonTest {
|
||||||
val imageButton = ImageButton(testContext)
|
private val imageButton = ImageButton(testContext)
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `Hide and disable`() {
|
fun `Hide and disable`() {
|
||||||
imageButton.hideAndDisable()
|
imageButton.hideAndDisable()
|
||||||
assertFalse(imageButton.isEnabled)
|
assertFalse(imageButton.isEnabled)
|
||||||
assertEquals(4, imageButton.visibility)
|
assertEquals(View.INVISIBLE, imageButton.visibility)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `Show and enable`() {
|
fun `Show and enable`() {
|
||||||
imageButton.showAndEnable()
|
imageButton.showAndEnable()
|
||||||
assertTrue(imageButton.isEnabled)
|
assertTrue(imageButton.isEnabled)
|
||||||
assertEquals(0, imageButton.visibility)
|
assertEquals(View.VISIBLE, imageButton.visibility)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,23 +4,23 @@
|
||||||
|
|
||||||
package org.mozilla.fenix.ext
|
package org.mozilla.fenix.ext
|
||||||
|
|
||||||
import org.mozilla.fenix.TestApplication
|
import android.util.Log
|
||||||
import org.junit.Test
|
|
||||||
import org.junit.runner.RunWith
|
|
||||||
import org.robolectric.RobolectricTestRunner
|
|
||||||
import org.robolectric.annotation.Config
|
|
||||||
import io.mockk.mockk
|
import io.mockk.mockk
|
||||||
import io.mockk.mockkStatic
|
import io.mockk.mockkStatic
|
||||||
import io.mockk.verify
|
import io.mockk.verify
|
||||||
import android.util.Log
|
|
||||||
import org.junit.Before
|
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)
|
@RunWith(RobolectricTestRunner::class)
|
||||||
@Config(application = TestApplication::class)
|
@Config(application = TestApplication::class)
|
||||||
|
|
||||||
class LogTest {
|
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
|
@Before
|
||||||
fun setup() {
|
fun setup() {
|
||||||
|
|
|
@ -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
|
package org.mozilla.fenix.ext
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
@ -18,7 +22,6 @@ import org.robolectric.annotation.Config
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner::class)
|
@RunWith(RobolectricTestRunner::class)
|
||||||
@Config(application = TestApplication::class)
|
@Config(application = TestApplication::class)
|
||||||
|
|
||||||
class NavControllerTest {
|
class NavControllerTest {
|
||||||
|
|
||||||
private val navController: NavController = mockk(relaxed = true)
|
private val navController: NavController = mockk(relaxed = true)
|
||||||
|
|
|
@ -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
|
package org.mozilla.fenix.ext
|
||||||
|
|
||||||
import assertk.assertThat
|
import assertk.assertThat
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package org.mozilla.fenix.whatsnew
|
|
||||||
|
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
/* 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
|
* 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/. */
|
* 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 androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import mozilla.components.support.test.robolectric.testContext
|
import mozilla.components.support.test.robolectric.testContext
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
|
|
Loading…
Reference in New Issue
Block a user