Skip to content

Commit

Permalink
[ConsentV2] Create field trial for Consent V2 NTP experiment
Browse files Browse the repository at this point in the history
Change-Id: I623046c73eb3b2c4b9448392fcafd8461fae1e4f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3572830
Reviewed-by: Yue Zhang <yuezhanggg@chromium.org>
Commit-Queue: Mei Liang <meiliang@chromium.org>
Auto-Submit: Mei Liang <meiliang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#990256}
  • Loading branch information
Mei Liang authored and Chromium LUCI CQ committed Apr 8, 2022
1 parent 1c23be8 commit e4d6125
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 13 deletions.
48 changes: 35 additions & 13 deletions chrome/test/data/webui/new_tab_page/modules/cart/module_test.ts
Expand Up @@ -36,7 +36,10 @@ suite('NewTabPageModulesChromeCartModuleTest', () => {

suite('Normal cart without rule-based discount', () => {
suiteSetup(() => {
loadTimeData.overrideValues({ruleBasedDiscountEnabled: false});
loadTimeData.overrideValues({
ruleBasedDiscountEnabled: false,
modulesCartDiscountConsentVariation: DiscountConsentVariation.Default
});
});

test('creates no module if no cart item', async () => {
Expand Down Expand Up @@ -732,15 +735,17 @@ suite('NewTabPageModulesChromeCartModuleTest', () => {
// Arrange.
const moduleElement =
await chromeCartDescriptor.initialize(0) as ChromeCartModuleElement;
assertTrue(!!moduleElement);
assertTrue(!!moduleElement, 'Module should exist');
document.body.append(moduleElement);
moduleElement.$.consentCardElement.render();

// Assert.
const consentCard = $$<HTMLElement>(moduleElement, '#consentCard')!;
const consentToast = moduleElement.$.confirmDiscountConsentToast;
assertEquals(true, isVisible(consentCard));
assertEquals(false, consentToast.open);
assertEquals(
true, isVisible(consentCard), 'Consent card should be visible');
assertEquals(
false, consentToast.open, 'Consent toast should not be opened');
assertEquals(
loadTimeData.getString('modulesCartDiscountConsentContent'),
consentCard.querySelector<HTMLElement>('#consentContent')!.innerText);
Expand All @@ -760,8 +765,12 @@ suite('NewTabPageModulesChromeCartModuleTest', () => {
await flushTasks();

// Assert.
assertEquals(false, isVisible(consentCard));
assertEquals(true, consentToast.open);
assertEquals(
false, isVisible(consentCard),
'Consent card should not be visible after clicking the cancel button');
assertEquals(
true, consentToast.open,
'Consent toast should be opened after clicking the cancel button');
assertEquals(
'Reject confirmation!',
moduleElement.$.confirmDiscountConsentMessage.innerText);
Expand All @@ -771,24 +780,33 @@ suite('NewTabPageModulesChromeCartModuleTest', () => {
moduleElement.$.confirmDiscountConsentButton.click();

// Assert.
assertEquals(false, consentToast.open);
assertEquals(false, isVisible(consentCard));
assertEquals(
false, consentToast.open,
'Consent toast should not be opened after acting on the toast');
assertEquals(
false, isVisible(consentCard),
'Consent card should not be visible after acting on the toast');

// Act.
moduleElement.showDiscountConsent = true;
moduleElement.$.consentCardElement.render();

// Assert.
assertEquals(true, isVisible(consentCard));
assertEquals(
true, isVisible(consentCard), 'Consent card should be visible');
assertEquals(0, metrics.count('NewTabPage.Carts.AcceptDiscountConsent'));

// Act.
consentCard.querySelector<HTMLElement>('#actionButton')!.click();
await flushTasks();

// Assert.
assertEquals(false, isVisible(consentCard));
assertEquals(true, consentToast.open);
assertEquals(
false, isVisible(consentCard),
'Consent card should not be visible after accepting');
assertEquals(
true, consentToast.open,
'Consent toast should be opened after accepting');
assertEquals(
'Accept confirmation!',
moduleElement.$.confirmDiscountConsentMessage.innerText);
Expand All @@ -797,8 +815,12 @@ suite('NewTabPageModulesChromeCartModuleTest', () => {
moduleElement.$.confirmDiscountConsentButton.click();

// Assert.
assertEquals(false, consentToast.open);
assertEquals(false, isVisible(consentCard));
assertEquals(
false, consentToast.open,
'Consent toast should not be opened after acting on confirm toast');
assertEquals(
false, isVisible(consentCard),
'Consent card should not be visible after confirm toast');
assertEquals(1, metrics.count('NewTabPage.Carts.AcceptDiscountConsent'));
});

Expand Down
24 changes: 24 additions & 0 deletions testing/variations/fieldtrial_testing_config.json
Expand Up @@ -2801,6 +2801,30 @@
]
}
],
"DiscountConsentV2": [
{
"platforms": [
"linux",
"mac",
"windows"
],
"experiments": [
{
"name": "enabled_ntp_dialog_20220323",
"params": {
"discount-consent-ntp-variation": "3",
"step-one-one-cart-content": "Get discount codes for $1",
"step-one-three-carts-content": "Get discount codes for $1, $2, and more",
"step-one-two-carts-content": "Get discount codes for $1 and $2",
"step-two-content": "Let Google use your carts to find personalized discounts when available"
},
"enable_features": [
"DiscountConsentV2"
]
}
]
}
],
"DnsHttpsSvcbSchemeUpgrade": [
{
"platforms": [
Expand Down

0 comments on commit e4d6125

Please sign in to comment.