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"
22 // A collections of functions designed for use with content_shell based browser
24 // Note: if a function here also works with browser_tests, it should be in
25 // content\public\test\browser_test_utils.h
29 class MessageLoopRunner
;
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
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
,
53 const std::string data
,
54 const GURL
& base_url
);
56 // Navigates |window| to |url|, blocking until the given number of navigations
58 void NavigateToURLBlockUntilNavigationsComplete(Shell
* window
,
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
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
{
79 ~ShellAddedObserver();
81 // Will run a message loop to wait for the new window if it hasn't been
82 // created since the constructor.
86 void ShellCreated(Shell
* shell
);
89 scoped_refptr
<MessageLoopRunner
> runner_
;
91 DISALLOW_COPY_AND_ASSIGN(ShellAddedObserver
);
95 void SetWindowBounds(gfx::NativeWindow window
, const gfx::Rect
& bounds
);
98 } // namespace content
100 #endif // CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_UTILS_H_