spdy_session_test_util.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright (c) 2013 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 NET_SPDY_SPDY_SESSION_TEST_UTIL_H_
  5. #define NET_SPDY_SPDY_SESSION_TEST_UTIL_H_
  6. #include <stdint.h>
  7. #include <string>
  8. #include "base/pending_task.h"
  9. #include "base/task/task_observer.h"
  10. namespace net {
  11. // SpdySessionTestTaskObserver is a TaskObserver that monitors the
  12. // completion of all tasks executed by the current MessageLoop, recording the
  13. // number of tasks that refer to a specific function and filename.
  14. class SpdySessionTestTaskObserver : public base::TaskObserver {
  15. public:
  16. // Creates a SpdySessionTaskObserver that will record all tasks that are
  17. // executed that were posted by the function named by |function_name|, located
  18. // in the file |file_name|.
  19. // Example:
  20. // file_name = "foo.cc"
  21. // function = "DoFoo"
  22. SpdySessionTestTaskObserver(const std::string& file_name,
  23. const std::string& function_name);
  24. ~SpdySessionTestTaskObserver() override;
  25. // Implements TaskObserver.
  26. void WillProcessTask(const base::PendingTask& pending_task,
  27. bool was_blocked_or_low_priority) override;
  28. void DidProcessTask(const base::PendingTask& pending_task) override;
  29. // Returns the number of tasks posted by the given function and file.
  30. uint16_t executed_count() const { return executed_count_; }
  31. private:
  32. uint16_t executed_count_ = 0;
  33. std::string file_name_;
  34. std::string function_name_;
  35. };
  36. } // namespace net
  37. #endif // NET_SPDY_SPDY_SESSION_TEST_UTIL_H_