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/site_instance_impl.h" | 5 #include "content/browser/site_instance_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 EXPECT_TRUE(RenderProcessHost::AllHostsIterator().IsAtEnd()); | 115 EXPECT_TRUE(RenderProcessHost::AllHostsIterator().IsAtEnd()); |
116 | 116 |
117 SetBrowserClientForTesting(old_browser_client_); | 117 SetBrowserClientForTesting(old_browser_client_); |
118 SiteInstanceImpl::set_render_process_host_factory(nullptr); | 118 SiteInstanceImpl::set_render_process_host_factory(nullptr); |
119 | 119 |
120 // http://crbug.com/143565 found SiteInstanceTest leaking an | 120 // http://crbug.com/143565 found SiteInstanceTest leaking an |
121 // AppCacheDatabase. This happens because some part of the test indirectly | 121 // AppCacheDatabase. This happens because some part of the test indirectly |
122 // calls StoragePartitionImplMap::PostCreateInitialization(), which posts | 122 // calls StoragePartitionImplMap::PostCreateInitialization(), which posts |
123 // a task to the IO thread to create the AppCacheDatabase. Since the | 123 // a task to the IO thread to create the AppCacheDatabase. Since the |
124 // message loop is not running, the AppCacheDatabase ends up getting | 124 // message loop is not running, the AppCacheDatabase ends up getting |
125 // created when DrainMessageLoops() gets called at the end of a test case. | 125 // created when DrainMessageLoop() gets called at the end of a test case. |
126 // Immediately after, the test case ends and the AppCacheDatabase gets | 126 // Immediately after, the test case ends and the AppCacheDatabase gets |
127 // scheduled for deletion. Here, call DrainMessageLoops() again so the | 127 // scheduled for deletion. Here, call DrainMessageLoop() again so the |
128 // AppCacheDatabase actually gets deleted. | 128 // AppCacheDatabase actually gets deleted. |
129 DrainMessageLoops(); | 129 DrainMessageLoop(); |
130 } | 130 } |
131 | 131 |
132 void set_privileged_process_id(int process_id) { | 132 void set_privileged_process_id(int process_id) { |
133 browser_client_.set_privileged_process_id(process_id); | 133 browser_client_.set_privileged_process_id(process_id); |
134 } | 134 } |
135 | 135 |
136 void DrainMessageLoops() { | 136 void DrainMessageLoop() { |
137 // We don't just do this in TearDown() because we create TestBrowserContext | 137 // We don't just do this in TearDown() because we create TestBrowserContext |
138 // objects in each test, which will be destructed before | 138 // objects in each test, which will be destructed before |
139 // TearDown() is called. | 139 // TearDown() is called. |
140 base::RunLoop().RunUntilIdle(); | 140 base::RunLoop().RunUntilIdle(); |
141 message_loop_.RunUntilIdle(); | |
142 } | 141 } |
143 | 142 |
144 SiteInstanceTestBrowserClient* browser_client() { return &browser_client_; } | 143 SiteInstanceTestBrowserClient* browser_client() { return &browser_client_; } |
145 | 144 |
146 private: | 145 private: |
147 base::MessageLoopForUI message_loop_; | 146 base::MessageLoopForUI message_loop_; |
148 TestBrowserThread ui_thread_; | 147 TestBrowserThread ui_thread_; |
149 TestBrowserThread file_user_blocking_thread_; | 148 TestBrowserThread file_user_blocking_thread_; |
150 TestBrowserThread io_thread_; | 149 TestBrowserThread io_thread_; |
151 | 150 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 std::unique_ptr<WebContentsImpl> web_contents(static_cast<WebContentsImpl*>( | 198 std::unique_ptr<WebContentsImpl> web_contents(static_cast<WebContentsImpl*>( |
200 WebContents::Create(WebContents::CreateParams( | 199 WebContents::Create(WebContents::CreateParams( |
201 browser_context.get(), | 200 browser_context.get(), |
202 SiteInstance::Create(browser_context.get()))))); | 201 SiteInstance::Create(browser_context.get()))))); |
203 EXPECT_EQ(0, browser_client()->GetAndClearSiteInstanceDeleteCount()); | 202 EXPECT_EQ(0, browser_client()->GetAndClearSiteInstanceDeleteCount()); |
204 EXPECT_EQ(0, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); | 203 EXPECT_EQ(0, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); |
205 } | 204 } |
206 | 205 |
207 // Make sure that we flush any messages related to the above WebContentsImpl | 206 // Make sure that we flush any messages related to the above WebContentsImpl |
208 // destruction. | 207 // destruction. |
209 DrainMessageLoops(); | 208 DrainMessageLoop(); |
210 | 209 |
211 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); | 210 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); |
212 EXPECT_EQ(1, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); | 211 EXPECT_EQ(1, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); |
213 // contents is now deleted, along with instance and browsing_instance | 212 // contents is now deleted, along with instance and browsing_instance |
214 } | 213 } |
215 | 214 |
216 // Test that NavigationEntries with SiteInstances can be cloned, but that their | 215 // Test that NavigationEntries with SiteInstances can be cloned, but that their |
217 // SiteInstances can be changed afterwards. Also tests that the ref counts are | 216 // SiteInstances can be changed afterwards. Also tests that the ref counts are |
218 // updated properly after the change. | 217 // updated properly after the change. |
219 TEST_F(SiteInstanceTest, CloneNavigationEntry) { | 218 TEST_F(SiteInstanceTest, CloneNavigationEntry) { |
(...skipping 17 matching lines...) Expand all Loading... |
237 // e1, since e2 should no longer be referencing it. | 236 // e1, since e2 should no longer be referencing it. |
238 e1.reset(); | 237 e1.reset(); |
239 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); | 238 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); |
240 EXPECT_EQ(1, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); | 239 EXPECT_EQ(1, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); |
241 | 240 |
242 // The second SiteInstance should go away after resetting e2. | 241 // The second SiteInstance should go away after resetting e2. |
243 e2.reset(); | 242 e2.reset(); |
244 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); | 243 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); |
245 EXPECT_EQ(1, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); | 244 EXPECT_EQ(1, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); |
246 | 245 |
247 DrainMessageLoops(); | 246 DrainMessageLoop(); |
248 } | 247 } |
249 | 248 |
250 // Test to ensure GetProcess returns and creates processes correctly. | 249 // Test to ensure GetProcess returns and creates processes correctly. |
251 TEST_F(SiteInstanceTest, GetProcess) { | 250 TEST_F(SiteInstanceTest, GetProcess) { |
252 // Ensure that GetProcess returns a process. | 251 // Ensure that GetProcess returns a process. |
253 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 252 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
254 std::unique_ptr<RenderProcessHost> host1; | 253 std::unique_ptr<RenderProcessHost> host1; |
255 scoped_refptr<SiteInstanceImpl> instance( | 254 scoped_refptr<SiteInstanceImpl> instance( |
256 SiteInstanceImpl::Create(browser_context.get())); | 255 SiteInstanceImpl::Create(browser_context.get())); |
257 host1.reset(instance->GetProcess()); | 256 host1.reset(instance->GetProcess()); |
258 EXPECT_TRUE(host1.get() != nullptr); | 257 EXPECT_TRUE(host1.get() != nullptr); |
259 | 258 |
260 // Ensure that GetProcess creates a new process. | 259 // Ensure that GetProcess creates a new process. |
261 scoped_refptr<SiteInstanceImpl> instance2( | 260 scoped_refptr<SiteInstanceImpl> instance2( |
262 SiteInstanceImpl::Create(browser_context.get())); | 261 SiteInstanceImpl::Create(browser_context.get())); |
263 std::unique_ptr<RenderProcessHost> host2(instance2->GetProcess()); | 262 std::unique_ptr<RenderProcessHost> host2(instance2->GetProcess()); |
264 EXPECT_TRUE(host2.get() != nullptr); | 263 EXPECT_TRUE(host2.get() != nullptr); |
265 EXPECT_NE(host1.get(), host2.get()); | 264 EXPECT_NE(host1.get(), host2.get()); |
266 | 265 |
267 DrainMessageLoops(); | 266 DrainMessageLoop(); |
268 } | 267 } |
269 | 268 |
270 // Test to ensure SetSite and site() work properly. | 269 // Test to ensure SetSite and site() work properly. |
271 TEST_F(SiteInstanceTest, SetSite) { | 270 TEST_F(SiteInstanceTest, SetSite) { |
272 scoped_refptr<SiteInstanceImpl> instance(SiteInstanceImpl::Create(nullptr)); | 271 scoped_refptr<SiteInstanceImpl> instance(SiteInstanceImpl::Create(nullptr)); |
273 EXPECT_FALSE(instance->HasSite()); | 272 EXPECT_FALSE(instance->HasSite()); |
274 EXPECT_TRUE(instance->GetSiteURL().is_empty()); | 273 EXPECT_TRUE(instance->GetSiteURL().is_empty()); |
275 | 274 |
276 instance->SetSite(GURL("http://www.google.com/index.html")); | 275 instance->SetSite(GURL("http://www.google.com/index.html")); |
277 EXPECT_EQ(GURL("http://google.com"), instance->GetSiteURL()); | 276 EXPECT_EQ(GURL("http://google.com"), instance->GetSiteURL()); |
278 | 277 |
279 EXPECT_TRUE(instance->HasSite()); | 278 EXPECT_TRUE(instance->HasSite()); |
280 | 279 |
281 DrainMessageLoops(); | 280 DrainMessageLoop(); |
282 } | 281 } |
283 | 282 |
284 // Test to ensure GetSiteForURL properly returns sites for URLs. | 283 // Test to ensure GetSiteForURL properly returns sites for URLs. |
285 TEST_F(SiteInstanceTest, GetSiteForURL) { | 284 TEST_F(SiteInstanceTest, GetSiteForURL) { |
286 // Pages are irrelevant. | 285 // Pages are irrelevant. |
287 GURL test_url = GURL("http://www.google.com/index.html"); | 286 GURL test_url = GURL("http://www.google.com/index.html"); |
288 GURL site_url = SiteInstanceImpl::GetSiteForURL(nullptr, test_url); | 287 GURL site_url = SiteInstanceImpl::GetSiteForURL(nullptr, test_url); |
289 EXPECT_EQ(GURL("http://google.com"), site_url); | 288 EXPECT_EQ(GURL("http://google.com"), site_url); |
290 EXPECT_EQ("http", site_url.scheme()); | 289 EXPECT_EQ("http", site_url.scheme()); |
291 EXPECT_EQ("google.com", site_url.host()); | 290 EXPECT_EQ("google.com", site_url.host()); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 EXPECT_EQ(GURL("http://google.com"), site_url); | 373 EXPECT_EQ(GURL("http://google.com"), site_url); |
375 | 374 |
376 // Guest URLs are special and need to have the path in the site as well, | 375 // Guest URLs are special and need to have the path in the site as well, |
377 // since it affects the StoragePartition configuration. | 376 // since it affects the StoragePartition configuration. |
378 std::string guest_url(kGuestScheme); | 377 std::string guest_url(kGuestScheme); |
379 guest_url.append("://abc123/path"); | 378 guest_url.append("://abc123/path"); |
380 test_url = GURL(guest_url); | 379 test_url = GURL(guest_url); |
381 site_url = SiteInstanceImpl::GetSiteForURL(nullptr, test_url); | 380 site_url = SiteInstanceImpl::GetSiteForURL(nullptr, test_url); |
382 EXPECT_EQ(test_url, site_url); | 381 EXPECT_EQ(test_url, site_url); |
383 | 382 |
384 DrainMessageLoops(); | 383 DrainMessageLoop(); |
385 } | 384 } |
386 | 385 |
387 // Test of distinguishing URLs from different sites. Most of this logic is | 386 // Test of distinguishing URLs from different sites. Most of this logic is |
388 // tested in RegistryControlledDomainTest. This test focuses on URLs with | 387 // tested in RegistryControlledDomainTest. This test focuses on URLs with |
389 // different schemes or ports. | 388 // different schemes or ports. |
390 TEST_F(SiteInstanceTest, IsSameWebSite) { | 389 TEST_F(SiteInstanceTest, IsSameWebSite) { |
391 GURL url_foo = GURL("http://foo/a.html"); | 390 GURL url_foo = GURL("http://foo/a.html"); |
392 GURL url_foo2 = GURL("http://foo/b.html"); | 391 GURL url_foo2 = GURL("http://foo/b.html"); |
393 GURL url_foo_https = GURL("https://foo/a.html"); | 392 GURL url_foo_https = GURL("https://foo/a.html"); |
394 GURL url_foo_port = GURL("http://foo:8080/a.html"); | 393 GURL url_foo_port = GURL("http://foo:8080/a.html"); |
(...skipping 20 matching lines...) Expand all Loading... |
415 // Navigating to a blank page is considered the same site. | 414 // Navigating to a blank page is considered the same site. |
416 EXPECT_TRUE(SiteInstance::IsSameWebSite(nullptr, url_foo, url_blank)); | 415 EXPECT_TRUE(SiteInstance::IsSameWebSite(nullptr, url_foo, url_blank)); |
417 EXPECT_TRUE(SiteInstance::IsSameWebSite(nullptr, url_foo_https, url_blank)); | 416 EXPECT_TRUE(SiteInstance::IsSameWebSite(nullptr, url_foo_https, url_blank)); |
418 EXPECT_TRUE(SiteInstance::IsSameWebSite(nullptr, url_foo_port, url_blank)); | 417 EXPECT_TRUE(SiteInstance::IsSameWebSite(nullptr, url_foo_port, url_blank)); |
419 | 418 |
420 // Navigating from a blank site is not considered to be the same site. | 419 // Navigating from a blank site is not considered to be the same site. |
421 EXPECT_FALSE(SiteInstance::IsSameWebSite(nullptr, url_blank, url_foo)); | 420 EXPECT_FALSE(SiteInstance::IsSameWebSite(nullptr, url_blank, url_foo)); |
422 EXPECT_FALSE(SiteInstance::IsSameWebSite(nullptr, url_blank, url_foo_https)); | 421 EXPECT_FALSE(SiteInstance::IsSameWebSite(nullptr, url_blank, url_foo_https)); |
423 EXPECT_FALSE(SiteInstance::IsSameWebSite(nullptr, url_blank, url_foo_port)); | 422 EXPECT_FALSE(SiteInstance::IsSameWebSite(nullptr, url_blank, url_foo_port)); |
424 | 423 |
425 DrainMessageLoops(); | 424 DrainMessageLoop(); |
426 } | 425 } |
427 | 426 |
428 // Test to ensure that there is only one SiteInstance per site in a given | 427 // Test to ensure that there is only one SiteInstance per site in a given |
429 // BrowsingInstance, when process-per-site is not in use. | 428 // BrowsingInstance, when process-per-site is not in use. |
430 TEST_F(SiteInstanceTest, OneSiteInstancePerSite) { | 429 TEST_F(SiteInstanceTest, OneSiteInstancePerSite) { |
431 ASSERT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( | 430 ASSERT_FALSE(base::CommandLine::ForCurrentProcess()->HasSwitch( |
432 switches::kProcessPerSite)); | 431 switches::kProcessPerSite)); |
433 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 432 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
434 BrowsingInstance* browsing_instance = | 433 BrowsingInstance* browsing_instance = |
435 new BrowsingInstance(browser_context.get()); | 434 new BrowsingInstance(browser_context.get()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 | 486 |
488 // Should be able to see that we don't have SiteInstances. | 487 // Should be able to see that we don't have SiteInstances. |
489 EXPECT_FALSE(browsing_instance->HasSiteInstance( | 488 EXPECT_FALSE(browsing_instance->HasSiteInstance( |
490 GURL("https://www.google.com"))); | 489 GURL("https://www.google.com"))); |
491 EXPECT_FALSE(browsing_instance2->HasSiteInstance( | 490 EXPECT_FALSE(browsing_instance2->HasSiteInstance( |
492 GURL("http://www.yahoo.com"))); | 491 GURL("http://www.yahoo.com"))); |
493 | 492 |
494 // browsing_instances will be deleted when their SiteInstances are deleted. | 493 // browsing_instances will be deleted when their SiteInstances are deleted. |
495 // The processes will be unregistered when the RPH scoped_ptrs go away. | 494 // The processes will be unregistered when the RPH scoped_ptrs go away. |
496 | 495 |
497 DrainMessageLoops(); | 496 DrainMessageLoop(); |
498 } | 497 } |
499 | 498 |
500 // Test to ensure that there is only one RenderProcessHost per site for an | 499 // Test to ensure that there is only one RenderProcessHost per site for an |
501 // entire BrowserContext, if process-per-site is in use. | 500 // entire BrowserContext, if process-per-site is in use. |
502 TEST_F(SiteInstanceTest, OneSiteInstancePerSiteInBrowserContext) { | 501 TEST_F(SiteInstanceTest, OneSiteInstancePerSiteInBrowserContext) { |
503 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 502 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
504 switches::kProcessPerSite); | 503 switches::kProcessPerSite); |
505 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 504 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
506 scoped_refptr<BrowsingInstance> browsing_instance = | 505 scoped_refptr<BrowsingInstance> browsing_instance = |
507 new BrowsingInstance(browser_context.get()); | 506 new BrowsingInstance(browser_context.get()); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 EXPECT_FALSE(browsing_instance2->HasSiteInstance( | 566 EXPECT_FALSE(browsing_instance2->HasSiteInstance( |
568 GURL("http://www.yahoo.com"))); // different BI, same browser context | 567 GURL("http://www.yahoo.com"))); // different BI, same browser context |
569 EXPECT_FALSE(browsing_instance->HasSiteInstance( | 568 EXPECT_FALSE(browsing_instance->HasSiteInstance( |
570 GURL("https://www.google.com"))); // not visited before | 569 GURL("https://www.google.com"))); // not visited before |
571 EXPECT_FALSE(browsing_instance3->HasSiteInstance( | 570 EXPECT_FALSE(browsing_instance3->HasSiteInstance( |
572 GURL("http://www.yahoo.com"))); // different BI, different context | 571 GURL("http://www.yahoo.com"))); // different BI, different context |
573 | 572 |
574 // browsing_instances will be deleted when their SiteInstances are deleted. | 573 // browsing_instances will be deleted when their SiteInstances are deleted. |
575 // The processes will be unregistered when the RPH scoped_ptrs go away. | 574 // The processes will be unregistered when the RPH scoped_ptrs go away. |
576 | 575 |
577 DrainMessageLoops(); | 576 DrainMessageLoop(); |
578 } | 577 } |
579 | 578 |
580 static scoped_refptr<SiteInstanceImpl> CreateSiteInstance( | 579 static scoped_refptr<SiteInstanceImpl> CreateSiteInstance( |
581 BrowserContext* browser_context, | 580 BrowserContext* browser_context, |
582 const GURL& url) { | 581 const GURL& url) { |
583 return SiteInstanceImpl::CreateForURL(browser_context, url); | 582 return SiteInstanceImpl::CreateForURL(browser_context, url); |
584 } | 583 } |
585 | 584 |
586 // Test to ensure that pages that require certain privileges are grouped | 585 // Test to ensure that pages that require certain privileges are grouped |
587 // in processes with similar pages. | 586 // in processes with similar pages. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 EXPECT_EQ(webui1_instance->GetProcess(), webui2_instance->GetProcess()); | 632 EXPECT_EQ(webui1_instance->GetProcess(), webui2_instance->GetProcess()); |
634 | 633 |
635 // Make sure none of differing privilege processes are mixed. | 634 // Make sure none of differing privilege processes are mixed. |
636 EXPECT_NE(extension1_instance->GetProcess(), webui1_instance->GetProcess()); | 635 EXPECT_NE(extension1_instance->GetProcess(), webui1_instance->GetProcess()); |
637 | 636 |
638 for (size_t i = 0; i < kMaxRendererProcessCount; ++i) { | 637 for (size_t i = 0; i < kMaxRendererProcessCount; ++i) { |
639 EXPECT_NE(extension1_instance->GetProcess(), hosts[i]); | 638 EXPECT_NE(extension1_instance->GetProcess(), hosts[i]); |
640 EXPECT_NE(webui1_instance->GetProcess(), hosts[i]); | 639 EXPECT_NE(webui1_instance->GetProcess(), hosts[i]); |
641 } | 640 } |
642 | 641 |
643 DrainMessageLoops(); | 642 DrainMessageLoop(); |
644 | 643 |
645 // Disable the process limit override. | 644 // Disable the process limit override. |
646 RenderProcessHost::SetMaxRendererProcessCount(0u); | 645 RenderProcessHost::SetMaxRendererProcessCount(0u); |
647 } | 646 } |
648 | 647 |
649 // Test to ensure that HasWrongProcessForURL behaves properly for different | 648 // Test to ensure that HasWrongProcessForURL behaves properly for different |
650 // types of URLs. | 649 // types of URLs. |
651 TEST_F(SiteInstanceTest, HasWrongProcessForURL) { | 650 TEST_F(SiteInstanceTest, HasWrongProcessForURL) { |
652 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 651 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
653 std::unique_ptr<RenderProcessHost> host; | 652 std::unique_ptr<RenderProcessHost> host; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 // WebUI uses process-per-site, so another instance will use the same process | 694 // WebUI uses process-per-site, so another instance will use the same process |
696 // even if we haven't called GetProcess yet. Make sure HasWrongProcessForURL | 695 // even if we haven't called GetProcess yet. Make sure HasWrongProcessForURL |
697 // doesn't crash (http://crbug.com/137070). | 696 // doesn't crash (http://crbug.com/137070). |
698 scoped_refptr<SiteInstanceImpl> webui_instance2( | 697 scoped_refptr<SiteInstanceImpl> webui_instance2( |
699 SiteInstanceImpl::Create(browser_context.get())); | 698 SiteInstanceImpl::Create(browser_context.get())); |
700 webui_instance2->SetSite(webui_url); | 699 webui_instance2->SetSite(webui_url); |
701 EXPECT_FALSE(webui_instance2->HasWrongProcessForURL(webui_url)); | 700 EXPECT_FALSE(webui_instance2->HasWrongProcessForURL(webui_url)); |
702 EXPECT_TRUE( | 701 EXPECT_TRUE( |
703 webui_instance2->HasWrongProcessForURL(GURL("http://google.com"))); | 702 webui_instance2->HasWrongProcessForURL(GURL("http://google.com"))); |
704 | 703 |
705 DrainMessageLoops(); | 704 DrainMessageLoop(); |
706 } | 705 } |
707 | 706 |
708 // Test to ensure that HasWrongProcessForURL behaves properly even when | 707 // Test to ensure that HasWrongProcessForURL behaves properly even when |
709 // --site-per-process is used (http://crbug.com/160671). | 708 // --site-per-process is used (http://crbug.com/160671). |
710 TEST_F(SiteInstanceTest, HasWrongProcessForURLInSitePerProcess) { | 709 TEST_F(SiteInstanceTest, HasWrongProcessForURLInSitePerProcess) { |
711 IsolateAllSitesForTesting(base::CommandLine::ForCurrentProcess()); | 710 IsolateAllSitesForTesting(base::CommandLine::ForCurrentProcess()); |
712 | 711 |
713 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 712 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
714 std::unique_ptr<RenderProcessHost> host; | 713 std::unique_ptr<RenderProcessHost> host; |
715 scoped_refptr<SiteInstanceImpl> instance( | 714 scoped_refptr<SiteInstanceImpl> instance( |
(...skipping 11 matching lines...) Expand all Loading... |
727 host.reset(instance->GetProcess()); | 726 host.reset(instance->GetProcess()); |
728 EXPECT_TRUE(host.get() != nullptr); | 727 EXPECT_TRUE(host.get() != nullptr); |
729 EXPECT_TRUE(instance->HasProcess()); | 728 EXPECT_TRUE(instance->HasProcess()); |
730 | 729 |
731 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://evernote.com"))); | 730 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://evernote.com"))); |
732 EXPECT_FALSE(instance->HasWrongProcessForURL( | 731 EXPECT_FALSE(instance->HasWrongProcessForURL( |
733 GURL("javascript:alert(document.location.href);"))); | 732 GURL("javascript:alert(document.location.href);"))); |
734 | 733 |
735 EXPECT_TRUE(instance->HasWrongProcessForURL(GURL("chrome://gpu"))); | 734 EXPECT_TRUE(instance->HasWrongProcessForURL(GURL("chrome://gpu"))); |
736 | 735 |
737 DrainMessageLoops(); | 736 DrainMessageLoop(); |
738 } | 737 } |
739 | 738 |
740 // Test that we do not reuse a process in process-per-site mode if it has the | 739 // Test that we do not reuse a process in process-per-site mode if it has the |
741 // wrong bindings for its URL. http://crbug.com/174059. | 740 // wrong bindings for its URL. http://crbug.com/174059. |
742 TEST_F(SiteInstanceTest, ProcessPerSiteWithWrongBindings) { | 741 TEST_F(SiteInstanceTest, ProcessPerSiteWithWrongBindings) { |
743 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 742 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
744 std::unique_ptr<RenderProcessHost> host; | 743 std::unique_ptr<RenderProcessHost> host; |
745 std::unique_ptr<RenderProcessHost> host2; | 744 std::unique_ptr<RenderProcessHost> host2; |
746 scoped_refptr<SiteInstanceImpl> instance( | 745 scoped_refptr<SiteInstanceImpl> instance( |
747 SiteInstanceImpl::Create(browser_context.get())); | 746 SiteInstanceImpl::Create(browser_context.get())); |
(...skipping 19 matching lines...) Expand all Loading... |
767 // same process. Make sure it doesn't use the same process if the bindings | 766 // same process. Make sure it doesn't use the same process if the bindings |
768 // are missing. | 767 // are missing. |
769 scoped_refptr<SiteInstanceImpl> instance2( | 768 scoped_refptr<SiteInstanceImpl> instance2( |
770 SiteInstanceImpl::Create(browser_context.get())); | 769 SiteInstanceImpl::Create(browser_context.get())); |
771 instance2->SetSite(webui_url); | 770 instance2->SetSite(webui_url); |
772 host2.reset(instance2->GetProcess()); | 771 host2.reset(instance2->GetProcess()); |
773 EXPECT_TRUE(host2.get() != nullptr); | 772 EXPECT_TRUE(host2.get() != nullptr); |
774 EXPECT_TRUE(instance2->HasProcess()); | 773 EXPECT_TRUE(instance2->HasProcess()); |
775 EXPECT_NE(host.get(), host2.get()); | 774 EXPECT_NE(host.get(), host2.get()); |
776 | 775 |
777 DrainMessageLoops(); | 776 DrainMessageLoop(); |
778 } | 777 } |
779 | 778 |
780 // Test that we do not register processes with empty sites for process-per-site | 779 // Test that we do not register processes with empty sites for process-per-site |
781 // mode. | 780 // mode. |
782 TEST_F(SiteInstanceTest, NoProcessPerSiteForEmptySite) { | 781 TEST_F(SiteInstanceTest, NoProcessPerSiteForEmptySite) { |
783 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 782 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
784 switches::kProcessPerSite); | 783 switches::kProcessPerSite); |
785 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 784 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
786 std::unique_ptr<RenderProcessHost> host; | 785 std::unique_ptr<RenderProcessHost> host; |
787 scoped_refptr<SiteInstanceImpl> instance( | 786 scoped_refptr<SiteInstanceImpl> instance( |
788 SiteInstanceImpl::Create(browser_context.get())); | 787 SiteInstanceImpl::Create(browser_context.get())); |
789 | 788 |
790 instance->SetSite(GURL()); | 789 instance->SetSite(GURL()); |
791 EXPECT_TRUE(instance->HasSite()); | 790 EXPECT_TRUE(instance->HasSite()); |
792 EXPECT_TRUE(instance->GetSiteURL().is_empty()); | 791 EXPECT_TRUE(instance->GetSiteURL().is_empty()); |
793 host.reset(instance->GetProcess()); | 792 host.reset(instance->GetProcess()); |
794 | 793 |
795 EXPECT_FALSE(RenderProcessHostImpl::GetProcessHostForSite( | 794 EXPECT_FALSE(RenderProcessHostImpl::GetProcessHostForSite( |
796 browser_context.get(), GURL())); | 795 browser_context.get(), GURL())); |
797 | 796 |
798 DrainMessageLoops(); | 797 DrainMessageLoop(); |
799 } | 798 } |
800 | 799 |
801 TEST_F(SiteInstanceTest, DefaultSubframeSiteInstance) { | 800 TEST_F(SiteInstanceTest, DefaultSubframeSiteInstance) { |
802 if (AreAllSitesIsolatedForTesting()) | 801 if (AreAllSitesIsolatedForTesting()) |
803 return; // --top-document-isolation is not possible. | 802 return; // --top-document-isolation is not possible. |
804 | 803 |
805 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 804 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
806 switches::kTopDocumentIsolation); | 805 switches::kTopDocumentIsolation); |
807 | 806 |
808 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 807 std::unique_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); | 840 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); |
842 EXPECT_EQ(0, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); | 841 EXPECT_EQ(0, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); |
843 | 842 |
844 // Free the subframe instance, which should free the browsing instance. | 843 // Free the subframe instance, which should free the browsing instance. |
845 subframe_instance = nullptr; | 844 subframe_instance = nullptr; |
846 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); | 845 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); |
847 EXPECT_EQ(1, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); | 846 EXPECT_EQ(1, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); |
848 } | 847 } |
849 | 848 |
850 } // namespace content | 849 } // namespace content |
OLD | NEW |