| 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 "base/compiler_specific.h" | 5 #include "base/compiler_specific.h" |
| 6 #include "base/stl_util.h" | 6 #include "base/stl_util.h" |
| 7 #include "base/string16.h" | 7 #include "base/string16.h" |
| 8 #include "content/browser/browser_thread_impl.h" | 8 #include "content/browser/browser_thread_impl.h" |
| 9 #include "content/browser/browsing_instance.h" | 9 #include "content/browser/browsing_instance.h" |
| 10 #include "content/browser/child_process_security_policy_impl.h" | 10 #include "content/browser/child_process_security_policy_impl.h" |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 EXPECT_EQ(1, browsing_delete_counter); | 244 EXPECT_EQ(1, browsing_delete_counter); |
| 245 // browsing_instance is now deleted | 245 // browsing_instance is now deleted |
| 246 | 246 |
| 247 // Ensure that instances are deleted when their RenderViewHosts are gone. | 247 // Ensure that instances are deleted when their RenderViewHosts are gone. |
| 248 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 248 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
| 249 instance = | 249 instance = |
| 250 TestSiteInstance::CreateTestSiteInstance(browser_context.get(), | 250 TestSiteInstance::CreateTestSiteInstance(browser_context.get(), |
| 251 &site_delete_counter, | 251 &site_delete_counter, |
| 252 &browsing_delete_counter); | 252 &browsing_delete_counter); |
| 253 { | 253 { |
| 254 WebContentsImpl web_contents(browser_context.get(), | 254 WebContentsImpl web_contents(browser_context.get(), instance, |
| 255 instance, | 255 MSG_ROUTING_NONE, NULL, NULL, NULL); |
| 256 MSG_ROUTING_NONE, | |
| 257 NULL, | |
| 258 NULL); | |
| 259 EXPECT_EQ(1, site_delete_counter); | 256 EXPECT_EQ(1, site_delete_counter); |
| 260 EXPECT_EQ(1, browsing_delete_counter); | 257 EXPECT_EQ(1, browsing_delete_counter); |
| 261 } | 258 } |
| 262 | 259 |
| 263 // Make sure that we flush any messages related to the above WebContentsImpl | 260 // Make sure that we flush any messages related to the above WebContentsImpl |
| 264 // destruction. | 261 // destruction. |
| 265 MessageLoop::current()->RunAllPending(); | 262 MessageLoop::current()->RunAllPending(); |
| 266 | 263 |
| 267 EXPECT_EQ(2, site_delete_counter); | 264 EXPECT_EQ(2, site_delete_counter); |
| 268 EXPECT_EQ(2, browsing_delete_counter); | 265 EXPECT_EQ(2, browsing_delete_counter); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 static_cast<SiteInstanceImpl*>( | 406 static_cast<SiteInstanceImpl*>( |
| 410 browsing_instance->GetSiteInstanceForURL(url_a1))); | 407 browsing_instance->GetSiteInstanceForURL(url_a1))); |
| 411 EXPECT_TRUE(site_instance_a1.get() != NULL); | 408 EXPECT_TRUE(site_instance_a1.get() != NULL); |
| 412 | 409 |
| 413 // A separate site should create a separate SiteInstance. | 410 // A separate site should create a separate SiteInstance. |
| 414 const GURL url_b1("http://www.yahoo.com/"); | 411 const GURL url_b1("http://www.yahoo.com/"); |
| 415 scoped_refptr<SiteInstanceImpl> site_instance_b1( | 412 scoped_refptr<SiteInstanceImpl> site_instance_b1( |
| 416 static_cast<SiteInstanceImpl*>( | 413 static_cast<SiteInstanceImpl*>( |
| 417 browsing_instance->GetSiteInstanceForURL(url_b1))); | 414 browsing_instance->GetSiteInstanceForURL(url_b1))); |
| 418 EXPECT_NE(site_instance_a1.get(), site_instance_b1.get()); | 415 EXPECT_NE(site_instance_a1.get(), site_instance_b1.get()); |
| 416 EXPECT_TRUE(site_instance_a1->IsRelatedSiteInstance(site_instance_b1)); |
| 419 | 417 |
| 420 // Getting the new SiteInstance from the BrowsingInstance and from another | 418 // Getting the new SiteInstance from the BrowsingInstance and from another |
| 421 // SiteInstance in the BrowsingInstance should give the same result. | 419 // SiteInstance in the BrowsingInstance should give the same result. |
| 422 EXPECT_EQ(site_instance_b1.get(), | 420 EXPECT_EQ(site_instance_b1.get(), |
| 423 site_instance_a1->GetRelatedSiteInstance(url_b1)); | 421 site_instance_a1->GetRelatedSiteInstance(url_b1)); |
| 424 | 422 |
| 425 // A second visit to the original site should return the same SiteInstance. | 423 // A second visit to the original site should return the same SiteInstance. |
| 426 const GURL url_a2("http://www.google.com/2.html"); | 424 const GURL url_a2("http://www.google.com/2.html"); |
| 427 EXPECT_EQ(site_instance_a1.get(), | 425 EXPECT_EQ(site_instance_a1.get(), |
| 428 browsing_instance->GetSiteInstanceForURL(url_a2)); | 426 browsing_instance->GetSiteInstanceForURL(url_a2)); |
| 429 EXPECT_EQ(site_instance_a1.get(), | 427 EXPECT_EQ(site_instance_a1.get(), |
| 430 site_instance_a1->GetRelatedSiteInstance(url_a2)); | 428 site_instance_a1->GetRelatedSiteInstance(url_a2)); |
| 431 | 429 |
| 432 // A visit to the original site in a new BrowsingInstance (same or different | 430 // A visit to the original site in a new BrowsingInstance (same or different |
| 433 // browser context) should return a different SiteInstance. | 431 // browser context) should return a different SiteInstance. |
| 434 TestBrowsingInstance* browsing_instance2 = | 432 TestBrowsingInstance* browsing_instance2 = |
| 435 new TestBrowsingInstance(NULL, &delete_counter); | 433 new TestBrowsingInstance(NULL, &delete_counter); |
| 436 browsing_instance2->set_use_process_per_site(false); | 434 browsing_instance2->set_use_process_per_site(false); |
| 437 // Ensure the new SiteInstance is ref counted so that it gets deleted. | 435 // Ensure the new SiteInstance is ref counted so that it gets deleted. |
| 438 scoped_refptr<SiteInstanceImpl> site_instance_a2_2( | 436 scoped_refptr<SiteInstanceImpl> site_instance_a2_2( |
| 439 static_cast<SiteInstanceImpl*>( | 437 static_cast<SiteInstanceImpl*>( |
| 440 browsing_instance2->GetSiteInstanceForURL(url_a2))); | 438 browsing_instance2->GetSiteInstanceForURL(url_a2))); |
| 441 EXPECT_NE(site_instance_a1.get(), site_instance_a2_2.get()); | 439 EXPECT_NE(site_instance_a1.get(), site_instance_a2_2.get()); |
| 440 EXPECT_FALSE(site_instance_a1->IsRelatedSiteInstance(site_instance_a2_2)); |
| 442 | 441 |
| 443 // Should be able to see that we do have SiteInstances. | 442 // Should be able to see that we do have SiteInstances. |
| 444 EXPECT_TRUE(browsing_instance->HasSiteInstance( | 443 EXPECT_TRUE(browsing_instance->HasSiteInstance( |
| 445 GURL("http://mail.google.com"))); | 444 GURL("http://mail.google.com"))); |
| 446 EXPECT_TRUE(browsing_instance2->HasSiteInstance( | 445 EXPECT_TRUE(browsing_instance2->HasSiteInstance( |
| 447 GURL("http://mail.google.com"))); | 446 GURL("http://mail.google.com"))); |
| 448 EXPECT_TRUE(browsing_instance->HasSiteInstance( | 447 EXPECT_TRUE(browsing_instance->HasSiteInstance( |
| 449 GURL("http://mail.yahoo.com"))); | 448 GURL("http://mail.yahoo.com"))); |
| 450 | 449 |
| 451 // Should be able to see that we don't have SiteInstances. | 450 // Should be able to see that we don't have SiteInstances. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 470 static_cast<SiteInstanceImpl*>( | 469 static_cast<SiteInstanceImpl*>( |
| 471 browsing_instance->GetSiteInstanceForURL(url_a1))); | 470 browsing_instance->GetSiteInstanceForURL(url_a1))); |
| 472 EXPECT_TRUE(site_instance_a1.get() != NULL); | 471 EXPECT_TRUE(site_instance_a1.get() != NULL); |
| 473 | 472 |
| 474 // A separate site should create a separate SiteInstance. | 473 // A separate site should create a separate SiteInstance. |
| 475 const GURL url_b1("http://www.yahoo.com/"); | 474 const GURL url_b1("http://www.yahoo.com/"); |
| 476 scoped_refptr<SiteInstanceImpl> site_instance_b1( | 475 scoped_refptr<SiteInstanceImpl> site_instance_b1( |
| 477 static_cast<SiteInstanceImpl*>( | 476 static_cast<SiteInstanceImpl*>( |
| 478 browsing_instance->GetSiteInstanceForURL(url_b1))); | 477 browsing_instance->GetSiteInstanceForURL(url_b1))); |
| 479 EXPECT_NE(site_instance_a1.get(), site_instance_b1.get()); | 478 EXPECT_NE(site_instance_a1.get(), site_instance_b1.get()); |
| 479 EXPECT_TRUE(site_instance_a1->IsRelatedSiteInstance(site_instance_b1)); |
| 480 | 480 |
| 481 // Getting the new SiteInstance from the BrowsingInstance and from another | 481 // Getting the new SiteInstance from the BrowsingInstance and from another |
| 482 // SiteInstance in the BrowsingInstance should give the same result. | 482 // SiteInstance in the BrowsingInstance should give the same result. |
| 483 EXPECT_EQ(site_instance_b1.get(), | 483 EXPECT_EQ(site_instance_b1.get(), |
| 484 site_instance_a1->GetRelatedSiteInstance(url_b1)); | 484 site_instance_a1->GetRelatedSiteInstance(url_b1)); |
| 485 | 485 |
| 486 // A second visit to the original site should return the same SiteInstance. | 486 // A second visit to the original site should return the same SiteInstance. |
| 487 const GURL url_a2("http://www.google.com/2.html"); | 487 const GURL url_a2("http://www.google.com/2.html"); |
| 488 EXPECT_EQ(site_instance_a1.get(), | 488 EXPECT_EQ(site_instance_a1.get(), |
| 489 browsing_instance->GetSiteInstanceForURL(url_a2)); | 489 browsing_instance->GetSiteInstanceForURL(url_a2)); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 host.reset(instance->GetProcess()); | 616 host.reset(instance->GetProcess()); |
| 617 EXPECT_TRUE(host.get() != NULL); | 617 EXPECT_TRUE(host.get() != NULL); |
| 618 EXPECT_TRUE(instance->HasProcess()); | 618 EXPECT_TRUE(instance->HasProcess()); |
| 619 | 619 |
| 620 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://evernote.com"))); | 620 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://evernote.com"))); |
| 621 EXPECT_FALSE(instance->HasWrongProcessForURL( | 621 EXPECT_FALSE(instance->HasWrongProcessForURL( |
| 622 GURL("javascript:alert(document.location.href);"))); | 622 GURL("javascript:alert(document.location.href);"))); |
| 623 | 623 |
| 624 EXPECT_TRUE(instance->HasWrongProcessForURL(GURL("chrome://settings"))); | 624 EXPECT_TRUE(instance->HasWrongProcessForURL(GURL("chrome://settings"))); |
| 625 } | 625 } |
| OLD | NEW |