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/browser_test_utils.h" | 5 #include "content/public/test/browser_test_utils.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/process/kill.h" | 10 #include "base/process/kill.h" |
11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
15 #include "base/test/test_timeouts.h" | 15 #include "base/test/test_timeouts.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "content/browser/renderer_host/render_widget_host_impl.h" | 17 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 18 #include "content/browser/web_contents/web_contents_impl.h" |
18 #include "content/browser/web_contents/web_contents_view.h" | 19 #include "content/browser/web_contents/web_contents_view.h" |
19 #include "content/common/input/synthetic_web_input_event_builders.h" | 20 #include "content/common/input/synthetic_web_input_event_builders.h" |
20 #include "content/public/browser/browser_context.h" | 21 #include "content/public/browser/browser_context.h" |
21 #include "content/public/browser/dom_operation_notification_details.h" | 22 #include "content/public/browser/dom_operation_notification_details.h" |
22 #include "content/public/browser/histogram_fetcher.h" | 23 #include "content/public/browser/histogram_fetcher.h" |
23 #include "content/public/browser/navigation_entry.h" | 24 #include "content/public/browser/navigation_entry.h" |
24 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
25 #include "content/public/browser/notification_types.h" | 26 #include "content/public/browser/notification_types.h" |
26 #include "content/public/browser/render_frame_host.h" | 27 #include "content/public/browser/render_frame_host.h" |
27 #include "content/public/browser/render_process_host.h" | 28 #include "content/public/browser/render_process_host.h" |
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 message_loop_runner_->Run(); | 834 message_loop_runner_->Run(); |
834 } | 835 } |
835 // The queue should not be empty, unless we were quit because of a timeout. | 836 // The queue should not be empty, unless we were quit because of a timeout. |
836 if (message_queue_.empty()) | 837 if (message_queue_.empty()) |
837 return false; | 838 return false; |
838 *message = message_queue_.front(); | 839 *message = message_queue_.front(); |
839 message_queue_.pop(); | 840 message_queue_.pop(); |
840 return true; | 841 return true; |
841 } | 842 } |
842 | 843 |
| 844 class WebContentsAddedObserver::RenderViewCreatedObserver |
| 845 : public WebContentsObserver { |
| 846 public: |
| 847 explicit RenderViewCreatedObserver(WebContents* web_contents) |
| 848 : WebContentsObserver(web_contents), |
| 849 render_view_created_called_(false), |
| 850 main_frame_created_called_(false) {} |
| 851 |
| 852 // WebContentsObserver: |
| 853 void RenderViewCreated(RenderViewHost* rvh) override { |
| 854 render_view_created_called_ = true; |
| 855 } |
| 856 |
| 857 void RenderFrameCreated(RenderFrameHost* rfh) override { |
| 858 if (rfh == web_contents()->GetMainFrame()) |
| 859 main_frame_created_called_ = true; |
| 860 } |
| 861 |
| 862 bool render_view_created_called_; |
| 863 bool main_frame_created_called_; |
| 864 }; |
| 865 |
| 866 WebContentsAddedObserver::WebContentsAddedObserver() |
| 867 : web_contents_created_callback_( |
| 868 base::Bind(&WebContentsAddedObserver::WebContentsCreated, |
| 869 base::Unretained(this))), |
| 870 web_contents_(NULL) { |
| 871 WebContentsImpl::FriendZone::AddCreatedCallbackForTesting( |
| 872 web_contents_created_callback_); |
| 873 } |
| 874 |
| 875 WebContentsAddedObserver::~WebContentsAddedObserver() { |
| 876 WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting( |
| 877 web_contents_created_callback_); |
| 878 } |
| 879 |
| 880 void WebContentsAddedObserver::WebContentsCreated(WebContents* web_contents) { |
| 881 DCHECK(!web_contents_); |
| 882 web_contents_ = web_contents; |
| 883 child_observer_.reset(new RenderViewCreatedObserver(web_contents)); |
| 884 |
| 885 if (runner_.get()) |
| 886 runner_->QuitClosure().Run(); |
| 887 } |
| 888 |
| 889 WebContents* WebContentsAddedObserver::GetWebContents() { |
| 890 if (web_contents_) |
| 891 return web_contents_; |
| 892 |
| 893 runner_ = new MessageLoopRunner(); |
| 894 runner_->Run(); |
| 895 return web_contents_; |
| 896 } |
| 897 |
| 898 bool WebContentsAddedObserver::RenderViewCreatedCalled() { |
| 899 if (child_observer_) { |
| 900 return child_observer_->render_view_created_called_ && |
| 901 child_observer_->main_frame_created_called_; |
| 902 } |
| 903 return false; |
| 904 } |
| 905 |
843 } // namespace content | 906 } // namespace content |
OLD | NEW |