Commit 2ebfa978 authored by Robbie McElrath's avatar Robbie McElrath Committed by Commit Bot

Fix network service crash when --log-net-log flag isn't valid

Bug: 931502
Change-Id: I081a32b007d9dad40007b04821548df9ae5c3619
Reviewed-on: https://chromium-review.googlesource.com/c/1471022
Commit-Queue: Robbie McElrath <rmcelrath@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#631997}
parent 14c38ce3
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "net/http/http_response_headers.h" #include "net/http/http_response_headers.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h" #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "services/network/public/cpp/features.h" #include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/network_switches.h"
#include "services/network/public/cpp/resource_request.h" #include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/simple_url_loader.h" #include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/network_service_test.mojom.h" #include "services/network/public/mojom/network_service_test.mojom.h"
...@@ -364,6 +365,39 @@ IN_PROC_BROWSER_TEST_F(NetworkServiceInProcessBrowserTest, Basic) { ...@@ -364,6 +365,39 @@ IN_PROC_BROWSER_TEST_F(NetworkServiceInProcessBrowserTest, Basic) {
LoadBasicRequest(partition->GetNetworkContext(), test_url)); LoadBasicRequest(partition->GetNetworkContext(), test_url));
} }
class NetworkServiceInvalidLogBrowserTest : public ContentBrowserTest {
public:
NetworkServiceInvalidLogBrowserTest() {
scoped_feature_list_.InitAndEnableFeature(
network::features::kNetworkService);
}
void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitchASCII(network::switches::kLogNetLog, "/abc/def");
}
void SetUpOnMainThread() override {
host_resolver()->AddRule("*", "127.0.0.1");
EXPECT_TRUE(embedded_test_server()->Start());
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(NetworkServiceInvalidLogBrowserTest);
};
// Verifies that an invalid --log-net-log flag won't crash the browser.
IN_PROC_BROWSER_TEST_F(NetworkServiceInvalidLogBrowserTest, Basic) {
GURL test_url = embedded_test_server()->GetURL("foo.com", "/echo");
StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
BrowserContext::GetDefaultStoragePartition(
shell()->web_contents()->GetBrowserContext()));
NavigateToURL(shell(), test_url);
ASSERT_EQ(net::OK,
LoadBasicRequest(partition->GetNetworkContext(), test_url));
}
} // namespace } // namespace
} // namespace content } // namespace content
...@@ -129,14 +129,15 @@ CONTENT_EXPORT network::mojom::NetworkService* GetNetworkServiceFromConnector( ...@@ -129,14 +129,15 @@ CONTENT_EXPORT network::mojom::NetworkService* GetNetworkServiceFromConnector(
base::File file(log_path, base::File::FLAG_CREATE_ALWAYS | base::File file(log_path, base::File::FLAG_CREATE_ALWAYS |
base::File::FLAG_WRITE); base::File::FLAG_WRITE);
LOG_IF(ERROR, !file.IsValid()) if (!file.IsValid()) {
<< "Failed opening: " << log_path.value(); LOG(ERROR) << "Failed opening: " << log_path.value();
} else {
// TODO(mmenke): Get capture mode from the command line. // TODO(mmenke): Get capture mode from the command line.
(*g_network_service_ptr) (*g_network_service_ptr)
->StartNetLog(std::move(file), ->StartNetLog(std::move(file),
network::mojom::NetLogCaptureMode::DEFAULT, network::mojom::NetLogCaptureMode::DEFAULT,
std::move(client_constants)); std::move(client_constants));
}
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment