[go: nahoru, domu]

[M123] Change NTP Wallpaper Search button's visibility logic

Changes wallpaper search button's setting observer logic so that it only hides the button, does not show it. This prevents the button from showing if Wallpaper Search's enablement logic changed since the NTP loaded, and has somehow diverged from Customize Chrome's.

(cherry picked from commit 30139ce7ad2b4fa8c613a7d04d5e54d05a797d99)

Change-Id: Iba4867adee740d98b0af320ea77ea4619d5cab01
Bug: 328085545
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5353693
Reviewed-by: Riley Tatum <rtatum@google.com>
Commit-Queue: Paul Adedeji <pauladedeji@google.com>
Auto-Submit: Paul Adedeji <pauladedeji@google.com>
Commit-Queue: Riley Tatum <rtatum@google.com>
Cr-Original-Commit-Position: refs/heads/main@{#1269882}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5363752
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/branch-heads/6312@{#532}
Cr-Branched-From: 6711dcdae48edaf98cbc6964f90fac85b7d9986e-refs/heads/main@{#1262506}
diff --git a/chrome/browser/resources/new_tab_page/app.ts b/chrome/browser/resources/new_tab_page/app.ts
index f44789d..9c155734 100644
--- a/chrome/browser/resources/new_tab_page/app.ts
+++ b/chrome/browser/resources/new_tab_page/app.ts
@@ -470,7 +470,12 @@
     this.setWallpaperSearchButtonVisibilityListener_ =
         this.callbackRouter_.setWallpaperSearchButtonVisibility.addListener(
             (visible: boolean) => {
-              this.wallpaperSearchButtonEnabled_ = visible;
+              // We only show the button if wallpaper search is enabled when the
+              // NTP loads. This prevents the button from showing if Customize
+              // Chrome doesn't have the wallpaper search element yet.
+              if (!visible) {
+                this.wallpaperSearchButtonEnabled_ = visible;
+              }
             });
 
     // Open Customize Chrome if there are Customize Chrome URL params.
diff --git a/chrome/browser/ui/webui/side_panel/customize_chrome/wallpaper_search/wallpaper_search_interactive_uitest.cc b/chrome/browser/ui/webui/side_panel/customize_chrome/wallpaper_search/wallpaper_search_interactive_uitest.cc
index 692ff38..102cd4a8 100644
--- a/chrome/browser/ui/webui/side_panel/customize_chrome/wallpaper_search/wallpaper_search_interactive_uitest.cc
+++ b/chrome/browser/ui/webui/side_panel/customize_chrome/wallpaper_search/wallpaper_search_interactive_uitest.cc
@@ -123,9 +123,8 @@
             static_cast<int>(
                 optimization_guide::prefs::FeatureOptInState::kEnabled));
       }),
-      // 6. Ensure the wallpaper search button is visible.
-      WaitForElementVisible(kNewTabPageElementId,
-                            kWallpaperSearchButtonContainer));
+      // 6. Ensure the wallpaper search button is still hidden.
+      WaitForStateChange(kNewTabPageElementId, wallpaper_search_button_hidden));
 }
 
 class WallpaperSearchOptimizationGuideInteractiveTest
diff --git a/chrome/test/data/webui/new_tab_page/app_test.ts b/chrome/test/data/webui/new_tab_page/app_test.ts
index 26e099d..98c5481 100644
--- a/chrome/test/data/webui/new_tab_page/app_test.ts
+++ b/chrome/test/data/webui/new_tab_page/app_test.ts
@@ -1372,7 +1372,8 @@
           });
 
       test(
-          'button hides/shows in accordance with callback router', async () => {
+          'button hides in accordance with callback router', async () => {
+            // Both buttons shown.
             assertNotStyle(
                 $$(app, '#customizeButtonContainer')!, 'display', 'none');
             assertNotStyle(
@@ -1381,6 +1382,7 @@
             callbackRouterRemote.setWallpaperSearchButtonVisibility(false);
             await callbackRouterRemote.$.flushForTesting();
 
+            // Wallpaper search button hides.
             assertNotStyle(
                 $$(app, '#customizeButtonContainer')!, 'display', 'none');
             assertStyle(
@@ -1389,9 +1391,10 @@
             callbackRouterRemote.setWallpaperSearchButtonVisibility(true);
             await callbackRouterRemote.$.flushForTesting();
 
+            // Wallpaper search button remains hidden.
             assertNotStyle(
                 $$(app, '#customizeButtonContainer')!, 'display', 'none');
-            assertNotStyle(
+            assertStyle(
                 $$(app, '#wallpaperSearchButtonContainer')!, 'display', 'none');
           });
     });