summaryrefslogtreecommitdiffhomepage
path: root/android/test/e2e/src
diff options
context:
space:
mode:
authorAlbin <albin@mullvad.net>2023-03-22 09:07:53 +0100
committerAlbin <albin@mullvad.net>2023-03-22 10:39:58 +0100
commit68c356e5afa2165cadef86d43966e51d9203102c (patch)
tree0a172dacad334066be40ea1239691ed963139dac /android/test/e2e/src
parente5d106c9260e0f282c75d105da7b0247535cdfdd (diff)
downloadmullvadvpn-68c356e5afa2165cadef86d43966e51d9203102c.tar.xz
mullvadvpn-68c356e5afa2165cadef86d43966e51d9203102c.zip
Apply project-wide `kotlinLangStyle` formatting
Diffstat (limited to 'android/test/e2e/src')
-rw-r--r--android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/ConnectionTest.kt8
-rw-r--r--android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/EndToEndTest.kt28
-rw-r--r--android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/LoginTest.kt4
-rw-r--r--android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/interactor/SystemSettingsInteractor.kt19
-rw-r--r--android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/misc/CleanupAccountTestRule.kt5
-rw-r--r--android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/misc/ConnCheckState.kt5
-rw-r--r--android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/misc/SimpleMullvadHttpClient.kt122
7 files changed, 76 insertions, 115 deletions
diff --git a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/ConnectionTest.kt b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/ConnectionTest.kt
index 8f72fef0be..488162b08c 100644
--- a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/ConnectionTest.kt
+++ b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/ConnectionTest.kt
@@ -12,13 +12,9 @@ import org.junit.Test
class ConnectionTest : EndToEndTest() {
- @Rule
- @JvmField
- val cleanupAccountTestRule = CleanupAccountTestRule()
+ @Rule @JvmField val cleanupAccountTestRule = CleanupAccountTestRule()
- @Rule
- @JvmField
- val forgetAllVpnAppsInSettingsTestRule = ForgetAllVpnAppsInSettingsTestRule()
+ @Rule @JvmField val forgetAllVpnAppsInSettingsTestRule = ForgetAllVpnAppsInSettingsTestRule()
@Test
fun testConnectAndVerifyWithConnectionCheck() {
diff --git a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/EndToEndTest.kt b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/EndToEndTest.kt
index f8f5bb8f6c..3514405dd9 100644
--- a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/EndToEndTest.kt
+++ b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/EndToEndTest.kt
@@ -19,16 +19,15 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
abstract class EndToEndTest {
- @Rule
- @JvmField
- val rule = CaptureScreenshotOnFailedTestRule(LOG_TAG)
+ @Rule @JvmField val rule = CaptureScreenshotOnFailedTestRule(LOG_TAG)
@Rule
@JvmField
- val permissionRule: GrantPermissionRule = GrantPermissionRule.grant(
- Manifest.permission.WRITE_EXTERNAL_STORAGE,
- Manifest.permission.READ_EXTERNAL_STORAGE
- )
+ val permissionRule: GrantPermissionRule =
+ GrantPermissionRule.grant(
+ Manifest.permission.WRITE_EXTERNAL_STORAGE,
+ Manifest.permission.READ_EXTERNAL_STORAGE
+ )
lateinit var device: UiDevice
lateinit var targetContext: Context
@@ -41,14 +40,13 @@ abstract class EndToEndTest {
device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
targetContext = InstrumentationRegistry.getInstrumentation().targetContext
- validTestAccountToken = InstrumentationRegistry.getArguments()
- .getRequiredArgument(VALID_TEST_ACCOUNT_TOKEN_ARGUMENT_KEY)
- invalidTestAccountToken = InstrumentationRegistry.getArguments()
- .getRequiredArgument(INVALID_TEST_ACCOUNT_TOKEN_ARGUMENT_KEY)
+ validTestAccountToken =
+ InstrumentationRegistry.getArguments()
+ .getRequiredArgument(VALID_TEST_ACCOUNT_TOKEN_ARGUMENT_KEY)
+ invalidTestAccountToken =
+ InstrumentationRegistry.getArguments()
+ .getRequiredArgument(INVALID_TEST_ACCOUNT_TOKEN_ARGUMENT_KEY)
- app = AppInteractor(
- device,
- targetContext
- )
+ app = AppInteractor(device, targetContext)
}
}
diff --git a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/LoginTest.kt b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/LoginTest.kt
index 9cec30d872..646af7a18e 100644
--- a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/LoginTest.kt
+++ b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/LoginTest.kt
@@ -15,9 +15,7 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class LoginTest : EndToEndTest() {
- @Rule
- @JvmField
- val cleanupAccountTestRule = CleanupAccountTestRule()
+ @Rule @JvmField val cleanupAccountTestRule = CleanupAccountTestRule()
@Test
fun testLoginWithInvalidCredentials() {
diff --git a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/interactor/SystemSettingsInteractor.kt b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/interactor/SystemSettingsInteractor.kt
index 9e5f0aa665..bcf4adcc9e 100644
--- a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/interactor/SystemSettingsInteractor.kt
+++ b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/interactor/SystemSettingsInteractor.kt
@@ -7,18 +7,15 @@ import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import net.mullvad.mullvadvpn.test.common.extension.findObjectByCaseInsensitiveText
-class SystemSettingsInteractor(
- private val uiDevice: UiDevice,
- private val context: Context
-) {
+class SystemSettingsInteractor(private val uiDevice: UiDevice, private val context: Context) {
fun openVpnSettings() {
- val intent = Intent("com.intent.MAIN").apply {
- addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
- addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
- }
- intent.component = ComponentName.unflattenFromString(
- "com.android.settings/.Settings\$VpnSettingsActivity"
- )
+ val intent =
+ Intent("com.intent.MAIN").apply {
+ addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
+ addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ }
+ intent.component =
+ ComponentName.unflattenFromString("com.android.settings/.Settings\$VpnSettingsActivity")
context.startActivity(intent)
Thread.sleep(1000)
}
diff --git a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/misc/CleanupAccountTestRule.kt b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/misc/CleanupAccountTestRule.kt
index 2b69436f6d..2e19cb42fe 100644
--- a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/misc/CleanupAccountTestRule.kt
+++ b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/misc/CleanupAccountTestRule.kt
@@ -13,8 +13,9 @@ class CleanupAccountTestRule : TestWatcher() {
override fun starting(description: Description) {
Log.d(LOG_TAG, "Cleaning up account before test: ${description.methodName}")
val targetContext = InstrumentationRegistry.getInstrumentation().targetContext
- val validTestAccountToken = InstrumentationRegistry.getArguments()
- .getRequiredArgument(VALID_TEST_ACCOUNT_TOKEN_ARGUMENT_KEY)
+ val validTestAccountToken =
+ InstrumentationRegistry.getArguments()
+ .getRequiredArgument(VALID_TEST_ACCOUNT_TOKEN_ARGUMENT_KEY)
MullvadAccountInteractor(SimpleMullvadHttpClient(targetContext), validTestAccountToken)
.cleanupAccount()
}
diff --git a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/misc/ConnCheckState.kt b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/misc/ConnCheckState.kt
index 744e80124e..75004270a4 100644
--- a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/misc/ConnCheckState.kt
+++ b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/misc/ConnCheckState.kt
@@ -1,6 +1,3 @@
package net.mullvad.mullvadvpn.test.e2e.misc
-data class ConnCheckState(
- val isConnected: Boolean,
- val ipAddress: String
-)
+data class ConnCheckState(val isConnected: Boolean, val ipAddress: String)
diff --git a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/misc/SimpleMullvadHttpClient.kt b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/misc/SimpleMullvadHttpClient.kt
index bc56737b04..b97fb28f45 100644
--- a/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/misc/SimpleMullvadHttpClient.kt
+++ b/android/test/e2e/src/main/kotlin/net/mullvad/mullvadvpn/test/e2e/misc/SimpleMullvadHttpClient.kt
@@ -23,17 +23,13 @@ class SimpleMullvadHttpClient(context: Context) {
Log.v(LOG_TAG, "Remove all devices")
val token = login(accountToken)
val devices = getDeviceList(token)
- devices.forEach {
- removeDevice(token, it)
- }
+ devices.forEach { removeDevice(token, it) }
Log.v(LOG_TAG, "All devices removed")
}
fun login(accountToken: String): String {
Log.v(LOG_TAG, "Attempt login with account token: $accountToken")
- val json = JSONObject().apply {
- put("account_number", accountToken)
- }
+ val json = JSONObject().apply { put("account_number", accountToken) }
return sendSimpleSynchronousRequest(Request.Method.POST, AUTH_URL, json)!!.let { response ->
response.getString("access_token").also { accessToken ->
Log.v(LOG_TAG, "Successfully logged in and received access token: $accessToken")
@@ -44,21 +40,20 @@ class SimpleMullvadHttpClient(context: Context) {
fun getDeviceList(accessToken: String): List<String> {
Log.v(LOG_TAG, "Get devices")
- val response = sendSimpleSynchronousRequestArray(
- Request.Method.GET,
- DEVICE_LIST_URL,
- token = accessToken
- )
+ val response =
+ sendSimpleSynchronousRequestArray(
+ Request.Method.GET,
+ DEVICE_LIST_URL,
+ token = accessToken
+ )
- return response!!.iterator<JSONObject>().asSequence().toList()
+ return response!!
+ .iterator<JSONObject>()
+ .asSequence()
+ .toList()
.also {
- it
- .map { jsonObject ->
- jsonObject.getString("name")
- }
- .also { deviceNames ->
- Log.v(LOG_TAG, "Devices received: $deviceNames")
- }
+ it.map { jsonObject -> jsonObject.getString("name") }
+ .also { deviceNames -> Log.v(LOG_TAG, "Devices received: $deviceNames") }
}
.map { it.getString("id") }
.toList()
@@ -74,13 +69,8 @@ class SimpleMullvadHttpClient(context: Context) {
}
fun runConnectionCheck(): ConnCheckState? {
- return sendSimpleSynchronousRequestString(
- Request.Method.GET,
- CONN_CHECK_URL
- )
- ?.let { respose ->
- JSONObject(respose)
- }
+ return sendSimpleSynchronousRequestString(Request.Method.GET, CONN_CHECK_URL)
+ ?.let { respose -> JSONObject(respose) }
?.let { json ->
ConnCheckState(
isConnected = json.getBoolean("mullvad_exit_ip"),
@@ -96,24 +86,19 @@ class SimpleMullvadHttpClient(context: Context) {
token: String? = null
): JSONObject? {
val future = RequestFuture.newFuture<JSONObject>()
- val request = object : JsonObjectRequest(
- method,
- url,
- body,
- future,
- future
- ) {
- override fun getHeaders(): MutableMap<String, String> {
- val headers = HashMap<String, String>()
- if (body != null) {
- headers.put("Content-Type", "application/json")
- }
- if (token != null) {
- headers.put("Authorization", "Bearer $token")
+ val request =
+ object : JsonObjectRequest(method, url, body, future, future) {
+ override fun getHeaders(): MutableMap<String, String> {
+ val headers = HashMap<String, String>()
+ if (body != null) {
+ headers.put("Content-Type", "application/json")
+ }
+ if (token != null) {
+ headers.put("Authorization", "Bearer $token")
+ }
+ return headers
}
- return headers
}
- }
queue.add(request)
return try {
future.get().also { response ->
@@ -132,28 +117,22 @@ class SimpleMullvadHttpClient(context: Context) {
token: String? = null
): String? {
val future = RequestFuture.newFuture<String>()
- val request = object : StringRequest(
- method,
- url,
- future,
- future
- ) {
- override fun getHeaders(): MutableMap<String, String> {
- val headers = HashMap<String, String>()
- if (body != null) {
- headers.put("Content-Type", "application/json")
- }
- if (token != null) {
- headers.put("Authorization", "Bearer $token")
+ val request =
+ object : StringRequest(method, url, future, future) {
+ override fun getHeaders(): MutableMap<String, String> {
+ val headers = HashMap<String, String>()
+ if (body != null) {
+ headers.put("Content-Type", "application/json")
+ }
+ if (token != null) {
+ headers.put("Authorization", "Bearer $token")
+ }
+ return headers
}
- return headers
}
- }
queue.add(request)
return try {
- future.get().also { response ->
- Log.v(LOG_TAG, "String request response: $response")
- }
+ future.get().also { response -> Log.v(LOG_TAG, "String request response: $response") }
} catch (e: Exception) {
Log.v(LOG_TAG, "String request error: ${e.message}")
throw TestEventException(REQUEST_ERROR_MESSAGE)
@@ -167,22 +146,17 @@ class SimpleMullvadHttpClient(context: Context) {
token: String? = null
): JSONArray? {
val future = RequestFuture.newFuture<JSONArray>()
- val request = object : JsonArrayRequest(
- method,
- url,
- null,
- future,
- future
- ) {
- override fun getHeaders(): MutableMap<String, String> {
- val headers = HashMap<String, String>()
- headers.put("Content-Type", "application/json")
- if (token != null) {
- headers.put("Authorization", "Bearer $token")
+ val request =
+ object : JsonArrayRequest(method, url, null, future, future) {
+ override fun getHeaders(): MutableMap<String, String> {
+ val headers = HashMap<String, String>()
+ headers.put("Content-Type", "application/json")
+ if (token != null) {
+ headers.put("Authorization", "Bearer $token")
+ }
+ return headers
}
- return headers
}
- }
queue.add(request)
return try {
future.get().also { response ->