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/command_line.h" | |
5 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
6 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
7 #include "base/string16.h" | 8 #include "base/string16.h" |
8 #include "content/browser/browser_thread_impl.h" | 9 #include "content/browser/browser_thread_impl.h" |
9 #include "content/browser/browsing_instance.h" | 10 #include "content/browser/browsing_instance.h" |
10 #include "content/browser/child_process_security_policy_impl.h" | 11 #include "content/browser/child_process_security_policy_impl.h" |
11 #include "content/browser/renderer_host/render_process_host_impl.h" | 12 #include "content/browser/renderer_host/render_process_host_impl.h" |
12 #include "content/browser/renderer_host/render_view_host_impl.h" | 13 #include "content/browser/renderer_host/render_view_host_impl.h" |
13 #include "content/browser/renderer_host/test_render_view_host.h" | 14 #include "content/browser/renderer_host/test_render_view_host.h" |
14 #include "content/browser/site_instance_impl.h" | 15 #include "content/browser/site_instance_impl.h" |
15 #include "content/browser/web_contents/navigation_entry_impl.h" | 16 #include "content/browser/web_contents/navigation_entry_impl.h" |
16 #include "content/browser/web_contents/web_contents_impl.h" | 17 #include "content/browser/web_contents/web_contents_impl.h" |
17 #include "content/public/browser/web_ui_controller_factory.h" | 18 #include "content/public/browser/web_ui_controller_factory.h" |
18 #include "content/public/common/content_client.h" | 19 #include "content/public/common/content_client.h" |
19 #include "content/public/common/content_constants.h" | 20 #include "content/public/common/content_constants.h" |
21 #include "content/public/common/content_switches.h" | |
20 #include "content/public/common/url_constants.h" | 22 #include "content/public/common/url_constants.h" |
21 #include "content/public/test/mock_render_process_host.h" | 23 #include "content/public/test/mock_render_process_host.h" |
22 #include "content/public/test/test_browser_context.h" | 24 #include "content/public/test/test_browser_context.h" |
23 #include "content/public/test/test_browser_thread.h" | 25 #include "content/public/test/test_browser_thread.h" |
24 #include "content/test/test_content_browser_client.h" | 26 #include "content/test/test_content_browser_client.h" |
25 #include "content/test/test_content_client.h" | 27 #include "content/test/test_content_client.h" |
26 #include "googleurl/src/url_util.h" | 28 #include "googleurl/src/url_util.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
28 | 30 |
29 using content::BrowserContext; | 31 using content::BrowserContext; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 public: | 87 public: |
86 SiteInstanceTestBrowserClient() | 88 SiteInstanceTestBrowserClient() |
87 : privileged_process_id_(-1) { | 89 : privileged_process_id_(-1) { |
88 } | 90 } |
89 | 91 |
90 virtual content::WebUIControllerFactory* | 92 virtual content::WebUIControllerFactory* |
91 GetWebUIControllerFactory() OVERRIDE { | 93 GetWebUIControllerFactory() OVERRIDE { |
92 return &factory_; | 94 return &factory_; |
93 } | 95 } |
94 | 96 |
95 virtual bool ShouldUseProcessPerSite(BrowserContext* browser_context, | |
96 const GURL& effective_url) OVERRIDE { | |
97 return false; | |
98 } | |
99 | |
100 virtual bool IsSuitableHost(content::RenderProcessHost* process_host, | 97 virtual bool IsSuitableHost(content::RenderProcessHost* process_host, |
101 const GURL& site_url) OVERRIDE { | 98 const GURL& site_url) OVERRIDE { |
102 return (privileged_process_id_ == process_host->GetID()) == | 99 return (privileged_process_id_ == process_host->GetID()) == |
103 site_url.SchemeIs(kPrivilegedScheme); | 100 site_url.SchemeIs(kPrivilegedScheme); |
104 } | 101 } |
105 | 102 |
106 void set_privileged_process_id(int process_id) { | 103 void set_privileged_process_id(int process_id) { |
107 privileged_process_id_ = process_id; | 104 privileged_process_id_ = process_id; |
108 } | 105 } |
109 | 106 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 content::TestBrowserThread ui_thread_; | 145 content::TestBrowserThread ui_thread_; |
149 content::TestBrowserThread file_user_blocking_thread_; | 146 content::TestBrowserThread file_user_blocking_thread_; |
150 content::TestBrowserThread io_thread_; | 147 content::TestBrowserThread io_thread_; |
151 | 148 |
152 SiteInstanceTestClient client_; | 149 SiteInstanceTestClient client_; |
153 SiteInstanceTestBrowserClient browser_client_; | 150 SiteInstanceTestBrowserClient browser_client_; |
154 content::ContentClient* old_client_; | 151 content::ContentClient* old_client_; |
155 content::ContentBrowserClient* old_browser_client_; | 152 content::ContentBrowserClient* old_browser_client_; |
156 }; | 153 }; |
157 | 154 |
155 // Subclass of BrowsingInstance that updates a counter when deleted and | |
156 // returns TestSiteInstances from GetSiteInstanceForURL. | |
158 class TestBrowsingInstance : public BrowsingInstance { | 157 class TestBrowsingInstance : public BrowsingInstance { |
159 public: | 158 public: |
160 TestBrowsingInstance(BrowserContext* browser_context, int* delete_counter) | 159 TestBrowsingInstance(BrowserContext* browser_context, int* delete_counter) |
161 : BrowsingInstance(browser_context), | 160 : BrowsingInstance(browser_context), |
162 use_process_per_site_(false), | |
163 delete_counter_(delete_counter) { | 161 delete_counter_(delete_counter) { |
164 } | 162 } |
165 | 163 |
166 // Overrides BrowsingInstance::ShouldUseProcessPerSite so that we can test | |
167 // both alternatives without using command-line switches. | |
168 bool ShouldUseProcessPerSite(const GURL& url) { | |
169 return use_process_per_site_; | |
170 } | |
171 | |
172 void set_use_process_per_site(bool use_process_per_site) { | |
173 use_process_per_site_ = use_process_per_site; | |
174 } | |
175 | |
176 // Make a few methods public for tests. | 164 // Make a few methods public for tests. |
177 using BrowsingInstance::ShouldUseProcessPerSite; | |
178 using BrowsingInstance::browser_context; | 165 using BrowsingInstance::browser_context; |
179 using BrowsingInstance::HasSiteInstance; | 166 using BrowsingInstance::HasSiteInstance; |
180 using BrowsingInstance::GetSiteInstanceForURL; | 167 using BrowsingInstance::GetSiteInstanceForURL; |
181 using BrowsingInstance::RegisterSiteInstance; | 168 using BrowsingInstance::RegisterSiteInstance; |
182 using BrowsingInstance::UnregisterSiteInstance; | 169 using BrowsingInstance::UnregisterSiteInstance; |
183 | 170 |
184 private: | 171 private: |
185 virtual ~TestBrowsingInstance() { | 172 virtual ~TestBrowsingInstance() { |
186 (*delete_counter_)++; | 173 (*delete_counter_)++; |
187 } | 174 } |
188 | 175 |
189 // Set by individual tests. | |
190 bool use_process_per_site_; | |
191 | |
192 int* delete_counter_; | 176 int* delete_counter_; |
193 }; | 177 }; |
194 | 178 |
179 // Subclass of SiteInstanceImpl that updates a counter when deleted. | |
195 class TestSiteInstance : public SiteInstanceImpl { | 180 class TestSiteInstance : public SiteInstanceImpl { |
196 public: | 181 public: |
197 static TestSiteInstance* CreateTestSiteInstance( | 182 static TestSiteInstance* CreateTestSiteInstance( |
198 BrowserContext* browser_context, | 183 BrowserContext* browser_context, |
199 int* site_delete_counter, | 184 int* site_delete_counter, |
200 int* browsing_delete_counter) { | 185 int* browsing_delete_counter) { |
201 TestBrowsingInstance* browsing_instance = | 186 TestBrowsingInstance* browsing_instance = |
202 new TestBrowsingInstance(browser_context, browsing_delete_counter); | 187 new TestBrowsingInstance(browser_context, browsing_delete_counter); |
203 return new TestSiteInstance(browsing_instance, site_delete_counter); | 188 return new TestSiteInstance(browsing_instance, site_delete_counter); |
204 } | 189 } |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
403 | 388 |
404 // JavaScript links should be considered same site for anything. | 389 // JavaScript links should be considered same site for anything. |
405 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_javascript, url_foo)); | 390 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_javascript, url_foo)); |
406 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_javascript, url_foo_https)); | 391 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_javascript, url_foo_https)); |
407 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_javascript, url_foo_port)); | 392 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_javascript, url_foo_port)); |
408 } | 393 } |
409 | 394 |
410 // Test to ensure that there is only one SiteInstance per site in a given | 395 // Test to ensure that there is only one SiteInstance per site in a given |
411 // BrowsingInstance, when process-per-site is not in use. | 396 // BrowsingInstance, when process-per-site is not in use. |
412 TEST_F(SiteInstanceTest, OneSiteInstancePerSite) { | 397 TEST_F(SiteInstanceTest, OneSiteInstancePerSite) { |
398 ASSERT_FALSE(CommandLine::ForCurrentProcess()->HasSwitch( | |
399 switches::kProcessPerSite)); | |
413 int delete_counter = 0; | 400 int delete_counter = 0; |
401 scoped_ptr<content::TestBrowserContext> browser_context( | |
402 new content::TestBrowserContext()); | |
414 TestBrowsingInstance* browsing_instance = | 403 TestBrowsingInstance* browsing_instance = |
415 new TestBrowsingInstance(NULL, &delete_counter); | 404 new TestBrowsingInstance(browser_context.get(), &delete_counter); |
416 browsing_instance->set_use_process_per_site(false); | |
417 | 405 |
418 const GURL url_a1("http://www.google.com/1.html"); | 406 const GURL url_a1("http://www.google.com/1.html"); |
419 scoped_refptr<SiteInstanceImpl> site_instance_a1( | 407 scoped_refptr<SiteInstanceImpl> site_instance_a1( |
420 static_cast<SiteInstanceImpl*>( | 408 static_cast<SiteInstanceImpl*>( |
421 browsing_instance->GetSiteInstanceForURL(url_a1))); | 409 browsing_instance->GetSiteInstanceForURL(url_a1))); |
422 EXPECT_TRUE(site_instance_a1.get() != NULL); | 410 EXPECT_TRUE(site_instance_a1.get() != NULL); |
423 | 411 |
424 // A separate site should create a separate SiteInstance. | 412 // A separate site should create a separate SiteInstance. |
425 const GURL url_b1("http://www.yahoo.com/"); | 413 const GURL url_b1("http://www.yahoo.com/"); |
426 scoped_refptr<SiteInstanceImpl> site_instance_b1( | 414 scoped_refptr<SiteInstanceImpl> site_instance_b1( |
(...skipping 10 matching lines...) Expand all Loading... | |
437 // A second visit to the original site should return the same SiteInstance. | 425 // A second visit to the original site should return the same SiteInstance. |
438 const GURL url_a2("http://www.google.com/2.html"); | 426 const GURL url_a2("http://www.google.com/2.html"); |
439 EXPECT_EQ(site_instance_a1.get(), | 427 EXPECT_EQ(site_instance_a1.get(), |
440 browsing_instance->GetSiteInstanceForURL(url_a2)); | 428 browsing_instance->GetSiteInstanceForURL(url_a2)); |
441 EXPECT_EQ(site_instance_a1.get(), | 429 EXPECT_EQ(site_instance_a1.get(), |
442 site_instance_a1->GetRelatedSiteInstance(url_a2)); | 430 site_instance_a1->GetRelatedSiteInstance(url_a2)); |
443 | 431 |
444 // A visit to the original site in a new BrowsingInstance (same or different | 432 // A visit to the original site in a new BrowsingInstance (same or different |
445 // browser context) should return a different SiteInstance. | 433 // browser context) should return a different SiteInstance. |
446 TestBrowsingInstance* browsing_instance2 = | 434 TestBrowsingInstance* browsing_instance2 = |
447 new TestBrowsingInstance(NULL, &delete_counter); | 435 new TestBrowsingInstance(browser_context.get(), &delete_counter); |
448 browsing_instance2->set_use_process_per_site(false); | |
449 // Ensure the new SiteInstance is ref counted so that it gets deleted. | 436 // Ensure the new SiteInstance is ref counted so that it gets deleted. |
450 scoped_refptr<SiteInstanceImpl> site_instance_a2_2( | 437 scoped_refptr<SiteInstanceImpl> site_instance_a2_2( |
451 static_cast<SiteInstanceImpl*>( | 438 static_cast<SiteInstanceImpl*>( |
452 browsing_instance2->GetSiteInstanceForURL(url_a2))); | 439 browsing_instance2->GetSiteInstanceForURL(url_a2))); |
453 EXPECT_NE(site_instance_a1.get(), site_instance_a2_2.get()); | 440 EXPECT_NE(site_instance_a1.get(), site_instance_a2_2.get()); |
454 EXPECT_FALSE(site_instance_a1->IsRelatedSiteInstance(site_instance_a2_2)); | 441 EXPECT_FALSE(site_instance_a1->IsRelatedSiteInstance(site_instance_a2_2)); |
455 | 442 |
443 // The two SiteInstances for http://google.com should not use the same process | |
444 // if process-per-site is not enabled. | |
445 scoped_ptr<content::RenderProcessHost> process_a1( | |
446 site_instance_a1->GetProcess()); | |
447 scoped_ptr<content::RenderProcessHost> process_a2_2( | |
448 site_instance_a2_2->GetProcess()); | |
449 EXPECT_NE(process_a1.get(), process_a2_2.get()); | |
450 | |
456 // Should be able to see that we do have SiteInstances. | 451 // Should be able to see that we do have SiteInstances. |
457 EXPECT_TRUE(browsing_instance->HasSiteInstance( | 452 EXPECT_TRUE(browsing_instance->HasSiteInstance( |
458 GURL("http://mail.google.com"))); | 453 GURL("http://mail.google.com"))); |
459 EXPECT_TRUE(browsing_instance2->HasSiteInstance( | 454 EXPECT_TRUE(browsing_instance2->HasSiteInstance( |
460 GURL("http://mail.google.com"))); | 455 GURL("http://mail.google.com"))); |
461 EXPECT_TRUE(browsing_instance->HasSiteInstance( | 456 EXPECT_TRUE(browsing_instance->HasSiteInstance( |
462 GURL("http://mail.yahoo.com"))); | 457 GURL("http://mail.yahoo.com"))); |
463 | 458 |
464 // Should be able to see that we don't have SiteInstances. | 459 // Should be able to see that we don't have SiteInstances. |
465 EXPECT_FALSE(browsing_instance->HasSiteInstance( | 460 EXPECT_FALSE(browsing_instance->HasSiteInstance( |
466 GURL("https://www.google.com"))); | 461 GURL("https://www.google.com"))); |
467 EXPECT_FALSE(browsing_instance2->HasSiteInstance( | 462 EXPECT_FALSE(browsing_instance2->HasSiteInstance( |
468 GURL("http://www.yahoo.com"))); | 463 GURL("http://www.yahoo.com"))); |
469 | 464 |
470 // browsing_instances will be deleted when their SiteInstances are deleted | 465 // browsing_instances will be deleted when their SiteInstances are deleted. |
466 // The processes will be unregistered when the RPH scoped_ptrs go away. | |
awong
2012/06/27 00:26:54
Do we have a way to assert these two assumptions i
Charlie Reis
2012/06/27 20:53:43
Actually, we already have the first assumption tes
| |
471 } | 467 } |
472 | 468 |
473 // Test to ensure that there is only one SiteInstance per site for an entire | 469 // Test to ensure that there is only one RenderProcessHost per site for an |
474 // BrowserContext, if process-per-site is in use. | 470 // entire BrowserContext, if process-per-site is in use. |
475 TEST_F(SiteInstanceTest, OneSiteInstancePerSiteInBrowserContext) { | 471 TEST_F(SiteInstanceTest, OneSiteInstancePerSiteInBrowserContext) { |
472 CommandLine::ForCurrentProcess()->AppendSwitch( | |
473 switches::kProcessPerSite); | |
476 int delete_counter = 0; | 474 int delete_counter = 0; |
475 scoped_ptr<content::TestBrowserContext> browser_context( | |
476 new content::TestBrowserContext()); | |
477 TestBrowsingInstance* browsing_instance = | 477 TestBrowsingInstance* browsing_instance = |
478 new TestBrowsingInstance(NULL, &delete_counter); | 478 new TestBrowsingInstance(browser_context.get(), &delete_counter); |
479 browsing_instance->set_use_process_per_site(true); | |
480 | 479 |
481 const GURL url_a1("http://www.google.com/1.html"); | 480 const GURL url_a1("http://www.google.com/1.html"); |
482 scoped_refptr<SiteInstanceImpl> site_instance_a1( | 481 scoped_refptr<SiteInstanceImpl> site_instance_a1( |
483 static_cast<SiteInstanceImpl*>( | 482 static_cast<SiteInstanceImpl*>( |
484 browsing_instance->GetSiteInstanceForURL(url_a1))); | 483 browsing_instance->GetSiteInstanceForURL(url_a1))); |
485 EXPECT_TRUE(site_instance_a1.get() != NULL); | 484 EXPECT_TRUE(site_instance_a1.get() != NULL); |
485 scoped_ptr<content::RenderProcessHost> process_a1( | |
486 site_instance_a1->GetProcess()); | |
486 | 487 |
487 // A separate site should create a separate SiteInstance. | 488 // A separate site should create a separate SiteInstance. |
488 const GURL url_b1("http://www.yahoo.com/"); | 489 const GURL url_b1("http://www.yahoo.com/"); |
489 scoped_refptr<SiteInstanceImpl> site_instance_b1( | 490 scoped_refptr<SiteInstanceImpl> site_instance_b1( |
490 static_cast<SiteInstanceImpl*>( | 491 static_cast<SiteInstanceImpl*>( |
491 browsing_instance->GetSiteInstanceForURL(url_b1))); | 492 browsing_instance->GetSiteInstanceForURL(url_b1))); |
492 EXPECT_NE(site_instance_a1.get(), site_instance_b1.get()); | 493 EXPECT_NE(site_instance_a1.get(), site_instance_b1.get()); |
493 EXPECT_TRUE(site_instance_a1->IsRelatedSiteInstance(site_instance_b1)); | 494 EXPECT_TRUE(site_instance_a1->IsRelatedSiteInstance(site_instance_b1)); |
494 | 495 |
495 // Getting the new SiteInstance from the BrowsingInstance and from another | 496 // Getting the new SiteInstance from the BrowsingInstance and from another |
496 // SiteInstance in the BrowsingInstance should give the same result. | 497 // SiteInstance in the BrowsingInstance should give the same result. |
497 EXPECT_EQ(site_instance_b1.get(), | 498 EXPECT_EQ(site_instance_b1.get(), |
498 site_instance_a1->GetRelatedSiteInstance(url_b1)); | 499 site_instance_a1->GetRelatedSiteInstance(url_b1)); |
499 | 500 |
500 // A second visit to the original site should return the same SiteInstance. | 501 // A second visit to the original site should return the same SiteInstance. |
501 const GURL url_a2("http://www.google.com/2.html"); | 502 const GURL url_a2("http://www.google.com/2.html"); |
502 EXPECT_EQ(site_instance_a1.get(), | 503 EXPECT_EQ(site_instance_a1.get(), |
503 browsing_instance->GetSiteInstanceForURL(url_a2)); | 504 browsing_instance->GetSiteInstanceForURL(url_a2)); |
504 EXPECT_EQ(site_instance_a1.get(), | 505 EXPECT_EQ(site_instance_a1.get(), |
505 site_instance_a1->GetRelatedSiteInstance(url_a2)); | 506 site_instance_a1->GetRelatedSiteInstance(url_a2)); |
506 | 507 |
507 // A visit to the original site in a new BrowsingInstance (same browser | 508 // A visit to the original site in a new BrowsingInstance (same browser |
508 // context) should also return the same SiteInstance. | 509 // context) should return a different SiteInstance with the same process. |
509 // This BrowsingInstance doesn't get its own SiteInstance within the test, so | 510 TestBrowsingInstance* browsing_instance2 = |
510 // it won't be deleted by its children. Thus, we'll keep a ref count to it | 511 new TestBrowsingInstance(browser_context.get(), &delete_counter); |
511 // to make sure it gets deleted. | 512 scoped_refptr<SiteInstanceImpl> site_instance_a1_2( |
512 scoped_refptr<TestBrowsingInstance> browsing_instance2( | 513 static_cast<SiteInstanceImpl*>( |
513 new TestBrowsingInstance(NULL, &delete_counter)); | 514 browsing_instance2->GetSiteInstanceForURL(url_a1))); |
514 browsing_instance2->set_use_process_per_site(true); | 515 EXPECT_TRUE(site_instance_a1.get() != NULL); |
awong
2012/06/27 00:26:54
should we assert that site_instance_a1 != site_ins
Charlie Reis
2012/06/27 20:53:43
Good call. Added.
| |
515 EXPECT_EQ(site_instance_a1.get(), | 516 EXPECT_EQ(process_a1.get(), site_instance_a1_2->GetProcess()); |
516 browsing_instance2->GetSiteInstanceForURL(url_a2)); | |
517 | 517 |
518 // A visit to the original site in a new BrowsingInstance (different browser | 518 // A visit to the original site in a new BrowsingInstance (different browser |
519 // context) should return a different SiteInstance. | 519 // context) should return a different SiteInstance with a different process. |
520 scoped_ptr<content::TestBrowserContext> browser_context( | 520 scoped_ptr<content::TestBrowserContext> browser_context2( |
521 new content::TestBrowserContext()); | 521 new content::TestBrowserContext()); |
522 TestBrowsingInstance* browsing_instance3 = | 522 TestBrowsingInstance* browsing_instance3 = |
523 new TestBrowsingInstance(browser_context.get(), &delete_counter); | 523 new TestBrowsingInstance(browser_context2.get(), &delete_counter); |
524 browsing_instance3->set_use_process_per_site(true); | |
525 // Ensure the new SiteInstance is ref counted so that it gets deleted. | |
526 scoped_refptr<SiteInstanceImpl> site_instance_a2_3( | 524 scoped_refptr<SiteInstanceImpl> site_instance_a2_3( |
527 static_cast<SiteInstanceImpl*>( | 525 static_cast<SiteInstanceImpl*>( |
528 browsing_instance3->GetSiteInstanceForURL(url_a2))); | 526 browsing_instance3->GetSiteInstanceForURL(url_a2))); |
529 EXPECT_NE(site_instance_a1.get(), site_instance_a2_3.get()); | 527 EXPECT_TRUE(site_instance_a2_3.get() != NULL); |
528 scoped_ptr<content::RenderProcessHost> process_a2_3( | |
529 site_instance_a2_3->GetProcess()); | |
530 EXPECT_NE(process_a1.get(), process_a2_3.get()); | |
awong
2012/06/27 00:26:54
Same question about comparing the site instances..
Charlie Reis
2012/06/27 20:53:43
Done.
| |
530 | 531 |
531 // Should be able to see that we do have SiteInstances. | 532 // Should be able to see that we do have SiteInstances. |
532 EXPECT_TRUE(browsing_instance->HasSiteInstance( | 533 EXPECT_TRUE(browsing_instance->HasSiteInstance( |
533 GURL("http://mail.google.com"))); // visited before | 534 GURL("http://mail.google.com"))); // visited before |
534 EXPECT_TRUE(browsing_instance2->HasSiteInstance( | 535 EXPECT_TRUE(browsing_instance2->HasSiteInstance( |
535 GURL("http://mail.google.com"))); // visited before | 536 GURL("http://mail.google.com"))); // visited before |
536 EXPECT_TRUE(browsing_instance->HasSiteInstance( | 537 EXPECT_TRUE(browsing_instance->HasSiteInstance( |
537 GURL("http://mail.yahoo.com"))); // visited before | 538 GURL("http://mail.yahoo.com"))); // visited before |
538 EXPECT_TRUE(browsing_instance2->HasSiteInstance( | |
539 GURL("http://www.yahoo.com"))); // different BI, but same browser context | |
540 | 539 |
541 // Should be able to see that we don't have SiteInstances. | 540 // Should be able to see that we don't have SiteInstances. |
541 EXPECT_FALSE(browsing_instance2->HasSiteInstance( | |
542 GURL("http://www.yahoo.com"))); // different BI, same browser context | |
542 EXPECT_FALSE(browsing_instance->HasSiteInstance( | 543 EXPECT_FALSE(browsing_instance->HasSiteInstance( |
543 GURL("https://www.google.com"))); // not visited before | 544 GURL("https://www.google.com"))); // not visited before |
544 EXPECT_FALSE(browsing_instance3->HasSiteInstance( | 545 EXPECT_FALSE(browsing_instance3->HasSiteInstance( |
545 GURL("http://www.yahoo.com"))); // different BI, different context | 546 GURL("http://www.yahoo.com"))); // different BI, different context |
546 | 547 |
547 // browsing_instances will be deleted when their SiteInstances are deleted | 548 // browsing_instances will be deleted when their SiteInstances are deleted. |
549 // The processes will be unregistered when the RPH scoped_ptrs go away. | |
548 } | 550 } |
549 | 551 |
550 static SiteInstanceImpl* CreateSiteInstance( | 552 static SiteInstanceImpl* CreateSiteInstance( |
551 content::RenderProcessHostFactory* factory, const GURL& url) { | 553 content::RenderProcessHostFactory* factory, const GURL& url) { |
552 SiteInstanceImpl* instance = | 554 SiteInstanceImpl* instance = |
553 reinterpret_cast<SiteInstanceImpl*>( | 555 reinterpret_cast<SiteInstanceImpl*>( |
554 SiteInstance::CreateForURL(NULL, url)); | 556 SiteInstance::CreateForURL(NULL, url)); |
555 instance->set_render_process_host_factory(factory); | 557 instance->set_render_process_host_factory(factory); |
556 return instance; | 558 return instance; |
557 } | 559 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
632 host.reset(instance->GetProcess()); | 634 host.reset(instance->GetProcess()); |
633 EXPECT_TRUE(host.get() != NULL); | 635 EXPECT_TRUE(host.get() != NULL); |
634 EXPECT_TRUE(instance->HasProcess()); | 636 EXPECT_TRUE(instance->HasProcess()); |
635 | 637 |
636 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://evernote.com"))); | 638 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://evernote.com"))); |
637 EXPECT_FALSE(instance->HasWrongProcessForURL( | 639 EXPECT_FALSE(instance->HasWrongProcessForURL( |
638 GURL("javascript:alert(document.location.href);"))); | 640 GURL("javascript:alert(document.location.href);"))); |
639 | 641 |
640 EXPECT_TRUE(instance->HasWrongProcessForURL(GURL("chrome://settings"))); | 642 EXPECT_TRUE(instance->HasWrongProcessForURL(GURL("chrome://settings"))); |
641 } | 643 } |
OLD | NEW |