From f88f181ac11953d608814305e8589bd8ab989053 Mon Sep 17 00:00:00 2001 From: Emily Kager Date: Tue, 16 Apr 2019 10:20:48 -0700 Subject: [PATCH 1/6] Closes #1655 - Use accent bright for switch in quick settings --- app/src/main/res/layout/fragment_quick_settings_dialog_sheet.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/layout/fragment_quick_settings_dialog_sheet.xml b/app/src/main/res/layout/fragment_quick_settings_dialog_sheet.xml index a5639e13b..128275bb0 100644 --- a/app/src/main/res/layout/fragment_quick_settings_dialog_sheet.xml +++ b/app/src/main/res/layout/fragment_quick_settings_dialog_sheet.xml @@ -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" /> From 42056fed7ca1b6f21ba848bda3f1b33a9f1d7548 Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Tue, 16 Apr 2019 15:22:05 +0200 Subject: [PATCH 2/6] Update GeckoView to 68.0.20190414095735 (following AC). --- buildSrc/src/main/java/Gecko.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/java/Gecko.kt b/buildSrc/src/main/java/Gecko.kt index 6cb15ff4a..cc381c8e3 100644 --- a/buildSrc/src/main/java/Gecko.kt +++ b/buildSrc/src/main/java/Gecko.kt @@ -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" } From 493bab42a419f42dd943e6c8b0c018100c3039fe Mon Sep 17 00:00:00 2001 From: Kevin Brosnan Date: Wed, 10 Apr 2019 09:59:38 -0700 Subject: [PATCH 3/6] UI tests for the home screen --- app/build.gradle | 33 +++++++++++++++- .../mozilla/fenix/ExampleInstrumentedTest.kt | 24 ------------ .../mozilla/fenix/FirefoxTestApplication.kt | 7 ++++ .../org/mozilla/fenix/FirefoxTestRunner.kt | 16 ++++++++ .../fenix/helpers/HomeActivityTestRule.kt | 18 +++++++++ .../org/mozilla/fenix/ui/HomeScreenTest.kt | 32 +++++++++++++++ .../fenix/ui/robots/HomeScreenRobot.kt | 39 +++++++++++++++++++ buildSrc/src/main/java/Dependencies.kt | 23 +++++++---- 8 files changed, 159 insertions(+), 33 deletions(-) delete mode 100644 app/src/androidTest/java/org/mozilla/fenix/ExampleInstrumentedTest.kt create mode 100644 app/src/androidTest/java/org/mozilla/fenix/FirefoxTestApplication.kt create mode 100644 app/src/androidTest/java/org/mozilla/fenix/FirefoxTestRunner.kt create mode 100644 app/src/androidTest/java/org/mozilla/fenix/helpers/HomeActivityTestRule.kt create mode 100644 app/src/androidTest/java/org/mozilla/fenix/ui/HomeScreenTest.kt create mode 100644 app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt diff --git a/app/build.gradle b/app/build.gradle index 00cec3506..9bc32abf1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 diff --git a/app/src/androidTest/java/org/mozilla/fenix/ExampleInstrumentedTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ExampleInstrumentedTest.kt deleted file mode 100644 index f3ee17ba6..000000000 --- a/app/src/androidTest/java/org/mozilla/fenix/ExampleInstrumentedTest.kt +++ /dev/null @@ -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) - } -} diff --git a/app/src/androidTest/java/org/mozilla/fenix/FirefoxTestApplication.kt b/app/src/androidTest/java/org/mozilla/fenix/FirefoxTestApplication.kt new file mode 100644 index 000000000..f5cbdf46b --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/fenix/FirefoxTestApplication.kt @@ -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() diff --git a/app/src/androidTest/java/org/mozilla/fenix/FirefoxTestRunner.kt b/app/src/androidTest/java/org/mozilla/fenix/FirefoxTestRunner.kt new file mode 100644 index 000000000..7d1717720 --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/fenix/FirefoxTestRunner.kt @@ -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) + } +} diff --git a/app/src/androidTest/java/org/mozilla/fenix/helpers/HomeActivityTestRule.kt b/app/src/androidTest/java/org/mozilla/fenix/helpers/HomeActivityTestRule.kt new file mode 100644 index 000000000..bc11ca5dc --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/fenix/helpers/HomeActivityTestRule.kt @@ -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::class.java, initialTouchMode, launchActivity) diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/HomeScreenTest.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/HomeScreenTest.kt new file mode 100644 index 000000000..c5f4054be --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/HomeScreenTest.kt @@ -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() + } + } +} diff --git a/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt new file mode 100644 index 000000000..6256104d7 --- /dev/null +++ b/app/src/androidTest/java/org/mozilla/fenix/ui/robots/HomeScreenRobot.kt @@ -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))) diff --git a/buildSrc/src/main/java/Dependencies.kt b/buildSrc/src/main/java/Dependencies.kt index e5c22401b..785683510 100644 --- a/buildSrc/src/main/java/Dependencies.kt +++ b/buildSrc/src/main/java/Dependencies.kt @@ -27,10 +27,7 @@ private object Versions { const val appservices_gradle_plugin = "0.4.2" const val mozilla_android_components = "0.50.0-SNAPSHOT" const val mozilla_appservices = "0.23.0" - - 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,13 @@ 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" } @Suppress("unused") @@ -119,9 +123,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 +157,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}" } From d9bc4bf502ae39f6df4732a52b748e9a30f292f7 Mon Sep 17 00:00:00 2001 From: Sawyer Blatz Date: Tue, 16 Apr 2019 08:09:19 -0700 Subject: [PATCH 4/6] Fixes #1632: Hides keyboard on exit, shows on entry --- .../java/org/mozilla/fenix/HomeActivity.kt | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt index 8e2ae4499..59135c270 100644 --- a/app/src/main/java/org/mozilla/fenix/HomeActivity.kt +++ b/app/src/main/java/org/mozilla/fenix/HomeActivity.kt @@ -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 } From bc07da91a24610920819349688dc5d0a85fc0630 Mon Sep 17 00:00:00 2001 From: Emily Kager Date: Tue, 16 Apr 2019 09:34:44 -0700 Subject: [PATCH 5/6] Closes #1644 - Correct progress bar gravity --- .../org/mozilla/fenix/components/toolbar/ToolbarUIView.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarUIView.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarUIView.kt index 2b0951985..8783497f6 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarUIView.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/ToolbarUIView.kt @@ -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 } } From 8e5958580e5c606ad067c2107015df603dcea968 Mon Sep 17 00:00:00 2001 From: Emily Kager Date: Tue, 16 Apr 2019 10:08:05 -0700 Subject: [PATCH 6/6] For #1658 - Reload current session (if exists) when theme changes --- .../mozilla/fenix/settings/ThemeFragment.kt | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/settings/ThemeFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/ThemeFragment.kt index 9bee3a158..717d01225 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/ThemeFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/ThemeFragment.kt @@ -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() + } }