Skip to content

Commit

Permalink
[gbb-cct] Adding workflow of triggering page insights hub
Browse files Browse the repository at this point in the history
Change-Id: Ibbe95a342b21d16990809986a4b538999a81b3bb

Bug: b/290846116
Change-Id: Ibbe95a342b21d16990809986a4b538999a81b3bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4774000
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Reviewed-by: Jinsuk Kim <jinsukkim@chromium.org>
Commit-Queue: Kamal Choudhury <kamalchoudhury@google.com>
Cr-Commit-Position: refs/heads/main@{#1187307}
  • Loading branch information
Kamal Choudhury authored and Chromium LUCI CQ committed Aug 23, 2023
1 parent f9020b6 commit a1a44e1
Show file tree
Hide file tree
Showing 11 changed files with 354 additions and 47 deletions.
13 changes: 8 additions & 5 deletions chrome/browser/ui/android/page_insights/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import("//build/config/android/config.gni")
import("//build/config/android/rules.gni")
import("//third_party/protobuf/proto_library.gni")

android_library("java") {
sources = [
Expand All @@ -20,7 +19,7 @@ android_library("java") {

deps = [
":java_resources",
":proto",
":proto_java",
"//base:base_java",
"//base:jni_java",
"//build/android:build_java",
Expand All @@ -35,8 +34,8 @@ android_library("java") {
"//components/browser_ui/bottomsheet/android:manager_java",
"//components/browser_ui/widget/android:java",
"//components/sync/android:sync_java",
"//third_party/android_deps:protobuf_lite_runtime_java",
"//third_party/androidx:androidx_annotation_annotation_java",
"//third_party/protobuf:protobuf_lite",
"//ui/android:ui_no_recycler_view_java",
"//url:gurl_java",
]
Expand All @@ -50,6 +49,7 @@ generate_jni("jni_headers") {
android_resources("java_resources") {
sources = [
"java/res/drawable/page_insights_icon.xml",
"java/res/layout/page_insights_sheet_content.xml",
"java/res/layout/page_insights_sheet_toolbar.xml",
"java/res/values/dimens.xml",
]
Expand All @@ -60,12 +60,11 @@ android_resources("java_resources") {
]
}

proto_library("proto") {
proto_java_library("proto_java") {
proto_path = "java/src/org/chromium/chrome/browser/page_insights/proto"
sources = [ "$proto_path/page_insights.proto" ]
}


robolectric_library("junit") {
sources = [
"java/src/org/chromium/chrome/browser/page_insights/PageInsightsActivatorUnitTest.java",
Expand All @@ -75,6 +74,7 @@ robolectric_library("junit") {
deps = [
":java",
":jni_headers",
":proto_java",
"//base:base_java",
"//base:base_java_test_support",
"//base:base_junit_test_support",
Expand All @@ -88,7 +88,10 @@ robolectric_library("junit") {
"//chrome/browser/tab:java",
"//components/browser_ui/bottomsheet/android:java",
"//components/browser_ui/bottomsheet/android:manager_java",
"//components/browser_ui/bottomsheet/android/test:java",
"//components/sync/android:sync_java",
"//content/public/test/android:content_java_test_support",
"//third_party/android_deps:com_google_protobuf_protobuf_javalite_java",
"//third_party/androidx:androidx_test_runner_java",
"//third_party/junit",
"//third_party/mockito:mockito_java",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2023 The Chromium Authors
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<!-- A content layout designed for page insight bottom-sheet -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<!-- xUIKit container for main page (Feed Page). -->
<FrameLayout
android:id="@+id/page_insights_feed_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent">
</FrameLayout>

<!-- xUIKit container for child page. -->
<FrameLayout
android:id="@+id/page_insights_child_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:visibility="gone">
</FrameLayout>

</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ found in the LICENSE file.
android:src="@drawable/drag_handlebar" />

<org.chromium.components.browser_ui.widget.text.TextViewWithCompoundDrawables
android:id="@+id/page_insights_main_header"
android:id="@+id/page_insights_feed_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="@dimen/page_insights_header_text_margin"
android:drawableStart="@drawable/page_insights_icon"
android:drawablePadding="@dimen/page_insights_title_margin"
android:text="@string/page_insights_hub_title_text"
android:textAppearance="@style/TextAppearance.Headline2.Primary.Baseline" />
android:textAppearance="@style/TextAppearance.Headline2.Primary.Baseline"/>

<LinearLayout
android:id="@+id/page_insights_child_page_header"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public PageInsightsCoordinator(Context context, ObservableSupplier<Tab> tabProvi
* Launch PageInsights hub in bottom sheet container and fetch the data to show.
*/
public void launch() {
mMediator.requestShowContent();
mMediator.openInExpandedState();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,12 @@ private void setAutoTriggerReady() {

@Test
@MediumTest
public void testRoundTopCornerAtExpandedState() throws Exception {
createAndLaunchPageInsightsCoordinator();
public void testRoundTopCornerAtExpandedStateAfterPeekState() throws Exception {
createPageInsightsCoordinator();
assertEquals(SheetState.HIDDEN, mPageInsightsController.getSheetState());
setAutoTriggerReady();

hideTopBar(); // Signal for auto triggering the PIH in Peek state
assertEquals(0.f, mPageInsightsCoordinator.getCornerRadiusForTesting(), ASSERTION_DELTA);

expandSheet();
Expand All @@ -215,8 +219,23 @@ public void testRoundTopCornerAtExpandedState() throws Exception {

@Test
@MediumTest
public void testResizeContent() throws Exception {
public void testRoundTopCornerAtFirstExpandedState() throws Exception {
createAndLaunchPageInsightsCoordinator();

int maxCornerRadiusPx = sTestRule.getActivity().getResources().getDimensionPixelSize(
R.dimen.bottom_sheet_corner_radius);
assertEquals(maxCornerRadiusPx, mPageInsightsCoordinator.getCornerRadiusForTesting(),
ASSERTION_DELTA);
}

@Test
@MediumTest
public void testResizeContent() throws Exception {
createPageInsightsCoordinator();
assertEquals(SheetState.HIDDEN, mPageInsightsController.getSheetState());
setAutoTriggerReady();

hideTopBar(); // Signal for auto triggering the PIH
int peekHeight = mPageInsightsController.getCurrentOffset();
verify(mBrowserControlsSizer).setBottomControlsHeight(eq(peekHeight), eq(0));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,56 @@

package org.chromium.chrome.browser.page_insights;

import org.chromium.chrome.browser.page_insights.proto.PageInsights.AutoPeekConditions;
import org.chromium.chrome.browser.page_insights.proto.PageInsights.Page;
import org.chromium.chrome.browser.page_insights.proto.PageInsights.PageInsightsMetadata;

/**
* Class to provide a {@link PageInsights} data and helper methods
*/
public class PageInsightsDataLoader {
private float mConfidence = 0.51f;

public PageInsightsDataLoader() {}
private PageInsightsMetadata mPageInsightsMetadata;

public PageInsightsDataLoader() {
Page childPage = Page.newBuilder()
.setId(Page.PageID.PEOPLE_ALSO_VIEW)
.setTitle("People also view")
.build();
Page feedPage = Page.newBuilder()
.setId(Page.PageID.SINGLE_FEED_ROOT)
.setTitle("Related Insights")
.build();
AutoPeekConditions mAutoPeekConditions = AutoPeekConditions.newBuilder()
.setConfidence(mConfidence)
.setPageScrollFraction(0.4f)
.setMinimumSecondsOnPage(30)
.build();
mPageInsightsMetadata = PageInsightsMetadata.newBuilder()
.setFeedPage(feedPage)
.addPages(childPage)
.setAutoPeekConditions(mAutoPeekConditions)
.build();
}

PageInsightsDataLoader loadInsightsData() {
// TODO(mako): Fetch page insights real data
return this;
}

float getConfidence() {
// TODO(mako): Return real confidence
return mConfidence;
PageInsightsMetadata getData() {
return mPageInsightsMetadata;
}

void setConfidenceForTesting(float confidence) {
// TODO(mako): Return real confidence
mConfidence = confidence;
mPageInsightsMetadata =
mPageInsightsMetadata.toBuilder()
.setAutoPeekConditions(mPageInsightsMetadata.getAutoPeekConditions()
.toBuilder()
.setConfidence(confidence)
.build())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@
import android.view.View;

import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import com.google.protobuf.ByteString;

import org.chromium.base.MathUtils;
import org.chromium.base.supplier.ObservableSupplier;
import org.chromium.chrome.browser.browser_controls.BrowserControlsSizer;
import org.chromium.chrome.browser.browser_controls.BrowserControlsStateProvider;
import org.chromium.chrome.browser.browser_controls.BrowserControlsUtils;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.page_insights.proto.PageInsights.Page;
import org.chromium.chrome.browser.page_insights.proto.PageInsights.PageInsightsMetadata;
import org.chromium.chrome.browser.tab.EmptyTabObserver;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetContent;
Expand All @@ -45,7 +50,7 @@
*/
public class PageInsightsMediator extends EmptyTabObserver implements BottomSheetObserver {
private static final int DEFAULT_TRIGGER_DELAY_MS = (int) DateUtils.MINUTE_IN_MILLIS;
private static final double MINIMUM_CONFIDENCE = 50;
private static final float MINIMUM_CONFIDENCE = 0.5f;
static final String PAGE_INSIGHTS_CAN_AUTOTRIGGER_AFTER_END =
"page_insights_can_autotrigger_after_end";

Expand Down Expand Up @@ -207,17 +212,54 @@ private void maybeAutoTriggerPageInsights() {
return;
}

mPageInsightsDataLoader.loadInsightsData();
PageInsightsMetadata metadata = mPageInsightsDataLoader.getData();
boolean hasEnoughConfidence =
mPageInsightsDataLoader.loadInsightsData().getConfidence() * 100
> MINIMUM_CONFIDENCE;
metadata.getAutoPeekConditions().getConfidence() > MINIMUM_CONFIDENCE;
if (hasEnoughConfidence) {
requestShowContent();
openInPeekState(metadata);
resetAutoTriggerTimer();
}
}

void requestShowContent() {
private void openInPeekState(PageInsightsMetadata metadata) {
mSheetContent.setFeedPage(getXSurfaceView(metadata.getFeedPage().getElementsOutput()));
mSheetContent.showFeedPage();
mSheetController.requestShowContent(mSheetContent, true);
}

// TODO(kamalchoudhury): Add logic for opening the sheet with loading indicator before loading
// data
void openInExpandedState() {
mPageInsightsDataLoader.loadInsightsData();
PageInsightsMetadata metadata = mPageInsightsDataLoader.getData();
mSheetContent.setFeedPage(getXSurfaceView(metadata.getFeedPage().getElementsOutput()));
mSheetContent.showFeedPage();
mSheetController.requestShowContent(mSheetContent, true);
setCornerRadiusPx(mMaxCornerRadiusPx);
mSheetController.expandSheet();
}

// TODO(edmundw): Implement the complete function
private View getXSurfaceView(ByteString elementsOutput) {
return new View(mContext);
}

@VisibleForTesting
// TODO(kamalchoudhury): Make this function private when xUIKit code is written
void changeToChildPage(int id) {
PageInsightsMetadata metadata = mPageInsightsDataLoader.getData();
for (int i = 0; i < metadata.getPagesCount(); i++) {
Page currPage = metadata.getPages(i);
if (id == currPage.getId().getNumber()) {
mSheetContent.showChildPage(
getXSurfaceView(currPage.getElementsOutput()), currPage.getTitle());
}
}
}

PageInsightsSheetContent getSheetContent() {
return mSheetContent;
}

// BottomSheetObserver
Expand Down

0 comments on commit a1a44e1

Please sign in to comment.