Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / content / public / test / content_browser_test_utils.h
blob77d537c473af7d7e64abceba35a6e9799fd634e3
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 "content/public/common/page_type.h"
11 #include "ui/gfx/native_widget_types.h"
12 #include "url/gurl.h"
14 namespace base {
15 class FilePath;
18 namespace gfx {
19 class Rect;
22 // A collections of functions designed for use with content_shell based browser
23 // tests.
24 // Note: if a function here also works with browser_tests, it should be in
25 // content\public\test\browser_test_utils.h
27 namespace content {
29 class MessageLoopRunner;
30 class Shell;
32 // Generate the file path for testing a particular test.
33 // The file for the tests is all located in
34 // content/test/data/dir/<file>
35 // The returned path is FilePath format.
36 base::FilePath GetTestFilePath(const char* dir, const char* file);
38 // Generate the URL for testing a particular test.
39 // HTML for the tests is all located in
40 // test_root_directory/dir/<file>
41 // The returned path is GURL format.
42 GURL GetTestUrl(const char* dir, const char* file);
44 // Navigates |window| to |url|, blocking until the navigation finishes.
45 // Returns true if the page was loaded successfully and the last committed
46 // URL matches |url|.
47 // TODO(alexmos): any tests that use this function and expect successful
48 // navigations should do EXPECT_TRUE(NavigateToURL()).
49 bool NavigateToURL(Shell* window, const GURL& url);
51 void LoadDataWithBaseURL(Shell* window,
52 const GURL& url,
53 const std::string data,
54 const GURL& base_url);
56 // Navigates |window| to |url|, blocking until the given number of navigations
57 // finishes.
58 void NavigateToURLBlockUntilNavigationsComplete(Shell* window,
59 const GURL& url,
60 int number_of_navigations);
62 // Navigates |window| to |url|, blocks until the navigation finishes, and
63 // checks that the navigation did not commit (e.g., due to a crash or
64 // download).
65 bool NavigateToURLAndExpectNoCommit(Shell* window, const GURL& url);
67 // Reloads |window|, blocking until the given number of navigations finishes.
68 void ReloadBlockUntilNavigationsComplete(Shell* window,
69 int number_of_navigations);
71 // Wait until an application modal dialog is requested.
72 void WaitForAppModalDialog(Shell* window);
74 // Used to wait for a new Shell window to be created. Instantiate this object
75 // before the operation that will create the window.
76 class ShellAddedObserver {
77 public:
78 ShellAddedObserver();
79 ~ShellAddedObserver();
81 // Will run a message loop to wait for the new window if it hasn't been
82 // created since the constructor.
83 Shell* GetShell();
85 private:
86 void ShellCreated(Shell* shell);
88 Shell* shell_;
89 scoped_refptr<MessageLoopRunner> runner_;
91 DISALLOW_COPY_AND_ASSIGN(ShellAddedObserver);
94 #if defined OS_MACOSX
95 void SetWindowBounds(gfx::NativeWindow window, const gfx::Rect& bounds);
96 #endif
98 } // namespace content
100 #endif // CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_UTILS_H_