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

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

Issue 9147051: Don't swap processes for javascript: URLs. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Addressing feedback from creis. 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
OLDNEW
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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 public: 144 public:
145 static TestSiteInstance* CreateTestSiteInstance( 145 static TestSiteInstance* CreateTestSiteInstance(
146 content::BrowserContext* browser_context, 146 content::BrowserContext* browser_context,
147 int* siteDeleteCounter, 147 int* siteDeleteCounter,
148 int* browsingDeleteCounter) { 148 int* browsingDeleteCounter) {
149 TestBrowsingInstance* browsing_instance = 149 TestBrowsingInstance* browsing_instance =
150 new TestBrowsingInstance(browser_context, browsingDeleteCounter); 150 new TestBrowsingInstance(browser_context, browsingDeleteCounter);
151 return new TestSiteInstance(browsing_instance, siteDeleteCounter); 151 return new TestSiteInstance(browsing_instance, siteDeleteCounter);
152 } 152 }
153 153
154 bool HasProcess() const OVERRIDE {
155 return hasProcess;
156 }
157
158 bool hasProcess;
awong 2012/01/12 22:56:41 incorrect naming convention. :( http://google-sty
nasko 2012/01/13 01:34:50 Moved to a different test that doesn't require mod
159
154 private: 160 private:
155 TestSiteInstance(BrowsingInstance* browsing_instance, int* deleteCounter) 161 TestSiteInstance(BrowsingInstance* browsing_instance, int* deleteCounter)
156 : SiteInstance(browsing_instance), deleteCounter_(deleteCounter) {} 162 : SiteInstance(browsing_instance), deleteCounter_(deleteCounter) {}
157 ~TestSiteInstance() { 163 ~TestSiteInstance() {
awong 2012/01/12 22:56:41 Since we're here, can we add a virtual in front of
nasko 2012/01/13 01:34:50 Done.
158 (*deleteCounter_)++; 164 (*deleteCounter_)++;
159 } 165 }
160 166
161 int* deleteCounter_; 167 int* deleteCounter_;
162 }; 168 };
163 169
164 } // namespace 170 } // namespace
165 171
166 // Test to ensure no memory leaks for SiteInstance objects. 172 // Test to ensure no memory leaks for SiteInstance objects.
167 TEST_F(SiteInstanceTest, SiteInstanceDestructor) { 173 TEST_F(SiteInstanceTest, SiteInstanceDestructor) {
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 // Make sure none of differing privilege processes are mixed. 545 // Make sure none of differing privilege processes are mixed.
540 EXPECT_NE(extension1_instance->GetProcess(), webui1_instance->GetProcess()); 546 EXPECT_NE(extension1_instance->GetProcess(), webui1_instance->GetProcess());
541 547
542 for (size_t i = 0; i < content::kMaxRendererProcessCount; ++i) { 548 for (size_t i = 0; i < content::kMaxRendererProcessCount; ++i) {
543 EXPECT_NE(extension1_instance->GetProcess(), hosts[i]); 549 EXPECT_NE(extension1_instance->GetProcess(), hosts[i]);
544 EXPECT_NE(webui1_instance->GetProcess(), hosts[i]); 550 EXPECT_NE(webui1_instance->GetProcess(), hosts[i]);
545 } 551 }
546 552
547 STLDeleteContainerPointers(hosts.begin(), hosts.end()); 553 STLDeleteContainerPointers(hosts.begin(), hosts.end());
548 } 554 }
555
556 // Test to ensure that javascript URLs always run in the same process.
557 TEST_F(SiteInstanceTest, HasWrongProcessForURL) {
558
559 int siteDeleteCounter = 0;
560 int browsingDeleteCounter = 0;
561 const GURL url_javascript = GURL("javascript:alert(document.location.href);");
562 const GURL goog = GURL("http://google.com");
563
564 TestSiteInstance* instance = TestSiteInstance::CreateTestSiteInstance(
awong 2012/01/12 22:56:41 Line indent on wrapping should be 4 spaces. http:
nasko 2012/01/13 01:34:50 Done.
565 NULL, &siteDeleteCounter,
566 &browsingDeleteCounter);
567
568 EXPECT_FALSE(instance->has_site());
569 EXPECT_TRUE(instance->site().is_empty());
570
571 instance->SetSite(GURL("http://www.evernote.com/"));
572 EXPECT_TRUE(instance->has_site());
573
574 // Check prior to "assigning" a process to the instance, which is expected
575 // to return false due to not being attached to any process yet.
576 EXPECT_FALSE(instance->HasWrongProcessForURL(goog));
577
578 instance->hasProcess = true;
579 EXPECT_TRUE(instance->HasProcess());
580
581 EXPECT_FALSE(instance->HasWrongProcessForURL(url_javascript));
582 }
OLDNEW
« content/browser/site_instance.h ('K') | « content/browser/site_instance.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698