-
Notifications
You must be signed in to change notification settings - Fork 921
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
Conversation
@@ -38,12 +43,20 @@ class HTTPSEverywhereService : public BaseBraveShieldsService { | |||
public: | |||
HTTPSEverywhereService(); | |||
~HTTPSEverywhereService() override; | |||
|
|||
static HTTPSEverywhereService* GetInstance(); | |||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestions, will do.
00dcd94
to
97646c4
Compare
There was a problem hiding this 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. |
There was a problem hiding this comment.
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; | ||
} | ||
|
||
|
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
Pushed out the nits, thanks for the review. |
Adds support for get all reports
This adds 2 browser tests to ensure HTTPS Everywhere is working:
In addition this also refactors HTTPSEverywhereService to be a singleton.
Fix brave/brave-browser#99
Submitter Checklist:
Test Plan:
Reviewer Checklist: