Skip to content

Commit

Permalink
Integrate browser-toolbar component.
Browse files Browse the repository at this point in the history
  • Loading branch information
pocmo authored and mergify[bot] committed Jul 8, 2021
1 parent 7910bdd commit c20a52c
Show file tree
Hide file tree
Showing 43 changed files with 597 additions and 1,359 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,12 @@ dependencies {
implementation "org.mozilla.components:browser-engine-gecko:${AndroidComponents.VERSION}"
implementation "org.mozilla.components:browser-domains:${AndroidComponents.VERSION}"
implementation "org.mozilla.components:browser-errorpages:${AndroidComponents.VERSION}"
implementation "org.mozilla.components:browser-menu:${AndroidComponents.VERSION}"
implementation "org.mozilla.components:browser-state:${AndroidComponents.VERSION}"
implementation "org.mozilla.components:browser-toolbar:${AndroidComponents.VERSION}"
implementation "org.mozilla.components:concept-engine:${AndroidComponents.VERSION}"
implementation "org.mozilla.components:concept-fetch:${AndroidComponents.VERSION}"
implementation "org.mozilla.components:concept-menu:${AndroidComponents.VERSION}"
implementation "org.mozilla.components:feature-app-links:${AndroidComponents.VERSION}"
implementation "org.mozilla.components:feature-customtabs:${AndroidComponents.VERSION}"
implementation "org.mozilla.components:feature-contextmenu:${AndroidComponents.VERSION}"
Expand All @@ -182,6 +185,7 @@ dependencies {
implementation "org.mozilla.components:feature-session:${AndroidComponents.VERSION}"
implementation "org.mozilla.components:feature-search:${AndroidComponents.VERSION}"
implementation "org.mozilla.components:feature-tabs:${AndroidComponents.VERSION}"
implementation "org.mozilla.components:feature-toolbar:${AndroidComponents.VERSION}"
implementation "org.mozilla.components:lib-crash:${AndroidComponents.VERSION}"
implementation "org.mozilla.components:lib-state:${AndroidComponents.VERSION}"
implementation "org.mozilla.components:service-glean:${AndroidComponents.VERSION}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ToggleBlockTest {
fun SimpleToggleTest() {
// Load mozilla.org
TestHelper.inlineAutocompleteEditText.waitForExists(TestHelper.waitingTime)
Espresso.onView(ViewMatchers.withId(R.id.urlView))
Espresso.onView(ViewMatchers.withId(R.id.mozac_browser_toolbar_edit_url_view))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
.check(ViewAssertions.matches(ViewMatchers.hasFocus()))
.perform(
Expand All @@ -92,9 +92,11 @@ class ToggleBlockTest {
waitForWebContent()
TestHelper.progressBar.waitUntilGone(TestHelper.waitingTime)

// The blocking badge is not disabled
Espresso.onView(ViewMatchers.withId(R.id.block))
.check(ViewAssertions.matches(Matchers.not(ViewMatchers.isDisplayed())))
// Blocking is on
Espresso.onView(ViewMatchers.withId(R.id.mozac_browser_toolbar_tracking_protection_indicator))
.check(ViewAssertions.matches(ViewMatchers.withContentDescription(
R.string.mozac_browser_toolbar_content_description_tracking_protection_on_no_trackers_blocked
)))

// Open the menu
Espresso.onView(ViewMatchers.withId(R.id.menuView))
Expand All @@ -110,8 +112,10 @@ class ToggleBlockTest {
waitForWebContent()

// Now the blocking badge is visible
Espresso.onView(ViewMatchers.withId(R.id.block))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
Espresso.onView(ViewMatchers.withId(R.id.mozac_browser_toolbar_tracking_protection_indicator))
.check(ViewAssertions.matches(ViewMatchers.withContentDescription(
R.string.mozac_browser_toolbar_content_description_tracking_protection_off_for_a_site1
)))
Espresso.onView(ViewMatchers.withId(R.id.webview)).perform(ViewActions.click())

// Open the menu again. Now the switch is disabled and the tracker count should be disabled.
Expand Down Expand Up @@ -147,7 +151,7 @@ class ToggleBlockTest {
throw AssertionError("Could not start web server", e)
}
TestHelper.inlineAutocompleteEditText.waitForExists(TestHelper.waitingTime)
Espresso.onView(ViewMatchers.withId(R.id.urlView))
Espresso.onView(ViewMatchers.withId(R.id.mozac_browser_toolbar_edit_url_view))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
.check(ViewAssertions.matches(ViewMatchers.hasFocus()))
.perform(
Expand All @@ -157,9 +161,11 @@ class ToggleBlockTest {
waitForWebContent()
TestHelper.progressBar.waitUntilGone(TestHelper.waitingTime)

// The blocking badge is disabled
Espresso.onView(ViewMatchers.withId(R.id.block))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
// Blocking is on
Espresso.onView(ViewMatchers.withId(R.id.mozac_browser_toolbar_tracking_protection_indicator))
.check(ViewAssertions.matches(ViewMatchers.withContentDescription(
R.string.mozac_browser_toolbar_content_description_tracking_protection_on_no_trackers_blocked
)))

// Open the menu again. Now the switch is disabled and the tracker count should be disabled.
Espresso.onView(ViewMatchers.withId(R.id.menuView))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,18 @@ class URLExceptionTest {
private fun addException(url: String) {
// Load site
TestHelper.inlineAutocompleteEditText.waitForExists(TestHelper.waitingTime)
Espresso.onView(ViewMatchers.withId(R.id.urlView))
Espresso.onView(ViewMatchers.withId(R.id.mozac_browser_toolbar_edit_url_view))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
.check(ViewAssertions.matches(ViewMatchers.hasFocus()))
.perform(ViewActions.typeText(url), ViewActions.pressImeActionButton())
waitForWebContent()
TestHelper.progressBar.waitUntilGone(TestHelper.waitingTime)

// The blocking badge is not disabled
Espresso.onView(ViewMatchers.withId(R.id.block))
.check(ViewAssertions.matches(Matchers.not(ViewMatchers.isDisplayed())))
Espresso.onView(ViewMatchers.withId(R.id.mozac_browser_toolbar_tracking_protection_indicator))
.check(ViewAssertions.matches(ViewMatchers.withContentDescription(
R.string.mozac_browser_toolbar_content_description_tracking_protection_on_no_trackers_blocked
)))

// Open the menu
Espresso.onView(ViewMatchers.withId(R.id.menuView))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ inline fun runWithIdleRes(ir: IdlingResource?, pendingCheck: () -> Unit) {
}
}

private val browserURLbar = mDevice.findObject(UiSelector().resourceId("$packageName:id/display_url"))
private val browserURLbar = mDevice.findObject(
UiSelector().resourceId("$packageName:id/mozac_browser_toolbar_url_view")
)

private val floatingEraseButton = onView(allOf(withId(R.id.erase), isDisplayed()))

Expand All @@ -224,7 +226,7 @@ private val mainMenu = onView(withId(R.id.menuView))
private val shareAppsList =
mDevice.findObject(UiSelector().resourceId("android:id/resolver_list"))

private val securityIcon = onView(withId(R.id.security_info))
private val securityIcon = onView(withId(R.id.mozac_browser_toolbar_security_indicator))

private val site_identity_state = onView(withId(R.id.site_identity_state))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ fun customTab(interact: CustomTabRobot.() -> Unit): CustomTabRobot.Transition {

private fun actionButton(description: String) = onView(withContentDescription(description))

private val menuButton = onView(withId(R.id.menuView))
private val menuButton = onView(withId(R.id.mozac_browser_toolbar_menu))

private val shareButton = onView(withId(R.id.share))

private fun customMenuItem(description: String) = onView(withText(description))

private val closeCustomTabButton = onView(withId(R.id.customtab_close))
private val closeCustomTabButton = onView(withContentDescription(R.string.mozac_feature_customtabs_exit_button))

private val openInFocusButton = onView(withId(R.id.open_in_firefox_focus))
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fun searchScreen(interact: SearchRobot.() -> Unit): SearchRobot.Transition {
}

private val searchBar =
mDevice.findObject(UiSelector().resourceId("$packageName:id/urlView"))
mDevice.findObject(UiSelector().resourceId("$packageName:id/mozac_browser_toolbar_edit_url_view"))
private val searchHint = mDevice.findObject(
UiSelector()
Expand All @@ -114,4 +114,4 @@ private val suggestionsList = mDevice.findObject(
.resourceId("$packageName:id/suggestionList")
)

private val clearSearchButton = onView(withId(R.id.clearView))
private val clearSearchButton = onView(withId(R.id.mozac_browser_toolbar_clear_view))
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object EspressoHelper {
}

fun navigateToWebsite(input: String) {
Espresso.onView(ViewMatchers.withId(R.id.urlView))
Espresso.onView(ViewMatchers.withId(R.id.mozac_browser_toolbar_edit_url_view))
.check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
.check(ViewAssertions.matches(ViewMatchers.hasFocus()))
.perform(ViewActions.replaceText(input), ViewActions.pressImeActionButton())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ public void tearDownWebServer() {
@Test
public void takeScreenshotsOfMenuandAllowlist() throws UiObjectNotFoundException {
SystemClock.sleep(5000);
onView(withId(R.id.urlView))
onView(withId(R.id.mozac_browser_toolbar_edit_url_view))
.check(matches(isDisplayed()))
.check(matches(hasFocus()))
.perform(click(), replaceText(webServer.url("/").toString()));

onView(withId(R.id.urlView))
onView(withId(R.id.mozac_browser_toolbar_edit_url_view))
.check(matches(isDisplayed()))
.check(matches(hasFocus()))
.perform(pressImeActionButton());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void takeScreenshotsOfBrowsingScreen() throws Exception {
}

private void takeScreenshotsOfBrowsingView() {
onView(withId(R.id.urlView))
onView(withId(R.id.mozac_browser_toolbar_edit_url_view))
.check(matches(isDisplayed()));

// click yes, then go into search dialog and change to twitter, or create twitter engine
Expand Down Expand Up @@ -142,7 +142,7 @@ private void takeScreenshotsOfBrowsingView() {
.check(matches(isDisplayed()));
device.pressBack();

onView(withId(R.id.urlView))
onView(withId(R.id.mozac_browser_toolbar_edit_url_view))
.check(matches(isDisplayed()))
.check(matches(hasFocus()))
.perform(click(), replaceText(webServer.url("/").toString()));
Expand All @@ -157,7 +157,7 @@ private void takeScreenshotsOfBrowsingView() {
.perform(click());
} catch (AssertionError dne) { }

onView(withId(R.id.urlView))
onView(withId(R.id.mozac_browser_toolbar_edit_url_view))
.check(matches(isDisplayed()))
.check(matches(hasFocus()))
.perform(pressImeActionButton());
Expand All @@ -167,19 +167,19 @@ private void takeScreenshotsOfBrowsingView() {
.enabled(true))
.waitForExists(waitingTime);

onView(withId(R.id.display_url))
onView(withId(R.id.mozac_browser_toolbar_url_view))
.check(matches(isDisplayed()))
.check(matches(withText(containsString(webServer.getHostName()))));

// Check add link to autocomplete text
onView(withId(R.id.display_url)).perform(click());
onView(withId(R.id.mozac_browser_toolbar_url_view)).perform(click());
onView(withId(R.id.addToAutoComplete))
.check(matches(isDisplayed()));
Screengrab.screenshot("Addlink_autocomplete");
onView(withId(R.id.addToAutoComplete))
.perform(click());
Screengrab.screenshot("new_customURL_popup");
onView(withId(R.id.display_url)).perform(click());
onView(withId(R.id.mozac_browser_toolbar_url_view)).perform(click());
onView(withId(R.id.addToAutoComplete))
.perform(click());
Screengrab.screenshot("customURL_alreadyexists_popup");
Expand Down Expand Up @@ -300,7 +300,7 @@ private void takeScreenshotofInsecureCon() throws Exception {
private void takeScreenshotofSecureCon() throws Exception {

// take the security info of google.com for https connection
onView(withId(R.id.urlView))
onView(withId(R.id.mozac_browser_toolbar_edit_url_view))
.check(matches(isDisplayed()))
.check(matches(hasFocus()))
.perform(click(), replaceText("www.google.com"), pressImeActionButton());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private enum ErrorTypes {
@Test
public void takeScreenshotsOfErrorPages() {
for (ErrorTypes error: ErrorTypes.values()) {
onView(withId(R.id.urlView))
onView(withId(R.id.mozac_browser_toolbar_edit_url_view))
.check(matches(isDisplayed()))
.check(matches(hasFocus()))
.perform(click(), replaceText("error:" + error.value), pressImeActionButton());
Expand All @@ -88,7 +88,7 @@ public void takeScreenshotsOfErrorPages() {

Screengrab.screenshot(error.name());

onView(withId(R.id.display_url))
onView(withId(R.id.mozac_browser_toolbar_edit_url_view))
.check(matches(isDisplayed()))
.perform(click());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private enum TipTypes {

@Test
public void takeScreenshotOfHomeScreen() {
onView(withId(R.id.urlView))
onView(withId(R.id.mozac_browser_toolbar_edit_url_view))
.check(matches(isDisplayed()))
.check(matches(hasFocus()));
SystemClock.sleep(5000);
Expand All @@ -68,7 +68,7 @@ public void takeScreenshotOfMenu() {
@Test
public void takeScreenshotOfTips() {
for (TipTypes tip: TipTypes.values()) {
onView(withId(R.id.urlView))
onView(withId(R.id.mozac_browser_toolbar_edit_url_view))
.check(matches(isDisplayed()))
.check(matches(hasFocus()))
.perform(click(), replaceText("l10n:tip:" + tip.value), pressImeActionButton());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ public void tearDownWebServer() {

@Test
public void takeScreenshotOfNotification() throws Exception {
onView(withId(R.id.urlView))
onView(withId(R.id.mozac_browser_toolbar_edit_url_view))
.check(matches(isDisplayed()))
.check(matches(hasFocus()))
.perform(click(), replaceText(webServer.url("/").toString()), pressImeActionButton());

onView(withId(R.id.display_url))
onView(withId(R.id.mozac_browser_toolbar_url_view))
.check(matches(isDisplayed()))
.check(matches(withText(containsString(webServer.getHostName()))));

Expand Down
Original file line number Diff line number Diff line change
@@ -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/. */

package org.mozilla.focus.browser

import android.view.View
import android.widget.PopupWindow
import mozilla.components.concept.menu.MenuController
import mozilla.components.concept.menu.Orientation
import mozilla.components.concept.menu.candidate.MenuCandidate
import mozilla.components.support.base.observer.Observable
import mozilla.components.support.base.observer.ObserverRegistry
import org.mozilla.focus.ext.ifCustomTab
import org.mozilla.focus.fragment.BrowserFragment
import org.mozilla.focus.menu.browser.BrowserMenu

/**
* This adapter bridges between `browser-toolbar` and the custom, legacy [BrowserMenu] in Focus.
* It allows launching [BrowserMenu] from `BrowserToolbar`.
*/
class BrowserMenuControllerAdapter(
private val fragment: BrowserFragment
) : MenuController, Observable<MenuController.Observer> by ObserverRegistry() {
override fun dismiss() {
// Not used.
}

override fun show(anchor: View, orientation: Orientation?): PopupWindow {
val menu = BrowserMenu(fragment.requireContext(), fragment, fragment.tab.ifCustomTab()?.config)
menu.show(anchor)

return menu
}

override fun submitList(list: List<MenuCandidate>) {
// Not used.
}
}
14 changes: 2 additions & 12 deletions app/src/main/java/org/mozilla/focus/browser/DisplayToolbar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package org.mozilla.focus.browser
import android.content.Context
import com.google.android.material.appbar.AppBarLayout
import android.util.AttributeSet
import android.util.TypedValue
import kotlinx.android.synthetic.main.browser_display_toolbar.view.*

/**
Expand All @@ -17,11 +16,6 @@ class DisplayToolbar(
context: Context,
attrs: AttributeSet
) : AppBarLayout(context, attrs), AppBarLayout.OnOffsetChangedListener {
private val collapsedProgressTranslationY: Float by lazy {
TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 2f, resources.displayMetrics)
}

init {
addOnOffsetChangedListener(this)
}
Expand All @@ -34,16 +28,12 @@ class DisplayToolbar(
val totalScrollRange = appBarLayout.totalScrollRange
val isCollapsed = Math.abs(verticalOffset) == totalScrollRange

// If the toolbar is collapsed then we will move the progress view so that it's
// still fully visible.
progress.translationY = if (isCollapsed) collapsedProgressTranslationY else 0f

if (verticalOffset == 0 || isCollapsed) {
// If the app bar is completely expanded or collapsed we want full opacity. We
// even want full opacity for a collapsed app bar because while loading a website
// the toolbar sometimes pops out when the URL changes. Without setting it to
// opaque the toolbar content might be invisible in this case (See issue #1126)
toolbarContent.alpha = 1f
browserToolbar.alpha = 1f
return
}

Expand All @@ -58,6 +48,6 @@ class DisplayToolbar(
// The calculated value is reversed and we need to invert it (e.g. 0.8 -> 0.2)
alpha = 1 - alpha

toolbarContent.alpha = alpha
browserToolbar.alpha = alpha
}
}
Loading

0 comments on commit c20a52c

Please sign in to comment.