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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 { | |
Charlie Reis
2012/01/12 22:01:14
Please add OVERRIDE, so that we'll remember to upd
nasko
2012/01/12 22:47:47
Done.
| |
155 return hasProcess; | |
156 } | |
157 | |
158 bool hasProcess; | |
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() { |
158 (*deleteCounter_)++; | 164 (*deleteCounter_)++; |
159 } | 165 } |
160 | 166 |
161 int* deleteCounter_; | 167 int* deleteCounter_; |
162 }; | 168 }; |
163 | 169 |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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, SameProcessForJavascript) { | |
Charlie Reis
2012/01/12 22:01:14
Maybe we can make this a more general test and cal
nasko
2012/01/12 22:47:47
Added a test case before we've assigned a process
awong
2012/01/12 22:56:41
Don't worry about me :) If you commit first, then
nasko
2012/01/13 01:34:50
Done.
| |
558 | |
559 int siteDeleteCounter = 0; | |
560 int browsingDeleteCounter = 0; | |
561 | |
562 TestSiteInstance* instance = TestSiteInstance::CreateTestSiteInstance( | |
563 NULL, &siteDeleteCounter, | |
564 &browsingDeleteCounter); | |
565 | |
566 GURL url_javascript = GURL("javascript:alert(document.location.href);"); | |
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 instance->hasProcess = true; | |
575 EXPECT_TRUE(instance->HasProcess()); | |
576 | |
577 EXPECT_FALSE(instance->HasWrongProcessForURL(url_javascript)); | |
578 } | |
OLD | NEW |