Skip to content

Commit

Permalink
add descriptor d
Browse files Browse the repository at this point in the history
Change-Id: I9ae6468f19b6464dcf215864327788df73997b91
Bug: b/300944749
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4944297
Reviewed-by: Alex Gough <ajgo@chromium.org>
Commit-Queue: Paul Adedeji <pauladedeji@google.com>
Reviewed-by: Tibor Goldschwendt <tiborg@chromium.org>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#1211734}
  • Loading branch information
Paul Adedeji authored and Chromium LUCI CQ committed Oct 18, 2023
1 parent 658ded3 commit 6380f66
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@
margin: 16px 16px 8px;
}

#descriptorMenuD cr-button {
background-color: var(--sys-color-neutral-container);
height: 40px;
min-width: 40px;
padding: 0px;
}

.descriptor-d {
border-radius: 50%;
height: 28px;
width: 28px;
}

#btnContainer {
display: flex;
justify-content: flex-end;
Expand Down Expand Up @@ -114,6 +127,14 @@ <h2 slot="heading">Wallpaper Search</h2>
</button>
</template>
</cr-action-menu>
<div id="descriptorMenuD">
<template is="dom-repeat" items="[[descriptorD_]]">
<cr-button on-click="onDescriptorLabelClickD_">
<span class="descriptor-d" style$="background-color: [[item]];">
</span>
</cr-button>
</template>
</div>
<div id="btnContainer">
<cr-button
id="submitButton"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ import {CustomizeChromePageHandlerInterface, DescriptorA, DescriptorB, Descripto
import {CustomizeChromeApiProxy} from './customize_chrome_api_proxy.js';
import {getTemplate} from './wallpaper_search.html.js';

export const DESCRIPTOR_C_VALUE =
['#EF4837', '#0984E3', '#F9CC18', '#23CC6A', '#474747'];

export interface WallpaperSearchElement {
$: {
combobox: CustomizeChromeCombobox,
descriptorMenuA: CrActionMenuElement,
descriptorMenuB: CrActionMenuElement,
descriptorMenuC: CrActionMenuElement,
descriptorMenuD: CrActionMenuElement,
heading: SpHeading,
submitButton: CrButtonElement,
};
Expand Down Expand Up @@ -54,6 +58,10 @@ export class WallpaperSearchElement extends PolymerElement {
type: Object,
value: null,
},
descriptorD_: {
type: Array,
value: DESCRIPTOR_C_VALUE,
},
emptyContainers_: Object,
results_: Object,
submitBtnText_: {
Expand All @@ -65,11 +73,13 @@ export class WallpaperSearchElement extends PolymerElement {
}

private descriptors_: Descriptors|null;
private descriptorD_: string[];
private emptyContainers_: number[];
private results_: WallpaperSearchResult[];
private selectedDescriptorA_: string|null;
private selectedDescriptorB_: string|null;
private selectedDescriptorC_: string|null;
private selectedDescriptorD_: string|null;
private submitBtnText_: string;

private pageHandler_: CustomizeChromePageHandlerInterface;
Expand Down Expand Up @@ -116,6 +126,11 @@ export class WallpaperSearchElement extends PolymerElement {
this.$.descriptorMenuC.close();
}

private onDescriptorLabelClickD_(e: DomRepeatEvent<string>) {
this.selectedDescriptorD_ = e.model.item;
this.$.descriptorMenuC.close();
}

private onDescriptorMenuClickA_(e: Event) {
this.$.descriptorMenuA.showAt(e.target as HTMLElement);
}
Expand All @@ -128,12 +143,17 @@ export class WallpaperSearchElement extends PolymerElement {
this.$.descriptorMenuC.showAt(e.target as HTMLElement);
}

private onDescriptorMenuClickD_(e: Event) {
this.$.descriptorMenuD.showAt(e.target as HTMLElement);
}

private async onSearchClick_() {
assert(this.descriptors_);
const descriptorA = this.selectedDescriptorA_ ||
getRandomDescriptorA(this.descriptors_.descriptorA);
const {results} = await this.pageHandler_.getWallpaperSearchResults(
descriptorA, this.selectedDescriptorB_, this.selectedDescriptorC_);
descriptorA, this.selectedDescriptorB_, this.selectedDescriptorC_,
this.selectedDescriptorD_);
this.results_ = results;
this.emptyContainers_ = Array.from(
{length: results.length > 0 ? 6 - results.length : 0}, () => 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ interface CustomizeChromePageHandler {
// Retrieves NTP descriptors.
GetDescriptors() => (Descriptors? descriptors);

// Searches NTP wallpaper for `query`. Returns list of sanitized image data.
GetWallpaperSearchResults(string descriptor_a, string? descriptor_b,
string? descriptor_c) => (array<WallpaperSearchResult> results);
// Searches NTP wallpaper for descriptors.
// Returns list of sanitized image data.
GetWallpaperSearchResults(string descriptor_a,
string? descriptor_b, string? descriptor_c,
string? descriptor_d) => (array<WallpaperSearchResult> results);

// Sets wallpaper search result of index to background image.
SetBackgroundToWallpaperSearchResult(mojo_base.mojom.Token result_id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ void CustomizeChromePageHandler::GetWallpaperSearchResults(
const std::string& descriptor_a,
const absl::optional<std::string>& descriptor_b,
const absl::optional<std::string>& descriptor_c,
const absl::optional<std::string>& descriptor_d,
GetWallpaperSearchResultsCallback callback) {
callback = mojo::WrapCallbackWithDefaultInvokeIfNotRun(
std::move(callback),
Expand All @@ -494,7 +495,8 @@ void CustomizeChromePageHandler::GetWallpaperSearchResults(
chrome_intelligence_modelexecution_proto::WallpaperSearchRequest request;
request.set_query(base::StrCat(
{descriptor_a, descriptor_b ? " " : "", descriptor_b.value_or(""),
descriptor_c ? " " : "", descriptor_c.value_or("")}));
descriptor_c ? " " : "", descriptor_c.value_or(""),
descriptor_d ? " " : "", descriptor_d.value_or("")}));
optimization_guide_keyed_service->ExecuteModel(
optimization_guide::proto::ModelExecutionFeature::
MODEL_EXECUTION_FEATURE_WALLPAPER_SEARCH,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class CustomizeChromePageHandler
const std::string& descriptor_a,
const absl::optional<std::string>& descriptor_b,
const absl::optional<std::string>& descriptor_c,
const absl::optional<std::string>& descriptor_d,
GetWallpaperSearchResultsCallback callback) override;
void SetBackgroundToWallpaperSearchResult(
const base::Token& result_id) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1027,8 +1027,9 @@ TEST_F(CustomizeChromePageHandlerWithWallpaperSearchTest,
CustomizeChromePageHandler::GetWallpaperSearchResultsCallback>
callback;

handler().GetWallpaperSearchResults("foo", "bar", "baz", callback.Get());
EXPECT_EQ("foo bar baz", request.query());
handler().GetWallpaperSearchResults("foo", "bar", "baz", "qux",
callback.Get());
EXPECT_EQ("foo bar baz qux", request.query());

chrome_intelligence_modelexecution_proto::WallpaperSearchResponse response;

Expand Down Expand Up @@ -1104,8 +1105,8 @@ TEST_F(CustomizeChromePageHandlerWithWallpaperSearchTest,
testing::NiceMock<base::MockCallback<
CustomizeChromePageHandler::GetWallpaperSearchResultsCallback>>
callback;
handler().GetWallpaperSearchResults("foo", absl::nullopt, "bar",
callback.Get());
handler().GetWallpaperSearchResults("foo", absl::nullopt, absl::nullopt,
"bar", callback.Get());

EXPECT_EQ("foo bar", request.query());
}
Expand Down Expand Up @@ -1133,7 +1134,7 @@ TEST_F(CustomizeChromePageHandlerWithWallpaperSearchTest,
callback;

handler().GetWallpaperSearchResults("foo", absl::nullopt, absl::nullopt,
callback.Get());
absl::nullopt, callback.Get());
EXPECT_EQ("foo", request.query());

std::vector<side_panel::mojom::WallpaperSearchResultPtr> images;
Expand Down Expand Up @@ -1167,7 +1168,7 @@ TEST_F(CustomizeChromePageHandlerWithWallpaperSearchTest,
callback;

handler().GetWallpaperSearchResults("foo", absl::nullopt, absl::nullopt,
callback.Get());
absl::nullopt, callback.Get());
EXPECT_EQ("foo", request.query());

chrome_intelligence_modelexecution_proto::WallpaperSearchResponse response;
Expand Down Expand Up @@ -1225,7 +1226,7 @@ TEST_F(CustomizeChromePageHandlerWithWallpaperSearchTest,
callback;

handler().GetWallpaperSearchResults("foo", absl::nullopt, absl::nullopt,
callback.Get());
absl::nullopt, callback.Get());
EXPECT_EQ("foo", request.query());

chrome_intelligence_modelexecution_proto::WallpaperSearchResponse response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'chrome://customize-chrome-side-panel.top-chrome/wallpaper_search.js';

import {CustomizeChromePageCallbackRouter, CustomizeChromePageHandlerRemote, Descriptors} from 'chrome://customize-chrome-side-panel.top-chrome/customize_chrome.mojom-webui.js';
import {CustomizeChromeApiProxy} from 'chrome://customize-chrome-side-panel.top-chrome/customize_chrome_api_proxy.js';
import {WallpaperSearchElement} from 'chrome://customize-chrome-side-panel.top-chrome/wallpaper_search.js';
import {DESCRIPTOR_C_VALUE, WallpaperSearchElement} from 'chrome://customize-chrome-side-panel.top-chrome/wallpaper_search.js';
import {assertEquals, assertFalse, assertNotEquals, assertTrue} from 'chrome://webui-test/chai_assert.js';
import {flushTasks, waitAfterNextRender} from 'chrome://webui-test/polymer_test_util.js';
import {TestMock} from 'chrome://webui-test/test_mock.js';
Expand Down Expand Up @@ -100,6 +100,11 @@ suite('WallpaperSearchTest', () => {
wallpaperSearchElement.shadowRoot!
.querySelectorAll('#descriptorMenuC .dropdown-item')
.length);
assertEquals(
5,
wallpaperSearchElement.shadowRoot!
.querySelectorAll('#descriptorMenuD cr-button')
.length);
});

test('descriptor menus open and close', async () => {
Expand Down Expand Up @@ -145,12 +150,17 @@ suite('WallpaperSearchTest', () => {
wallpaperSearchElement, '#descriptorMenuB .dropdown-item')!.click();
$$<HTMLElement>(
wallpaperSearchElement, '#descriptorMenuC .dropdown-item')!.click();
$$<HTMLElement>(
wallpaperSearchElement, '#descriptorMenuD cr-button')!.click();
wallpaperSearchElement.$.submitButton.click();

assertEquals(1, handler.getCallCount('getWallpaperSearchResults'));
assertEquals('bar', handler.getArgs('getWallpaperSearchResults')[0][0]);
assertEquals('foo', handler.getArgs('getWallpaperSearchResults')[0][1]);
assertEquals('baz', handler.getArgs('getWallpaperSearchResults')[0][2]);
assertEquals(
DESCRIPTOR_C_VALUE[0],
handler.getArgs('getWallpaperSearchResults')[0][3]);
});

test('selects random descriptor', async () => {
Expand Down Expand Up @@ -191,6 +201,8 @@ suite('WallpaperSearchTest', () => {
undefined, handler.getArgs('getWallpaperSearchResults')[0][1]);
assertEquals(
undefined, handler.getArgs('getWallpaperSearchResults')[0][2]);
assertEquals(
undefined, handler.getArgs('getWallpaperSearchResults')[0][3]);
});

test('empty result shows no tiles', async () => {
Expand Down

0 comments on commit 6380f66

Please sign in to comment.