Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

For #9599: Ability to edit top site URLs #9600

Merged
merged 3 commits into from
Feb 23, 2021

Conversation

pepve
Copy link
Contributor

@pepve pepve commented Feb 4, 2021

  • Add functionality to edit both the title and the URL of a top site simultaneously
  • Deprecate functionality to edit only the title of a top site

Replace the functionality to rename top sites with functionality to update both the title and the URL.

Pull Request checklist

  • Quality: This PR builds and passes detekt/ktlint checks (A pre-push hook is recommended)
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry or does not need one
  • Accessibility: The code in this PR follows accessibility best practices or does not include any user facing features

After merge

  • Milestone: Make sure issues closed by this pull request are added to the milestone of the version currently in development.
  • Breaking Changes: If this is a breaking change, please push a draft PR on Reference Browser to address the breaking issues.

@codecov
Copy link

codecov bot commented Feb 4, 2021

Codecov Report

Merging #9600 (f84dc4e) into master (69a800e) will decrease coverage by 7.26%.
The diff coverage is 80.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #9600      +/-   ##
============================================
- Coverage     73.89%   66.63%   -7.27%     
+ Complexity     5576      553    -5023     
============================================
  Files           768      120     -648     
  Lines         28608     3809   -24799     
  Branches       4710      614    -4096     
============================================
- Hits          21140     2538   -18602     
+ Misses         5023      958    -4065     
+ Partials       2445      313    -2132     
Impacted Files Coverage Δ Complexity Δ
...onents/feature/top/sites/DefaultTopSitesStorage.kt 70.27% <0.00%> (ø) 12.00 <0.00> (ø)
...la/components/feature/top/sites/TopSitesStorage.kt 0.00% <ø> (ø) 0.00 <0.00> (ø)
.../components/feature/top/sites/PinnedSiteStorage.kt 78.12% <80.00%> (+78.12%) 10.00 <2.00> (+10.00)
...a/components/feature/top/sites/TopSitesUseCases.kt 82.35% <100.00%> (ø) 1.00 <0.00> (ø)
...onents/feature/customtabs/CustomTabConfigHelper.kt
...a/components/browser/search/SearchEngineManager.kt
...components/browser/state/reducer/TabListReducer.kt
.../feature/downloads/SimpleDownloadDialogFragment.kt
...java/mozilla/components/concept/menu/MenuButton.kt
...engine/manifest/parser/WebAppManifestIconParser.kt
... and 645 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 69a800e...f84dc4e. Read the comment docs.

@gabrielluong gabrielluong self-assigned this Feb 4, 2021
@@ -76,6 +76,16 @@ class DefaultTopSitesStorage(
}
}

