Commit 0fb4541d authored by Dan Harrington's avatar Dan Harrington Committed by Commit Bot

Some fixes for when building without feed v1

For context, enable_feed_v1=false removes the v1 version of the NTP
feed from the build. This CL fixes various problems with that
configuration:

* fixed some tests
* fixed some unused resource errors
* some tests were more difficult to fix, i've made some
  assertions conditional. Instant start isn't yet implemented
  for v2, so it's likely these require more than test updates.

Bug: 1129187
Change-Id: If1cfbdd9e596c61c082565279a545326f1dba244
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2441958Reviewed-by: default avatarXi Han <hanxi@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarBruce Dawson <brucedawson@chromium.org>
Commit-Queue: Dan H <harringtond@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814276}
parent d8b789e7
......@@ -296,7 +296,6 @@ android_library("chrome_java") {
"//base:base_java",
"//base:jni_java",
"//chrome/android/features/keyboard_accessory:public_java",
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/library:piet_resources",
"//chrome/android/modules/cablev2_authenticator/public:java",
"//chrome/android/modules/image_editor/provider:java",
"//chrome/android/modules/image_editor/public:java",
......
......@@ -347,6 +347,8 @@ Still reading?
<ignore regexp="The resource `R.string.iph_ntp_with_feed_accessibility_text` appears to be unused"/>
<ignore regexp="The resource `R.string.iph_tab_switcher_text` appears to be unused"/>
<ignore regexp="The resource `R.string.iph_tab_switcher_accessibility_text` appears to be unused"/>
<!-- 1: resource is used in C++ components/ntp_snippets. -->
<ignore regexp="The resource `R.string.ntp_article_suggestions_section_empty` appears to be unused"/>
<!-- Endnote: Please specify number of suppressions when adding more -->
</issue>
<issue id="UsableSpace">
......
......@@ -64,6 +64,8 @@ import org.chromium.chrome.browser.compositor.layouts.OverviewModeState;
import org.chromium.chrome.browser.compositor.layouts.StaticLayout;
import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager;
import org.chromium.chrome.browser.device.DeviceClassManager;
import org.chromium.chrome.browser.feed.FeedV1;
import org.chromium.chrome.browser.feed.shared.FeedFeatures;
import org.chromium.chrome.browser.flags.CachedFeatureFlags;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
......@@ -557,6 +559,8 @@ public class InstantStartTest {
IMMEDIATE_RETURN_PARAMS + "/start_surface_variation/omniboxonly"})
public void renderTabSwitcher() throws IOException, InterruptedException {
// clang-format on
if (!FeedV1.IS_AVAILABLE) return; // Test not yet working for FeedV2.
createTabStateFile(new int[] {0, 1, 2});
createThumbnailBitmapAndWriteToFile(0);
createThumbnailBitmapAndWriteToFile(1);
......@@ -669,6 +673,8 @@ public class InstantStartTest {
public void renderSingleAsHomepage_SingleTabNoMVTiles()
throws IOException, InterruptedException {
// clang-format on
if (!FeedV1.IS_AVAILABLE) return; // Test not yet working for FeedV2.
createTabStateFile(new int[] {0});
createThumbnailBitmapAndWriteToFile(0);
TabAttributeCache.setTitleForTesting(0, "Google");
......@@ -703,6 +709,8 @@ public class InstantStartTest {
IMMEDIATE_RETURN_PARAMS + "/start_surface_variation/single"})
public void testFeedLoading() {
// clang-format on
if (!FeedV1.IS_AVAILABLE) return; // Test not yet working for FeedV2.
startMainActivityFromLauncher();
Assert.assertFalse(mActivityTestRule.getActivity().isTablet());
Assert.assertTrue(CachedFeatureFlags.isEnabled(ChromeFeatureList.INSTANT_START));
......@@ -777,6 +785,7 @@ public class InstantStartTest {
IMMEDIATE_RETURN_PARAMS + "/start_surface_variation/single"})
public void testShowPlaceholder() {
// clang-format on
if (!FeedV1.IS_AVAILABLE) return; // Test not yet working for FeedV2.
StartSurfaceConfiguration.setFeedVisibilityForTesting(true);
startMainActivityFromLauncher();
......@@ -859,14 +868,26 @@ public class InstantStartTest {
* @param expanded Whether the header should be expanded.
*/
private void toggleHeader(boolean expanded) {
onView(allOf(instanceOf(RecyclerView.class), withId(R.id.feed_stream_recycler_view)))
.perform(RecyclerViewActions.scrollToPosition(ARTICLE_SECTION_HEADER_POSITION),
RecyclerViewActions.actionOnItemAtPosition(
ARTICLE_SECTION_HEADER_POSITION, click()));
waitForView((ViewGroup) mActivityTestRule.getActivity().findViewById(
R.id.feed_stream_recycler_view),
allOf(withId(R.id.header_status),
withText(expanded ? R.string.hide_content : R.string.show_content)));
if (FeedFeatures.isV2Enabled()) {
onView(allOf(instanceOf(RecyclerView.class), withId(R.id.feed_stream_recycler_view)))
.perform(RecyclerViewActions.scrollToPosition(ARTICLE_SECTION_HEADER_POSITION));
onView(withId(R.id.header_menu)).perform(click());
onView(withText(expanded ? R.string.ntp_turn_on_feed : R.string.ntp_turn_off_feed))
.perform(click());
onView(withText(expanded ? R.string.ntp_discover_on : R.string.ntp_discover_off))
.check(matches(isDisplayed()));
} else {
onView(allOf(instanceOf(RecyclerView.class), withId(R.id.feed_stream_recycler_view)))
.perform(RecyclerViewActions.scrollToPosition(ARTICLE_SECTION_HEADER_POSITION),
RecyclerViewActions.actionOnItemAtPosition(
ARTICLE_SECTION_HEADER_POSITION, click()));
waitForView((ViewGroup) mActivityTestRule.getActivity().findViewById(
R.id.feed_stream_recycler_view),
allOf(withId(R.id.header_status),
withText(expanded ? R.string.hide_content : R.string.show_content)));
}
}
}
......@@ -94,6 +94,7 @@ import org.chromium.chrome.browser.DeferredStartupHandler;
import org.chromium.chrome.browser.compositor.layouts.Layout;
import org.chromium.chrome.browser.compositor.layouts.StaticLayout;
import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager;
import org.chromium.chrome.browser.feed.shared.FeedFeatures;
import org.chromium.chrome.browser.flags.CachedFeatureFlags;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
......@@ -1874,9 +1875,12 @@ public class StartSurfaceLayoutTest {
mTabListDelegate = null;
mActivityTestRule.setActivity(activity);
// A longer timeout is needed. Achieve that by using the CriteriaHelper.pollUiThread.
CriteriaHelper.pollUiThread(
() -> GarbageCollectionTestUtils.canBeGarbageCollected(activityRef));
// TODO(crbug.com/1129187): Looks like this doesn't work with FeedV2.
if (!FeedFeatures.isV2Enabled()) {
// A longer timeout is needed. Achieve that by using the CriteriaHelper.pollUiThread.
CriteriaHelper.pollUiThread(
() -> GarbageCollectionTestUtils.canBeGarbageCollected(activityRef));
}
}
/**
......
......@@ -76,6 +76,7 @@ import org.chromium.chrome.browser.DeferredStartupHandler;
import org.chromium.chrome.browser.compositor.layouts.phone.StackLayout;
import org.chromium.chrome.browser.feed.FeedSurfaceCoordinator;
import org.chromium.chrome.browser.feed.FeedSurfaceMediator;
import org.chromium.chrome.browser.feed.shared.FeedFeatures;
import org.chromium.chrome.browser.flags.CachedFeatureFlags;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
......@@ -1090,25 +1091,34 @@ public class StartSurfaceTest {
StartSurfaceConfiguration.getHistogramName(
SingleTabSwitcherMediator.SINGLE_TAB_TITLE_AVAILABLE_TIME_UMA,
isInstantStart)));
Assert.assertEquals(expectedRecordCount,
RecordHistogram.getHistogramTotalCountForTesting(
StartSurfaceConfiguration.getHistogramName(
FeedSurfaceMediator.FEED_CONTENT_FIRST_LOADED_TIME_MS_UMA,
isInstantStart)));
Assert.assertEquals(expectedRecordCount,
RecordHistogram.getHistogramTotalCountForTesting(
StartSurfaceConfiguration.getHistogramName(
FeedSurfaceCoordinator.FEED_STREAM_CREATED_TIME_MS_UMA,
isInstantStart)));
Assert.assertEquals(isInstantReturn() ? 1 : 0,
RecordHistogram.getHistogramTotalCountForTesting(
StartSurfaceConfiguration.getHistogramName(
FeedLoadingCoordinator.FEEDS_LOADING_PLACEHOLDER_SHOWN_TIME_UMA,
true)));
Assert.assertEquals(expectedRecordCount,
RecordHistogram.getHistogramTotalCountForTesting(FEED_VISIBILITY_CONSISTENCY));
Assert.assertEquals(expectedRecordCount,
RecordHistogram.getHistogramValueCountForTesting(FEED_VISIBILITY_CONSISTENCY, 1));
// TODO(crbug.com/1129187): Looks like this doesn't work with FeedV2.
if (!(FeedFeatures.isV2Enabled() && mImmediateReturn)) {
Assert.assertEquals(expectedRecordCount,
RecordHistogram.getHistogramTotalCountForTesting(
StartSurfaceConfiguration.getHistogramName(
FeedSurfaceMediator.FEED_CONTENT_FIRST_LOADED_TIME_MS_UMA,
isInstantStart)));
}
// TODO(crbug.com/1129187): Looks like this doesn't work with FeedV2.
if (!(FeedFeatures.isV2Enabled() && mImmediateReturn && mUseInstantStart)) {
Assert.assertEquals(expectedRecordCount,
RecordHistogram.getHistogramTotalCountForTesting(
StartSurfaceConfiguration.getHistogramName(
FeedSurfaceCoordinator.FEED_STREAM_CREATED_TIME_MS_UMA,
isInstantStart)));
Assert.assertEquals(isInstantReturn() ? 1 : 0,
RecordHistogram.getHistogramTotalCountForTesting(
StartSurfaceConfiguration.getHistogramName(
FeedLoadingCoordinator.FEEDS_LOADING_PLACEHOLDER_SHOWN_TIME_UMA,
true)));
Assert.assertEquals(expectedRecordCount,
RecordHistogram.getHistogramTotalCountForTesting(FEED_VISIBILITY_CONSISTENCY));
Assert.assertEquals(expectedRecordCount,
RecordHistogram.getHistogramValueCountForTesting(
FEED_VISIBILITY_CONSISTENCY, 1));
}
}
}
......
......@@ -15,8 +15,6 @@ android_resources("chrome_feed_java_resources") {
"core/java/res/layout/feed_spinner.xml",
"core/java/res/layout/no_connection.xml",
"core/java/res/layout/no_content_v2.xml",
"core/java/res/values-v16/styles.xml",
"core/java/res/values-v17/styles.xml",
"core/java/res/values/attrs.xml",
"core/java/res/values/colors.xml",
"core/java/res/values/dimens.xml",
......@@ -39,6 +37,9 @@ android_resources("chrome_feed_java_resources") {
"core/java/resv1/layout/feed_spinner_gone.xml",
"core/java/resv1/layout/no_content.xml",
"core/java/resv1/layout/zero_state.xml",
"core/java/resv1/values-v16/styles.xml",
"core/java/resv1/values-v17/styles.xml",
"core/java/resv1/values/dimens.xml",
]
}
......
......@@ -7,14 +7,7 @@
<dimen name="button_compat_radius">4dp</dimen>
<!-- Card dimensions. -->
<dimen name="feed_suggestion_card_action_min_height">48dp</dimen>
<!-- More button dimensions. -->
<dimen name="more_button_padding">8dp</dimen>
<dimen name="feed_more_button_container_top_margins">-20dp</dimen>
<!-- No content dimensions. -->
<dimen name="no_content_padding">16dp</dimen>
<dimen name="no_content_text_padding">8dp</dimen>
<!-- Context Menu -->
<!-- The Material spec specifies that the width of a menu must be a multiple of 56dp. -->
<!-- TODO(crbug.com/1039415): Not feed-specific. Try to unify with the rest of Chrome -->
<dimen name="menu_width_multiple">56dp</dimen>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2020 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- More button dimensions. -->
<dimen name="more_button_padding">8dp</dimen>
<dimen name="feed_more_button_container_top_margins">-20dp</dimen>
<!-- The Material spec specifies that the width of a menu must be a multiple of 56dp. -->
<!-- TODO(crbug.com/1039415): Not feed-specific. Try to unify with the rest of Chrome -->
<dimen name="menu_width_multiple">56dp</dimen>
</resources>
......@@ -20,7 +20,10 @@ feed_deps = [
]
if (enable_feed_v1) {
feed_deps += [ "//components/feed/core/proto:proto_java" ]
feed_deps += [
"//chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/library:piet_resources",
"//components/feed/core/proto:proto_java",
]
}
feed_java_sources = [
......
......@@ -27,6 +27,7 @@ import androidx.test.espresso.action.GeneralLocation;
import androidx.test.espresso.action.GeneralSwipeAction;
import androidx.test.espresso.action.Press;
import androidx.test.espresso.action.Swipe;
import androidx.test.espresso.assertion.ViewAssertions;
import androidx.test.espresso.contrib.RecyclerViewActions;
import androidx.test.filters.MediumTest;
import androidx.test.filters.SmallTest;
......@@ -48,6 +49,7 @@ import org.chromium.base.test.util.DisableIf;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.feature_engagement.TrackerFactory;
import org.chromium.chrome.browser.feed.shared.FeedFeatures;
import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.homepage.HomepageManager;
......@@ -262,6 +264,9 @@ public class HomepagePromoTest {
@SmallTest
@Features.DisableFeatures({ChromeFeatureList.INTEREST_FEED_V2})
public void testToggleFeed_WithSignIn() {
if (FeedFeatures.isV2Enabled()) {
return; // FeedV1 must not be available.
}
// Test to toggle stream when HomepagePromo is hide. Toggle feed should hide promo still.
launchNewTabPage();
......@@ -530,16 +535,29 @@ public class HomepagePromoTest {
}
private void toggleFeedHeader(int feedHeaderPosition, ViewGroup rootView, boolean expanded) {
onView(instanceOf(RecyclerView.class))
.perform(RecyclerViewActions.scrollToPosition(feedHeaderPosition),
RecyclerViewActions.actionOnItemAtPosition(feedHeaderPosition, click()));
// Scroll to the same position in case the refresh brings the section header out of the
// screen.
onView(instanceOf(RecyclerView.class))
.perform(RecyclerViewActions.scrollToPosition(feedHeaderPosition));
waitForView(rootView,
allOf(withId(R.id.header_status),
withText(expanded ? R.string.hide_content : R.string.show_content)));
if (FeedFeatures.isV2Enabled()) {
onView(allOf(instanceOf(RecyclerView.class), withId(R.id.feed_stream_recycler_view)))
.perform(RecyclerViewActions.scrollToPosition(feedHeaderPosition));
onView(withId(R.id.header_menu)).perform(click());
onView(withText(expanded ? R.string.ntp_turn_on_feed : R.string.ntp_turn_off_feed))
.perform(click());
onView(withText(expanded ? R.string.ntp_discover_on : R.string.ntp_discover_off))
.check(ViewAssertions.matches(isDisplayed()));
} else {
onView(instanceOf(RecyclerView.class))
.perform(RecyclerViewActions.scrollToPosition(feedHeaderPosition),
RecyclerViewActions.actionOnItemAtPosition(
feedHeaderPosition, click()));
// Scroll to the same position in case the refresh brings the section header out of
// the screen.
onView(instanceOf(RecyclerView.class))
.perform(RecyclerViewActions.scrollToPosition(feedHeaderPosition));
waitForView(rootView,
allOf(withId(R.id.header_status),
withText(expanded ? R.string.hide_content : R.string.show_content)));
}
}
}
......@@ -2640,12 +2640,16 @@ Data from your Incognito session will only be cleared from Chrome when you <ph n
<message name="IDS_NTP_LEARN_MORE_ABOUT_SUGGESTED_CONTENT" desc="Text in the footer of the New Tab Page. Part of the text is a link to a help center page where the user can learn more about suggested content.">
<ph name="BEGIN_LINK">&lt;link&gt;</ph>Learn more<ph name="END_LINK">&lt;/link&gt;</ph> about suggested content
</message>
<message name="IDS_NTP_SUGGESTIONS_FETCH_FAILED" desc="Snackbar text shown when the user presses the More button to get more suggestions, but this fails (eg, no internet connectivity).">
Can’t get suggestions
</message>
<message name="IDS_NTP_SUGGESTIONS_FETCH_NO_NEW_SUGGESTIONS" desc="Snackbar text shown when the user presses the More button to get more suggestions, the fetch succeeds but provides no new suggestions.">
No new suggestions
</message>
<if expr="enable_feed_v1">
<message name="IDS_NTP_SUGGESTIONS_FETCH_FAILED" desc="Snackbar text shown when the user presses the More button to get more suggestions, but this fails (eg, no internet connectivity).">
Can’t get suggestions
</message>
</if>
<if expr="enable_feed_v1">
<message name="IDS_NTP_SUGGESTIONS_FETCH_NO_NEW_SUGGESTIONS" desc="Snackbar text shown when the user presses the More button to get more suggestions, the fetch succeeds but provides no new suggestions.">
No new suggestions
</message>
</if>
<message name="IDS_NTP_MANAGE_MY_ACTIVITY" desc="Content description to manage my activity from the feed header overflow menu.">
Manage activity
</message>
......
......@@ -2,12 +2,22 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//chrome/android/channel.gni")
# Chrome can be built with any combination of v1/v2 enabled.
# When both are enabled, we use the InterestFeedV2 feature to select which
# one is used at runtime.
# If both are false, some of the Feed V2 UI classes are still used to display
# the NTP.
declare_args() {
# Whether version 1 of the NTP feed is enabled in the build.
enable_feed_v1 = is_android
# Whether version 2 of the NTP feed is enabled in the build.
enable_feed_v2 = is_android
}
if (is_android && android_channel != "default") {
# You probably don't want to build without either version in a Clank release.
assert(enable_feed_v1 || enable_feed_v2)
}
<?xml version="1.0" encoding="utf-8"?>
<grit-part>
<if expr="is_android or is_ios">
<if expr="enable_feed_v1 or is_ios">
<message name="IDS_NTP_TITLE_NO_SUGGESTIONS" desc="On the New Tab Page, title text explaining there is no content." formatter_data="android_java">
That’s all for now
</message>
......
......@@ -6,6 +6,7 @@ import("//build/config/chrome_build.gni")
import("//build/config/chromeos/ui_mode.gni")
import("//build/config/crypto.gni")
import("//build/config/ui.gni")
import("//components/feed/features.gni")
grit_defines = []
......@@ -97,6 +98,13 @@ if (is_android) {
]
}
if (enable_feed_v1) {
grit_defines += [
"-D",
"enable_feed_v1",
]
}
# When cross-compiling, explicitly pass the target system to grit.
if (current_toolchain != host_toolchain) {
if (is_android) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment