summaryrefslogtreecommitdiff
path: root/chromium/net/spdy/spdy_session_test_util.h
blob: 819b15c8da03ae3d6dea6c71c8f12a636305ba1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef NET_SPDY_SPDY_SESSION_TEST_UTIL_H_
#define NET_SPDY_SPDY_SESSION_TEST_UTIL_H_

#include <stdint.h>

#include <string>

#include "base/message_loop/message_loop.h"
#include "base/pending_task.h"

namespace net {

// SpdySessionTestTaskObserver is a MessageLoop::TaskObserver that monitors the
// completion of all tasks executed by the current MessageLoop, recording the
// number of tasks that refer to a specific function and filename.
class SpdySessionTestTaskObserver : public base::MessageLoop::TaskObserver {
 public:
  // Creates a SpdySessionTaskObserver that will record all tasks that are
  // executed that were posted by the function named by |function_name|, located
  // in the file |file_name|.
  // Example:
  //  file_name = "foo.cc"
  //  function = "DoFoo"
  SpdySessionTestTaskObserver(const std::string& file_name,
                              const std::string& function_name);
  ~SpdySessionTestTaskObserver() override;

  // Implements MessageLoop::TaskObserver.
  void WillProcessTask(const base::PendingTask& pending_task) override;
  void DidProcessTask(const base::PendingTask& pending_task) override;

  // Returns the number of tasks posted by the given function and file.
  uint16_t executed_count() const { return executed_count_; }

 private:
  uint16_t executed_count_;
  std::string file_name_;
  std::string function_name_;
};

}  // namespace net

#endif  // NET_SPDY_SPDY_SESSION_TEST_UTIL_H_