override fun editTopSite(topSite: TopSite, title: String, url: String) {
Copy link
Member

Choose a reason for hiding this comment

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

Let's remove renameTopSite since I don't imagine any consumers of it after this. Can we also call it updateTopSite instead of editTopSite?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done and done!

@gabrielluong
Copy link
Member

I'm planning to look at how the edit bookmarks (use case if there is one?) works tomorrow to investigate how it works - looking for clues on how/if it handles empty URL provided and perhaps malformed URLs. Will also look at other browser to see how much we will need to dive into this. Feel free to also investigate this, I just want to make sure we cover our bases. Thanks again for contributing!

@mergify
Copy link
Contributor

mergify bot commented Feb 6, 2021

This pull request has conflicts when rebasing. Could you fix it @pepve? 🙏

@pepve
Copy link
Contributor Author

pepve commented Feb 10, 2021

I just rebased on the latest master. I also added a commit with a test to improve the (measured) test coverage, please review, I'm not entirely sure of the mockDao function I came up with.

About validation, can we pick that up in a separate issue? From the AC perspective it was already possible to add any random string as a URL. And the new update logic doesn't change that. The new issue will then of course block the Fenix issue I'm doing this for: #17636.

@mergify
Copy link
Contributor

mergify bot commented Feb 12, 2021

This pull request has conflicts when rebasing. Could you fix it @pepve? 🙏

Comment on lines +20 to +21
@VisibleForTesting
internal var currentTimeMillis: () -> Long = { System.currentTimeMillis() }
Copy link
Member

Choose a reason for hiding this comment

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

There's nothing wrong in particular about this, but from looking around our codebase, I would be more comfortable being consistent and calling System.currentTimeMillis() where it is.

Copy link
Contributor Author

@pepve pepve Feb 14, 2021

Choose a reason for hiding this comment

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

I use it to inject a constant time from the tests (in addAllDefaultSites and addPinnedSite) so that I can use verify without much effort. What would be a good alternative?

Copy link
Member

Choose a reason for hiding this comment

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

I think we can just check for anyLong() as an alternative.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried that but I think it doesn't work because the long is wrapped in an object. I think this works:
verify(obj).method(eq("foo"), anyLong())
But this doesn't:
verify(obj).method(SomeClass(eq("foo"), anyLong()))
And our case matches the latter. But I don't really have a lot of experience in this area so please correct me if I'm missing something. The real problem I think we're having is that there is no consistent way to mock time used throughout the project. Code that does straight calls to System.currentTimeMillis() is just not very unit-testable. Perhaps we should make an issue about this?

@@ -49,6 +49,9 @@ permalink: /changelog/
* **lib-state**
* Add `threadNamePrefix` parameter to `Store` to give threads created by the `Store` a specific name.

* **feature-top-sites**
* ⚠️ **This is a breaking change**: Replace `TopSitesUseCases.renameTopSites` (which only updates the title) with `TopSitesUseCases.updateTopSites` (which also updates the url). [#9599](https://github.com/mozilla-mobile/android-components/issues/9599)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* ⚠️ **This is a breaking change**: Replace `TopSitesUseCases.renameTopSites` (which only updates the title) with `TopSitesUseCases.updateTopSites` (which also updates the url). [#9599](https://github.com/mozilla-mobile/android-components/issues/9599)
* ⚠️ **This is a breaking change**: Replace `TopSitesUseCases.renameTopSites` with `TopSitesUseCases.updateTopSites` which will allow for updating the title and url of a top site. [#9599](https://github.com/mozilla-mobile/android-components/issues/9599)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

class PinnedSitesStorageTest {

@Test
fun `add all default sites`() = runBlocking {
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we can simply use the addAllPinnedSites as the test name and the others.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@@ -0,0 +1,127 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
Copy link
Member

Choose a reason for hiding this comment

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

This is nice!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you!

)
entity.id = pinnedSiteDao.insertPinnedSite(entity)
pinnedSiteDao.insertPinnedSite(entity)
Copy link
Member

Choose a reason for hiding this comment

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

Just noticed this change from your comments in https://github.com/mozilla-mobile/android-components/pull/9600/files#r575826087, can we revert this change for now?

I see we are doing entity.id in a number of places for adding items to the RoomDB - LoginExceptionStorage, TabCollectionStorage. If we think this should be changed, I think we should make a change that also accounts for those 2 other storage. I mostly don't understand the meaning behind the change so happy to be enlighten.

I think this also resolves us from having to return Unit in the other files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines +20 to +21
@VisibleForTesting
internal var currentTimeMillis: () -> Long = { System.currentTimeMillis() }
Copy link
Member

Choose a reason for hiding this comment

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

I think we can just check for anyLong() as an alternative.

@mergify
Copy link
Contributor

mergify bot commented Feb 16, 2021

This pull request has conflicts when rebasing. Could you fix it @pepve? 🙏

@pepve
Copy link
Contributor Author

pepve commented Feb 23, 2021

@gabrielluong is there anything else I can do to help progress this?

@gabrielluong gabrielluong added the 🛬 needs landing (squash) PRs that are ready to land (squashed) label Feb 23, 2021
@mergify mergify bot merged commit 93ee2f3 into mozilla-mobile:master Feb 23, 2021
@pepve
Copy link
Contributor Author

pepve commented Feb 24, 2021

Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🛬 needs landing (squash) PRs that are ready to land (squashed)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants