blob: 6c3871847199c29ff2941763eecb22d6c68bb6b7 [file] [log] [blame]
[email protected]78089f02012-07-19 06:11:281// 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#include "content/test/content_browser_test_utils.h"
6
7#include "base/bind.h"
[email protected]57999812013-02-24 05:40:528#include "base/files/file_path.h"
[email protected]78089f02012-07-19 06:11:289#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"
[email protected]4cdc9a22012-07-26 03:39:3115#include "content/public/test/browser_test_utils.h"
[email protected]78089f02012-07-19 06:11:2816#include "content/public/test/test_navigation_observer.h"
[email protected]a7fe9112012-07-20 02:34:4517#include "content/public/test/test_utils.h"
[email protected]de7d61ff2013-08-20 11:30:4118#include "content/shell/browser/shell.h"
19#include "content/shell/browser/shell_javascript_dialog_manager.h"
[email protected]78089f02012-07-19 06:11:2820#include "net/base/net_util.h"
21
22namespace content {
23
[email protected]d30a36f2013-02-07 04:16:2624base::FilePath GetTestFilePath(const char* dir, const char* file) {
25 base::FilePath path;
[email protected]78089f02012-07-19 06:11:2826 PathService::Get(DIR_TEST_DATA, &path);
[email protected]d30a36f2013-02-07 04:16:2627 return path.Append(base::FilePath().AppendASCII(dir).Append(
28 base::FilePath().AppendASCII(file)));
[email protected]78089f02012-07-19 06:11:2829}
30
31GURL GetTestUrl(const char* dir, const char* file) {
32 return net::FilePathToFileURL(GetTestFilePath(dir, file));
33}
34
[email protected]4cdc9a22012-07-26 03:39:3135void NavigateToURLBlockUntilNavigationsComplete(Shell* window,
36 const GURL& url,
37 int number_of_navigations) {
38 WaitForLoadStop(window->web_contents());
[email protected]cbb1ef592013-06-05 19:49:4639 TestNavigationObserver same_tab_observer(window->web_contents(),
40 number_of_navigations);
[email protected]78089f02012-07-19 06:11:2841
42 window->LoadURL(url);
43
44 base::RunLoop run_loop;
45 same_tab_observer.WaitForObservation(
46 base::Bind(&RunThisRunLoop, base::Unretained(&run_loop)),
47 GetQuitTaskForRunLoop(&run_loop));
48}
49
[email protected]4cdc9a22012-07-26 03:39:3150void NavigateToURL(Shell* window, const GURL& url) {
51 NavigateToURLBlockUntilNavigationsComplete(window, url, 1);
52}
53
[email protected]95b27912012-07-23 23:14:5954void WaitForAppModalDialog(Shell* window) {
[email protected]71a88bb2013-02-01 22:05:1555 ShellJavaScriptDialogManager* dialog_manager=
56 static_cast<ShellJavaScriptDialogManager*>(
57 window->GetJavaScriptDialogManager());
[email protected]95b27912012-07-23 23:14:5958
59 scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner();
[email protected]71a88bb2013-02-01 22:05:1560 dialog_manager->set_dialog_request_callback(runner->QuitClosure());
[email protected]95b27912012-07-23 23:14:5961 runner->Run();
62}
63
[email protected]9e00e6352012-07-30 17:05:1864ShellAddedObserver::ShellAddedObserver()
65 : shell_(NULL) {
66 Shell::SetShellCreatedCallback(
67 base::Bind(&ShellAddedObserver::ShellCreated, base::Unretained(this)));
68}
69
70ShellAddedObserver::~ShellAddedObserver() {
71}
72
73Shell* ShellAddedObserver::GetShell() {
74 if (shell_)
75 return shell_;
76
77 runner_ = new MessageLoopRunner();
78 runner_->Run();
79 return shell_;
80}
81
82void ShellAddedObserver::ShellCreated(Shell* shell) {
83 DCHECK(!shell_);
84 shell_ = shell;
[email protected]fc72bb12013-06-02 21:13:4685 if (runner_.get())
[email protected]9e00e6352012-07-30 17:05:1886 runner_->QuitClosure().Run();
87}
88
[email protected]78089f02012-07-19 06:11:2889} // namespace content