Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: content/browser/site_instance_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698