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

[navigation #4] SERP headers navigation responder #887

Merged
merged 20 commits into from
Feb 9, 2023

Conversation

mallexxx
Copy link
Collaborator

@mallexxx mallexxx commented Dec 12, 2022

Task/Issue URL: https://app.asana.com/0/0/1203487090719126/f
Tech Design URL: https://app.asana.com/0/481882893211075/1203268245242140
CC: @tomasstrba @bwaresiak

Description:
Moves adding headers to Search Queries to a separate Navigation Responder

Steps to test this PR:

  1. Validate SERP queries are redirected with appended headers
  2. Validate HTTPS Upgrade service in decidePolicyForNavigation action correctly upgrades to HTTPS

@tomasstrba tomasstrba self-requested a review December 12, 2022 14:36
@tomasstrba tomasstrba self-assigned this Dec 12, 2022
Copy link
Contributor

@tomasstrba tomasstrba left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

@tomasstrba tomasstrba assigned mallexxx and unassigned tomasstrba Dec 13, 2022
@mallexxx mallexxx changed the title [navigation] SERP headers navigation responder ✅ [navigation] SERP headers navigation responder Dec 13, 2022
@mallexxx mallexxx changed the title ✅ [navigation] SERP headers navigation responder ✅ [#3 navigation] SERP headers navigation responder Feb 3, 2023
@mallexxx mallexxx changed the title ✅ [#3 navigation] SERP headers navigation responder ✅ [navigation #3] SERP headers navigation responder Feb 3, 2023
@mallexxx mallexxx changed the title ✅ [navigation #3] SERP headers navigation responder [navigation #3] SERP headers navigation responder Feb 6, 2023
@mallexxx mallexxx changed the title [navigation #3] SERP headers navigation responder [navigation #4] SERP headers navigation responder Feb 7, 2023
@mallexxx mallexxx changed the base branch from alex/navigation/adclick to alex/gobackforward-republished February 7, 2023 09:03
@mallexxx mallexxx assigned tomasstrba and unassigned mallexxx Feb 7, 2023
Copy link
Contributor

@tomasstrba tomasstrba left a comment

Choose a reason for hiding this comment

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

@mallexxx, I am getting an assertion right after I run the app. Let me know if I am doing something wrong or you can't reproduce it.

Screenshot 2023-02-08 at 10 18 09 AM

The code looks good, I like the code coverage 🥇 . I just added few notes below.


func decidePolicy(for navigationAction: NavigationAction, preferences: inout NavigationPreferences) async -> NavigationActionPolicy? {
guard let mainFrame = navigationAction.mainFrameTarget,
navigationAction.url.isDuckDuckGo,
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to speed things up, do you think it makes sense to have navigationAction.url.isDuckDuckGo as first condition?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don‘t think it makes sense since the main frame check is actually faster than comparing strings, but it‘s microoptimization anyways

Copy link
Contributor

Choose a reason for hiding this comment

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

The main frame check is definitely faster, but useless for 99 percent of request since the URL isn't duckduckgo.com. Anyway, I don't mind leaving it as it is.


print(url)
tab.setContent(.url(url))
waitForExpectations(timeout: 50)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to use a lower value than 50?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

forgotten test value 🙄


override func setUp() {
// disable waiting for CBR compilation on navigation
MockPrivacyConfiguration.isFeatureKeyEnabled = { _, _ in
Copy link
Contributor

Choose a reason for hiding this comment

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

I know it isn't the scope of this PR, but why is MockPrivacyConfiguration global? I am afraid it breaks the encapsulation of unit tests

@MainActor
func testOnDDGRequest_headersAdded() {
var onNavAction: (@MainActor (NavigationAction) -> NavigationActionPolicy?)!
TestTabExtensionsBuilder.shared = TestTabExtensionsBuilder(load: []) { builder in { _, _ in
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, the test uses TestTabExtensionsBuilder.shared, which is a global state. Can it be refactored to use an instance of TestTabExtensionsBuilder instead of static reference to TestTabExtensionsBuilder? It doesn't need to be refactored in this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed! 👍


let tab = Tab(content: .none, shouldLoadInBackground: true)

for child in Mirror(reflecting: urls).children.filter({ $0.label!.hasPrefix("ddg") }) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to refactor this to more readable variant by declaring two structs:

  • DDGUrls
  • NotDDGUrls
    ?

@tomasstrba tomasstrba assigned mallexxx and unassigned tomasstrba Feb 8, 2023
Copy link
Contributor

@tomasstrba tomasstrba left a comment

Choose a reason for hiding this comment

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

LGTM! 👍 Works like a charm! 👏

Do you plan to address the issue of accessing the global state from unit tests in future, or is this a final design?

@mallexxx
Copy link
Collaborator Author

mallexxx commented Feb 8, 2023

updated the PR cleaning up things

@mallexxx mallexxx merged commit ba59440 into alex/gobackforward-republished Feb 9, 2023
@mallexxx mallexxx deleted the alex/navigation/serp-headers branch February 9, 2023 15:37
mallexxx added a commit that referenced this pull request Feb 13, 2023
* canGoBack, canGoForward RePublished, Tab.publishers refactored

* redo redirect(_:NavigationAction, invalidatingBackItemIfNeeded)

* tests

* don‘t use shared state in tests

* fix RELEASE

* rollback renaming

* drop RePublished

* fix header name

* [navigation #4] SERP headers navigation responder (#887)

* SERP headers handling in SerpHeadersNavigationResponder
mallexxx added a commit that referenced this pull request Feb 13, 2023
* AdClickAttributionTabExtension+NavigationResponder

* fix TabExtension test overrides, adClick extension tests

* fix AdClickAttributionTabExtensionTests teardown

* cleanup

* don‘t use shared state in tests

* fix adClick inherited attribution initialization

* cleanup

* Adjust adClick tests to better match UserScripts/UserContentController behaviour; cleanup

* fix RELEASE

* remove Swifter dependency

* fix file header

* [navigation #3+4] canGoBack/GoForward; SERP headers (#885)

* canGoBack, canGoForward RePublished, Tab.publishers refactored

* redo redirect(_:NavigationAction, invalidatingBackItemIfNeeded)

* tests

* don‘t use shared state in tests

* fix RELEASE

* rollback renaming

* drop RePublished

* fix header name

* [navigation #4] SERP headers navigation responder (#887)

* SERP headers handling in SerpHeadersNavigationResponder

* convert TabTests to custom SchemeHandler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants