Remove ScopedTaskEnvironment from NetTestSuite.
Remove global ScopedTaskEnvironment instance that lives across all of
net_unittests. Add a local variable or test fixture member to whichever
test would crash/fail without that. Change type from default to IO
for whichever test would crash/fail without that.
In some cases, like HttpServerPropertiesManagerTest, make member private
and add protected accessors. In most other cases make member protected
and access directly from tests. I was mostly doing this by occurrence,
and I'm happy to change any test in either direction.
I made scoped_task_environment_ the last member unless it was necessary
to construct it before the constructor of some other members. I
generally made it a private member, unless it is manipulated from a test
and I was too lazy to write an accessor, or unless it needed to be
created before other, non-private members, because I did not feel like
the ugliness of multiple alternating private and protected sections is
justified. I'm happy to change this is necessary.
Bug: 791831
Change-Id: I578690820c07264372cff9dbd8bd9c944c243ba8
Reviewed-on: https://chromium-review.googlesource.com/1037405
Commit-Queue: Bence Béky <[email protected]>
Reviewed-by: Helen Li <[email protected]>
Cr-Commit-Position: refs/heads/master@{#556667}
diff --git a/net/disk_cache/disk_cache_test_base.h b/net/disk_cache/disk_cache_test_base.h
index 64e7e4e..ced13dbe 100644
--- a/net/disk_cache/disk_cache_test_base.h
+++ b/net/disk_cache/disk_cache_test_base.h
@@ -15,17 +15,10 @@
#include "base/threading/thread.h"
#include "net/base/cache_type.h"
#include "net/disk_cache/disk_cache.h"
+#include "net/test/test_with_scoped_task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
-namespace base {
-namespace test {
-
-class ScopedTaskEnvironment;
-
-} // namespace test
-} // namespace base
-
namespace net {
class IOBuffer;
@@ -47,7 +40,8 @@
// Mac, so this needs to be a PlatformTest. Even tests that do not require a
// cache (and that do not need to be a DiskCacheTestWithCache) are susceptible
// to this problem; all such tests should use TEST_F(DiskCacheTest, ...).
-class DiskCacheTest : public PlatformTest {
+class DiskCacheTest : public PlatformTest,
+ public net::WithScopedTaskEnvironment {
protected:
DiskCacheTest();
~DiskCacheTest() override;
@@ -81,13 +75,7 @@
std::unique_ptr<disk_cache::Backend::Iterator> iterator_;
};
- // Assumes NetTestSuite is available.
DiskCacheTestWithCache();
-
- // Does not take ownership of |scoped_task_env|, and will not use it past
- // TearDown(). Does not require NetTestSuite.
- explicit DiskCacheTestWithCache(
- base::test::ScopedTaskEnvironment* scoped_task_env);
~DiskCacheTestWithCache() override;
void CreateBackend(uint32_t flags);
@@ -182,7 +170,6 @@
// before and after this method will not be the same.
void AddDelay();
- // DiskCacheTest:
void TearDown() override;
// cache_ will always have a valid object, regardless of how the cache was
@@ -210,7 +197,6 @@
private:
void InitMemoryCache();
void InitDiskCache();
- base::test::ScopedTaskEnvironment* scoped_task_env_;
DISALLOW_COPY_AND_ASSIGN(DiskCacheTestWithCache);
};