Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NTP: Prevent top sites interface from handling duplicated site entries #5173

Merged
merged 1 commit into from
Apr 10, 2020

Conversation

cezaraugusto
Copy link
Contributor

Fix brave/brave-browser#9008

Submitter Checklist:

Test Plan:

Covered by automated tests npm run test-unit

(Manual) Test Plan

  1. Check you have an existing profile with some top site. If you do not, navigate some websites until
    typing chrome.topSites.get(site => console.log(site)) in your NTP console outputs more than one result (this bug only happens in existing profiles w/ top sites).
  2. Copy/paste the code below in devtools on your NTP console tab. The code is corrupted storage with two top sites repeated and pinned at indexes 1 and 2, respectively.
  3. Refresh the page
  4. You should see Google Translate and GitHub as top sites, pinned, at indexes 1 and 2, respectively. If you had any top site before this check, they should be there too, but pinned indexes should be respected.
👉👉👉👉👉👉👉Code you need to copy 👈👈👈👈👈👈👈
localStorage.setItem('grid-sites-data-v1', JSON.stringify({
  gridSites: [
    {
      title: "Google Translate",
      url: "https://translate.google.com/",
      id: "topsite-3742-1585908285880",
      letter: "G",
      favicon: "chrome://favicon/size/64@1x/https://translate.google.com/",
      pinnedIndex: 1
    },
    {
      title: "GitHub",
      url: "https://github.com/congard",
      id: "topsite-3742-1585908285881",
      letter: "C",
      favicon: "chrome://favicon/size/64@1x/https://github.com/congard",
      bookmarkInfo: {},
      pinnedIndex: 2
    },
    {
      title: "Google Translate",
      url: "https://translate.google.com/",
      id: "topsite-3742-1585908285880",
      letter: "G",
      favicon: "chrome://favicon/size/64@1x/https://translate.google.com/",
      pinnedIndex: 1
    },
    {
      title: "GitHub",
      url: "https://github.com/congard",
      id: "topsite-3742-1585908285881",
      letter: "C",
      favicon: "chrome://favicon/size/64@1x/https://github.com/congard",
      bookmarkInfo: {},
      pinnedIndex: 2
    },
    {
      title: "Google Translate",
      url: "https://translate.google.com/",
      id: "topsite-3742-1585908285880",
      letter: "G",
      favicon: "chrome://favicon/size/64@1x/https://translate.google.com/",
      pinnedIndex: 1
    },
    {
      title: "GitHub",
      url: "https://github.com/congard",
      id: "topsite-3742-1585908285881",
      letter: "C",
      favicon: "chrome://favicon/size/64@1x/https://github.com/congard",
      bookmarkInfo: {},
      pinnedIndex: 2
    },
    {
      title: "Google Translate",
      url: "https://translate.google.com/",
      id: "topsite-3742-1585908285880",
      letter: "G",
      favicon: "chrome://favicon/size/64@1x/https://translate.google.com/",
      pinnedIndex: 1
    },
    {
      title: "GitHub",
      url: "https://github.com/congard",
      id: "topsite-3742-1585908285881",
      letter: "C",
      favicon: "chrome://favicon/size/64@1x/https://github.com/congard",
      bookmarkInfo: {},
      pinnedIndex: 2
    },
    {
      title: "Google Translate",
      url: "https://translate.google.com/",
      id: "topsite-3742-1585908285880",
      letter: "G",
      favicon: "chrome://favicon/size/64@1x/https://translate.google.com/",
      pinnedIndex: 1
    },
    {
      title: "GitHub",
      url: "https://github.com/congard",
      id: "topsite-3742-1585908285881",
      letter: "C",
      favicon: "chrome://favicon/size/64@1x/https://github.com/congard",
      bookmarkInfo: {},
      pinnedIndex: 2
    },
    {
      title: "Google Translate",
      url: "https://translate.google.com/",
      id: "topsite-3742-1585908285880",
      letter: "G",
      favicon: "chrome://favicon/size/64@1x/https://translate.google.com/",
      pinnedIndex: 1
    },
    {
      title: "GitHub",
      url: "https://github.com/congard",
      id: "topsite-3742-1585908285881",
      letter: "C",
      favicon: "chrome://favicon/size/64@1x/https://github.com/congard",
      bookmarkInfo: {},
      pinnedIndex: 2
    },
    {
      title: "Google Translate",
      url: "https://translate.google.com/",
      id: "topsite-3742-1585908285880",
      letter: "G",
      favicon: "chrome://favicon/size/64@1x/https://translate.google.com/",
      pinnedIndex: 1
    },
    {
      title: "GitHub",
      url: "https://github.com/congard",
      id: "topsite-3742-1585908285881",
      letter: "C",
      favicon: "chrome://favicon/size/64@1x/https://github.com/congard",
      bookmarkInfo: {},
      pinnedIndex: 2
    },
    {
      title: "Google Translate",
      url: "https://translate.google.com/",
      id: "topsite-3742-1585908285880",
      letter: "G",
      favicon: "chrome://favicon/size/64@1x/https://translate.google.com/",
      pinnedIndex: 1
    },
    {
      title: "GitHub",
      url: "https://github.com/congard",
      id: "topsite-3742-1585908285881",
      letter: "C",
      favicon: "chrome://favicon/size/64@1x/https://github.com/congard",
      bookmarkInfo: {},
      pinnedIndex: 2
    }
  ],
  removedSites: [],
  shouldShowSiteRemovedNotification: false,
  legacy: {
    pinnedTopSites: [],
    ignoredTopSites: []
  }
}
))

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

