Skip to content

Commit

Permalink
Refactor more tests after rebase.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Efremov committed Oct 14, 2019
1 parent 13a18cd commit ad7a139
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 55 deletions.
50 changes: 10 additions & 40 deletions browser/net/brave_block_safebrowsing_urls_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,53 +10,25 @@
#include <vector>

#include "brave/browser/net/url_context.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#include "url/url_constants.h"

namespace {

const char kInvalidUrl[] = "https://no-thanks.invalid";
} // namespace

class BraveBlockReportingUrlsHelperTest : public testing::Test {
public:
BraveBlockReportingUrlsHelperTest()
: thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
context_(new net::TestURLRequestContext(true)) {}
~BraveBlockReportingUrlsHelperTest() override {}
void SetUp() override { context_->Init(); }
net::TestURLRequestContext* context() { return context_.get(); }
void CheckUrl(const std::string& test_url,
const char* expected_url,
int expected_error);

private:
content::TestBrowserThreadBundle thread_bundle_;
std::unique_ptr<net::TestURLRequestContext> context_;
};

void BraveBlockReportingUrlsHelperTest::CheckUrl(const std::string& test_url,
const char* expected_url,
int expected_error) {
net::TestDelegate test_delegate;
GURL url(test_url);
std::unique_ptr<net::URLRequest> request = context()->CreateRequest(
url, net::IDLE, &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS);
std::shared_ptr<brave::BraveRequestInfo> before_url_context(
new brave::BraveRequestInfo());
brave::BraveRequestInfo::FillCTXFromRequest(request.get(),
before_url_context);
brave::ResponseCallback callback;
void CheckUrl(const std::string& test_url,
const char* expected_url,
int expected_error) {
GURL new_url;
int ret =
brave::OnBeforeURLRequest_BlockSafeBrowsingReportingURLs(url, &new_url);
int rc = brave::OnBeforeURLRequest_BlockSafeBrowsingReportingURLs(
GURL(test_url), &new_url);
EXPECT_EQ(new_url, GURL(expected_url));
EXPECT_EQ(ret, expected_error);
EXPECT_EQ(rc, expected_error);
}

TEST_F(BraveBlockReportingUrlsHelperTest, PreserveNormalUrls) {
TEST(BraveBlockReportingUrlsHelperTest, PreserveNormalUrls) {
const std::vector<const std::string> normalUrls({
"https://brave.com/",
"https://safebrowsing.google.com/safebrowsing",
Expand All @@ -68,7 +40,7 @@ TEST_F(BraveBlockReportingUrlsHelperTest, PreserveNormalUrls) {
}
}

TEST_F(BraveBlockReportingUrlsHelperTest, CancelReportingUrl) {
TEST(BraveBlockReportingUrlsHelperTest, CancelReportingUrl) {
const std::vector<const std::string> reportingUrls({
"https://sb-ssl.google.com/safebrowsing/clientreport/download",
"https://sb-ssl.google.com/safebrowsing/clientreport/chrome-reset",
Expand All @@ -87,5 +59,3 @@ TEST_F(BraveBlockReportingUrlsHelperTest, CancelReportingUrl) {
CheckUrl(url, kInvalidUrl, net::ERR_ABORTED);
}
}

} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -211,21 +211,23 @@ TEST(BraveStaticRedirectNetworkDelegateHelperTest, ModifySafeBrowsingURLV5) {
// TODO(@fmarier): Re-enable download protection once we have
// truncated the list of metadata that it sends to the server
// (brave/brave-browser#6267).
//TEST(BraveStaticRedirectNetworkDelegateHelperTest,
// ModifySafeBrowsingFileCheckURL) {
// const GURL url(
// "https://sb-ssl.google.com/safebrowsing/clientreport/download?"
// "key=DUMMY_KEY");
// GURL expected_url(
// "https://sb-ssl.brave.com/safebrowsing/clientreport/download?"
// "key=DUMMY_KEY");

// auto request_info = std::make_shared<brave::BraveRequestInfo>(url);
// int rc =
// OnBeforeURLRequest_StaticRedirectWork(ResponseCallback(), request_info);
// EXPECT_EQ(request_info->new_url_spec, expected_url);
// EXPECT_EQ(rc, net::OK);
//}
#if 0
TEST(BraveStaticRedirectNetworkDelegateHelperTest,
ModifySafeBrowsingFileCheckURL) {
const GURL url(
"https://sb-ssl.google.com/safebrowsing/clientreport/download?"
"key=DUMMY_KEY");
GURL expected_url(
"https://sb-ssl.brave.com/safebrowsing/clientreport/download?"
"key=DUMMY_KEY");

auto request_info = std::make_shared<brave::BraveRequestInfo>(url);
int rc =
OnBeforeURLRequest_StaticRedirectWork(ResponseCallback(), request_info);
EXPECT_EQ(request_info->new_url_spec, expected_url);
EXPECT_EQ(rc, net::OK);
}
#endif // 0

#if BUILDFLAG(ENABLE_BRAVE_TRANSLATE_GO)
TEST(BraveStaticRedirectNetworkDelegateHelperTest, RedirectTranslate) {
Expand Down

0 comments on commit ad7a139

Please sign in to comment.