Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(841)

Unified Diff: net/http/http_server_properties_manager_unittest.cc

Issue 2563273002: Change the net_task_runner to use a TestMockTimeTaskRunner in unittests so that (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/http_server_properties_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_server_properties_manager_unittest.cc
diff --git a/net/http/http_server_properties_manager_unittest.cc b/net/http/http_server_properties_manager_unittest.cc
index 97b5a249984a528b74cf243bd41bf4d882e02059..93be7453b1b3deffd29e20234c5f37d63b56ca20 100644
--- a/net/http/http_server_properties_manager_unittest.cc
+++ b/net/http/http_server_properties_manager_unittest.cc
@@ -16,6 +16,7 @@
#include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
+#include "base/test/test_mock_time_task_runner.h"
#include "base/test/test_simple_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/values.h"
@@ -26,9 +27,20 @@
namespace net {
+class HttpServerPropertiesManagerPeer {
+ public:
+ static void SetNetworkTaskRunnerForTimer(
+ HttpServerPropertiesManager* manager,
+ scoped_refptr<base::SingleThreadTaskRunner> network_task_runner) {
+ manager->network_prefs_update_timer_->SetTaskRunner(
+ std::move(network_task_runner));
+ }
+};
+
namespace {
using base::StringPrintf;
+using base::TestMockTimeTaskRunner;
using ::testing::_;
using ::testing::Invoke;
using ::testing::Mock;
@@ -149,14 +161,20 @@ static const int kHttpServerPropertiesVersions[] = {3, 4, 5};
class HttpServerPropertiesManagerTest : public testing::TestWithParam<int> {
protected:
- HttpServerPropertiesManagerTest() {}
+ HttpServerPropertiesManagerTest()
+ : net_test_task_runner_(new TestMockTimeTaskRunner()) {}
void SetUp() override {
one_day_from_now_ = base::Time::Now() + base::TimeDelta::FromDays(1);
pref_delegate_ = new MockPrefDelegate;
http_server_props_manager_.reset(
new StrictMock<TestingHttpServerPropertiesManager>(
- pref_delegate_, base::ThreadTaskRunnerHandle::Get()));
+ pref_delegate_, net_test_task_runner_));
+ // Set up the network timer in manager to post tasks to
+ // |net_test_task_runner_|.
+ HttpServerPropertiesManagerPeer::SetNetworkTaskRunnerForTimer(
+ http_server_props_manager_.get(), net_test_task_runner_);
Ryan Hamilton 2016/12/11 19:36:57 Instead of doing this in the test, can you change
Zhongyi Shi 2016/12/12 05:08:39 Done.
+
ExpectCacheUpdate();
base::RunLoop().RunUntilIdle();
}
@@ -218,6 +236,7 @@ class HttpServerPropertiesManagerTest : public testing::TestWithParam<int> {
std::unique_ptr<TestingHttpServerPropertiesManager>
http_server_props_manager_;
base::Time one_day_from_now_;
+ scoped_refptr<TestMockTimeTaskRunner> net_test_task_runner_;
private:
DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest);
@@ -357,6 +376,8 @@ TEST_P(HttpServerPropertiesManagerTest,
pref_delegate_->SetPrefs(http_server_properties_dict);
base::RunLoop().RunUntilIdle();
Ryan Hamilton 2016/12/11 19:36:57 base::RunLoop().RunUntilIdle(); runs the main mess
Zhongyi Shi 2016/12/12 04:38:54 Yup. This is the pref's thread's runner. And in th
+ net_test_task_runner_->FastForwardUntilNoTasksRemain();
+
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
// Verify SupportsSpdy.
@@ -447,7 +468,7 @@ TEST_P(HttpServerPropertiesManagerTest,
TEST_P(HttpServerPropertiesManagerTest, BadCachedHostPortPair) {
ExpectCacheUpdate();
- // The prefs are automaticalls updated in the case corruption is detected.
+ // The prefs are automatically updated in the case corruption is detected.
ExpectPrefsUpdate();
ExpectScheduleUpdatePrefsOnNetworkThread();
@@ -509,6 +530,7 @@ TEST_P(HttpServerPropertiesManagerTest, BadCachedHostPortPair) {
pref_delegate_->SetPrefs(http_server_properties_dict);
base::RunLoop().RunUntilIdle();
+ net_test_task_runner_->FastForwardUntilNoTasksRemain();
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
// Verify that nothing is set.
@@ -528,7 +550,7 @@ TEST_P(HttpServerPropertiesManagerTest, BadCachedHostPortPair) {
TEST_P(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) {
ExpectCacheUpdate();
- // The prefs are automaticalls updated in the case corruption is detected.
+ // The prefs are automatically updated in the case corruption is detected.
ExpectPrefsUpdate();
ExpectScheduleUpdatePrefsOnNetworkThread();
@@ -573,6 +595,7 @@ TEST_P(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) {
pref_delegate_->SetPrefs(http_server_properties_dict);
base::RunLoop().RunUntilIdle();
+ net_test_task_runner_->FastForwardUntilNoTasksRemain();
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
// Verify alternative service is not set.
@@ -597,6 +620,7 @@ TEST_P(HttpServerPropertiesManagerTest, SupportsSpdy) {
// Run the task.
base::RunLoop().RunUntilIdle();
+ net_test_task_runner_->FastForwardUntilNoTasksRemain();
EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(spdy_server));
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
@@ -618,6 +642,8 @@ TEST_P(HttpServerPropertiesManagerTest, GetAlternativeServices) {
// Run the task.
base::RunLoop().RunUntilIdle();
+ net_test_task_runner_->FastForwardUntilNoTasksRemain();
+
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
AlternativeServiceVector alternative_service_vector =
@@ -649,6 +675,8 @@ TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServices) {
// Run the task.
base::RunLoop().RunUntilIdle();
+ net_test_task_runner_->FastForwardUntilNoTasksRemain();
+
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
AlternativeServiceVector alternative_service_vector =
@@ -712,6 +740,8 @@ TEST_P(HttpServerPropertiesManagerTest, ConfirmAlternativeService) {
// Run the task.
base::RunLoop().RunUntilIdle();
+ net_test_task_runner_->FastForwardUntilNoTasksRemain();
+
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
EXPECT_FALSE(http_server_props_manager_->IsAlternativeServiceBroken(
@@ -734,6 +764,8 @@ TEST_P(HttpServerPropertiesManagerTest, SupportsQuic) {
// Run the task.
base::RunLoop().RunUntilIdle();
+ net_test_task_runner_->FastForwardUntilNoTasksRemain();
+
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address));
@@ -756,6 +788,8 @@ TEST_P(HttpServerPropertiesManagerTest, ServerNetworkStats) {
// Run the task.
base::RunLoop().RunUntilIdle();
+ net_test_task_runner_->FastForwardUntilNoTasksRemain();
+
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
const ServerNetworkStats* stats2 =
@@ -779,6 +813,7 @@ TEST_P(HttpServerPropertiesManagerTest, QuicServerInfo) {
// Run the task.
base::RunLoop().RunUntilIdle();
+ net_test_task_runner_->FastForwardUntilNoTasksRemain();
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo(
@@ -807,6 +842,7 @@ TEST_P(HttpServerPropertiesManagerTest, Clear) {
// Run the task.
base::RunLoop().RunUntilIdle();
+ net_test_task_runner_->FastForwardUntilNoTasksRemain();
EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(spdy_server));
EXPECT_TRUE(HasAlternativeService(spdy_server));
@@ -912,6 +948,7 @@ TEST_P(HttpServerPropertiesManagerTest, BadSupportsQuic) {
pref_delegate_->SetPrefs(http_server_properties_dict);
base::RunLoop().RunUntilIdle();
+ net_test_task_runner_->FastForwardUntilNoTasksRemain();
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
// Verify alternative service.
@@ -983,6 +1020,7 @@ TEST_P(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) {
ExpectPrefsUpdate();
ExpectCacheUpdate();
http_server_props_manager_->ScheduleUpdateCacheOnPrefThread();
+ net_test_task_runner_->FastForwardUntilNoTasksRemain();
base::RunLoop().RunUntilIdle();
// Verify preferences.
@@ -1114,6 +1152,8 @@ TEST_P(HttpServerPropertiesManagerTest,
ExpectPrefsUpdate();
ExpectCacheUpdate();
http_server_props_manager_->ScheduleUpdateCacheOnPrefThread();
+
+ net_test_task_runner_->FastForwardUntilNoTasksRemain();
base::RunLoop().RunUntilIdle();
const base::DictionaryValue& pref_dict =
@@ -1241,6 +1281,7 @@ TEST_P(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdatePrefs1) {
// Shutdown comes before the task is executed.
http_server_props_manager_->ShutdownOnPrefThread();
// Run the task after shutdown, but before deletion.
+ net_test_task_runner_->FastForwardUntilNoTasksRemain();
base::RunLoop().RunUntilIdle();
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
http_server_props_manager_.reset();
« no previous file with comments | « net/http/http_server_properties_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698