add a use_alsa gyp setting
[chromium-blink-merge.git] / content / test / content_browser_test_utils.cc
blobc67050c90241f4ab29f627974a1fb856826f38b0
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 #include "content/test/content_browser_test_utils.h"
7 #include "base/bind.h"
8 #include "base/files/file_path.h"
9 #include "base/path_service.h"
10 #include "base/run_loop.h"
11 #include "content/public/browser/navigation_controller.h"
12 #include "content/public/browser/notification_source.h"
13 #include "content/public/browser/web_contents.h"
14 #include "content/public/common/content_paths.h"
15 #include "content/public/test/browser_test_utils.h"
16 #include "content/public/test/test_navigation_observer.h"
17 #include "content/public/test/test_utils.h"
18 #include "content/shell/shell.h"
19 #include "content/shell/shell_javascript_dialog_manager.h"
20 #include "net/base/net_util.h"
22 namespace content {
24 base::FilePath GetTestFilePath(const char* dir, const char* file) {
25 base::FilePath path;
26 PathService::Get(DIR_TEST_DATA, &path);
27 return path.Append(base::FilePath().AppendASCII(dir).Append(
28 base::FilePath().AppendASCII(file)));
31 GURL GetTestUrl(const char* dir, const char* file) {
32 return net::FilePathToFileURL(GetTestFilePath(dir, file));
35 void NavigateToURLBlockUntilNavigationsComplete(Shell* window,
36 const GURL& url,
37 int number_of_navigations) {
38 WaitForLoadStop(window->web_contents());
39 NavigationController* controller = &window->web_contents()->GetController();
40 TestNavigationObserver same_tab_observer(
41 Source<NavigationController>(controller),
42 NULL,
43 number_of_navigations);
45 window->LoadURL(url);
47 base::RunLoop run_loop;
48 same_tab_observer.WaitForObservation(
49 base::Bind(&RunThisRunLoop, base::Unretained(&run_loop)),
50 GetQuitTaskForRunLoop(&run_loop));
53 void NavigateToURL(Shell* window, const GURL& url) {
54 NavigateToURLBlockUntilNavigationsComplete(window, url, 1);
57 void WaitForAppModalDialog(Shell* window) {
58 ShellJavaScriptDialogManager* dialog_manager=
59 static_cast<ShellJavaScriptDialogManager*>(
60 window->GetJavaScriptDialogManager());
62 scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner();
63 dialog_manager->set_dialog_request_callback(runner->QuitClosure());
64 runner->Run();
67 ShellAddedObserver::ShellAddedObserver()
68 : shell_(NULL) {
69 Shell::SetShellCreatedCallback(
70 base::Bind(&ShellAddedObserver::ShellCreated, base::Unretained(this)));
73 ShellAddedObserver::~ShellAddedObserver() {
76 Shell* ShellAddedObserver::GetShell() {
77 if (shell_)
78 return shell_;
80 runner_ = new MessageLoopRunner();
81 runner_->Run();
82 return shell_;
85 void ShellAddedObserver::ShellCreated(Shell* shell) {
86 DCHECK(!shell_);
87 shell_ = shell;
88 if (runner_)
89 runner_->QuitClosure().Run();
92 } // namespace content