Removing uses of X11 native key events.
[chromium-blink-merge.git] / content / public / test / content_browser_test_utils.h
blob87e7e1c38918ea8e93175f6305d2f916b7e1b928
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_UTILS_H_
6 #define CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_UTILS_H_
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "ui/gfx/native_widget_types.h"
11 #include "url/gurl.h"
13 namespace base {
14 class FilePath;
17 namespace gfx {
18 class Rect;
21 // A collections of functions designed for use with content_shell based browser
22 // tests.
23 // Note: if a function here also works with browser_tests, it should be in
24 // content\public\test\browser_test_utils.h
26 namespace content {
28 class MessageLoopRunner;
29 class RenderViewCreatedObserver;
30 class Shell;
31 class WebContents;
33 // Generate the file path for testing a particular test.
34 // The file for the tests is all located in
35 // content/test/data/dir/<file>
36 // The returned path is FilePath format.
37 base::FilePath GetTestFilePath(const char* dir, const char* file);
39 // Generate the URL for testing a particular test.
40 // HTML for the tests is all located in
41 // test_root_directory/dir/<file>
42 // The returned path is GURL format.
43 GURL GetTestUrl(const char* dir, const char* file);
45 // Navigates the selected tab of |window| to |url|, blocking until the
46 // navigation finishes.
47 void NavigateToURL(Shell* window, const GURL& url);
48 void LoadDataWithBaseURL(Shell* window,
49 const GURL& url,
50 const std::string data,
51 const GURL& base_url);
53 // Navigates the selected tab of |window| to |url|, blocking until the given
54 // number of navigations finishes.
55 void NavigateToURLBlockUntilNavigationsComplete(Shell* window,
56 const GURL& url,
57 int number_of_navigations);
58 // Reloads the selected tab of |window|, blocking until the given number of
59 // navigations finishes.
60 void ReloadBlockUntilNavigationsComplete(Shell* window,
61 int number_of_navigations);
63 // Wait until an application modal dialog is requested.
64 void WaitForAppModalDialog(Shell* window);
66 // Used to wait for a new Shell window to be created. Instantiate this object
67 // before the operation that will create the window.
68 class ShellAddedObserver {
69 public:
70 ShellAddedObserver();
71 ~ShellAddedObserver();
73 // Will run a message loop to wait for the new window if it hasn't been
74 // created since the constructor.
75 Shell* GetShell();
77 private:
78 void ShellCreated(Shell* shell);
80 Shell* shell_;
81 scoped_refptr<MessageLoopRunner> runner_;
83 DISALLOW_COPY_AND_ASSIGN(ShellAddedObserver);
86 // Used to wait for a new WebContents to be created. Instantiate this object
87 // before the operation that will create the window.
88 class WebContentsAddedObserver {
89 public:
90 WebContentsAddedObserver();
91 ~WebContentsAddedObserver();
93 // Will run a message loop to wait for the new window if it hasn't been
94 // created since the constructor
95 WebContents* GetWebContents();
97 // Will tell whether RenderViewCreated Callback has invoked
98 bool RenderViewCreatedCalled();
100 base::Callback<void(WebContents*)> web_contents_created_callback_;
102 private:
103 void WebContentsCreated(WebContents* web_contents);
105 // Callback invoked on WebContents creation.
106 WebContents* web_contents_;
107 scoped_ptr<RenderViewCreatedObserver> child_observer_;
108 scoped_refptr<MessageLoopRunner> runner_;
110 DISALLOW_COPY_AND_ASSIGN(WebContentsAddedObserver);
113 #if defined OS_MACOSX
114 void SetWindowBounds(gfx::NativeWindow window, const gfx::Rect& bounds);
115 #endif
117 } // namespace content
119 #endif // CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_UTILS_H_