1
0
Fork 0

Merge branch 'master' into a-s-networking

master
Colin Lee 2019-04-17 10:36:35 -05:00 committed by GitHub
commit f48ee405b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 200 additions and 43 deletions

View File

@ -27,7 +27,8 @@ android {
targetSdkVersion Config.targetSdkVersion
versionCode Config.versionCode
versionName Config.versionName + Config.generateVersionSuffix()
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments clearPackageData: 'true'
manifestPlaceholders.isRaptorEnabled = "false"
}
@ -50,6 +51,10 @@ android {
}
}
testOptions {
execution 'ANDROIDX_TEST_ORCHESTRATOR'
}
flavorDimensions "abi", "channel"
productFlavors {
@ -333,8 +338,32 @@ dependencies {
implementation Deps.adjust
implementation Deps.installreferrer // Required by Adjust
// androidTestImplementation Deps.tools_test_runner
// androidTestImplementation Deps.tools_espresso_core
androidTestImplementation Deps.uiautomator
androidTestImplementation Deps.espresso_core, {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestImplementation(Deps.espresso_contrib) {
exclude module: 'appcompat-v7'
exclude module: 'support-v4'
exclude module: 'support-annotations'
exclude module: 'recyclerview-v7'
exclude module: 'design'
exclude module: 'espresso-core'
}
androidTestImplementation Deps.espresso_idling_resources
androidTestImplementation Deps.tools_test_runner
androidTestImplementation Deps.tools_espresso_core
androidTestImplementation Deps.tools_test_rules
androidTestUtil Deps.orchestrator
androidTestImplementation Deps.espresso_core, {
exclude group: 'com.android.support', module: 'support-annotations'
}
testImplementation Deps.junit_jupiter_api
testImplementation Deps.junit_jupiter_params

View File

@ -1,24 +0,0 @@
package org.mozilla.fenix
import androidx.test.InstrumentationRegistry
import androidx.test.runner.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
/* ktlint-disable no-wildcard-imports */
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
assertEquals("org.mozilla.fenix", appContext.packageName)
}
}

View File

@ -0,0 +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
class FirefoxTestApplication : HomeActivity()

View File

@ -0,0 +1,16 @@
/* 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
import android.app.Application
import android.content.Context
import androidx.test.runner.AndroidJUnitRunner
class FirefoxTestRunner : AndroidJUnitRunner() {
override fun newApplication(cl: ClassLoader?, className: String?, context: Context?): Application {
return super.newApplication(cl, FirefoxTestApplication::class.java.name, context)
}
}

View File

@ -0,0 +1,18 @@
/* 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.helpers
import androidx.test.rule.ActivityTestRule
import org.mozilla.fenix.HomeActivity
/**
* A [org.junit.Rule] to handle shared test set up for tests on [HomeActivity].
*
* @param initialTouchMode See [ActivityTestRule]
* @param launchActivity See [ActivityTestRule]
*/
class HomeActivityTestRule(initialTouchMode: Boolean = false, launchActivity: Boolean = true) :
ActivityTestRule<HomeActivity>(HomeActivity::class.java, initialTouchMode, launchActivity)

View File

@ -0,0 +1,32 @@
/* 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.ui
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.ui.robots.homeScreen
/**
* Tests for verifying the presence of home screen elements
*
*/
class HomeScreenTest {
/* ktlint-disable no-blank-line-before-rbrace */ // This imposes unreadable grouping.
@get:Rule
val activityTestRule = HomeActivityTestRule()
@Test
fun homeScreenItemsTest() {
homeScreen {
verifyHomeScreen()
verifyHomePrivateBrowsingButton()
verifyHomeMenu()
verifyHomeWordmark()
verifyHomeToolbar()
verifyHomeComponent()
}
}
}

View File

@ -0,0 +1,39 @@
/* 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/. */
@file:Suppress("TooManyFunctions")
package org.mozilla.fenix.ui.robots
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import androidx.test.espresso.matcher.ViewMatchers.Visibility
class HomeScreenRobot {
fun verifyHomeScreen() = homeScreen()
fun verifyHomePrivateBrowsingButton() = homePrivateBrowsingButton()
fun verifyHomeMenu() = homeMenu()
fun verifyHomeWordmark() = homeWordmark()
fun verifyHomeToolbar() = homeToolbar()
fun verifyHomeComponent() = homeComponent()
}
fun homeScreen(interact: HomeScreenRobot.() -> Unit) {
HomeScreenRobot().interact()
}
private fun homeScreen() = onView(ViewMatchers.withResourceName("homeLayout"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun homePrivateBrowsingButton() = onView(ViewMatchers.withResourceName("privateBrowsingButton"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun homeMenu() = onView(ViewMatchers.withResourceName("menuButton"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun homeWordmark() = onView(ViewMatchers.withResourceName("wordmark"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun homeToolbar() = onView(ViewMatchers.withResourceName("toolbar"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
private fun homeComponent() = onView(ViewMatchers.withResourceName("home_component"))
.check(matches(withEffectiveVisibility(Visibility.VISIBLE)))

View File

@ -4,6 +4,7 @@
package org.mozilla.fenix
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Build
@ -11,6 +12,7 @@ import android.os.Bundle
import android.preference.PreferenceManager
import android.util.AttributeSet
import android.view.View
import android.view.inputmethod.InputMethodManager
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.navigation.fragment.NavHostFragment
@ -105,6 +107,8 @@ open class HomeActivity : AppCompatActivity() {
navHost.navController.popBackStack(R.id.browserFragment, true)
allSessionsRemoved = false
}
showSoftwareKeyboardIfNecessary()
}
override fun onDestroy() {
@ -140,6 +144,27 @@ open class HomeActivity : AppCompatActivity() {
super.onBackPressed()
}
override fun onPause() {
super.onPause()
hideSoftwareKeyboardIfNecessary()
}
private fun showSoftwareKeyboardIfNecessary() {
(getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager).apply {
currentFocus?.also {
this.showSoftInput(it, 0)
}
}
}
private fun hideSoftwareKeyboardIfNecessary() {
(getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager).apply {
currentFocus?.also {
this.hideSoftInputFromWindow(it.windowToken, 0)
}
}
}
private fun handleCrashIfNecessary(intent: Intent?) {
if (intent == null) { return }
if (!Crash.isCrashIntent(intent)) { return }

View File

@ -5,7 +5,6 @@
package org.mozilla.fenix.components.toolbar
import android.graphics.drawable.BitmapDrawable
import android.view.Gravity
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.ImageView
@ -62,7 +61,7 @@ class ToolbarUIView(
val isCustomTabSession = (session?.isCustomTabSession() == true)
urlBoxView = if (isCustomTabSession) { null } else urlBackground
progressBarGravity = if (isCustomTabSession) { Gravity.TOP } else Gravity.BOTTOM
progressBarGravity = if (isCustomTabSession) { PROGRESS_BOTTOM } else PROGRESS_TOP
textColor = ContextCompat.getColor(context, R.color.photonGrey30)
@ -173,6 +172,8 @@ class ToolbarUIView(
}
companion object {
private const val PROGRESS_BOTTOM = 0
private const val PROGRESS_TOP = 1
const val browserActionMarginDp = 8
}
}

View File

@ -10,6 +10,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.preference.PreferenceFragmentCompat
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.requireComponents
class ThemeFragment : PreferenceFragmentCompat() {
private lateinit var radioLightTheme: RadioButtonPreference
@ -64,8 +65,7 @@ class ThemeFragment : PreferenceFragmentCompat() {
val keyLightTheme = getString(R.string.pref_key_light_theme)
radioLightTheme = requireNotNull(findPreference(keyLightTheme))
radioLightTheme.onClickListener {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
activity?.recreate()
setNewTheme(AppCompatDelegate.MODE_NIGHT_NO)
}
}
@ -75,8 +75,7 @@ class ThemeFragment : PreferenceFragmentCompat() {
val keyBatteryTheme = getString(R.string.pref_key_auto_battery_theme)
radioAutoBatteryTheme = requireNotNull(findPreference(keyBatteryTheme))
radioAutoBatteryTheme.onClickListener {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY)
activity?.recreate()
setNewTheme(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY)
}
}
@ -84,8 +83,7 @@ class ThemeFragment : PreferenceFragmentCompat() {
val keyDarkTheme = getString(R.string.pref_key_dark_theme)
radioDarkTheme = requireNotNull(findPreference(keyDarkTheme))
radioDarkTheme.onClickListener {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
activity?.recreate()
setNewTheme(AppCompatDelegate.MODE_NIGHT_YES)
}
}
@ -94,9 +92,14 @@ class ThemeFragment : PreferenceFragmentCompat() {
radioFollowDeviceTheme = requireNotNull(findPreference(keyDeviceTheme))
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
radioFollowDeviceTheme.onClickListener {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
activity?.recreate()
setNewTheme(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
}
}
}
private fun setNewTheme(mode: Int) {
AppCompatDelegate.setDefaultNightMode(mode)
activity?.recreate()
requireComponents.useCases.sessionUseCases.reload.invoke()
}
}

View File

@ -52,6 +52,7 @@
android:drawableStart="@drawable/ic_tracking_protection"
android:paddingEnd="24dp"
android:text="@string/preferences_tracking_protection"
android:thumbTint="?accentBright"
app:layout_constraintBottom_toTopOf="@id/report_problem"
app:layout_constraintTop_toBottomOf="@id/line_divider_security" />

View File

@ -28,9 +28,6 @@ private object Versions {
const val mozilla_android_components = "0.50.0-SNAPSHOT"
const val mozilla_appservices = "0.25.2"
const val test_tools = "1.0.2"
const val espresso_core = "2.2.2"
const val autodispose = "1.1.0"
const val adjust = "4.11.4"
const val installreferrer = "1.0"
@ -41,6 +38,14 @@ private object Versions {
const val glide = "4.9.0"
const val flipper = "0.18.0"
const val soLoader = "0.5.1"
const val espresso_core = "2.2.2"
const val espresso_version = "3.0.2"
const val orchestrator = "1.1.1"
const val tools_test_rules = "1.1.1"
const val tools_test_runner = "1.1.1"
const val uiautomator = "2.1.3"
const val test_tools = "1.0.2"
}
@Suppress("unused")
@ -119,9 +124,6 @@ object Deps {
const val leanplum = "com.leanplum:leanplum-core:${Versions.leanplum}"
const val tools_test_runner = "com.android.support.test:runner:${Versions.test_tools}"
const val tools_espresso_core = "com.android.support.test.espresso:espresso-core:${Versions.espresso_core}"
const val androidx_annotation = "androidx.annotation:annotation:${Versions.androidx_annotation}"
const val androidx_fragment = "androidx.fragment:fragment:${Versions.androidx_fragment}"
const val androidx_appcompat = "androidx.appcompat:appcompat:${Versions.androidx_appcompat}"
@ -156,4 +158,12 @@ object Deps {
const val flipper = "com.facebook.flipper:flipper:${Versions.flipper}"
const val soLoader = "com.facebook.soloader:soloader:${Versions.soLoader}"
const val espresso_contrib = "com.android.support.test.espresso:espresso-contrib:${Versions.espresso_version}"
const val espresso_core = "com.android.support.test.espresso:espresso-core:${Versions.espresso_core}"
const val espresso_idling_resources = "com.android.support.test.espresso:espresso-idling-resource:${Versions.espresso_version}"
const val orchestrator = "androidx.test:orchestrator:${Versions.orchestrator}"
const val tools_test_rules = "com.android.support.test:rules:${Versions.tools_test_rules}"
const val tools_test_runner = "com.android.support.test:runner:${Versions.tools_test_runner}"
const val uiautomator = "com.android.support.test.uiautomator:uiautomator-v18:${Versions.uiautomator}"
}

View File

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
internal object GeckoVersions {
const val nightly_version = "68.0.20190408104625"
const val nightly_version = "68.0.20190414095735"
const val beta_version = "67.0.20190318154932"
const val release_version = "66.0.20190320150847"
}