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

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

Issue 12451: Don't create separate SiteInstances for pages from the same domain and scheme... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years 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 | « chrome/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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "chrome/browser/navigation_entry.h" 5 #include "chrome/browser/navigation_entry.h"
6 #include "chrome/browser/render_view_host.h" 6 #include "chrome/browser/render_view_host.h"
7 #include "chrome/browser/web_contents.h" 7 #include "chrome/browser/web_contents.h"
8 #include "chrome/common/render_messages.h" 8 #include "chrome/common/render_messages.h"
9 #include "chrome/test/testing_profile.h" 9 #include "chrome/test/testing_profile.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 EXPECT_TRUE(instance.get()->site().is_empty()); 195 EXPECT_TRUE(instance.get()->site().is_empty());
196 196
197 instance.get()->SetSite(GURL("http://www.google.com/index.html")); 197 instance.get()->SetSite(GURL("http://www.google.com/index.html"));
198 EXPECT_EQ(GURL("http://google.com"), instance.get()->site()); 198 EXPECT_EQ(GURL("http://google.com"), instance.get()->site());
199 199
200 EXPECT_TRUE(instance->has_site()); 200 EXPECT_TRUE(instance->has_site());
201 } 201 }
202 202
203 // Test to ensure GetSiteForURL properly returns sites for URLs. 203 // Test to ensure GetSiteForURL properly returns sites for URLs.
204 TEST_F(SiteInstanceTest, GetSiteForURL) { 204 TEST_F(SiteInstanceTest, GetSiteForURL) {
205 // Pages are irrelevant.
205 GURL test_url = GURL("http://www.google.com/index.html"); 206 GURL test_url = GURL("http://www.google.com/index.html");
206 EXPECT_EQ(GURL("http://google.com"), SiteInstance::GetSiteForURL(test_url)); 207 EXPECT_EQ(GURL("http://google.com"), SiteInstance::GetSiteForURL(test_url));
207 208
209 // Ports are irrlevant.
208 test_url = GURL("https://www.google.com:8080"); 210 test_url = GURL("https://www.google.com:8080");
209 EXPECT_EQ(GURL("https://google.com:8080"), 211 EXPECT_EQ(GURL("https://google.com"), SiteInstance::GetSiteForURL(test_url));
210 SiteInstance::GetSiteForURL(test_url));
211 212
213 // Javascript URLs have no site.
212 test_url = GURL("javascript:foo();"); 214 test_url = GURL("javascript:foo();");
213 EXPECT_EQ(GURL::EmptyGURL(), SiteInstance::GetSiteForURL(test_url)); 215 EXPECT_EQ(GURL::EmptyGURL(), SiteInstance::GetSiteForURL(test_url));
214 216
215 test_url = GURL("http://foo/a.html"); 217 test_url = GURL("http://foo/a.html");
216 EXPECT_EQ(GURL("http://foo"), SiteInstance::GetSiteForURL(test_url)); 218 EXPECT_EQ(GURL("http://foo"), SiteInstance::GetSiteForURL(test_url));
217 219
218 test_url = GURL("file:///C:/Downloads/"); 220 test_url = GURL("file:///C:/Downloads/");
219 EXPECT_EQ(GURL::EmptyGURL(), SiteInstance::GetSiteForURL(test_url)); 221 EXPECT_EQ(GURL::EmptyGURL(), SiteInstance::GetSiteForURL(test_url));
220 222
221 // TODO(creis): Do we want to special case file URLs to ensure they have 223 // TODO(creis): Do we want to special case file URLs to ensure they have
222 // either no site or a special "file://" site? We currently return 224 // either no site or a special "file://" site? We currently return
223 // "file://home/" as the site, which seems broken. 225 // "file://home/" as the site, which seems broken.
224 // test_url = GURL("file://home/"); 226 // test_url = GURL("file://home/");
225 // EXPECT_EQ(GURL::EmptyGURL(), SiteInstance::GetSiteForURL(test_url)); 227 // EXPECT_EQ(GURL::EmptyGURL(), SiteInstance::GetSiteForURL(test_url));
226 } 228 }
227 229
228 // Test of distinguishing URLs from different sites. Most of this logic is 230 // Test of distinguishing URLs from different sites. Most of this logic is
229 // tested in RegistryControlledDomainTest. This test focuses on URLs with 231 // tested in RegistryControlledDomainTest. This test focuses on URLs with
230 // different schemes or ports. 232 // different schemes or ports.
231 TEST_F(SiteInstanceTest, IsSameWebSite) { 233 TEST_F(SiteInstanceTest, IsSameWebSite) {
232 GURL url_foo = GURL("http://foo/a.html"); 234 GURL url_foo = GURL("http://foo/a.html");
233 GURL url_foo2 = GURL("http://foo/b.html"); 235 GURL url_foo2 = GURL("http://foo/b.html");
234 GURL url_foo_https = GURL("https://foo/a.html"); 236 GURL url_foo_https = GURL("https://foo/a.html");
235 GURL url_foo_port = GURL("http://foo:8080/a.html"); 237 GURL url_foo_port = GURL("http://foo:8080/a.html");
236 GURL url_javascript = GURL("javascript:alert(1);"); 238 GURL url_javascript = GURL("javascript:alert(1);");
237 GURL url_crash = GURL("about:crash"); 239 GURL url_crash = GURL("about:crash");
238 GURL url_hang = GURL("about:hang"); 240 GURL url_hang = GURL("about:hang");
239 GURL url_shorthang = GURL("about:shorthang"); 241 GURL url_shorthang = GURL("about:shorthang");
240 242
243 // Same scheme and port -> same site.
241 EXPECT_TRUE(SiteInstance::IsSameWebSite(url_foo, url_foo2)); 244 EXPECT_TRUE(SiteInstance::IsSameWebSite(url_foo, url_foo2));
245
246 // Different scheme -> different site.
242 EXPECT_FALSE(SiteInstance::IsSameWebSite(url_foo, url_foo_https)); 247 EXPECT_FALSE(SiteInstance::IsSameWebSite(url_foo, url_foo_https));
243 EXPECT_FALSE(SiteInstance::IsSameWebSite(url_foo, url_foo_port)); 248
249 // Different port -> same site.
250 // (Changes to document.domain make renderer ignore the port.)
251 EXPECT_TRUE(SiteInstance::IsSameWebSite(url_foo, url_foo_port));
244 252
245 // JavaScript links should be considered same site for anything. 253 // JavaScript links should be considered same site for anything.
246 EXPECT_TRUE(SiteInstance::IsSameWebSite(url_javascript, url_foo)); 254 EXPECT_TRUE(SiteInstance::IsSameWebSite(url_javascript, url_foo));
247 EXPECT_TRUE(SiteInstance::IsSameWebSite(url_javascript, url_foo_https)); 255 EXPECT_TRUE(SiteInstance::IsSameWebSite(url_javascript, url_foo_https));
248 EXPECT_TRUE(SiteInstance::IsSameWebSite(url_javascript, url_foo_port)); 256 EXPECT_TRUE(SiteInstance::IsSameWebSite(url_javascript, url_foo_port));
249 257
250 // The crash/hang URLs should also be treated as same site. (Bug 1143809.) 258 // The crash/hang URLs should also be treated as same site. (Bug 1143809.)
251 EXPECT_TRUE(SiteInstance::IsSameWebSite(url_crash, url_foo)); 259 EXPECT_TRUE(SiteInstance::IsSameWebSite(url_crash, url_foo));
252 EXPECT_TRUE(SiteInstance::IsSameWebSite(url_hang, url_foo)); 260 EXPECT_TRUE(SiteInstance::IsSameWebSite(url_hang, url_foo));
253 EXPECT_TRUE(SiteInstance::IsSameWebSite(url_shorthang, url_foo)); 261 EXPECT_TRUE(SiteInstance::IsSameWebSite(url_shorthang, url_foo));
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 384
377 // Should be able to see that we don't have SiteInstances. 385 // Should be able to see that we don't have SiteInstances.
378 EXPECT_FALSE(browsing_instance->HasSiteInstance( 386 EXPECT_FALSE(browsing_instance->HasSiteInstance(
379 GURL("https://www.google.com"))); // not visited before 387 GURL("https://www.google.com"))); // not visited before
380 EXPECT_FALSE(browsing_instance3->HasSiteInstance( 388 EXPECT_FALSE(browsing_instance3->HasSiteInstance(
381 GURL("http://www.yahoo.com"))); // different BI, different profile 389 GURL("http://www.yahoo.com"))); // different BI, different profile
382 390
383 // browsing_instances will be deleted when their SiteInstances are deleted 391 // browsing_instances will be deleted when their SiteInstances are deleted
384 } 392 }
385 393
OLDNEW
« no previous file with comments | « chrome/browser/site_instance.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698