summaryrefslogtreecommitdiffstats
path: root/content/shell/layout_test_controller_host.h
blob: 7e63badcb13ef15fc793b4dc8e231b2fa9bff8dd (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
// Copyright (c) 2012 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 CONTENT_SHELL_LAYOUT_TEST_CONTROLLER_HOST_H_
#define CONTENT_SHELL_LAYOUT_TEST_CONTROLLER_HOST_H_
#pragma once

#include <map>
#include <string>

#include "base/cancelable_callback.h"
#include "content/public/browser/render_view_host_observer.h"

class SkBitmap;

namespace content {

class LayoutTestControllerHost : public RenderViewHostObserver {
 public:
  static LayoutTestControllerHost* FromRenderViewHost(
      RenderViewHost* render_view_host);

  // Initialize the LayoutTestControllerHost for a given test.
  static void Init(const std::string& expected_pixel_hash);

  explicit LayoutTestControllerHost(RenderViewHost* render_view_host);
  virtual ~LayoutTestControllerHost();

  bool should_stay_on_page_after_handling_before_unload() const {
    return should_stay_on_page_after_handling_before_unload_;
  }

  // RenderViewHostObserver implementation.
  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;

 private:
  void CaptureDump();
  void TimeoutHandler();

  // Message handlers.
  void OnDidFinishLoad();
  void OnTextDump(const std::string& dump);
  void OnImageDump(const std::string& actual_pixel_hash, const SkBitmap& image);

  // layoutTestController handlers.
  void OnNotifyDone();
  void OnDumpAsText();
  void OnDumpChildFramesAsText();
  void OnSetPrinting();
  void OnSetShouldStayOnPageAfterHandlingBeforeUnload(bool should_stay_on_page);
  void OnWaitUntilDone();

  void OnNotImplemented(const std::string& object_name,
                        const std::string& method_name);

  static std::map<RenderViewHost*, LayoutTestControllerHost*> controllers_;
  static std::string expected_pixel_hash_;

  bool captured_dump_;

  bool dump_as_text_;
  bool dump_child_frames_;
  bool is_printing_;
  bool should_stay_on_page_after_handling_before_unload_;
  bool wait_until_done_;

  base::CancelableClosure watchdog_;

  DISALLOW_COPY_AND_ASSIGN(LayoutTestControllerHost);
};

}  // namespace content

#endif  // CONTENT_SHELL_LAYOUT_TEST_CONTROLLER_HOST_H_