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
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68

content / public / test / hit_test_region_observer.h [blame]

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_PUBLIC_TEST_HIT_TEST_REGION_OBSERVER_H_
#define CONTENT_PUBLIC_TEST_HIT_TEST_REGION_OBSERVER_H_

#include <memory>
#include <vector>

#include "base/run_loop.h"
#include "components/viz/common/hit_test/aggregated_hit_test_region.h"
#include "components/viz/common/hit_test/hit_test_region_observer.h"
#include "components/viz/common/surfaces/frame_sink_id.h"

namespace content {
class RenderFrameHost;
class WebContents;

// Waits until hit test data for |child_frame| or |guest_web_contents| has been
// submitted, see HitTestRegionObserver::WaitForHitTestData().
void WaitForHitTestData(RenderFrameHost* child_frame);
void WaitForHitTestData(WebContents* guest_web_contents);

// TODO(jonross): Move this to components/viz/host/hit_test/ as a standalone
// HitTestDataWaiter (is-a HitTestRegionObserver) once Viz HitTesting is on by
// default, and there are no longer dependancies upon content.
//
// Test API which observes the arrival / change of hit test data within a Viz
// host.
//
// HitTestRegionObserver is bound to a viz::FrameSinkId for which it observers
// changes in hit test data.
class HitTestRegionObserver : public viz::HitTestRegionObserver {
 public:
  explicit HitTestRegionObserver(const viz::FrameSinkId& frame_sink_id);

  HitTestRegionObserver(const HitTestRegionObserver&) = delete;
  HitTestRegionObserver& operator=(const HitTestRegionObserver&) = delete;

  ~HitTestRegionObserver() override;

  // The following functions need to be called in order to wait for the change
  // in hit test data. The first one should be called before any potential
  // change to hit test data (to cache the current state) and the second one
  // should be called after the change. Note that if any change has occurred
  // after the call to WaitForHitTestData, WaitForHitTestDataChange will return
  // immediately and the desired data may not be returned. Looping until the
  // received data match the expected data should be useful in such case.
  void WaitForHitTestData();
  void WaitForHitTestDataChange();
  const std::vector<viz::AggregatedHitTestRegion>& GetHitTestData();

 private:
  // viz::HitTestRegionObserver:
  void OnAggregatedHitTestRegionListUpdated(
      const viz::FrameSinkId& frame_sink_id,
      const std::vector<viz::AggregatedHitTestRegion>& hit_test_data) override;

  viz::FrameSinkId const frame_sink_id_;
  std::unique_ptr<base::RunLoop> run_loop_;
  std::unique_ptr<base::RunLoop> hit_test_data_change_run_loop_;
  std::vector<viz::AggregatedHitTestRegion> cached_hit_test_data_;
};

}  // namespace content

#endif  // CONTENT_PUBLIC_TEST_HIT_TEST_REGION_OBSERVER_H_