OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/public/test/content_browser_test_utils.h" | 5 #include "content/public/test/content_browser_test_utils.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "content/browser/web_contents/web_contents_impl.h" |
11 #include "content/public/browser/navigation_controller.h" | 12 #include "content/public/browser/navigation_controller.h" |
12 #include "content/public/browser/notification_source.h" | 13 #include "content/public/browser/notification_source.h" |
13 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
14 #include "content/public/common/content_paths.h" | 15 #include "content/public/common/content_paths.h" |
15 #include "content/public/test/browser_test_utils.h" | 16 #include "content/public/test/browser_test_utils.h" |
16 #include "content/public/test/test_navigation_observer.h" | 17 #include "content/public/test/test_navigation_observer.h" |
17 #include "content/public/test/test_utils.h" | 18 #include "content/public/test/test_utils.h" |
18 #include "content/shell/browser/shell.h" | 19 #include "content/shell/browser/shell.h" |
19 #include "content/shell/browser/shell_javascript_dialog_manager.h" | 20 #include "content/shell/browser/shell_javascript_dialog_manager.h" |
20 #include "net/base/filename_util.h" | 21 #include "net/base/filename_util.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 return shell_; | 85 return shell_; |
85 } | 86 } |
86 | 87 |
87 void ShellAddedObserver::ShellCreated(Shell* shell) { | 88 void ShellAddedObserver::ShellCreated(Shell* shell) { |
88 DCHECK(!shell_); | 89 DCHECK(!shell_); |
89 shell_ = shell; | 90 shell_ = shell; |
90 if (runner_.get()) | 91 if (runner_.get()) |
91 runner_->QuitClosure().Run(); | 92 runner_->QuitClosure().Run(); |
92 } | 93 } |
93 | 94 |
| 95 class RenderViewCreatedObserver : public WebContentsObserver { |
| 96 public: |
| 97 RenderViewCreatedObserver(WebContents* web_contents) |
| 98 : WebContentsObserver(web_contents), |
| 99 render_view_created_called_(false) { |
| 100 } |
| 101 |
| 102 // WebContentsObserver: |
| 103 virtual void RenderViewCreated(RenderViewHost* rvh) OVERRIDE { |
| 104 render_view_created_called_ = true; |
| 105 } |
| 106 |
| 107 bool render_view_created_called_; |
| 108 }; |
| 109 |
| 110 WebContentsAddedObserver::WebContentsAddedObserver() |
| 111 : web_contents_created_callback_( |
| 112 base::Bind( |
| 113 &WebContentsAddedObserver::WebContentsCreated, |
| 114 base::Unretained(this))), |
| 115 web_contents_(NULL) { |
| 116 WebContentsImpl::AddCreatedCallback(web_contents_created_callback_); |
| 117 } |
| 118 |
| 119 WebContentsAddedObserver::~WebContentsAddedObserver() { |
| 120 WebContentsImpl::RemoveCreatedCallback(web_contents_created_callback_); |
| 121 } |
| 122 |
| 123 void WebContentsAddedObserver::WebContentsCreated(WebContents* web_contents) { |
| 124 DCHECK(!web_contents_); |
| 125 web_contents_ = web_contents; |
| 126 child_observer_.reset(new RenderViewCreatedObserver(web_contents)); |
| 127 |
| 128 if (runner_.get()) |
| 129 runner_->QuitClosure().Run(); |
| 130 } |
| 131 |
| 132 WebContents* WebContentsAddedObserver::GetWebContents() { |
| 133 if (web_contents_) |
| 134 return web_contents_; |
| 135 |
| 136 runner_ = new MessageLoopRunner(); |
| 137 runner_->Run(); |
| 138 return web_contents_; |
| 139 } |
| 140 |
| 141 bool WebContentsAddedObserver::RenderViewCreatedCalled() { |
| 142 if (child_observer_) |
| 143 return child_observer_->render_view_created_called_; |
| 144 |
| 145 return false; |
| 146 } |
| 147 |
94 } // namespace content | 148 } // namespace content |
OLD | NEW |