OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 10 #include "content/browser/child_process_security_policy.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 MessageLoopForUI message_loop_; | 110 MessageLoopForUI message_loop_; |
111 BrowserThreadImpl ui_thread_; | 111 BrowserThreadImpl ui_thread_; |
112 | 112 |
113 SiteInstanceTestBrowserClient browser_client_; | 113 SiteInstanceTestBrowserClient browser_client_; |
114 content::ContentBrowserClient* old_browser_client_; | 114 content::ContentBrowserClient* old_browser_client_; |
115 }; | 115 }; |
116 | 116 |
117 class TestBrowsingInstance : public BrowsingInstance { | 117 class TestBrowsingInstance : public BrowsingInstance { |
118 public: | 118 public: |
119 TestBrowsingInstance(content::BrowserContext* browser_context, | 119 TestBrowsingInstance(content::BrowserContext* browser_context, |
120 int* deleteCounter) | 120 int* delete_counter) |
121 : BrowsingInstance(browser_context), | 121 : BrowsingInstance(browser_context), |
122 use_process_per_site(false), | 122 use_process_per_site_(false), |
123 deleteCounter_(deleteCounter) { | 123 delete_counter_(delete_counter) { |
124 } | 124 } |
125 | 125 |
126 // Overrides BrowsingInstance::ShouldUseProcessPerSite so that we can test | 126 // Overrides BrowsingInstance::ShouldUseProcessPerSite so that we can test |
127 // both alternatives without using command-line switches. | 127 // both alternatives without using command-line switches. |
128 bool ShouldUseProcessPerSite(const GURL& url) { | 128 bool ShouldUseProcessPerSite(const GURL& url) { |
129 return use_process_per_site; | 129 return use_process_per_site_; |
| 130 } |
| 131 |
| 132 void set_use_process_per_site(bool use_process_per_site) { |
| 133 use_process_per_site_ = use_process_per_site; |
| 134 } |
| 135 |
| 136 private: |
| 137 virtual ~TestBrowsingInstance() { |
| 138 (*delete_counter_)++; |
130 } | 139 } |
131 | 140 |
132 // Set by individual tests. | 141 // Set by individual tests. |
133 bool use_process_per_site; | 142 bool use_process_per_site_; |
134 | 143 |
135 private: | 144 int* delete_counter_; |
136 ~TestBrowsingInstance() { | |
137 (*deleteCounter_)++; | |
138 } | |
139 | |
140 int* deleteCounter_; | |
141 }; | 145 }; |
142 | 146 |
143 class TestSiteInstance : public SiteInstance { | 147 class TestSiteInstance : public SiteInstance { |
144 public: | 148 public: |
145 static TestSiteInstance* CreateTestSiteInstance( | 149 static TestSiteInstance* CreateTestSiteInstance( |
146 content::BrowserContext* browser_context, | 150 content::BrowserContext* browser_context, |
147 int* siteDeleteCounter, | 151 int* site_delete_counter, |
148 int* browsingDeleteCounter) { | 152 int* browsing_delete_counter) { |
149 TestBrowsingInstance* browsing_instance = | 153 TestBrowsingInstance* browsing_instance = |
150 new TestBrowsingInstance(browser_context, browsingDeleteCounter); | 154 new TestBrowsingInstance(browser_context, browsing_delete_counter); |
151 return new TestSiteInstance(browsing_instance, siteDeleteCounter); | 155 return new TestSiteInstance(browsing_instance, site_delete_counter); |
152 } | 156 } |
153 | 157 |
154 private: | 158 private: |
155 TestSiteInstance(BrowsingInstance* browsing_instance, int* deleteCounter) | 159 TestSiteInstance(BrowsingInstance* browsing_instance, int* delete_counter) |
156 : SiteInstance(browsing_instance), deleteCounter_(deleteCounter) {} | 160 : SiteInstance(browsing_instance), delete_counter_(delete_counter) {} |
157 ~TestSiteInstance() { | 161 virtual ~TestSiteInstance() { |
158 (*deleteCounter_)++; | 162 (*delete_counter_)++; |
159 } | 163 } |
160 | 164 |
161 int* deleteCounter_; | 165 int* delete_counter_; |
162 }; | 166 }; |
163 | 167 |
164 } // namespace | 168 } // namespace |
165 | 169 |
166 // Test to ensure no memory leaks for SiteInstance objects. | 170 // Test to ensure no memory leaks for SiteInstance objects. |
167 TEST_F(SiteInstanceTest, SiteInstanceDestructor) { | 171 TEST_F(SiteInstanceTest, SiteInstanceDestructor) { |
168 // The existence of these factories will cause TabContents to create our test | 172 // The existence of these factories will cause TabContents to create our test |
169 // one instead of the real one. | 173 // one instead of the real one. |
170 MockRenderProcessHostFactory rph_factory; | 174 MockRenderProcessHostFactory rph_factory; |
171 TestRenderViewHostFactory rvh_factory(&rph_factory); | 175 TestRenderViewHostFactory rvh_factory(&rph_factory); |
172 int siteDeleteCounter = 0; | 176 int site_delete_counter = 0; |
173 int browsingDeleteCounter = 0; | 177 int browsing_delete_counter = 0; |
174 const GURL url("test:foo"); | 178 const GURL url("test:foo"); |
175 | 179 |
176 // Ensure that instances are deleted when their NavigationEntries are gone. | 180 // Ensure that instances are deleted when their NavigationEntries are gone. |
177 TestSiteInstance* instance = | 181 TestSiteInstance* instance = |
178 TestSiteInstance::CreateTestSiteInstance(NULL, &siteDeleteCounter, | 182 TestSiteInstance::CreateTestSiteInstance(NULL, &site_delete_counter, |
179 &browsingDeleteCounter); | 183 &browsing_delete_counter); |
180 EXPECT_EQ(0, siteDeleteCounter); | 184 EXPECT_EQ(0, site_delete_counter); |
181 | 185 |
182 NavigationEntryImpl* e1 = new NavigationEntryImpl( | 186 NavigationEntryImpl* e1 = new NavigationEntryImpl( |
183 instance, 0, url, content::Referrer(), string16(), | 187 instance, 0, url, content::Referrer(), string16(), |
184 content::PAGE_TRANSITION_LINK, false); | 188 content::PAGE_TRANSITION_LINK, false); |
185 | 189 |
186 // Redundantly setting e1's SiteInstance shouldn't affect the ref count. | 190 // Redundantly setting e1's SiteInstance shouldn't affect the ref count. |
187 e1->set_site_instance(instance); | 191 e1->set_site_instance(instance); |
188 EXPECT_EQ(0, siteDeleteCounter); | 192 EXPECT_EQ(0, site_delete_counter); |
189 | 193 |
190 // Add a second reference | 194 // Add a second reference |
191 NavigationEntryImpl* e2 = new NavigationEntryImpl( | 195 NavigationEntryImpl* e2 = new NavigationEntryImpl( |
192 instance, 0, url, content::Referrer(), string16(), | 196 instance, 0, url, content::Referrer(), string16(), |
193 content::PAGE_TRANSITION_LINK, false); | 197 content::PAGE_TRANSITION_LINK, false); |
194 | 198 |
195 // Now delete both entries and be sure the SiteInstance goes away. | 199 // Now delete both entries and be sure the SiteInstance goes away. |
196 delete e1; | 200 delete e1; |
197 EXPECT_EQ(0, siteDeleteCounter); | 201 EXPECT_EQ(0, site_delete_counter); |
198 EXPECT_EQ(0, browsingDeleteCounter); | 202 EXPECT_EQ(0, browsing_delete_counter); |
199 delete e2; | 203 delete e2; |
200 EXPECT_EQ(1, siteDeleteCounter); | 204 EXPECT_EQ(1, site_delete_counter); |
201 // instance is now deleted | 205 // instance is now deleted |
202 EXPECT_EQ(1, browsingDeleteCounter); | 206 EXPECT_EQ(1, browsing_delete_counter); |
203 // browsing_instance is now deleted | 207 // browsing_instance is now deleted |
204 | 208 |
205 // Ensure that instances are deleted when their RenderViewHosts are gone. | 209 // Ensure that instances are deleted when their RenderViewHosts are gone. |
206 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 210 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
207 instance = | 211 instance = |
208 TestSiteInstance::CreateTestSiteInstance(browser_context.get(), | 212 TestSiteInstance::CreateTestSiteInstance(browser_context.get(), |
209 &siteDeleteCounter, | 213 &site_delete_counter, |
210 &browsingDeleteCounter); | 214 &browsing_delete_counter); |
211 { | 215 { |
212 TabContents contents(browser_context.get(), | 216 TabContents contents(browser_context.get(), |
213 instance, | 217 instance, |
214 MSG_ROUTING_NONE, | 218 MSG_ROUTING_NONE, |
215 NULL, | 219 NULL, |
216 NULL); | 220 NULL); |
217 EXPECT_EQ(1, siteDeleteCounter); | 221 EXPECT_EQ(1, site_delete_counter); |
218 EXPECT_EQ(1, browsingDeleteCounter); | 222 EXPECT_EQ(1, browsing_delete_counter); |
219 } | 223 } |
220 | 224 |
221 // Make sure that we flush any messages related to the above TabContents | 225 // Make sure that we flush any messages related to the above TabContents |
222 // destruction. | 226 // destruction. |
223 MessageLoop::current()->RunAllPending(); | 227 MessageLoop::current()->RunAllPending(); |
224 | 228 |
225 EXPECT_EQ(2, siteDeleteCounter); | 229 EXPECT_EQ(2, site_delete_counter); |
226 EXPECT_EQ(2, browsingDeleteCounter); | 230 EXPECT_EQ(2, browsing_delete_counter); |
227 // contents is now deleted, along with instance and browsing_instance | 231 // contents is now deleted, along with instance and browsing_instance |
228 } | 232 } |
229 | 233 |
230 // Test that NavigationEntries with SiteInstances can be cloned, but that their | 234 // Test that NavigationEntries with SiteInstances can be cloned, but that their |
231 // SiteInstances can be changed afterwards. Also tests that the ref counts are | 235 // SiteInstances can be changed afterwards. Also tests that the ref counts are |
232 // updated properly after the change. | 236 // updated properly after the change. |
233 TEST_F(SiteInstanceTest, CloneNavigationEntry) { | 237 TEST_F(SiteInstanceTest, CloneNavigationEntry) { |
234 int siteDeleteCounter1 = 0; | 238 int site_delete_counter1 = 0; |
235 int siteDeleteCounter2 = 0; | 239 int site_delete_counter2 = 0; |
236 int browsingDeleteCounter = 0; | 240 int browsing_delete_counter = 0; |
237 const GURL url("test:foo"); | 241 const GURL url("test:foo"); |
238 | 242 |
239 SiteInstance* instance1 = | 243 SiteInstance* instance1 = |
240 TestSiteInstance::CreateTestSiteInstance(NULL, &siteDeleteCounter1, | 244 TestSiteInstance::CreateTestSiteInstance(NULL, &site_delete_counter1, |
241 &browsingDeleteCounter); | 245 &browsing_delete_counter); |
242 SiteInstance* instance2 = | 246 SiteInstance* instance2 = |
243 TestSiteInstance::CreateTestSiteInstance(NULL, &siteDeleteCounter2, | 247 TestSiteInstance::CreateTestSiteInstance(NULL, &site_delete_counter2, |
244 &browsingDeleteCounter); | 248 &browsing_delete_counter); |
245 | 249 |
246 NavigationEntryImpl* e1 = new NavigationEntryImpl( | 250 NavigationEntryImpl* e1 = new NavigationEntryImpl( |
247 instance1, 0, url, content::Referrer(), string16(), | 251 instance1, 0, url, content::Referrer(), string16(), |
248 content::PAGE_TRANSITION_LINK, false); | 252 content::PAGE_TRANSITION_LINK, false); |
249 // Clone the entry | 253 // Clone the entry |
250 NavigationEntryImpl* e2 = new NavigationEntryImpl(*e1); | 254 NavigationEntryImpl* e2 = new NavigationEntryImpl(*e1); |
251 | 255 |
252 // Should be able to change the SiteInstance of the cloned entry. | 256 // Should be able to change the SiteInstance of the cloned entry. |
253 e2->set_site_instance(instance2); | 257 e2->set_site_instance(instance2); |
254 | 258 |
255 // The first SiteInstance should go away after deleting e1, since e2 should | 259 // The first SiteInstance should go away after deleting e1, since e2 should |
256 // no longer be referencing it. | 260 // no longer be referencing it. |
257 delete e1; | 261 delete e1; |
258 EXPECT_EQ(1, siteDeleteCounter1); | 262 EXPECT_EQ(1, site_delete_counter1); |
259 EXPECT_EQ(0, siteDeleteCounter2); | 263 EXPECT_EQ(0, site_delete_counter2); |
260 | 264 |
261 // The second SiteInstance should go away after deleting e2. | 265 // The second SiteInstance should go away after deleting e2. |
262 delete e2; | 266 delete e2; |
263 EXPECT_EQ(1, siteDeleteCounter1); | 267 EXPECT_EQ(1, site_delete_counter1); |
264 EXPECT_EQ(1, siteDeleteCounter2); | 268 EXPECT_EQ(1, site_delete_counter2); |
265 | 269 |
266 // Both BrowsingInstances are also now deleted | 270 // Both BrowsingInstances are also now deleted |
267 EXPECT_EQ(2, browsingDeleteCounter); | 271 EXPECT_EQ(2, browsing_delete_counter); |
268 } | 272 } |
269 | 273 |
270 // Test to ensure GetProcess returns and creates processes correctly. | 274 // Test to ensure GetProcess returns and creates processes correctly. |
271 TEST_F(SiteInstanceTest, GetProcess) { | 275 TEST_F(SiteInstanceTest, GetProcess) { |
272 // Ensure that GetProcess returns a process. | 276 // Ensure that GetProcess returns a process. |
273 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 277 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
274 scoped_ptr<content::RenderProcessHost> host1; | 278 scoped_ptr<content::RenderProcessHost> host1; |
275 scoped_refptr<SiteInstance> instance( | 279 scoped_refptr<SiteInstance> instance( |
276 SiteInstance::CreateSiteInstance(browser_context.get())); | 280 SiteInstance::CreateSiteInstance(browser_context.get())); |
277 host1.reset(instance->GetProcess()); | 281 host1.reset(instance->GetProcess()); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 // The URLs specified by the ContentBrowserClient should also be treated as | 360 // The URLs specified by the ContentBrowserClient should also be treated as |
357 // same site. | 361 // same site. |
358 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_crash, url_foo)); | 362 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_crash, url_foo)); |
359 EXPECT_TRUE( | 363 EXPECT_TRUE( |
360 SiteInstance::IsSameWebSite(NULL, url_browser_specified, url_foo)); | 364 SiteInstance::IsSameWebSite(NULL, url_browser_specified, url_foo)); |
361 } | 365 } |
362 | 366 |
363 // Test to ensure that there is only one SiteInstance per site in a given | 367 // Test to ensure that there is only one SiteInstance per site in a given |
364 // BrowsingInstance, when process-per-site is not in use. | 368 // BrowsingInstance, when process-per-site is not in use. |
365 TEST_F(SiteInstanceTest, OneSiteInstancePerSite) { | 369 TEST_F(SiteInstanceTest, OneSiteInstancePerSite) { |
366 int deleteCounter = 0; | 370 int delete_counter = 0; |
367 TestBrowsingInstance* browsing_instance = | 371 TestBrowsingInstance* browsing_instance = |
368 new TestBrowsingInstance(NULL, &deleteCounter); | 372 new TestBrowsingInstance(NULL, &delete_counter); |
369 browsing_instance->use_process_per_site = false; | 373 browsing_instance->set_use_process_per_site(false); |
370 | 374 |
371 const GURL url_a1("http://www.google.com/1.html"); | 375 const GURL url_a1("http://www.google.com/1.html"); |
372 scoped_refptr<SiteInstance> site_instance_a1( | 376 scoped_refptr<SiteInstance> site_instance_a1( |
373 browsing_instance->GetSiteInstanceForURL(url_a1)); | 377 browsing_instance->GetSiteInstanceForURL(url_a1)); |
374 EXPECT_TRUE(site_instance_a1.get() != NULL); | 378 EXPECT_TRUE(site_instance_a1.get() != NULL); |
375 | 379 |
376 // A separate site should create a separate SiteInstance. | 380 // A separate site should create a separate SiteInstance. |
377 const GURL url_b1("http://www.yahoo.com/"); | 381 const GURL url_b1("http://www.yahoo.com/"); |
378 scoped_refptr<SiteInstance> site_instance_b1( | 382 scoped_refptr<SiteInstance> site_instance_b1( |
379 browsing_instance->GetSiteInstanceForURL(url_b1)); | 383 browsing_instance->GetSiteInstanceForURL(url_b1)); |
380 EXPECT_NE(site_instance_a1.get(), site_instance_b1.get()); | 384 EXPECT_NE(site_instance_a1.get(), site_instance_b1.get()); |
381 | 385 |
382 // Getting the new SiteInstance from the BrowsingInstance and from another | 386 // Getting the new SiteInstance from the BrowsingInstance and from another |
383 // SiteInstance in the BrowsingInstance should give the same result. | 387 // SiteInstance in the BrowsingInstance should give the same result. |
384 EXPECT_EQ(site_instance_b1.get(), | 388 EXPECT_EQ(site_instance_b1.get(), |
385 site_instance_a1->GetRelatedSiteInstance(url_b1)); | 389 site_instance_a1->GetRelatedSiteInstance(url_b1)); |
386 | 390 |
387 // A second visit to the original site should return the same SiteInstance. | 391 // A second visit to the original site should return the same SiteInstance. |
388 const GURL url_a2("http://www.google.com/2.html"); | 392 const GURL url_a2("http://www.google.com/2.html"); |
389 EXPECT_EQ(site_instance_a1.get(), | 393 EXPECT_EQ(site_instance_a1.get(), |
390 browsing_instance->GetSiteInstanceForURL(url_a2)); | 394 browsing_instance->GetSiteInstanceForURL(url_a2)); |
391 EXPECT_EQ(site_instance_a1.get(), | 395 EXPECT_EQ(site_instance_a1.get(), |
392 site_instance_a1->GetRelatedSiteInstance(url_a2)); | 396 site_instance_a1->GetRelatedSiteInstance(url_a2)); |
393 | 397 |
394 // A visit to the original site in a new BrowsingInstance (same or different | 398 // A visit to the original site in a new BrowsingInstance (same or different |
395 // browser context) should return a different SiteInstance. | 399 // browser context) should return a different SiteInstance. |
396 TestBrowsingInstance* browsing_instance2 = | 400 TestBrowsingInstance* browsing_instance2 = |
397 new TestBrowsingInstance(NULL, &deleteCounter); | 401 new TestBrowsingInstance(NULL, &delete_counter); |
398 browsing_instance2->use_process_per_site = false; | 402 browsing_instance2->set_use_process_per_site(false); |
399 // Ensure the new SiteInstance is ref counted so that it gets deleted. | 403 // Ensure the new SiteInstance is ref counted so that it gets deleted. |
400 scoped_refptr<SiteInstance> site_instance_a2_2( | 404 scoped_refptr<SiteInstance> site_instance_a2_2( |
401 browsing_instance2->GetSiteInstanceForURL(url_a2)); | 405 browsing_instance2->GetSiteInstanceForURL(url_a2)); |
402 EXPECT_NE(site_instance_a1.get(), site_instance_a2_2.get()); | 406 EXPECT_NE(site_instance_a1.get(), site_instance_a2_2.get()); |
403 | 407 |
404 // Should be able to see that we do have SiteInstances. | 408 // Should be able to see that we do have SiteInstances. |
405 EXPECT_TRUE(browsing_instance->HasSiteInstance( | 409 EXPECT_TRUE(browsing_instance->HasSiteInstance( |
406 GURL("http://mail.google.com"))); | 410 GURL("http://mail.google.com"))); |
407 EXPECT_TRUE(browsing_instance2->HasSiteInstance( | 411 EXPECT_TRUE(browsing_instance2->HasSiteInstance( |
408 GURL("http://mail.google.com"))); | 412 GURL("http://mail.google.com"))); |
409 EXPECT_TRUE(browsing_instance->HasSiteInstance( | 413 EXPECT_TRUE(browsing_instance->HasSiteInstance( |
410 GURL("http://mail.yahoo.com"))); | 414 GURL("http://mail.yahoo.com"))); |
411 | 415 |
412 // Should be able to see that we don't have SiteInstances. | 416 // Should be able to see that we don't have SiteInstances. |
413 EXPECT_FALSE(browsing_instance->HasSiteInstance( | 417 EXPECT_FALSE(browsing_instance->HasSiteInstance( |
414 GURL("https://www.google.com"))); | 418 GURL("https://www.google.com"))); |
415 EXPECT_FALSE(browsing_instance2->HasSiteInstance( | 419 EXPECT_FALSE(browsing_instance2->HasSiteInstance( |
416 GURL("http://www.yahoo.com"))); | 420 GURL("http://www.yahoo.com"))); |
417 | 421 |
418 // browsing_instances will be deleted when their SiteInstances are deleted | 422 // browsing_instances will be deleted when their SiteInstances are deleted |
419 } | 423 } |
420 | 424 |
421 // Test to ensure that there is only one SiteInstance per site for an entire | 425 // Test to ensure that there is only one SiteInstance per site for an entire |
422 // BrowserContext, if process-per-site is in use. | 426 // BrowserContext, if process-per-site is in use. |
423 TEST_F(SiteInstanceTest, OneSiteInstancePerSiteInBrowserContext) { | 427 TEST_F(SiteInstanceTest, OneSiteInstancePerSiteInBrowserContext) { |
424 int deleteCounter = 0; | 428 int delete_counter = 0; |
425 TestBrowsingInstance* browsing_instance = | 429 TestBrowsingInstance* browsing_instance = |
426 new TestBrowsingInstance(NULL, &deleteCounter); | 430 new TestBrowsingInstance(NULL, &delete_counter); |
427 browsing_instance->use_process_per_site = true; | 431 browsing_instance->set_use_process_per_site(true); |
428 | 432 |
429 const GURL url_a1("http://www.google.com/1.html"); | 433 const GURL url_a1("http://www.google.com/1.html"); |
430 scoped_refptr<SiteInstance> site_instance_a1( | 434 scoped_refptr<SiteInstance> site_instance_a1( |
431 browsing_instance->GetSiteInstanceForURL(url_a1)); | 435 browsing_instance->GetSiteInstanceForURL(url_a1)); |
432 EXPECT_TRUE(site_instance_a1.get() != NULL); | 436 EXPECT_TRUE(site_instance_a1.get() != NULL); |
433 | 437 |
434 // A separate site should create a separate SiteInstance. | 438 // A separate site should create a separate SiteInstance. |
435 const GURL url_b1("http://www.yahoo.com/"); | 439 const GURL url_b1("http://www.yahoo.com/"); |
436 scoped_refptr<SiteInstance> site_instance_b1( | 440 scoped_refptr<SiteInstance> site_instance_b1( |
437 browsing_instance->GetSiteInstanceForURL(url_b1)); | 441 browsing_instance->GetSiteInstanceForURL(url_b1)); |
(...skipping 10 matching lines...) Expand all Loading... |
448 browsing_instance->GetSiteInstanceForURL(url_a2)); | 452 browsing_instance->GetSiteInstanceForURL(url_a2)); |
449 EXPECT_EQ(site_instance_a1.get(), | 453 EXPECT_EQ(site_instance_a1.get(), |
450 site_instance_a1->GetRelatedSiteInstance(url_a2)); | 454 site_instance_a1->GetRelatedSiteInstance(url_a2)); |
451 | 455 |
452 // A visit to the original site in a new BrowsingInstance (same browser | 456 // A visit to the original site in a new BrowsingInstance (same browser |
453 // context) should also return the same SiteInstance. | 457 // context) should also return the same SiteInstance. |
454 // This BrowsingInstance doesn't get its own SiteInstance within the test, so | 458 // This BrowsingInstance doesn't get its own SiteInstance within the test, so |
455 // it won't be deleted by its children. Thus, we'll keep a ref count to it | 459 // it won't be deleted by its children. Thus, we'll keep a ref count to it |
456 // to make sure it gets deleted. | 460 // to make sure it gets deleted. |
457 scoped_refptr<TestBrowsingInstance> browsing_instance2( | 461 scoped_refptr<TestBrowsingInstance> browsing_instance2( |
458 new TestBrowsingInstance(NULL, &deleteCounter)); | 462 new TestBrowsingInstance(NULL, &delete_counter)); |
459 browsing_instance2->use_process_per_site = true; | 463 browsing_instance2->set_use_process_per_site(true); |
460 EXPECT_EQ(site_instance_a1.get(), | 464 EXPECT_EQ(site_instance_a1.get(), |
461 browsing_instance2->GetSiteInstanceForURL(url_a2)); | 465 browsing_instance2->GetSiteInstanceForURL(url_a2)); |
462 | 466 |
463 // A visit to the original site in a new BrowsingInstance (different browser | 467 // A visit to the original site in a new BrowsingInstance (different browser |
464 // context) should return a different SiteInstance. | 468 // context) should return a different SiteInstance. |
465 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); | 469 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
466 TestBrowsingInstance* browsing_instance3 = | 470 TestBrowsingInstance* browsing_instance3 = |
467 new TestBrowsingInstance(browser_context.get(), &deleteCounter); | 471 new TestBrowsingInstance(browser_context.get(), &delete_counter); |
468 browsing_instance3->use_process_per_site = true; | 472 browsing_instance3->set_use_process_per_site(true); |
469 // Ensure the new SiteInstance is ref counted so that it gets deleted. | 473 // Ensure the new SiteInstance is ref counted so that it gets deleted. |
470 scoped_refptr<SiteInstance> site_instance_a2_3( | 474 scoped_refptr<SiteInstance> site_instance_a2_3( |
471 browsing_instance3->GetSiteInstanceForURL(url_a2)); | 475 browsing_instance3->GetSiteInstanceForURL(url_a2)); |
472 EXPECT_NE(site_instance_a1.get(), site_instance_a2_3.get()); | 476 EXPECT_NE(site_instance_a1.get(), site_instance_a2_3.get()); |
473 | 477 |
474 // Should be able to see that we do have SiteInstances. | 478 // Should be able to see that we do have SiteInstances. |
475 EXPECT_TRUE(browsing_instance->HasSiteInstance( | 479 EXPECT_TRUE(browsing_instance->HasSiteInstance( |
476 GURL("http://mail.google.com"))); // visited before | 480 GURL("http://mail.google.com"))); // visited before |
477 EXPECT_TRUE(browsing_instance2->HasSiteInstance( | 481 EXPECT_TRUE(browsing_instance2->HasSiteInstance( |
478 GURL("http://mail.google.com"))); // visited before | 482 GURL("http://mail.google.com"))); // visited before |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 scoped_ptr<content::RenderProcessHost> extension_host( | 526 scoped_ptr<content::RenderProcessHost> extension_host( |
523 extension1_instance->GetProcess()); | 527 extension1_instance->GetProcess()); |
524 EXPECT_EQ(extension1_instance->GetProcess(), | 528 EXPECT_EQ(extension1_instance->GetProcess(), |
525 extension2_instance->GetProcess()); | 529 extension2_instance->GetProcess()); |
526 | 530 |
527 // Create some WebUI instances and make sure they share a process. | 531 // Create some WebUI instances and make sure they share a process. |
528 scoped_refptr<SiteInstance> webui1_instance(CreateSiteInstance(&rph_factory, | 532 scoped_refptr<SiteInstance> webui1_instance(CreateSiteInstance(&rph_factory, |
529 GURL(chrome::kChromeUIScheme + std::string("://newtab")))); | 533 GURL(chrome::kChromeUIScheme + std::string("://newtab")))); |
530 policy->GrantWebUIBindings(webui1_instance->GetProcess()->GetID()); | 534 policy->GrantWebUIBindings(webui1_instance->GetProcess()->GetID()); |
531 | 535 |
532 scoped_refptr<SiteInstance> webui2_instance( CreateSiteInstance(&rph_factory, | 536 scoped_refptr<SiteInstance> webui2_instance(CreateSiteInstance(&rph_factory, |
533 GURL(chrome::kChromeUIScheme + std::string("://history")))); | 537 GURL(chrome::kChromeUIScheme + std::string("://history")))); |
534 | 538 |
535 scoped_ptr<content::RenderProcessHost> dom_host( | 539 scoped_ptr<content::RenderProcessHost> dom_host( |
536 webui1_instance->GetProcess()); | 540 webui1_instance->GetProcess()); |
537 EXPECT_EQ(webui1_instance->GetProcess(), webui2_instance->GetProcess()); | 541 EXPECT_EQ(webui1_instance->GetProcess(), webui2_instance->GetProcess()); |
538 | 542 |
539 // Make sure none of differing privilege processes are mixed. | 543 // Make sure none of differing privilege processes are mixed. |
540 EXPECT_NE(extension1_instance->GetProcess(), webui1_instance->GetProcess()); | 544 EXPECT_NE(extension1_instance->GetProcess(), webui1_instance->GetProcess()); |
541 | 545 |
542 for (size_t i = 0; i < content::kMaxRendererProcessCount; ++i) { | 546 for (size_t i = 0; i < content::kMaxRendererProcessCount; ++i) { |
543 EXPECT_NE(extension1_instance->GetProcess(), hosts[i]); | 547 EXPECT_NE(extension1_instance->GetProcess(), hosts[i]); |
544 EXPECT_NE(webui1_instance->GetProcess(), hosts[i]); | 548 EXPECT_NE(webui1_instance->GetProcess(), hosts[i]); |
545 } | 549 } |
546 | 550 |
547 STLDeleteContainerPointers(hosts.begin(), hosts.end()); | 551 STLDeleteContainerPointers(hosts.begin(), hosts.end()); |
548 } | 552 } |
| 553 |
| 554 // Test to ensure that HasWrongProcessForURL behaves properly for different |
| 555 // types of URLs. |
| 556 TEST_F(SiteInstanceTest, HasWrongProcessForURL) { |
| 557 scoped_ptr<TestBrowserContext> browser_context(new TestBrowserContext()); |
| 558 scoped_ptr<content::RenderProcessHost> host; |
| 559 scoped_refptr<SiteInstance> instance( |
| 560 SiteInstance::CreateSiteInstance(browser_context.get())); |
| 561 |
| 562 EXPECT_FALSE(instance->has_site()); |
| 563 EXPECT_TRUE(instance->site().is_empty()); |
| 564 |
| 565 instance->SetSite(GURL("http://evernote.com/")); |
| 566 EXPECT_TRUE(instance->has_site()); |
| 567 |
| 568 // Check prior to "assigning" a process to the instance, which is expected |
| 569 // to return false due to not being attached to any process yet. |
| 570 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://google.com"))); |
| 571 |
| 572 // The call to GetProcess actually creates a new real process, which works |
| 573 // fine, but might be a cause for problems in different contexts. |
| 574 host.reset(instance->GetProcess()); |
| 575 EXPECT_TRUE(host.get() != NULL); |
| 576 EXPECT_TRUE(instance->HasProcess()); |
| 577 |
| 578 EXPECT_FALSE(instance->HasWrongProcessForURL(GURL("http://evernote.com"))); |
| 579 EXPECT_FALSE(instance->HasWrongProcessForURL( |
| 580 GURL("javascript:alert(document.location.href);"))); |
| 581 |
| 582 EXPECT_TRUE(instance->HasWrongProcessForURL(GURL("chrome://settings"))); |
| 583 } |
OLD | NEW |