After-merge Checklist:

  • The associated issue milestone is set to the smallest version that the
    changes has landed on.
  • All relevant documentation has been updated.

@cezaraugusto cezaraugusto self-assigned this Apr 7, 2020
@rebron
Copy link
Collaborator

rebron commented Apr 7, 2020

I had a broken top sites profile and tested the macOS version of PR build is working properly now for my top sites, no duplicate top sites and no overflow of top sites into a second or third row. Removing top sites and undoing is also working.

Copy link
Member

@simonhong simonhong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -115,3 +115,29 @@ export function filterFromExcludedSites (
.every((removedSite: NewTab.Site) => removedSite.url !== site.url)
})
}

export function equalsSite (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Should this method has export because it is only used in this file?

@bsclifton bsclifton added this to the 1.9.x - Nightly milestone Apr 8, 2020
@cezaraugusto cezaraugusto merged commit d601f8a into master Apr 10, 2020
@cezaraugusto cezaraugusto deleted the ca-9008 branch April 10, 2020 15:26
@bsclifton
Copy link
Member

bsclifton commented Apr 10, 2020

@cezaraugusto can you please create an uplift to 1.8 as #5097 was merged to 1.8? thanks 😄 👍 Great job on the tests here ❤️

Just created uplift with #5219 😄

@srirambv
Copy link
Contributor

srirambv commented Apr 22, 2020

@cezaraugusto ran throught the PR on

Brave 1.9.37 Chromium: 81.0.4044.113 (Official Build) nightly (64-bit)
Revision cf9d66371ea608e227eed56ccba3abc2701bd23d-refs/branch-heads/4044@{#936}
OS Windows 10 OS Version 1909 (Build 18363.778)

On existing profile with top tiles running chrome.topSites.get(site => console.log(site)) just showed 1 entry as per below screenshot
image
Running the corrupt local storage code and then reloading retains the existing top tile but expected pinned tiles are not in position 1 and 2 respectively
image

Verification PASSED on macOS 10.15.4 x64 using the following build:

Brave | 1.10.11 Chromium: 81.0.4044.122 (Official Build) nightly (64-bit)
-- | --
Revision | 44f4233f08910d83b146130c1938256a2e05b136-refs/branch-heads/4044@{#963}
OS | macOS Version 10.15.4 (Build 19E287)

Downloaded 1.9.15 CR: 81.0.4044.92 and populated the NTP tiles as per the following:

Screen Shot 2020-04-27 at 1 00 27 PM

Upgraded to 1.10.11 CR: 81.0.4044.122 and ensured no data loss occurred in terms of websites being removed from the NTP grid. Used the STR from #5173 (comment) and imported the data. Ensured that the pinned tabs were in the correct position:

Screen Shot 2020-04-27 at 1 05 24 PM

@srirambv
Copy link
Contributor

Rechecked again on 1.8.24 ->1.10.11
Before upgrade
image
After upgrade
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Duplicated top site entries after update
5 participants