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

Add HTTPSEverywhereService test #74

Merged
merged 2 commits into from
Mar 28, 2018
Merged

Add HTTPSEverywhereService test #74

merged 2 commits into from
Mar 28, 2018

Conversation

bbondy
Copy link
Member

@bbondy bbondy commented Mar 27, 2018

This adds 2 browser tests to ensure HTTPS Everywhere is working:

  1. Load a URL which has an HTTPSE rule and verify we rewrote it.
  2. Load a URL which has no HTTPSE rule and verify we did not rewrite it.

In addition this also refactors HTTPSEverywhereService to be a singleton.

Fix brave/brave-browser#99

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).

Test Plan:

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Adequate test coverage exists to prevent regressions

@bbondy bbondy self-assigned this Mar 27, 2018
@bbondy bbondy requested a review from garrettr March 27, 2018 20:45
@bbondy bbondy requested a review from simonhong March 28, 2018 01:47
@@ -38,12 +43,20 @@ class HTTPSEverywhereService : public BaseBraveShieldsService {
public:
HTTPSEverywhereService();
~HTTPSEverywhereService() override;

static HTTPSEverywhereService* GetInstance();

Copy link
Member

Choose a reason for hiding this comment

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

We can remove line 77 and its implementation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, will do if we keep the singleton depending on your answer above.

https_everywhere_service_ =
brave_shields::HTTPSEverywhereServiceFactory();
return https_everywhere_service_.get();
return brave_shields::HTTPSEverywhereService::GetInstance();
Copy link
Member

Choose a reason for hiding this comment

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

Q) Why do you want to use HTTPSEverywhereService as singleton?
In general, singleton is hard to determine its lifetime.
If there is no reason about that, making BraveBrowserProcessImpl control its lifetime seems fine.

Copy link
Member

Choose a reason for hiding this comment

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

Ah.. I assume that the reason is you want to test its internal state right?
If so, how about using g_browser_process?
With that, you can get HTTPSEverywhereService pointer from it by BraveBrowserProcessImpl casting.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there a case where we need to destroy or control its lifetime? Mainly it was just because there was a TODO in the SafeBrowsingService to make it a singleton in the last version of Chrome when this was implemented. The comment seems removed now but it also seems to hand roll a singleton now for it. I thought this service was most close to that.

Copy link
Member Author

Choose a reason for hiding this comment

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

We have g_browser_process readily available for that btw. No it was really just to resolve a TODO comment that the SafeBrowsingService had and these were similar to. I have no strong feelings though so I can drop that commit.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry I meant to say, we have g_brave_browser_process readily available for that.

bool GetHTTPSURL(const GURL* url, const uint64_t& request_id,
std::string& new_url);
bool GetHTTPSURLFromCacheOnly(const GURL* url,
const uint64_t& request_id, std::string& cached_url);

// Useful for tests to customize
static GURL g_https_everywhere_url;
Copy link
Member

@simonhong simonhong Mar 28, 2018

Choose a reason for hiding this comment

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

How about moving this to private section and add test class as a friend?
In general(in chromium), friend class is used to access/modify private member from test class.
For more clear, how about using SetHttpsEveryWhereURLForTest()?
Or, if we should use it in ctor, how about passing it as an argument?

Copy link
Member

Choose a reason for hiding this comment

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

Ah.. I see. you used static member because it's hard to change it during the test process initialization.
Ignore my previous comment about passing as an argument.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good suggestions, will do.

@bbondy bbondy force-pushed the httpse-tests branch 4 times, most recently from 00dcd94 to 97646c4 Compare March 28, 2018 03:56
simonhong
simonhong previously approved these changes Mar 28, 2018
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 with nits

return base::Singleton<AdBlockService>::get();
// The brave shields factory. Using the Brave Shields as a singleton
// is the job of the browser process.
// TODO(bbondy): consider making this a singleton.
Copy link
Member

Choose a reason for hiding this comment

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

nit: comment should be changed.

g_https_everywhere_url = url;
}


Copy link
Member

Choose a reason for hiding this comment

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

nit: two blank line

@@ -54,6 +56,9 @@ class HTTPSEverywhereService : public BaseBraveShieldsService {
std::string CorrecttoRuleToRE2Engine(const std::string& to);

private:
friend class ::HTTPSEverywhereServiceTest;
static GURL g_https_everywhere_url;
static void SetHttpsEveryWhereURLForTest(const GURL& url);
Copy link
Member

Choose a reason for hiding this comment

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

nit: need one blank line below.

@bbondy
Copy link
Member Author

bbondy commented Mar 28, 2018

Pushed out the nits, thanks for the review.

@bbondy bbondy merged commit f978d16 into master Mar 28, 2018
@bsclifton bsclifton deleted the httpse-tests branch June 18, 2018 06:29
NejcZdovc added a commit that referenced this pull request Dec 10, 2018
Adds support for get all reports
bbondy pushed a commit that referenced this pull request Feb 18, 2019
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.

2 participants