From 942341238b4ed5dcaa81cdc0652d566949b18b6c Mon Sep 17 00:00:00 2001 From: Mark Pilgrim Date: Fri, 2 Nov 2018 13:50:03 -0400 Subject: [PATCH] Disable network time tracker Fixes https://github.com/brave/brave-browser/issues/1971 --- .../network_time_tracker_unittest.cc | 76 +++++++++++++++++++ ...network_time-network_time_tracker.cc.patch | 13 ++++ 2 files changed, 89 insertions(+) create mode 100644 components/network_time/network_time_tracker_unittest.cc create mode 100644 patches/components-network_time-network_time_tracker.cc.patch diff --git a/components/network_time/network_time_tracker_unittest.cc b/components/network_time/network_time_tracker_unittest.cc new file mode 100644 index 000000000000..d1ed2e35b18d --- /dev/null +++ b/components/network_time/network_time_tracker_unittest.cc @@ -0,0 +1,76 @@ +#include "components/network_time/network_time_tracker.h" + +#include +#include +#include + +#include "base/compiler_specific.h" +#include "base/message_loop/message_loop.h" +#include "base/run_loop.h" +#include "base/strings/stringprintf.h" +#include "base/test/bind_test_util.h" +#include "base/test/scoped_task_environment.h" +#include "base/test/simple_test_clock.h" +#include "base/test/simple_test_tick_clock.h" +#include "components/client_update_protocol/ecdsa.h" +#include "components/network_time/network_time_pref_names.h" +#include "components/network_time/network_time_test_utils.h" +#include "components/prefs/testing_pref_service.h" +#include "net/http/http_response_headers.h" +#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h" +#include "services/network/test/test_url_loader_factory.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace network_time { + +class NetworkTimeTrackerTest : public ::testing::Test { + public: + ~NetworkTimeTrackerTest() override {} + + NetworkTimeTrackerTest() + : task_environment_( + base::test::ScopedTaskEnvironment::MainThreadType::IO), + clock_(new base::SimpleTestClock), + tick_clock_(new base::SimpleTestTickClock), + test_shared_loader_factory_( + base::MakeRefCounted( + &test_url_loader_factory_)) { + NetworkTimeTracker::RegisterPrefs(pref_service_.registry()); + tracker_.reset(new NetworkTimeTracker( + std::unique_ptr(clock_), + std::unique_ptr(tick_clock_), &pref_service_, + shared_url_loader_factory())); + } + +protected: + scoped_refptr shared_url_loader_factory() { + return test_shared_loader_factory_; + } + network::TestURLLoaderFactory* test_url_loader_factory() { + return &test_url_loader_factory_; + } + + base::test::ScopedTaskEnvironment task_environment_; + base::SimpleTestClock* clock_; + base::SimpleTestTickClock* tick_clock_; + TestingPrefServiceSimple pref_service_; + std::unique_ptr tracker_; + network::TestURLLoaderFactory test_url_loader_factory_; + scoped_refptr test_shared_loader_factory_; +}; + +TEST_F(NetworkTimeTrackerTest, Disabled) { + EXPECT_FALSE(tracker_->AreTimeFetchesEnabled()); +} + +TEST_F(NetworkTimeTrackerTest, NoFetch) { + bool network_access_occurred = false; + test_url_loader_factory()->SetInterceptor( + base::BindLambdaForTesting([&](const network::ResourceRequest& request) { + network_access_occurred = true; + })); + tracker_->QueryTimeServiceForTesting(); + EXPECT_FALSE(network_access_occurred); +} + +} // namespace network_time diff --git a/patches/components-network_time-network_time_tracker.cc.patch b/patches/components-network_time-network_time_tracker.cc.patch new file mode 100644 index 000000000000..413c41b1bfb3 --- /dev/null +++ b/patches/components-network_time-network_time_tracker.cc.patch @@ -0,0 +1,13 @@ +diff --git a/components/network_time/network_time_tracker.cc b/components/network_time/network_time_tracker.cc +index 34386ad169f8..ab8efddc9794 100644 +--- a/components/network_time/network_time_tracker.cc ++++ b/components/network_time/network_time_tracker.cc +@@ -277,7 +277,7 @@ void NetworkTimeTracker::UpdateNetworkTime(base::Time network_time, + } + + bool NetworkTimeTracker::AreTimeFetchesEnabled() const { +- return base::FeatureList::IsEnabled(kNetworkTimeServiceQuerying); ++ return false; // feature disabled in Brave + } + + NetworkTimeTracker::FetchBehavior NetworkTimeTracker::GetFetchBehavior() const {