xref: /aosp_15_r20/external/cronet/net/spdy/spdy_session_test_util.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2013 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef NET_SPDY_SPDY_SESSION_TEST_UTIL_H_
6 #define NET_SPDY_SPDY_SESSION_TEST_UTIL_H_
7 
8 #include <stdint.h>
9 
10 #include <string>
11 
12 #include "base/pending_task.h"
13 #include "base/task/task_observer.h"
14 
15 namespace net {
16 
17 // SpdySessionTestTaskObserver is a TaskObserver that monitors the
18 // completion of all tasks executed by the current MessageLoop, recording the
19 // number of tasks that refer to a specific function and filename.
20 class SpdySessionTestTaskObserver : public base::TaskObserver {
21  public:
22   // Creates a SpdySessionTaskObserver that will record all tasks that are
23   // executed that were posted by the function named by |function_name|, located
24   // in the file |file_name|.
25   // Example:
26   //  file_name = "foo.cc"
27   //  function = "DoFoo"
28   SpdySessionTestTaskObserver(const std::string& file_name,
29                               const std::string& function_name);
30   ~SpdySessionTestTaskObserver() override;
31 
32   // Implements TaskObserver.
33   void WillProcessTask(const base::PendingTask& pending_task,
34                        bool was_blocked_or_low_priority) override;
35   void DidProcessTask(const base::PendingTask& pending_task) override;
36 
37   // Returns the number of tasks posted by the given function and file.
executed_count()38   uint16_t executed_count() const { return executed_count_; }
39 
40  private:
41   uint16_t executed_count_ = 0;
42   std::string file_name_;
43   std::string function_name_;
44 };
45 
46 }  // namespace net
47 
48 #endif  // NET_SPDY_SPDY_SESSION_TEST_UTIL_H_
49