Skip to content
Snippets Groups Projects
Verified Commit 7ba9c195 authored by Dave Long's avatar Dave Long
Browse files

Issue #3487874 by jan kellermann, filipeabreu, valthebald, longwave: Olivero:...

Issue #3487874 by jan kellermann, filipeabreu, valthebald, longwave: Olivero: Avoid localStorage for anonymous user to prevent violation of data protection regulations

(cherry picked from commit 5e89fa50)
parent 74b90394
No related branches found
No related tags found
15 merge requests!11636Draft: Issue #3515643 by macsim: fieldNameExists method is inconsistent,!11515Issue #3480419 by mondrake, smustgrave, catch: Method...,!11380Issue #3490698 by catch, spokje: Bump MINIMUM_STABILITY back to 'stable' when...,!11281Use Drupal Core Leadership terminology in MAINTAINERS.txt,!11239Issue #3507548: Allow workspace changes listing to show all items, without a pager,!11238Fix issue #3051797,!11213Issue #3506743 by tomislav.matokovic: Increasing the color contrast for the navigation block title against the background of the navigation sidebar to at least 4.5:1,!11147Draft: Try to avoid manually setting required cache contexts,!11108Issue #3490298 by nicxvan: Profiles can be missed in OOP hooks,!11093Drupal on MongoDB 11.1.x,!11017Issue #3502540: Add date filter for moderated content.,!11009Issue #3486972 migrate feed icon,!10999Cleaning up Taxonomy hooks and updating baseline.,!10977Issue #3501457: Fix path used in a A11y Test Admin,!10881Issue #3489329 by mfb, casey: symfony/http-foundation commit 32310ff breaks PathValidator
Pipeline #374382 canceled
Pipeline: drupal

#374383

    <?php
    declare(strict_types=1);
    namespace Drupal\FunctionalJavascriptTests\Theme;
    use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
    /**
    * Tests usage of localStorage.
    *
    * @group olivero
    */
    final class OliveroAvoidStorageUsingTest extends WebDriverTestBase {
    /**
    * {@inheritdoc}
    */
    protected static $modules = ['block', 'node'];
    /**
    * {@inheritdoc}
    */
    protected $defaultTheme = 'olivero';
    /**
    * Tests use of localStorage.
    */
    public function testStorageUsing(): void {
    $this->drupalGet('<front>');
    // Check if initial no storage item is written.
    $this->assertJsCondition("localStorage.getItem('Drupal.olivero.stickyHeaderState') === null", 10000, 'Written not strictly necessary Drupal.olivero.stickyHeaderState to localStorage without consent.');
    // Resize and scroll to show stickyHeaderToggleButton.
    $session = $this->getSession();
    $session->resizeWindow(1280, 1024);
    $session->executeScript('window.scrollTo(0, 500);');
    // Click stickyHeaderToggleButton.
    $this->getSession()->getPage()->find('css', '.sticky-header-toggle')->click();
    // Test if localStorage is set now.
    $this->assertJsCondition("localStorage.getItem('Drupal.olivero.stickyHeaderState') !== null");
    // Click stickyHeaderToggleButton again.
    $this->getSession()->getPage()->find('css', '.sticky-header-toggle')->click();
    // Storage item should be removed now.
    $this->assertJsCondition("localStorage.getItem('Drupal.olivero.stickyHeaderState') === null", 10000, 'Storage item Drupal.olivero.stickyHeaderState should be removed.');
    }
    }
    ......@@ -58,6 +58,10 @@
    * Current state of the sticky header button.
    */
    function setStickyHeaderStorage(expandedState) {
    if (!expandedState) {
    localStorage.removeItem('Drupal.olivero.stickyHeaderState');
    return;
    }
    const now = new Date();
    const item = {
    ......@@ -70,6 +74,22 @@
    );
    }
    /**
    * Update the expiration date if the sticky header expanded state is set.
    *
    * @param {boolean} expandedState
    * Current state of the sticky header button.
    */
    function updateStickyHeaderStorage(expandedState) {
    const stickyHeaderState = localStorage.getItem(
    'Drupal.olivero.stickyHeaderState',
    );
    if (stickyHeaderState !== null) {
    setStickyHeaderStorage(expandedState);
    }
    }
    /**
    * Toggle the state of the sticky header between always pinned and
    * only pinned when scrolled to the top of the viewport.
    ......@@ -81,7 +101,6 @@
    if (isDesktopNav()) {
    siteHeaderFixable.classList.toggle('is-expanded', pinnedState);
    stickyHeaderToggleButton.setAttribute('aria-checked', pinnedState);
    setStickyHeaderStorage(pinnedState);
    }
    }
    ......@@ -182,7 +201,9 @@
    if (stickyHeaderToggleButton) {
    stickyHeaderToggleButton.addEventListener('click', () => {
    toggleStickyHeaderState(!stickyHeaderIsEnabled());
    const pinnedState = !stickyHeaderIsEnabled();
    toggleStickyHeaderState(pinnedState);
    setStickyHeaderStorage(pinnedState);
    });
    }
    ......@@ -209,7 +230,7 @@
    }
    monitorNavPosition();
    setStickyHeaderStorage(getStickyHeaderStorage());
    updateStickyHeaderStorage(getStickyHeaderStorage());
    toggleStickyHeaderState(getStickyHeaderStorage());
    }
    })(Drupal);
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment