| 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/browser/web_contents/test_web_contents.h" | 5 #include "content/browser/web_contents/test_web_contents.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "content/browser/browser_url_handler_impl.h" | 9 #include "content/browser/browser_url_handler_impl.h" |
| 10 #include "content/browser/renderer_host/render_view_host_impl.h" | 10 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 11 #include "content/browser/renderer_host/test_render_view_host.h" | 11 #include "content/browser/renderer_host/test_render_view_host.h" |
| 12 #include "content/browser/site_instance_impl.h" | 12 #include "content/browser/site_instance_impl.h" |
| 13 #include "content/browser/web_contents/navigation_entry_impl.h" | 13 #include "content/browser/web_contents/navigation_entry_impl.h" |
| 14 #include "content/common/view_messages.h" | 14 #include "content/common/view_messages.h" |
| 15 #include "content/public/browser/notification_registrar.h" |
| 16 #include "content/public/browser/notification_source.h" |
| 17 #include "content/public/browser/notification_types.h" |
| 15 #include "content/public/common/page_transition_types.h" | 18 #include "content/public/common/page_transition_types.h" |
| 16 #include "content/test/mock_render_process_host.h" | 19 #include "content/test/mock_render_process_host.h" |
| 17 #include "webkit/forms/password_form.h" | 20 #include "webkit/forms/password_form.h" |
| 18 #include "webkit/glue/webkit_glue.h" | 21 #include "webkit/glue/webkit_glue.h" |
| 19 | 22 |
| 20 namespace content { | 23 namespace content { |
| 21 | 24 |
| 22 TestWebContents::TestWebContents(BrowserContext* browser_context, | 25 TestWebContents::TestWebContents(BrowserContext* browser_context, |
| 23 SiteInstance* instance) | 26 SiteInstance* instance) |
| 24 : WebContentsImpl(browser_context, instance, MSG_ROUTING_NONE, NULL, NULL), | 27 : WebContentsImpl(browser_context, instance, MSG_ROUTING_NONE, NULL, NULL, |
| 28 NULL), |
| 25 transition_cross_site(false), | 29 transition_cross_site(false), |
| 26 delegate_view_override_(NULL), | 30 delegate_view_override_(NULL), |
| 27 expect_set_history_length_and_prune_(false), | 31 expect_set_history_length_and_prune_(false), |
| 28 expect_set_history_length_and_prune_site_instance_(NULL), | 32 expect_set_history_length_and_prune_site_instance_(NULL), |
| 29 expect_set_history_length_and_prune_history_length_(0), | 33 expect_set_history_length_and_prune_history_length_(0), |
| 30 expect_set_history_length_and_prune_min_page_id_(-1) { | 34 expect_set_history_length_and_prune_min_page_id_(-1) { |
| 31 } | 35 } |
| 32 | 36 |
| 33 TestWebContents::~TestWebContents() { | 37 TestWebContents::~TestWebContents() { |
| 34 } | 38 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); | 80 params.content_state = webkit_glue::CreateHistoryStateForURL(GURL(url)); |
| 77 | 81 |
| 78 DidNavigate(render_view_host, params); | 82 DidNavigate(render_view_host, params); |
| 79 } | 83 } |
| 80 | 84 |
| 81 WebPreferences TestWebContents::TestGetWebkitPrefs() { | 85 WebPreferences TestWebContents::TestGetWebkitPrefs() { |
| 82 return GetWebkitPrefs(); | 86 return GetWebkitPrefs(); |
| 83 } | 87 } |
| 84 | 88 |
| 85 bool TestWebContents::CreateRenderViewForRenderManager( | 89 bool TestWebContents::CreateRenderViewForRenderManager( |
| 86 RenderViewHost* render_view_host) { | 90 RenderViewHost* render_view_host, int opener_route_id) { |
| 87 // This will go to a TestRenderViewHost. | 91 // This will go to a TestRenderViewHost. |
| 88 static_cast<RenderViewHostImpl*>( | 92 static_cast<RenderViewHostImpl*>( |
| 89 render_view_host)->CreateRenderView(string16(), -1); | 93 render_view_host)->CreateRenderView(string16(), opener_route_id, -1); |
| 90 return true; | 94 return true; |
| 91 } | 95 } |
| 92 | 96 |
| 93 WebContents* TestWebContents::Clone() { | 97 WebContents* TestWebContents::Clone() { |
| 94 WebContentsImpl* contents = new TestWebContents( | 98 WebContentsImpl* contents = new TestWebContents( |
| 95 GetBrowserContext(), | 99 GetBrowserContext(), |
| 96 SiteInstance::Create(GetBrowserContext())); | 100 SiteInstance::Create(GetBrowserContext())); |
| 97 contents->GetControllerImpl().CopyStateFrom(controller_); | 101 contents->GetControllerImpl().CopyStateFrom(controller_); |
| 98 return contents; | 102 return contents; |
| 99 } | 103 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 render_manager_.current_host()); | 153 render_manager_.current_host()); |
| 150 rvh->SendShouldCloseACK(true); | 154 rvh->SendShouldCloseACK(true); |
| 151 } | 155 } |
| 152 | 156 |
| 153 RenderViewHostDelegate::View* TestWebContents::GetViewDelegate() { | 157 RenderViewHostDelegate::View* TestWebContents::GetViewDelegate() { |
| 154 if (delegate_view_override_) | 158 if (delegate_view_override_) |
| 155 return delegate_view_override_; | 159 return delegate_view_override_; |
| 156 return WebContentsImpl::GetViewDelegate(); | 160 return WebContentsImpl::GetViewDelegate(); |
| 157 } | 161 } |
| 158 | 162 |
| 163 void TestWebContents::SetOpener(TestWebContents* opener) { |
| 164 // This is normally only set in the WebContents constructor, which also |
| 165 // registers an observer for when the opener gets closed. |
| 166 opener_ = opener; |
| 167 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 168 content::Source<WebContents>(opener_)); |
| 169 } |
| 170 |
| 159 void TestWebContents::ExpectSetHistoryLengthAndPrune( | 171 void TestWebContents::ExpectSetHistoryLengthAndPrune( |
| 160 const SiteInstance* site_instance, | 172 const SiteInstance* site_instance, |
| 161 int history_length, | 173 int history_length, |
| 162 int32 min_page_id) { | 174 int32 min_page_id) { |
| 163 expect_set_history_length_and_prune_ = true; | 175 expect_set_history_length_and_prune_ = true; |
| 164 expect_set_history_length_and_prune_site_instance_ = | 176 expect_set_history_length_and_prune_site_instance_ = |
| 165 static_cast<const SiteInstanceImpl*>(site_instance); | 177 static_cast<const SiteInstanceImpl*>(site_instance); |
| 166 expect_set_history_length_and_prune_history_length_ = history_length; | 178 expect_set_history_length_and_prune_history_length_ = history_length; |
| 167 expect_set_history_length_and_prune_min_page_id_ = min_page_id; | 179 expect_set_history_length_and_prune_min_page_id_ = min_page_id; |
| 168 } | 180 } |
| 169 | 181 |
| 170 void TestWebContents::SetHistoryLengthAndPrune( | 182 void TestWebContents::SetHistoryLengthAndPrune( |
| 171 const SiteInstance* site_instance, int history_length, | 183 const SiteInstance* site_instance, int history_length, |
| 172 int32 min_page_id) { | 184 int32 min_page_id) { |
| 173 EXPECT_TRUE(expect_set_history_length_and_prune_); | 185 EXPECT_TRUE(expect_set_history_length_and_prune_); |
| 174 expect_set_history_length_and_prune_ = false; | 186 expect_set_history_length_and_prune_ = false; |
| 175 EXPECT_EQ(expect_set_history_length_and_prune_site_instance_, site_instance); | 187 EXPECT_EQ(expect_set_history_length_and_prune_site_instance_, site_instance); |
| 176 EXPECT_EQ(expect_set_history_length_and_prune_history_length_, | 188 EXPECT_EQ(expect_set_history_length_and_prune_history_length_, |
| 177 history_length); | 189 history_length); |
| 178 EXPECT_EQ(expect_set_history_length_and_prune_min_page_id_, min_page_id); | 190 EXPECT_EQ(expect_set_history_length_and_prune_min_page_id_, min_page_id); |
| 179 } | 191 } |
| 180 | 192 |
| 181 } // namespace content | 193 } // namespace content |
| OLD | NEW |