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_TEST_CONTENT_BROWSER_TEST_UTILS_H_ 6 #define CONTENT_TEST_CONTENT_BROWSER_TEST_UTILS_H_ 7 8 #include "base/memory/ref_counted.h" 9 #include "ui/gfx/native_widget_types.h" 10 #include "url/gurl.h" 11 12 namespace base { 13 class FilePath; 14 } 15 16 namespace gfx { 17 class Rect; 18 } 19 20 // A collections of functions designed for use with content_browsertests. 21 // Note: if a function here also works with browser_tests, it should be in 22 // content\public\test\browser_test_utils.h 23 24 namespace content { 25 26 class MessageLoopRunner; 27 class Shell; 28 29 // Generate the file path for testing a particular test. 30 // The file for the tests is all located in 31 // content/test/data/dir/<file> 32 // The returned path is FilePath format. 33 base::FilePath GetTestFilePath(const char* dir, const char* file); 34 35 // Generate the URL for testing a particular test. 36 // HTML for the tests is all located in 37 // test_root_directory/dir/<file> 38 // The returned path is GURL format. 39 GURL GetTestUrl(const char* dir, const char* file); 40 41 // Navigates the selected tab of |window| to |url|, blocking until the 42 // navigation finishes. 43 void NavigateToURL(Shell* window, const GURL& url); 44 45 // Navigates the selected tab of |window| to |url|, blocking until the given 46 // number of navigations finishes. 47 void NavigateToURLBlockUntilNavigationsComplete(Shell* window, 48 const GURL& url, 49 int number_of_navigations); 50 51 // Wait until an application modal dialog is requested. 52 void WaitForAppModalDialog(Shell* window); 53 54 // Used to wait for a new Shell window to be created. Instantiate this object 55 // before the operation that will create the window. 56 class ShellAddedObserver { 57 public: 58 ShellAddedObserver(); 59 ~ShellAddedObserver(); 60 61 // Will run a message loop to wait for the new window if it hasn't been 62 // created since the constructor. 63 Shell* GetShell(); 64 65 private: 66 void ShellCreated(Shell* shell); 67 68 Shell* shell_; 69 scoped_refptr<MessageLoopRunner> runner_; 70 71 DISALLOW_COPY_AND_ASSIGN(ShellAddedObserver); 72 }; 73 74 #if defined OS_MACOSX 75 void SetWindowBounds(gfx::NativeWindow window, const gfx::Rect& bounds); 76 #endif 77 78 } // namespace content 79 80 #endif // CONTENT_TEST_CONTENT_BROWSER_TEST_UTILS_H_ 81