Skip to content
Snippets Groups Projects
Verified Commit 5e89fa50 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
parent b801b77d
Branches
Tags
12 merge requests!11197Issue #3506427 by eduardo morales alberti: Remove responsive_image.ajax from hook,!11131[10.4.x-only-DO-NOT-MERGE]: Issue ##2842525 Ajax attached to Views exposed filter form does not trigger callbacks,!10786Issue #3490579 by shalini_jha, mstrelan: Add void return to all views...,!5423Draft: Resolve #3329907 "Test2",!3878Removed unused condition head title for views,!3818Issue #2140179: $entity->original gets stale between updates,!3478Issue #3337882: Deleted menus are not removed from content type config,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2062Issue #3246454: Add weekly granularity to views date sort,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation
Pipeline #373774 passed with warnings
Pipeline: drupal

#373793

    Pipeline: drupal

    #373788

      Pipeline: drupal

      #373780

        <?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.
        Please register or to comment