task_test_base.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_OFFLINE_PAGES_TASK_TASK_TEST_BASE_H_
  5. #define COMPONENTS_OFFLINE_PAGES_TASK_TASK_TEST_BASE_H_
  6. #include "base/test/task_environment.h"
  7. #include "components/offline_pages/task/task.h"
  8. #include "testing/gtest/include/gtest/gtest.h"
  9. namespace offline_pages {
  10. // Base class for testing prefetch requests with simulated responses.
  11. class TaskTestBase : public testing::Test {
  12. public:
  13. TaskTestBase();
  14. ~TaskTestBase() override;
  15. void SetUp() override;
  16. void TearDown() override;
  17. // Runs task with expectation that it correctly completes.
  18. // Task is also cleaned up after completing.
  19. void RunTask(std::unique_ptr<Task> task);
  20. // Runs task with expectation that it correctly completes.
  21. // Task is not cleaned up after completing.
  22. void RunTask(Task* task);
  23. void RunUntilIdle();
  24. void FastForwardBy(base::TimeDelta delta);
  25. scoped_refptr<base::SingleThreadTaskRunner> task_runner() {
  26. return task_environment_.GetMainThreadTaskRunner();
  27. }
  28. private:
  29. base::test::SingleThreadTaskEnvironment task_environment_{
  30. base::test::TaskEnvironment::MainThreadType::IO,
  31. base::test::TaskEnvironment::TimeSource::MOCK_TIME};
  32. };
  33. } // namespace offline_pages
  34. #endif // COMPONENTS_OFFLINE_PAGES_TASK_TASK_TEST_BASE_H_