| 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" | |
| 12 #include "content/public/browser/navigation_controller.h" | 11 #include "content/public/browser/navigation_controller.h" |
| 13 #include "content/public/browser/notification_source.h" | 12 #include "content/public/browser/notification_source.h" |
| 14 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 15 #include "content/public/common/content_paths.h" | 14 #include "content/public/common/content_paths.h" |
| 16 #include "content/public/test/browser_test_utils.h" | 15 #include "content/public/test/browser_test_utils.h" |
| 17 #include "content/public/test/test_navigation_observer.h" | 16 #include "content/public/test/test_navigation_observer.h" |
| 18 #include "content/public/test/test_utils.h" | 17 #include "content/public/test/test_utils.h" |
| 19 #include "content/shell/browser/shell.h" | 18 #include "content/shell/browser/shell.h" |
| 20 #include "content/shell/browser/shell_javascript_dialog_manager.h" | 19 #include "content/shell/browser/shell_javascript_dialog_manager.h" |
| 21 #include "net/base/filename_util.h" | 20 #include "net/base/filename_util.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 return shell_; | 107 return shell_; |
| 109 } | 108 } |
| 110 | 109 |
| 111 void ShellAddedObserver::ShellCreated(Shell* shell) { | 110 void ShellAddedObserver::ShellCreated(Shell* shell) { |
| 112 DCHECK(!shell_); | 111 DCHECK(!shell_); |
| 113 shell_ = shell; | 112 shell_ = shell; |
| 114 if (runner_.get()) | 113 if (runner_.get()) |
| 115 runner_->QuitClosure().Run(); | 114 runner_->QuitClosure().Run(); |
| 116 } | 115 } |
| 117 | 116 |
| 118 class RenderViewCreatedObserver : public WebContentsObserver { | |
| 119 public: | |
| 120 explicit RenderViewCreatedObserver(WebContents* web_contents) | |
| 121 : WebContentsObserver(web_contents), | |
| 122 render_view_created_called_(false) { | |
| 123 } | |
| 124 | |
| 125 // WebContentsObserver: | |
| 126 void RenderViewCreated(RenderViewHost* rvh) override { | |
| 127 render_view_created_called_ = true; | |
| 128 } | |
| 129 | |
| 130 bool render_view_created_called_; | |
| 131 }; | |
| 132 | |
| 133 WebContentsAddedObserver::WebContentsAddedObserver() | |
| 134 : web_contents_created_callback_( | |
| 135 base::Bind( | |
| 136 &WebContentsAddedObserver::WebContentsCreated, | |
| 137 base::Unretained(this))), | |
| 138 web_contents_(NULL) { | |
| 139 WebContentsImpl::FriendZone::AddCreatedCallbackForTesting( | |
| 140 web_contents_created_callback_); | |
| 141 } | |
| 142 | |
| 143 WebContentsAddedObserver::~WebContentsAddedObserver() { | |
| 144 WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting( | |
| 145 web_contents_created_callback_); | |
| 146 } | |
| 147 | |
| 148 void WebContentsAddedObserver::WebContentsCreated(WebContents* web_contents) { | |
| 149 DCHECK(!web_contents_); | |
| 150 web_contents_ = web_contents; | |
| 151 child_observer_.reset(new RenderViewCreatedObserver(web_contents)); | |
| 152 | |
| 153 if (runner_.get()) | |
| 154 runner_->QuitClosure().Run(); | |
| 155 } | |
| 156 | |
| 157 WebContents* WebContentsAddedObserver::GetWebContents() { | |
| 158 if (web_contents_) | |
| 159 return web_contents_; | |
| 160 | |
| 161 runner_ = new MessageLoopRunner(); | |
| 162 runner_->Run(); | |
| 163 return web_contents_; | |
| 164 } | |
| 165 | |
| 166 bool WebContentsAddedObserver::RenderViewCreatedCalled() { | |
| 167 if (child_observer_) | |
| 168 return child_observer_->render_view_created_called_; | |
| 169 | |
| 170 return false; | |
| 171 } | |
| 172 | 117 |
| 173 } // namespace content | 118 } // namespace content |
| OLD | NEW |