summaryrefslogtreecommitdiffstats
path: root/chrome/browser/devtools/devtools_window_testing.h
blob: 19fd9ee55d8ef31a1bb9053f078a10b899128aab (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
// 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.

#ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_TESTING_H_
#define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_TESTING_H_

#include "base/callback.h"
#include "base/macros.h"
#include "chrome/browser/devtools/devtools_window.h"
#include "ui/gfx/geometry/rect.h"

class Browser;
class Profile;

namespace content {
class DevToolsAgentHost;
class MessageLoopRunner;
class WebContents;
}

class DevToolsWindowTesting {
 public:
  virtual ~DevToolsWindowTesting();

  // The following methods block until DevToolsWindow is completely loaded.
  static DevToolsWindow* OpenDevToolsWindowSync(
      content::WebContents* inspected_web_contents,
      bool is_docked);
  static DevToolsWindow* OpenDevToolsWindowSync(
      Browser* browser, bool is_docked);
  static DevToolsWindow* OpenDevToolsWindowForWorkerSync(
      Profile* profile, content::DevToolsAgentHost* worker_agent);

  // Closes the window like it was user-initiated.
  static void CloseDevToolsWindow(DevToolsWindow* window);
  // Blocks until window is closed.
  static void CloseDevToolsWindowSync(DevToolsWindow* window);

  static DevToolsWindowTesting* Get(DevToolsWindow* window);

  Browser* browser();
  content::WebContents* main_web_contents();
  content::WebContents* toolbox_web_contents();
  void SetInspectedPageBounds(const gfx::Rect& bounds);
  void SetCloseCallback(const base::Closure& closure);

 private:
  friend class DevToolsWindow;
  friend class DevToolsWindowCreationObserver;

  explicit DevToolsWindowTesting(DevToolsWindow* window);
  static void WaitForDevToolsWindowLoad(DevToolsWindow* window);
  static void WindowClosed(DevToolsWindow* window);
  static DevToolsWindowTesting* Find(DevToolsWindow* window);

  DevToolsWindow* devtools_window_;
  base::Closure close_callback_;

  DISALLOW_COPY_AND_ASSIGN(DevToolsWindowTesting);
};

class DevToolsWindowCreationObserver {
 public:
  DevToolsWindowCreationObserver();
  ~DevToolsWindowCreationObserver();

  using DevToolsWindows = std::vector<DevToolsWindow*>;
  const DevToolsWindows& devtools_windows() { return devtools_windows_; }
  DevToolsWindow* devtools_window();

  void Wait();
  void WaitForLoad();
  void CloseAllSync();

 private:
  friend class DevToolsWindow;

  void DevToolsWindowCreated(DevToolsWindow* devtools_window);

  base::Callback<void(DevToolsWindow*)> creation_callback_;
  DevToolsWindows devtools_windows_;
  scoped_refptr<content::MessageLoopRunner> runner_;

  DISALLOW_COPY_AND_ASSIGN(DevToolsWindowCreationObserver);
};

#endif  // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_TESTING_H_