| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "base/test/histogram_tester.h" | 8 #include "base/test/histogram_tester.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "content/browser/frame_host/cross_site_transferring_request.h" | 10 #include "content/browser/frame_host/cross_site_transferring_request.h" |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 return favicon_received_; | 230 return favicon_received_; |
| 231 } | 231 } |
| 232 | 232 |
| 233 private: | 233 private: |
| 234 bool plugin_crashed_; | 234 bool plugin_crashed_; |
| 235 bool favicon_received_; | 235 bool favicon_received_; |
| 236 | 236 |
| 237 DISALLOW_COPY_AND_ASSIGN(PluginFaviconMessageObserver); | 237 DISALLOW_COPY_AND_ASSIGN(PluginFaviconMessageObserver); |
| 238 }; | 238 }; |
| 239 | 239 |
| 240 // Ensures that RenderFrameDeleted and RenderFrameCreated are called in a | |
| 241 // consistent manner. | |
| 242 class FrameLifetimeConsistencyChecker : public WebContentsObserver { | |
| 243 public: | |
| 244 explicit FrameLifetimeConsistencyChecker(WebContentsImpl* web_contents) | |
| 245 : WebContentsObserver(web_contents) { | |
| 246 RenderViewCreated(web_contents->GetRenderViewHost()); | |
| 247 RenderFrameCreated(web_contents->GetMainFrame()); | |
| 248 } | |
| 249 | |
| 250 void RenderFrameCreated(RenderFrameHost* render_frame_host) override { | |
| 251 std::pair<int, int> routing_pair = | |
| 252 std::make_pair(render_frame_host->GetProcess()->GetID(), | |
| 253 render_frame_host->GetRoutingID()); | |
| 254 bool was_live_already = !live_routes_.insert(routing_pair).second; | |
| 255 bool was_used_before = deleted_routes_.count(routing_pair) != 0; | |
| 256 | |
| 257 if (was_live_already) { | |
| 258 FAIL() << "RenderFrameCreated called more than once for routing pair: " | |
| 259 << Format(render_frame_host); | |
| 260 } else if (was_used_before) { | |
| 261 FAIL() << "RenderFrameCreated called for routing pair " | |
| 262 << Format(render_frame_host) << " that was previously deleted."; | |
| 263 } | |
| 264 } | |
| 265 | |
| 266 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override { | |
| 267 std::pair<int, int> routing_pair = | |
| 268 std::make_pair(render_frame_host->GetProcess()->GetID(), | |
| 269 render_frame_host->GetRoutingID()); | |
| 270 bool was_live = live_routes_.erase(routing_pair); | |
| 271 bool was_dead_already = !deleted_routes_.insert(routing_pair).second; | |
| 272 | |
| 273 if (was_dead_already) { | |
| 274 FAIL() << "RenderFrameDeleted called more than once for routing pair " | |
| 275 << Format(render_frame_host); | |
| 276 } else if (!was_live) { | |
| 277 FAIL() << "RenderFrameDeleted called for routing pair " | |
| 278 << Format(render_frame_host) | |
| 279 << " for which RenderFrameCreated was never called"; | |
| 280 } | |
| 281 } | |
| 282 | |
| 283 private: | |
| 284 std::string Format(RenderFrameHost* render_frame_host) { | |
| 285 return base::StringPrintf( | |
| 286 "(%d, %d -> %s )", | |
| 287 render_frame_host->GetProcess()->GetID(), | |
| 288 render_frame_host->GetRoutingID(), | |
| 289 render_frame_host->GetSiteInstance()->GetSiteURL().spec().c_str()); | |
| 290 } | |
| 291 std::set<std::pair<int, int> > live_routes_; | |
| 292 std::set<std::pair<int, int> > deleted_routes_; | |
| 293 }; | |
| 294 | |
| 295 } // namespace | 240 } // namespace |
| 296 | 241 |
| 297 class RenderFrameHostManagerTest | 242 class RenderFrameHostManagerTest : public RenderViewHostImplTestHarness { |
| 298 : public RenderViewHostImplTestHarness { | |
| 299 public: | 243 public: |
| 300 void SetUp() override { | 244 void SetUp() override { |
| 301 RenderViewHostImplTestHarness::SetUp(); | 245 RenderViewHostImplTestHarness::SetUp(); |
| 302 WebUIControllerFactory::RegisterFactory(&factory_); | 246 WebUIControllerFactory::RegisterFactory(&factory_); |
| 303 lifetime_checker_.reset(new FrameLifetimeConsistencyChecker(contents())); | |
| 304 } | 247 } |
| 305 | 248 |
| 306 void TearDown() override { | 249 void TearDown() override { |
| 307 lifetime_checker_.reset(); | |
| 308 RenderViewHostImplTestHarness::TearDown(); | 250 RenderViewHostImplTestHarness::TearDown(); |
| 309 WebUIControllerFactory::UnregisterFactoryForTesting(&factory_); | 251 WebUIControllerFactory::UnregisterFactoryForTesting(&factory_); |
| 310 } | 252 } |
| 311 | 253 |
| 312 void set_should_create_webui(bool should_create_webui) { | 254 void set_should_create_webui(bool should_create_webui) { |
| 313 factory_.set_should_create_webui(should_create_webui); | 255 factory_.set_should_create_webui(should_create_webui); |
| 314 } | 256 } |
| 315 | 257 |
| 316 void NavigateActiveAndCommit(const GURL& url) { | 258 void NavigateActiveAndCommit(const GURL& url) { |
| 317 // Note: we navigate the active RenderFrameHost because previous navigations | 259 // Note: we navigate the active RenderFrameHost because previous navigations |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 | 360 |
| 419 dest_rfh->SendNavigate(101, kDestUrl); | 361 dest_rfh->SendNavigate(101, kDestUrl); |
| 420 ntp_rfh->OnSwappedOut(); | 362 ntp_rfh->OnSwappedOut(); |
| 421 | 363 |
| 422 EXPECT_TRUE(ntp_rfh->is_swapped_out()); | 364 EXPECT_TRUE(ntp_rfh->is_swapped_out()); |
| 423 return ntp_rfh; | 365 return ntp_rfh; |
| 424 } | 366 } |
| 425 | 367 |
| 426 private: | 368 private: |
| 427 RenderFrameHostManagerTestWebUIControllerFactory factory_; | 369 RenderFrameHostManagerTestWebUIControllerFactory factory_; |
| 428 scoped_ptr<FrameLifetimeConsistencyChecker> lifetime_checker_; | |
| 429 }; | 370 }; |
| 430 | 371 |
| 431 // Tests that when you navigate from a chrome:// url to another page, and | 372 // Tests that when you navigate from a chrome:// url to another page, and |
| 432 // then do that same thing in another tab, that the two resulting pages have | 373 // then do that same thing in another tab, that the two resulting pages have |
| 433 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is | 374 // different SiteInstances, BrowsingInstances, and RenderProcessHosts. This is |
| 434 // a regression test for bug 9364. | 375 // a regression test for bug 9364. |
| 435 TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) { | 376 TEST_F(RenderFrameHostManagerTest, NewTabPageProcesses) { |
| 436 set_should_create_webui(true); | 377 set_should_create_webui(true); |
| 437 const GURL kChromeUrl("chrome://foo"); | 378 const GURL kChromeUrl("chrome://foo"); |
| 438 const GURL kDestUrl("http://www.google.com/"); | 379 const GURL kDestUrl("http://www.google.com/"); |
| (...skipping 1463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1902 #if 0 | 1843 #if 0 |
| 1903 // TODO(nick): Currently a proxy to the removed frame lingers in the parent. | 1844 // TODO(nick): Currently a proxy to the removed frame lingers in the parent. |
| 1904 // Enable this assert below once the proxies to the subframe are correctly | 1845 // Enable this assert below once the proxies to the subframe are correctly |
| 1905 // cleaned up after detach. | 1846 // cleaned up after detach. |
| 1906 ASSERT_TRUE(site_instance->HasOneRef()) | 1847 ASSERT_TRUE(site_instance->HasOneRef()) |
| 1907 << "This SiteInstance should be destroyable now."; | 1848 << "This SiteInstance should be destroyable now."; |
| 1908 #endif | 1849 #endif |
| 1909 } | 1850 } |
| 1910 | 1851 |
| 1911 } // namespace content | 1852 } // namespace content |
| OLD | NEW |