diff --git a/chrome/browser/resources/settings/lazy_load.ts b/chrome/browser/resources/settings/lazy_load.ts index e0c52c3867d68d..dfb78659d21fdb 100644 --- a/chrome/browser/resources/settings/lazy_load.ts +++ b/chrome/browser/resources/settings/lazy_load.ts @@ -137,6 +137,7 @@ export {SettingsDoNotTrackToggleElement} from './privacy_page/do_not_track_toggl export {SettingsPersonalizationOptionsElement} from './privacy_page/personalization_options.js'; export {PrivacyReviewStep} from './privacy_page/privacy_review/constants.js'; export {PrivacyReviewClearOnExitFragmentElement} from './privacy_page/privacy_review/privacy_review_clear_on_exit_fragment.js'; +export {PrivacyReviewCompletionFragmentElement} from './privacy_page/privacy_review/privacy_review_completion_fragment.js'; export {PrivacyReviewDescriptionItemElement} from './privacy_page/privacy_review/privacy_review_description_item.js'; export {PrivacyReviewHistorySyncFragmentElement} from './privacy_page/privacy_review/privacy_review_history_sync_fragment.js'; export {PrivacyReviewMsbbFragmentElement} from './privacy_page/privacy_review/privacy_review_msbb_fragment.js'; diff --git a/chrome/browser/resources/settings/privacy_page/privacy_review/privacy_review_completion_fragment.ts b/chrome/browser/resources/settings/privacy_page/privacy_review/privacy_review_completion_fragment.ts index 5bcdd855c6c5d3..bdb932fd486553 100644 --- a/chrome/browser/resources/settings/privacy_page/privacy_review/privacy_review_completion_fragment.ts +++ b/chrome/browser/resources/settings/privacy_page/privacy_review/privacy_review_completion_fragment.ts @@ -100,6 +100,13 @@ export class PrivacyReviewCompletionFragmentElement extends } } +declare global { + interface HTMLElementTagNameMap { + 'privacy-review-completion-fragment': + PrivacyReviewCompletionFragmentElement; + } +} + customElements.define( PrivacyReviewCompletionFragmentElement.is, PrivacyReviewCompletionFragmentElement); diff --git a/chrome/test/data/webui/settings/cr_settings_browsertest.js b/chrome/test/data/webui/settings/cr_settings_browsertest.js index 1ce612731ebc60..feba5f25fa2b7a 100644 --- a/chrome/test/data/webui/settings/cr_settings_browsertest.js +++ b/chrome/test/data/webui/settings/cr_settings_browsertest.js @@ -506,12 +506,16 @@ TEST_F( runMochaSuite('PrivacyReviewPage'); }); - TEST_F( 'CrSettingsPrivacyReviewPageTest', 'HistorySyncFragmentTests', function() { runMochaSuite('HistorySyncFragment'); }); +TEST_F( + 'CrSettingsPrivacyReviewPageTest', 'CompletionFragmentTests', function() { + runMochaSuite('CompletionFragment'); + }); + var CrSettingsRouteTest = class extends CrSettingsBrowserTest { /** @override */ get browsePreload() { diff --git a/chrome/test/data/webui/settings/privacy_review_page_test.ts b/chrome/test/data/webui/settings/privacy_review_page_test.ts index 513704e107e8de..068953b12d9929 100644 --- a/chrome/test/data/webui/settings/privacy_review_page_test.ts +++ b/chrome/test/data/webui/settings/privacy_review_page_test.ts @@ -5,7 +5,7 @@ // clang-format off import {webUIListenerCallback} from 'chrome://resources/js/cr.m.js'; import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; -import {CookiePrimarySetting, PrivacyReviewHistorySyncFragmentElement, PrivacyReviewStep, PrivacyReviewWelcomeFragmentElement, SafeBrowsingSetting, SettingsPrivacyReviewPageElement, SettingsRadioGroupElement} from 'chrome://settings/lazy_load.js'; +import {CookiePrimarySetting, PrivacyReviewCompletionFragmentElement, PrivacyReviewHistorySyncFragmentElement, PrivacyReviewStep, PrivacyReviewWelcomeFragmentElement, SafeBrowsingSetting, SettingsPrivacyReviewPageElement, SettingsRadioGroupElement} from 'chrome://settings/lazy_load.js'; import {MetricsBrowserProxyImpl, PrivacyGuideInteractions, PrivacyGuideSettingsStates, Router, routes, StatusAction, SyncBrowserProxyImpl, SyncPrefs, syncPrefsIndividualDataTypes, SyncStatus} from 'chrome://settings/settings.js'; import {assertEquals, assertFalse, assertTrue} from 'chrome://webui-test/chai_assert.js'; import {eventToPromise, flushTasks, isChildVisible} from 'chrome://webui-test/test_util.js'; @@ -32,6 +32,17 @@ function navigateToStep(step: PrivacyReviewStep) { flush(); } +/** + * Fire a sign in status change event and flush the UI. + */ +function setSignInState(signedIn: boolean) { + const event = { + signedIn: signedIn, + }; + webUIListenerCallback('update-sync-state', event); + flush(); +} + /** * Set all relevant sync status and fire a changed event and flush the UI. */ @@ -176,17 +187,6 @@ suite('PrivacyReviewPage', function() { flush(); } - /** - * Fire a sign in status change event and flush the UI. - */ - function setSignInState(signedIn: boolean) { - const event = { - signedIn: signedIn, - }; - webUIListenerCallback('update-sync-state', event); - flush(); - } - type AssertCardComponentsVisibleParams = { isSettingFooterVisibleExpected?: boolean, isBackButtonVisibleExpected?: boolean, @@ -1015,58 +1015,6 @@ suite('PrivacyReviewPage', function() { }); }); - test('completionCardSWAALinkClick', async function() { - navigateToStep(PrivacyReviewStep.COMPLETION); - setSignInState(true); - assertCompletionCardVisible(); - - const completionFragment = - page.shadowRoot!.querySelector('#' + PrivacyReviewStep.COMPLETION)!; - - assertTrue(isChildVisible(completionFragment, '#waaRow')); - completionFragment.shadowRoot!.querySelector( - '#waaRow')!.click(); - - flush(); - - const result = await testMetricsBrowserProxy.whenCalled( - 'recordPrivacyGuideEntryExitHistogram'); - assertEquals(PrivacyGuideInteractions.SWAA_COMPLETION_LINK, result); - }); - - test('completionCardPrivacySandboxLinkClick', async function() { - navigateToStep(PrivacyReviewStep.COMPLETION); - assertCompletionCardVisible(); - - const completionFragment = - page.shadowRoot!.querySelector('#' + PrivacyReviewStep.COMPLETION)!; - completionFragment.shadowRoot! - .querySelector('#privacySandboxRow')!.click(); - - flush(); - - const result = await testMetricsBrowserProxy.whenCalled( - 'recordPrivacyGuideEntryExitHistogram'); - assertEquals( - PrivacyGuideInteractions.PRIVACY_SANDBOX_COMPLETION_LINK, result); - }); - - test('completionCardGetsUpdated', function() { - navigateToStep(PrivacyReviewStep.COMPLETION); - setSignInState(true); - assertCompletionCardVisible(); - - const completionFragment = - page.shadowRoot!.querySelector('#' + PrivacyReviewStep.COMPLETION)!; - assertTrue(isChildVisible(completionFragment, '#privacySandboxRow')); - assertTrue(isChildVisible(completionFragment, '#waaRow')); - - // Sign the user out and expect the waa row to no longer be visible. - setSignInState(false); - assertTrue(isChildVisible(completionFragment, '#privacySandboxRow')); - assertFalse(isChildVisible(completionFragment, '#waaRow')); - }); - test('privacyReviewVisibilityChildAccount', function() { // Set the user to have a non-child account. const syncStatus: @@ -1284,3 +1232,51 @@ suite('HistorySyncFragment', function() { }); }); }); + +suite('CompletionFragment', function() { + let page: PrivacyReviewCompletionFragmentElement; + let testMetricsBrowserProxy: TestMetricsBrowserProxy; + + setup(function() { + testMetricsBrowserProxy = new TestMetricsBrowserProxy(); + MetricsBrowserProxyImpl.setInstance(testMetricsBrowserProxy); + + document.body.innerHTML = ''; + page = document.createElement('privacy-review-completion-fragment'); + document.body.appendChild(page); + return flushTasks(); + }); + + test('SWAALinkClick', async function() { + setSignInState(true); + + assertTrue(isChildVisible(page, '#waaRow')); + page.shadowRoot!.querySelector('#waaRow')!.click(); + flush(); + + const result = await testMetricsBrowserProxy.whenCalled( + 'recordPrivacyGuideEntryExitHistogram'); + assertEquals(PrivacyGuideInteractions.SWAA_COMPLETION_LINK, result); + }); + + test('privacySandboxLinkClick', async function() { + page.shadowRoot!.querySelector('#privacySandboxRow')!.click(); + flush(); + + const result = await testMetricsBrowserProxy.whenCalled( + 'recordPrivacyGuideEntryExitHistogram'); + assertEquals( + PrivacyGuideInteractions.PRIVACY_SANDBOX_COMPLETION_LINK, result); + }); + + test('updateFragmentFromSignIn', function() { + setSignInState(true); + assertTrue(isChildVisible(page, '#privacySandboxRow')); + assertTrue(isChildVisible(page, '#waaRow')); + + // Sign the user out and expect the waa row to no longer be visible. + setSignInState(false); + assertTrue(isChildVisible(page, '#privacySandboxRow')); + assertFalse(isChildVisible(page, '#waaRow')); + }); +});