| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/site_instance_impl.h" | 5 #include "content/browser/site_instance_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "content/browser/web_contents/web_contents_impl.h" | 21 #include "content/browser/web_contents/web_contents_impl.h" |
| 22 #include "content/browser/webui/content_web_ui_controller_factory.h" | 22 #include "content/browser/webui/content_web_ui_controller_factory.h" |
| 23 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 23 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
| 24 #include "content/public/common/content_client.h" | 24 #include "content/public/common/content_client.h" |
| 25 #include "content/public/common/content_constants.h" | 25 #include "content/public/common/content_constants.h" |
| 26 #include "content/public/common/content_switches.h" | 26 #include "content/public/common/content_switches.h" |
| 27 #include "content/public/common/url_constants.h" | 27 #include "content/public/common/url_constants.h" |
| 28 #include "content/public/common/url_utils.h" | 28 #include "content/public/common/url_utils.h" |
| 29 #include "content/public/test/mock_render_process_host.h" | 29 #include "content/public/test/mock_render_process_host.h" |
| 30 #include "content/public/test/test_browser_context.h" | 30 #include "content/public/test/test_browser_context.h" |
| 31 #include "content/public/test/test_browser_thread.h" | 31 #include "content/public/test/test_browser_thread_bundle.h" |
| 32 #include "content/public/test/test_utils.h" | 32 #include "content/public/test/test_utils.h" |
| 33 #include "content/test/test_content_browser_client.h" | 33 #include "content/test/test_content_browser_client.h" |
| 34 #include "content/test/test_content_client.h" | 34 #include "content/test/test_content_client.h" |
| 35 #include "content/test/test_render_view_host.h" | 35 #include "content/test/test_render_view_host.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| 37 #include "url/url_util.h" | 37 #include "url/url_util.h" |
| 38 | 38 |
| 39 namespace content { | 39 namespace content { |
| 40 | 40 |
| 41 const char kPrivilegedScheme[] = "privileged"; | 41 const char kPrivilegedScheme[] = "privileged"; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 88 |
| 89 private: | 89 private: |
| 90 int privileged_process_id_; | 90 int privileged_process_id_; |
| 91 | 91 |
| 92 int site_instance_delete_count_; | 92 int site_instance_delete_count_; |
| 93 int browsing_instance_delete_count_; | 93 int browsing_instance_delete_count_; |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 class SiteInstanceTest : public testing::Test { | 96 class SiteInstanceTest : public testing::Test { |
| 97 public: | 97 public: |
| 98 SiteInstanceTest() | 98 SiteInstanceTest() : old_browser_client_(nullptr) {} |
| 99 : ui_thread_(BrowserThread::UI, &message_loop_), | |
| 100 file_user_blocking_thread_(BrowserThread::FILE_USER_BLOCKING, | |
| 101 &message_loop_), | |
| 102 io_thread_(BrowserThread::IO, &message_loop_), | |
| 103 old_browser_client_(nullptr) {} | |
| 104 | 99 |
| 105 void SetUp() override { | 100 void SetUp() override { |
| 106 old_browser_client_ = SetBrowserClientForTesting(&browser_client_); | 101 old_browser_client_ = SetBrowserClientForTesting(&browser_client_); |
| 107 url::AddStandardScheme(kPrivilegedScheme, url::SCHEME_WITHOUT_PORT); | 102 url::AddStandardScheme(kPrivilegedScheme, url::SCHEME_WITHOUT_PORT); |
| 108 url::AddStandardScheme(kChromeUIScheme, url::SCHEME_WITHOUT_PORT); | 103 url::AddStandardScheme(kChromeUIScheme, url::SCHEME_WITHOUT_PORT); |
| 109 | 104 |
| 110 SiteInstanceImpl::set_render_process_host_factory(&rph_factory_); | 105 SiteInstanceImpl::set_render_process_host_factory(&rph_factory_); |
| 111 } | 106 } |
| 112 | 107 |
| 113 void TearDown() override { | 108 void TearDown() override { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 136 void DrainMessageLoop() { | 131 void DrainMessageLoop() { |
| 137 // We don't just do this in TearDown() because we create TestBrowserContext | 132 // We don't just do this in TearDown() because we create TestBrowserContext |
| 138 // objects in each test, which will be destructed before | 133 // objects in each test, which will be destructed before |
| 139 // TearDown() is called. | 134 // TearDown() is called. |
| 140 base::RunLoop().RunUntilIdle(); | 135 base::RunLoop().RunUntilIdle(); |
| 141 } | 136 } |
| 142 | 137 |
| 143 SiteInstanceTestBrowserClient* browser_client() { return &browser_client_; } | 138 SiteInstanceTestBrowserClient* browser_client() { return &browser_client_; } |
| 144 | 139 |
| 145 private: | 140 private: |
| 146 base::MessageLoopForUI message_loop_; | 141 TestBrowserThreadBundle test_browser_thread_bundle_; |
| 147 TestBrowserThread ui_thread_; | |
| 148 TestBrowserThread file_user_blocking_thread_; | |
| 149 TestBrowserThread io_thread_; | |
| 150 | 142 |
| 151 SiteInstanceTestBrowserClient browser_client_; | 143 SiteInstanceTestBrowserClient browser_client_; |
| 152 ContentBrowserClient* old_browser_client_; | 144 ContentBrowserClient* old_browser_client_; |
| 153 MockRenderProcessHostFactory rph_factory_; | 145 MockRenderProcessHostFactory rph_factory_; |
| 154 }; | 146 }; |
| 155 | 147 |
| 156 // Test to ensure no memory leaks for SiteInstance objects. | 148 // Test to ensure no memory leaks for SiteInstance objects. |
| 157 TEST_F(SiteInstanceTest, SiteInstanceDestructor) { | 149 TEST_F(SiteInstanceTest, SiteInstanceDestructor) { |
| 158 // The existence of this object will cause WebContentsImpl to create our | 150 // The existence of this object will cause WebContentsImpl to create our |
| 159 // test one instead of the real one. | 151 // test one instead of the real one. |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); | 832 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); |
| 841 EXPECT_EQ(0, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); | 833 EXPECT_EQ(0, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); |
| 842 | 834 |
| 843 // Free the subframe instance, which should free the browsing instance. | 835 // Free the subframe instance, which should free the browsing instance. |
| 844 subframe_instance = nullptr; | 836 subframe_instance = nullptr; |
| 845 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); | 837 EXPECT_EQ(1, browser_client()->GetAndClearSiteInstanceDeleteCount()); |
| 846 EXPECT_EQ(1, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); | 838 EXPECT_EQ(1, browser_client()->GetAndClearBrowsingInstanceDeleteCount()); |
| 847 } | 839 } |
| 848 | 840 |
| 849 } // namespace content | 841 } // namespace content |
| OLD | NEW |