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/stl_util-inl.h" | 5 #include "base/stl_util-inl.h" |
6 #include "base/string16.h" | 6 #include "base/string16.h" |
7 #include "chrome/common/chrome_constants.h" | 7 #include "chrome/common/chrome_constants.h" |
8 #include "chrome/common/render_messages.h" | 8 #include "chrome/common/render_messages.h" |
9 #include "chrome/common/url_constants.h" | |
10 #include "chrome/test/testing_profile.h" | 9 #include "chrome/test/testing_profile.h" |
11 #include "content/browser/browser_thread.h" | 10 #include "content/browser/browser_thread.h" |
12 #include "content/browser/browsing_instance.h" | 11 #include "content/browser/browsing_instance.h" |
13 #include "content/browser/child_process_security_policy.h" | 12 #include "content/browser/child_process_security_policy.h" |
14 #include "content/browser/content_browser_client.h" | 13 #include "content/browser/content_browser_client.h" |
15 #include "content/browser/renderer_host/browser_render_process_host.h" | 14 #include "content/browser/renderer_host/browser_render_process_host.h" |
16 #include "content/browser/renderer_host/render_view_host.h" | 15 #include "content/browser/renderer_host/render_view_host.h" |
17 #include "content/browser/renderer_host/test_render_view_host.h" | 16 #include "content/browser/renderer_host/test_render_view_host.h" |
18 #include "content/browser/site_instance.h" | 17 #include "content/browser/site_instance.h" |
19 #include "content/browser/tab_contents/navigation_entry.h" | 18 #include "content/browser/tab_contents/navigation_entry.h" |
20 #include "content/browser/tab_contents/tab_contents.h" | 19 #include "content/browser/tab_contents/tab_contents.h" |
21 #include "content/browser/webui/empty_web_ui_factory.h" | 20 #include "content/browser/webui/empty_web_ui_factory.h" |
22 #include "content/common/content_client.h" | 21 #include "content/common/content_client.h" |
| 22 #include "content/common/url_constants.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 // TODO(estade): this shouldn't need to be chrome:, but it does (or else GURL | 27 // TODO(estade): this shouldn't need to be chrome:, but it does (or else GURL |
28 // doesn't think that the webui URLs have a host). Figure out where this is | 28 // doesn't think that the webui URLs have a host). Figure out where this is |
29 // coming from and fix it. | 29 // coming from and fix it. |
30 const char kWebUIScheme[] = "chrome"; | 30 const char kWebUIScheme[] = "chrome"; |
| 31 const char kSameAsAnyInstanceURL[] = "about:internets"; |
31 | 32 |
32 class SiteInstanceTestWebUIFactory : public content::EmptyWebUIFactory { | 33 class SiteInstanceTestWebUIFactory : public content::EmptyWebUIFactory { |
33 public: | 34 public: |
34 virtual bool UseWebUIForURL(Profile* profile, const GURL& url) const { | 35 virtual bool UseWebUIForURL(Profile* profile, const GURL& url) const { |
35 return HasWebUIScheme(url); | 36 return HasWebUIScheme(url); |
36 } | 37 } |
37 virtual bool HasWebUIScheme(const GURL& url) const { | 38 virtual bool HasWebUIScheme(const GURL& url) const { |
38 return url.SchemeIs(kWebUIScheme); | 39 return url.SchemeIs(kWebUIScheme); |
39 } | 40 } |
40 }; | 41 }; |
41 | 42 |
42 class SiteInstanceTestBrowserClient : public content::ContentBrowserClient { | 43 class SiteInstanceTestBrowserClient : public content::ContentBrowserClient { |
43 public: | 44 public: |
44 virtual content::WebUIFactory* GetWebUIFactory() { | 45 virtual content::WebUIFactory* GetWebUIFactory() { |
45 return &factory_; | 46 return &factory_; |
46 } | 47 } |
47 | 48 |
| 49 virtual bool IsURLSameAsAnySiteInstance(const GURL& url) { |
| 50 return url.spec() == kSameAsAnyInstanceURL; |
| 51 } |
| 52 |
48 private: | 53 private: |
49 SiteInstanceTestWebUIFactory factory_; | 54 SiteInstanceTestWebUIFactory factory_; |
50 }; | 55 }; |
51 | 56 |
52 class SiteInstanceTest : public testing::Test { | 57 class SiteInstanceTest : public testing::Test { |
53 public: | 58 public: |
54 SiteInstanceTest() | 59 SiteInstanceTest() |
55 : ui_thread_(BrowserThread::UI, &message_loop_), | 60 : ui_thread_(BrowserThread::UI, &message_loop_), |
56 old_browser_client_(NULL) { | 61 old_browser_client_(NULL) { |
57 } | 62 } |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 // Test of distinguishing URLs from different sites. Most of this logic is | 298 // Test of distinguishing URLs from different sites. Most of this logic is |
294 // tested in RegistryControlledDomainTest. This test focuses on URLs with | 299 // tested in RegistryControlledDomainTest. This test focuses on URLs with |
295 // different schemes or ports. | 300 // different schemes or ports. |
296 TEST_F(SiteInstanceTest, IsSameWebSite) { | 301 TEST_F(SiteInstanceTest, IsSameWebSite) { |
297 GURL url_foo = GURL("http://foo/a.html"); | 302 GURL url_foo = GURL("http://foo/a.html"); |
298 GURL url_foo2 = GURL("http://foo/b.html"); | 303 GURL url_foo2 = GURL("http://foo/b.html"); |
299 GURL url_foo_https = GURL("https://foo/a.html"); | 304 GURL url_foo_https = GURL("https://foo/a.html"); |
300 GURL url_foo_port = GURL("http://foo:8080/a.html"); | 305 GURL url_foo_port = GURL("http://foo:8080/a.html"); |
301 GURL url_javascript = GURL("javascript:alert(1);"); | 306 GURL url_javascript = GURL("javascript:alert(1);"); |
302 GURL url_crash = GURL(chrome::kAboutCrashURL); | 307 GURL url_crash = GURL(chrome::kAboutCrashURL); |
303 GURL url_hang = GURL(chrome::kAboutHangURL); | 308 GURL url_browser_specified = GURL(kSameAsAnyInstanceURL); |
304 GURL url_shorthang = GURL(chrome::kAboutShorthangURL); | |
305 | 309 |
306 // Same scheme and port -> same site. | 310 // Same scheme and port -> same site. |
307 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_foo, url_foo2)); | 311 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_foo, url_foo2)); |
308 | 312 |
309 // Different scheme -> different site. | 313 // Different scheme -> different site. |
310 EXPECT_FALSE(SiteInstance::IsSameWebSite(NULL, url_foo, url_foo_https)); | 314 EXPECT_FALSE(SiteInstance::IsSameWebSite(NULL, url_foo, url_foo_https)); |
311 | 315 |
312 // Different port -> same site. | 316 // Different port -> same site. |
313 // (Changes to document.domain make renderer ignore the port.) | 317 // (Changes to document.domain make renderer ignore the port.) |
314 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_foo, url_foo_port)); | 318 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_foo, url_foo_port)); |
315 | 319 |
316 // JavaScript links should be considered same site for anything. | 320 // JavaScript links should be considered same site for anything. |
317 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_javascript, url_foo)); | 321 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_javascript, url_foo)); |
318 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_javascript, url_foo_https)); | 322 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_javascript, url_foo_https)); |
319 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_javascript, url_foo_port)); | 323 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_javascript, url_foo_port)); |
320 | 324 |
321 // The crash/hang URLs should also be treated as same site. (Bug 1143809.) | 325 // The URLs specified by the ContentBrowserClient should also be treated as |
| 326 // same site. |
322 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_crash, url_foo)); | 327 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_crash, url_foo)); |
323 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_hang, url_foo)); | 328 EXPECT_TRUE( |
324 EXPECT_TRUE(SiteInstance::IsSameWebSite(NULL, url_shorthang, url_foo)); | 329 SiteInstance::IsSameWebSite(NULL, url_browser_specified, url_foo)); |
325 } | 330 } |
326 | 331 |
327 // Test to ensure that there is only one SiteInstance per site in a given | 332 // Test to ensure that there is only one SiteInstance per site in a given |
328 // BrowsingInstance, when process-per-site is not in use. | 333 // BrowsingInstance, when process-per-site is not in use. |
329 TEST_F(SiteInstanceTest, OneSiteInstancePerSite) { | 334 TEST_F(SiteInstanceTest, OneSiteInstancePerSite) { |
330 int deleteCounter = 0; | 335 int deleteCounter = 0; |
331 TestBrowsingInstance* browsing_instance = | 336 TestBrowsingInstance* browsing_instance = |
332 new TestBrowsingInstance(NULL, &deleteCounter); | 337 new TestBrowsingInstance(NULL, &deleteCounter); |
333 browsing_instance->use_process_per_site = false; | 338 browsing_instance->use_process_per_site = false; |
334 | 339 |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 GURL("chrome-extension://baz/bar"))); | 574 GURL("chrome-extension://baz/bar"))); |
570 EXPECT_EQ(s5a, s5b); | 575 EXPECT_EQ(s5a, s5b); |
571 | 576 |
572 // The derived profiles with the different sites. | 577 // The derived profiles with the different sites. |
573 scoped_refptr<SiteInstance> s6a(instance1->GetSiteInstanceForURL( | 578 scoped_refptr<SiteInstance> s6a(instance1->GetSiteInstanceForURL( |
574 GURL("chrome-extension://baz/bar"))); | 579 GURL("chrome-extension://baz/bar"))); |
575 scoped_refptr<SiteInstance> s6b(instance3->GetSiteInstanceForURL( | 580 scoped_refptr<SiteInstance> s6b(instance3->GetSiteInstanceForURL( |
576 GURL("chrome-extension://foo/boo"))); | 581 GURL("chrome-extension://foo/boo"))); |
577 EXPECT_NE(s6a, s6b); | 582 EXPECT_NE(s6a, s6b); |
578 } | 583 } |
OLD | NEW |