summaryrefslogtreecommitdiffstats
path: root/android_webview/browser/test/rendering_test.cc
blob: c4ddb3b65d6aa5eaf80fa81045d5e96ba8a4a935 (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
// Copyright 2014 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.

#include "android_webview/browser/test/rendering_test.h"

#include "android_webview/browser/browser_view_renderer.h"
#include "android_webview/browser/child_frame.h"
#include "base/message_loop/message_loop.h"
#include "content/public/test/test_synchronous_compositor_android.h"

namespace android_webview {

RenderingTest::RenderingTest() : message_loop_(new base::MessageLoop) {
  ui_proxy_ = base::MessageLoopProxy::current();
}

RenderingTest::~RenderingTest() {
  if (window_.get())
    window_->Detach();
}

void RenderingTest::SetUpTestHarness() {
  DCHECK(!browser_view_renderer_.get());
  browser_view_renderer_.reset(
      new BrowserViewRenderer(this, base::MessageLoopProxy::current()));
  InitializeCompositor();
  Attach();
}

void RenderingTest::InitializeCompositor() {
  DCHECK(!compositor_.get());
  DCHECK(browser_view_renderer_.get());
  compositor_.reset(new content::TestSynchronousCompositor);
  compositor_->SetClient(browser_view_renderer_.get());
}

void RenderingTest::Attach() {
  window_.reset(
      new FakeWindow(browser_view_renderer_.get(), this, gfx::Rect(100, 100)));
}

void RenderingTest::RunTest() {
  SetUpTestHarness();

  ui_proxy_->PostTask(
      FROM_HERE, base::Bind(&RenderingTest::StartTest, base::Unretained(this)));
  message_loop_->Run();
}

void RenderingTest::StartTest() {
  EndTest();
}

void RenderingTest::EndTest() {
  ui_proxy_->PostTask(FROM_HERE, base::Bind(&RenderingTest::QuitMessageLoop,
                                            base::Unretained(this)));
}

void RenderingTest::QuitMessageLoop() {
  DCHECK_EQ(base::MessageLoop::current(), message_loop_.get());
  message_loop_->QuitWhenIdle();
}

bool RenderingTest::RequestDrawGL(bool wait_for_completion) {
  window_->RequestDrawGL(wait_for_completion);
  return true;
}

bool RenderingTest::WillDrawOnRT(SharedRendererState* functor,
                                 AwDrawGLInfo* draw_info) {
  draw_info->width = window_->surface_size().width();
  draw_info->height = window_->surface_size().height();
  draw_info->is_layer = false;
  gfx::Transform transform;
  transform.matrix().asColMajorf(draw_info->transform);
  return true;
}

void RenderingTest::OnNewPicture() {
}

void RenderingTest::PostInvalidate() {
  window_->PostInvalidate();
}

void RenderingTest::DetachFunctorFromView() {
}

gfx::Point RenderingTest::GetLocationOnScreen() {
  return gfx::Point();
}

bool RenderingTest::IsFlingActive() const {
  return false;
}

}  // namespace android_webview