Skip to content

Commit

Permalink
Fix Web Discovery Android test
Browse files Browse the repository at this point in the history
  • Loading branch information
DJAndries committed Jul 4, 2024
1 parent a81304d commit fad93bf
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
1 change: 0 additions & 1 deletion browser/sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ brave_chrome_browser_deps = [
"//brave/components/speedreader/common/buildflags",
"//brave/components/tor/buildflags",
"//brave/components/version_info",
"//brave/components/web_discovery/browser",
"//brave/components/web_discovery/common",
"//brave/components/web_discovery/common/buildflags",
"//brave/components/webcompat:core",
Expand Down
6 changes: 1 addition & 5 deletions components/web_discovery/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,11 @@ source_set("browser_tests") {
"//brave/components/constants",
"//brave/components/web_discovery/common",
"//brave/components/web_discovery/common:mojom",
"//chrome/test:test_support",
"//content/test:test_support",
"//net:test_support",
"//services/service_manager/public/cpp",
"//testing/gtest",
]
if (!is_android) {
deps += [ "//chrome/test:test_support_ui" ]
} else {
deps += [ "//chrome/test:test_support_ui_android" ]
}
defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ]
}
40 changes: 33 additions & 7 deletions components/web_discovery/browser/content_scraper_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@
#include "base/files/file_util.h"
#include "base/path_service.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "brave/components/constants/brave_paths.h"
#include "brave/components/web_discovery/browser/patterns.h"
#include "brave/components/web_discovery/browser/server_config_loader.h"
#include "brave/components/web_discovery/common/features.h"
#include "brave/components/web_discovery/common/web_discovery.mojom.h"
#include "chrome/test/base/ui_test_utils.h"
#include "chrome/test/base/chrome_test_utils.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_base.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_mock_cert_verifier.h"
#include "net/dns/mock_host_resolver.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "testing/gtest/include/gtest/gtest.h"
Expand All @@ -36,16 +41,18 @@ class WebDiscoveryContentScraperTest : public PlatformBrowserTest {
public:
WebDiscoveryContentScraperTest()
: scoped_features_(features::kWebDiscoveryNative) {}

// PlatformBrowserTest:
void SetUpOnMainThread() override {
InProcessBrowserTest::SetUpOnMainThread();
PlatformBrowserTest::SetUpOnMainThread();
base::FilePath data_path =
base::PathService::CheckedGet(brave::DIR_TEST_DATA);
data_path = data_path.AppendASCII("web_discovery");

host_resolver()->AddRule("*", "127.0.0.1");
auto& test_server = embedded_https_test_server();
test_server.ServeFilesFromDirectory(data_path);
ASSERT_TRUE(test_server.Start());
test_server_.ServeFilesFromDirectory(data_path);
mock_cert_verifier_.mock_cert_verifier()->set_default_result(net::OK);
ASSERT_TRUE(test_server_.Start());

InitScraper();
run_loop_ = std::make_unique<base::RunLoop>();
Expand All @@ -54,12 +61,29 @@ class WebDiscoveryContentScraperTest : public PlatformBrowserTest {
&page_content_));
}

void SetUpCommandLine(base::CommandLine* command_line) override {
PlatformBrowserTest::SetUpCommandLine(command_line);
mock_cert_verifier_.SetUpCommandLine(command_line);
}

void SetUpInProcessBrowserTestFixture() override {
PlatformBrowserTest::SetUpInProcessBrowserTestFixture();
mock_cert_verifier_.SetUpInProcessBrowserTestFixture();
}

void TearDownInProcessBrowserTestFixture() override {
mock_cert_verifier_.TearDownInProcessBrowserTestFixture();
PlatformBrowserTest::TearDownInProcessBrowserTestFixture();
}

protected:
mojo::Remote<mojom::DocumentExtractor> LoadTestPageAndGetExtractor() {
mojo::Remote<mojom::DocumentExtractor> remote;

auto url = embedded_https_test_server().GetURL("example.com", "/page.html");
auto* render_frame_host = ui_test_utils::NavigateToURL(browser(), url);
auto url = test_server_.GetURL("example.com", "/page.html");
auto* contents = chrome_test_utils::GetActiveWebContents(this);
EXPECT_TRUE(content::NavigateToURL(contents, url));
auto* render_frame_host = contents->GetPrimaryMainFrame();

if (render_frame_host) {
render_frame_host->GetRemoteInterfaces()->GetInterface(
Expand Down Expand Up @@ -148,6 +172,8 @@ class WebDiscoveryContentScraperTest : public PlatformBrowserTest {
&regex_util_);
}

content::ContentMockCertVerifier mock_cert_verifier_;
net::EmbeddedTestServer test_server_{net::EmbeddedTestServer::TYPE_HTTPS};
base::test::ScopedFeatureList scoped_features_;
RegexUtil regex_util_;
std::unique_ptr<ServerConfigLoader> server_config_loader_;
Expand Down
1 change: 0 additions & 1 deletion test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,6 @@ test("brave_browser_tests") {
"//brave/components/speedreader/common/buildflags",
"//brave/components/tor/buildflags",
"//brave/components/url_sanitizer/browser",
"//brave/components/web_discovery/browser:browser_tests",
"//brave/components/webcompat:core",
"//brave/renderer/skus:browser_tests",
"//brave/renderer/test:browser_tests",
Expand Down

0 comments on commit fad93bf

Please sign in to comment.