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. 4 5#ifndef CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_UTILS_H_ 6#define CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_UTILS_H_ 7 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" 12 13namespace base { 14class FilePath; 15} 16 17namespace gfx { 18class Rect; 19} 20 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 25 26namespace content { 27 28class MessageLoopRunner; 29class RenderViewCreatedObserver; 30class Shell; 31class WebContents; 32 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. 37base::FilePath GetTestFilePath(const char* dir, const char* file); 38 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. 43GURL GetTestUrl(const char* dir, const char* file); 44 45// Navigates the selected tab of |window| to |url|, blocking until the 46// navigation finishes. 47void NavigateToURL(Shell* window, const GURL& url); 48void LoadDataWithBaseURL(Shell* window, 49 const GURL& url, 50 const std::string data, 51 const GURL& base_url); 52 53// Navigates the selected tab of |window| to |url|, blocking until the given 54// number of navigations finishes. 55void 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. 60void ReloadBlockUntilNavigationsComplete(Shell* window, 61 int number_of_navigations); 62 63// Wait until an application modal dialog is requested. 64void WaitForAppModalDialog(Shell* window); 65 66// Used to wait for a new Shell window to be created. Instantiate this object 67// before the operation that will create the window. 68class ShellAddedObserver { 69 public: 70 ShellAddedObserver(); 71 ~ShellAddedObserver(); 72 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(); 76 77 private: 78 void ShellCreated(Shell* shell); 79 80 Shell* shell_; 81 scoped_refptr<MessageLoopRunner> runner_; 82 83 DISALLOW_COPY_AND_ASSIGN(ShellAddedObserver); 84}; 85 86// Used to wait for a new WebContents to be created. Instantiate this object 87// before the operation that will create the window. 88class WebContentsAddedObserver { 89 public: 90 WebContentsAddedObserver(); 91 ~WebContentsAddedObserver(); 92 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(); 96 97 // Will tell whether RenderViewCreated Callback has invoked 98 bool RenderViewCreatedCalled(); 99 100 base::Callback<void(WebContents*)> web_contents_created_callback_; 101 102 private: 103 void WebContentsCreated(WebContents* web_contents); 104 105 // Callback invoked on WebContents creation. 106 WebContents* web_contents_; 107 scoped_ptr<RenderViewCreatedObserver> child_observer_; 108 scoped_refptr<MessageLoopRunner> runner_; 109 110 DISALLOW_COPY_AND_ASSIGN(WebContentsAddedObserver); 111}; 112 113#if defined OS_MACOSX 114void SetWindowBounds(gfx::NativeWindow window, const gfx::Rect& bounds); 115#endif 116 117} // namespace content 118 119#endif // CONTENT_PUBLIC_TEST_CONTENT_BROWSER_TEST_UTILS_H_ 120