Skip to content

Commit

Permalink
Privacy Guide: browsertest refactoring (completion card)
Browse files Browse the repository at this point in the history
Move tests that purely test inner completion fragment functionality into
a separate completion fragment test suite. This reduces the runtime of
the main test suite significantly (from ~16s to ~9s on a Chromium build
machine) and should hence significantly contribute to fixing 1293840.

Before:
  [1/2] [...].HistorySyncFragmentTests (3416 ms)
  [2/2] [...].PrivacyReviewPageTests (15743 ms)

After:
  [1/3] [...].HistorySyncFragmentTests (3419 ms)
  [2/3] [...].CompletionFragmentTests (6043 ms)
  [3/3] [...].PrivacyReviewPageTests (9452 ms)

Bug: 1215630,1293840
Change-Id: I376ef562dd2693d53bf4dec04e46bd3a80226432
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3450117
Reviewed-by: Sean Harrison <[email protected]>
Commit-Queue: Rainhard Findling <[email protected]>
Reviewed-by: Demetrios Papadopoulos <[email protected]>
Cr-Commit-Position: refs/heads/main@{#969055}
  • Loading branch information
Rainhard Findling authored and Chromium LUCI CQ committed Feb 9, 2022
1 parent ee1d45d commit b81eced
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 65 deletions.
1 change: 1 addition & 0 deletions chrome/browser/resources/settings/lazy_load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ export class PrivacyReviewCompletionFragmentElement extends
}
}

declare global {
interface HTMLElementTagNameMap {
'privacy-review-completion-fragment':
PrivacyReviewCompletionFragmentElement;
}
}

customElements.define(
PrivacyReviewCompletionFragmentElement.is,
PrivacyReviewCompletionFragmentElement);
6 changes: 5 additions & 1 deletion chrome/test/data/webui/settings/cr_settings_browsertest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
124 changes: 60 additions & 64 deletions chrome/test/data/webui/settings/privacy_review_page_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<HTMLElement>(
'#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<HTMLElement>('#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:
Expand Down Expand Up @@ -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<HTMLElement>('#waaRow')!.click();
flush();

const result = await testMetricsBrowserProxy.whenCalled(
'recordPrivacyGuideEntryExitHistogram');
assertEquals(PrivacyGuideInteractions.SWAA_COMPLETION_LINK, result);
});

test('privacySandboxLinkClick', async function() {
page.shadowRoot!.querySelector<HTMLElement>('#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'));
});
});

0 comments on commit b81eced

Please sign in to comment.