summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/web_test/web_test_web_frame_widget_impl.h
blob: ba740c8ccb190fe58eff6aec9fec7c11b37b4ddd (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright 2016 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 THIRD_PARTY_BLINK_RENDERER_CORE_WEB_TEST_WEB_TEST_WEB_FRAME_WIDGET_IMPL_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_WEB_TEST_WEB_TEST_WEB_FRAME_WIDGET_IMPL_H_

#include <memory>
#include <utility>

#include "base/macros.h"
#include "third_party/blink/public/test/frame_widget_test_helper.h"
#include "third_party/blink/renderer/core/frame/web_frame_widget_impl.h"

namespace blink {

// WebTestWebFrameWidgetImpl is used to run web tests. This class is a subclass
// of WebFrameWidgetImpl that overrides the minimal necessary portions. These
// portions are limited:
// 1) Handling single threaded compositing.
// 2) Emulating drag and drop.
//
// This class exists inside blink so that it can subclass the WebFrameWidgetImpl
// yet still depends on content/web_test/renderer classes. This will eventually
// be cleaned up with more content code moving into blink but it is fine for
// now since it is only used in tests.
class WebTestWebFrameWidgetImpl : public WebFrameWidgetImpl,
                                  public FrameWidgetTestHelper {
 public:
  WebTestWebFrameWidgetImpl(
      base::PassKey<WebLocalFrame>,
      CrossVariantMojoAssociatedRemote<
          mojom::blink::FrameWidgetHostInterfaceBase> frame_widget_host,
      CrossVariantMojoAssociatedReceiver<mojom::blink::FrameWidgetInterfaceBase>
          frame_widget,
      CrossVariantMojoAssociatedRemote<mojom::blink::WidgetHostInterfaceBase>
          widget_host,
      CrossVariantMojoAssociatedReceiver<mojom::blink::WidgetInterfaceBase>
          widget,
      scoped_refptr<base::SingleThreadTaskRunner> task_runner,
      const viz::FrameSinkId& frame_sink_id,
      bool hidden,
      bool never_composited,
      bool is_for_child_local_root,
      bool is_for_nested_main_frame,
      content::TestRunner* test_runner);

  ~WebTestWebFrameWidgetImpl() override;

  // FrameWidgetTestHelper overrides.
  void Reset() override;
  content::EventSender* GetEventSender() override;
  void SynchronouslyCompositeAfterTest() override;
  void UpdateAllLifecyclePhasesAndComposite(
      base::OnceClosure completion_callback) override;

  // WebFrameWidget overrides.
  FrameWidgetTestHelper* GetFrameWidgetTestHelperForTesting() override;

  // FrameWidget overrides.
  void RequestDecode(const cc::PaintImage&,
                     base::OnceCallback<void(bool)>) override;

 private:
  // WebFrameWidgetImpl overrides.
  void BindLocalRoot(WebLocalFrame&) override;
  void StartDragging(const WebDragData& drag_data,
                     DragOperationsMask operations_allowed,
                     const SkBitmap& drag_image,
                     const gfx::Point& drag_image_offset) override;

  // WidgetBaseClient overrides:
  void ScheduleAnimation() override;
  void WillBeginMainFrame() override;
  void ScheduleAnimationForWebTests() override;

  content::TestRunner* GetTestRunner();

  void ScheduleAnimationInternal(bool do_raster);
  void AnimateNow();

  // When |do_raster| is false, only a main frame animation step is performed,
  // but when true, a full composite is performed and a frame submitted to the
  // display compositor if there is any damage.
  // Note that compositing has the potential to detach the current frame and
  // thus destroy |this| before returning.
  void SynchronouslyComposite(bool do_raster);

  // Perform the synchronous composite step for a given LayerTreeHost.
  static void DoComposite(cc::LayerTreeHost* layer_tree_host, bool do_raster);

  std::unique_ptr<content::EventSender> event_sender_;

  content::TestRunner* const test_runner_;

  // For collapsing multiple simulated ScheduleAnimation() calls.
  bool animation_scheduled_ = false;
  // When true, an AnimateNow() is scheduled that will perform a full composite.
  // Otherwise, any scheduled AnimateNow() calls will only perform the animation
  // step, which calls out to blink but doesn't composite for performance
  // reasons. See setAnimationRequiresRaster() in
  // https://chromium.googlesource.com/chromium/src/+/master/docs/testing/writing_web_tests.md
  // for details on the optimization.
  bool composite_requested_ = false;
  // Synchronous composites should not be nested inside another
  // composite, and this bool is used to guard against that.
  bool in_synchronous_composite_ = false;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_WEB_TEST_WEB_TEST_WEB_FRAME_WIDGET_IMPL_H_