Commit 2b9260e4 authored by Eric Roman's avatar Eric Roman Committed by Commit Bot

Fix --log-net-log when Network Service is enabled.

Bug: 894801
Change-Id: Ieb17a626284296b6f86f4cf9add2fca4359f7d8a
Reviewed-on: https://chromium-review.googlesource.com/c/1285649
Commit-Queue: Eric Roman <eroman@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600592}
parent 5fdb8d79
...@@ -138,6 +138,7 @@ ...@@ -138,6 +138,7 @@
#include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_context_getter.h"
#include "ppapi/buildflags/buildflags.h" #include "ppapi/buildflags/buildflags.h"
#include "printing/buildflags/buildflags.h" #include "printing/buildflags/buildflags.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/network_switches.h" #include "services/network/public/cpp/network_switches.h"
#include "services/preferences/public/cpp/in_process_service_factory.h" #include "services/preferences/public/cpp/in_process_service_factory.h"
#include "ui/base/idle/idle.h" #include "ui/base/idle/idle.h"
...@@ -1147,7 +1148,8 @@ void BrowserProcessImpl::PreCreateThreads( ...@@ -1147,7 +1148,8 @@ void BrowserProcessImpl::PreCreateThreads(
extensions::kExtensionScheme, true); extensions::kExtensionScheme, true);
#endif #endif
if (command_line.HasSwitch(network::switches::kLogNetLog)) { if (command_line.HasSwitch(network::switches::kLogNetLog) &&
!base::FeatureList::IsEnabled(network::features::kNetworkService)) {
base::FilePath log_file = base::FilePath log_file =
command_line.GetSwitchValuePath(network::switches::kLogNetLog); command_line.GetSwitchValuePath(network::switches::kLogNetLog);
if (log_file.empty()) { if (log_file.empty()) {
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/json/json_reader.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "services/network/public/cpp/network_switches.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace chrome_browser_net {
namespace {
// Tests for the --log-net-log command line flag.
class LogNetLogTest : public InProcessBrowserTest {
public:
void SetUpCommandLine(base::CommandLine* command_line) override {
ASSERT_TRUE(tmp_dir_.CreateUniqueTempDir());
net_log_path_ = tmp_dir_.GetPath().AppendASCII("netlog.json");
command_line->AppendSwitchPath(network::switches::kLogNetLog,
net_log_path_);
}
void TearDownInProcessBrowserTestFixture() override { VerifyNetLog(); }
// Verify that the netlog file was written and appears to be well formed.
void VerifyNetLog() {
// Read the netlog from disk.
std::string file_contents;
ASSERT_TRUE(base::ReadFileToString(net_log_path_, &file_contents))
<< "Could not read: " << net_log_path_;
// Parse it as JSON.
auto parsed = base::JSONReader::Read(file_contents);
ASSERT_TRUE(parsed);
// Ensure the root value is a dictionary.
base::DictionaryValue* main;
ASSERT_TRUE(parsed->GetAsDictionary(&main));
// Ensure it has a "constants" property.
base::DictionaryValue* constants;
ASSERT_TRUE(main->GetDictionary("constants", &constants));
ASSERT_FALSE(constants->empty());
// Ensure it has an "events" property.
base::ListValue* events;
ASSERT_TRUE(main->GetList("events", &events));
ASSERT_FALSE(events->empty());
}
base::FilePath net_log_path_;
base::ScopedTempDir tmp_dir_;
};
IN_PROC_BROWSER_TEST_F(LogNetLogTest, Basic) {
// Do an action that will result in the output of netlog events. This isn't
// strictly necessary since there is other networking that will happen
// implicitly to generate events.
ui_test_utils::NavigateToURL(browser(), GURL("http://127.0.0.1/foo"));
}
} // namespace
} // namespace chrome_browser_net
...@@ -663,6 +663,7 @@ test("browser_tests") { ...@@ -663,6 +663,7 @@ test("browser_tests") {
"../browser/net/errorpage_browsertest.cc", "../browser/net/errorpage_browsertest.cc",
"../browser/net/ftp_browsertest.cc", "../browser/net/ftp_browsertest.cc",
"../browser/net/load_timing_browsertest.cc", "../browser/net/load_timing_browsertest.cc",
"../browser/net/log_net_log_browsertest.cc",
"../browser/net/netinfo_network_quality_estimator_holdback_browsertest.cc", "../browser/net/netinfo_network_quality_estimator_holdback_browsertest.cc",
"../browser/net/network_connection_tracker_browsertest.cc", "../browser/net/network_connection_tracker_browsertest.cc",
"../browser/net/network_context_configuration_browsertest.cc", "../browser/net/network_context_configuration_browsertest.cc",
......
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