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" |
11 #include "content/browser/mock_content_browser_client.h" | 11 #include "content/browser/mock_content_browser_client.h" |
12 #include "content/browser/renderer_host/render_process_host_impl.h" | 12 #include "content/browser/renderer_host/render_process_host_impl.h" |
13 #include "content/browser/renderer_host/render_view_host.h" | 13 #include "content/browser/renderer_host/render_view_host.h" |
14 #include "content/browser/renderer_host/test_render_view_host.h" | 14 #include "content/browser/renderer_host/test_render_view_host.h" |
15 #include "content/browser/site_instance.h" | 15 #include "content/browser/site_instance.h" |
16 #include "content/browser/tab_contents/navigation_entry.h" | 16 #include "content/browser/tab_contents/navigation_entry_impl.h" |
17 #include "content/browser/tab_contents/tab_contents.h" | 17 #include "content/browser/tab_contents/tab_contents.h" |
18 #include "content/browser/webui/empty_web_ui_factory.h" | 18 #include "content/browser/webui/empty_web_ui_factory.h" |
19 #include "content/public/common/content_client.h" | 19 #include "content/public/common/content_client.h" |
20 #include "content/public/common/content_constants.h" | 20 #include "content/public/common/content_constants.h" |
21 #include "content/public/common/url_constants.h" | 21 #include "content/public/common/url_constants.h" |
22 #include "content/test/test_browser_context.h" | 22 #include "content/test/test_browser_context.h" |
23 #include "googleurl/src/url_util.h" | 23 #include "googleurl/src/url_util.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
25 | 25 |
26 using content::BrowserThread; | 26 using content::BrowserThread; |
27 using content::BrowserThreadImpl; | 27 using content::BrowserThreadImpl; |
| 28 using content::NavigationEntry; |
| 29 using content::NavigationEntryImpl; |
28 | 30 |
29 namespace { | 31 namespace { |
30 | 32 |
31 const char kSameAsAnyInstanceURL[] = "about:internets"; | 33 const char kSameAsAnyInstanceURL[] = "about:internets"; |
32 | 34 |
33 const char kPrivilegedScheme[] = "privileged"; | 35 const char kPrivilegedScheme[] = "privileged"; |
34 | 36 |
35 class SiteInstanceTestWebUIFactory : public content::EmptyWebUIFactory { | 37 class SiteInstanceTestWebUIFactory : public content::EmptyWebUIFactory { |
36 public: | 38 public: |
37 virtual bool UseWebUIForURL(content::BrowserContext* browser_context, | 39 virtual bool UseWebUIForURL(content::BrowserContext* browser_context, |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 int siteDeleteCounter = 0; | 172 int siteDeleteCounter = 0; |
171 int browsingDeleteCounter = 0; | 173 int browsingDeleteCounter = 0; |
172 const GURL url("test:foo"); | 174 const GURL url("test:foo"); |
173 | 175 |
174 // Ensure that instances are deleted when their NavigationEntries are gone. | 176 // Ensure that instances are deleted when their NavigationEntries are gone. |
175 TestSiteInstance* instance = | 177 TestSiteInstance* instance = |
176 TestSiteInstance::CreateTestSiteInstance(NULL, &siteDeleteCounter, | 178 TestSiteInstance::CreateTestSiteInstance(NULL, &siteDeleteCounter, |
177 &browsingDeleteCounter); | 179 &browsingDeleteCounter); |
178 EXPECT_EQ(0, siteDeleteCounter); | 180 EXPECT_EQ(0, siteDeleteCounter); |
179 | 181 |
180 NavigationEntry* e1 = new NavigationEntry(instance, 0, url, | 182 NavigationEntryImpl* e1 = new NavigationEntryImpl( |
181 content::Referrer(), | 183 instance, 0, url, content::Referrer(), string16(), |
182 string16(), | 184 content::PAGE_TRANSITION_LINK, false); |
183 content::PAGE_TRANSITION_LINK, | |
184 false); | |
185 | 185 |
186 // Redundantly setting e1's SiteInstance shouldn't affect the ref count. | 186 // Redundantly setting e1's SiteInstance shouldn't affect the ref count. |
187 e1->set_site_instance(instance); | 187 e1->set_site_instance(instance); |
188 EXPECT_EQ(0, siteDeleteCounter); | 188 EXPECT_EQ(0, siteDeleteCounter); |
189 | 189 |
190 // Add a second reference | 190 // Add a second reference |
191 NavigationEntry* e2 = new NavigationEntry(instance, 0, url, | 191 NavigationEntryImpl* e2 = new NavigationEntryImpl( |
192 content::Referrer(), string16(), | 192 instance, 0, url, content::Referrer(), string16(), |
193 content::PAGE_TRANSITION_LINK, | 193 content::PAGE_TRANSITION_LINK, false); |
194 false); | |
195 | 194 |
196 // Now delete both entries and be sure the SiteInstance goes away. | 195 // Now delete both entries and be sure the SiteInstance goes away. |
197 delete e1; | 196 delete e1; |
198 EXPECT_EQ(0, siteDeleteCounter); | 197 EXPECT_EQ(0, siteDeleteCounter); |
199 EXPECT_EQ(0, browsingDeleteCounter); | 198 EXPECT_EQ(0, browsingDeleteCounter); |
200 delete e2; | 199 delete e2; |
201 EXPECT_EQ(1, siteDeleteCounter); | 200 EXPECT_EQ(1, siteDeleteCounter); |
202 // instance is now deleted | 201 // instance is now deleted |
203 EXPECT_EQ(1, browsingDeleteCounter); | 202 EXPECT_EQ(1, browsingDeleteCounter); |
204 // browsing_instance is now deleted | 203 // browsing_instance is now deleted |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 int browsingDeleteCounter = 0; | 236 int browsingDeleteCounter = 0; |
238 const GURL url("test:foo"); | 237 const GURL url("test:foo"); |
239 | 238 |
240 SiteInstance* instance1 = | 239 SiteInstance* instance1 = |
241 TestSiteInstance::CreateTestSiteInstance(NULL, &siteDeleteCounter1, | 240 TestSiteInstance::CreateTestSiteInstance(NULL, &siteDeleteCounter1, |
242 &browsingDeleteCounter); | 241 &browsingDeleteCounter); |
243 SiteInstance* instance2 = | 242 SiteInstance* instance2 = |
244 TestSiteInstance::CreateTestSiteInstance(NULL, &siteDeleteCounter2, | 243 TestSiteInstance::CreateTestSiteInstance(NULL, &siteDeleteCounter2, |
245 &browsingDeleteCounter); | 244 &browsingDeleteCounter); |
246 | 245 |
247 NavigationEntry* e1 = new NavigationEntry(instance1, 0, url, | 246 NavigationEntryImpl* e1 = new NavigationEntryImpl( |
248 content::Referrer(), string16(), | 247 instance1, 0, url, content::Referrer(), string16(), |
249 content::PAGE_TRANSITION_LINK, | 248 content::PAGE_TRANSITION_LINK, false); |
250 false); | |
251 // Clone the entry | 249 // Clone the entry |
252 NavigationEntry* e2 = new NavigationEntry(*e1); | 250 NavigationEntryImpl* e2 = new NavigationEntryImpl(*e1); |
253 | 251 |
254 // Should be able to change the SiteInstance of the cloned entry. | 252 // Should be able to change the SiteInstance of the cloned entry. |
255 e2->set_site_instance(instance2); | 253 e2->set_site_instance(instance2); |
256 | 254 |
257 // The first SiteInstance should go away after deleting e1, since e2 should | 255 // The first SiteInstance should go away after deleting e1, since e2 should |
258 // no longer be referencing it. | 256 // no longer be referencing it. |
259 delete e1; | 257 delete e1; |
260 EXPECT_EQ(1, siteDeleteCounter1); | 258 EXPECT_EQ(1, siteDeleteCounter1); |
261 EXPECT_EQ(0, siteDeleteCounter2); | 259 EXPECT_EQ(0, siteDeleteCounter2); |
262 | 260 |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 // Make sure none of differing privilege processes are mixed. | 539 // Make sure none of differing privilege processes are mixed. |
542 EXPECT_NE(extension1_instance->GetProcess(), webui1_instance->GetProcess()); | 540 EXPECT_NE(extension1_instance->GetProcess(), webui1_instance->GetProcess()); |
543 | 541 |
544 for (size_t i = 0; i < content::kMaxRendererProcessCount; ++i) { | 542 for (size_t i = 0; i < content::kMaxRendererProcessCount; ++i) { |
545 EXPECT_NE(extension1_instance->GetProcess(), hosts[i]); | 543 EXPECT_NE(extension1_instance->GetProcess(), hosts[i]); |
546 EXPECT_NE(webui1_instance->GetProcess(), hosts[i]); | 544 EXPECT_NE(webui1_instance->GetProcess(), hosts[i]); |
547 } | 545 } |
548 | 546 |
549 STLDeleteContainerPointers(hosts.begin(), hosts.end()); | 547 STLDeleteContainerPointers(hosts.begin(), hosts.end()); |
550 } | 548 } |
OLD | NEW |