Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable network time tracker #792

Merged
merged 1 commit into from
Nov 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions components/network_time/network_time_tracker_unittest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include "components/network_time/network_time_tracker.h"

#include <memory>
#include <string>
#include <utility>

#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<network::WeakWrapperSharedURLLoaderFactory>(
&test_url_loader_factory_)) {
NetworkTimeTracker::RegisterPrefs(pref_service_.registry());
tracker_.reset(new NetworkTimeTracker(
std::unique_ptr<base::Clock>(clock_),
std::unique_ptr<const base::TickClock>(tick_clock_), &pref_service_,
shared_url_loader_factory()));
}

protected:
scoped_refptr<network::SharedURLLoaderFactory> 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<NetworkTimeTracker> tracker_;
network::TestURLLoaderFactory test_url_loader_factory_;
scoped_refptr<network::SharedURLLoaderFactory> 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
13 changes: 13 additions & 0 deletions patches/components-network_time-network_time_tracker.cc.patch
Original file line number Diff line number Diff line change
@@ -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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty sure we could remove this patch by disabling the feature instead

+ return false; // feature disabled in Brave
}

NetworkTimeTracker::FetchBehavior NetworkTimeTracker::GetFetchBehavior() const {