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 "chrome/browser/profiles/profile_destroyer.h" | 5 #include "chrome/browser/profiles/profile_destroyer.h" |
6 | 6 |
7 #include "chrome/test/base/browser_with_test_window_test.h" | 7 #include "chrome/test/base/browser_with_test_window_test.h" |
8 #include "chrome/test/base/testing_profile.h" | 8 #include "chrome/test/base/testing_profile.h" |
9 #include "content/public/browser/render_process_host.h" | 9 #include "content/public/browser/render_process_host.h" |
10 #include "content/public/browser/site_instance.h" | 10 #include "content/public/browser/site_instance.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 ASSERT_TRUE(render_process_host2.get() != NULL); | 79 ASSERT_TRUE(render_process_host2.get() != NULL); |
80 | 80 |
81 // destroying the browser should not destroy the off the record profile... | 81 // destroying the browser should not destroy the off the record profile... |
82 set_browser(NULL); | 82 set_browser(NULL); |
83 EXPECT_FALSE(off_the_record_profile_->destroyed_otr_profile_); | 83 EXPECT_FALSE(off_the_record_profile_->destroyed_otr_profile_); |
84 | 84 |
85 // until we destroy the render process host holding on to it... | 85 // until we destroy the render process host holding on to it... |
86 render_process_host1.release()->Cleanup(); | 86 render_process_host1.release()->Cleanup(); |
87 | 87 |
88 // And asynchronicity kicked in properly. | 88 // And asynchronicity kicked in properly. |
89 MessageLoop::current()->RunUntilIdle(); | 89 base::MessageLoop::current()->RunUntilIdle(); |
90 EXPECT_FALSE(off_the_record_profile_->destroyed_otr_profile_); | 90 EXPECT_FALSE(off_the_record_profile_->destroyed_otr_profile_); |
91 | 91 |
92 // I meant, ALL the render process hosts... :-) | 92 // I meant, ALL the render process hosts... :-) |
93 render_process_host2.release()->Cleanup(); | 93 render_process_host2.release()->Cleanup(); |
94 MessageLoop::current()->RunUntilIdle(); | 94 base::MessageLoop::current()->RunUntilIdle(); |
95 EXPECT_TRUE(off_the_record_profile_->destroyed_otr_profile_); | 95 EXPECT_TRUE(off_the_record_profile_->destroyed_otr_profile_); |
96 } | 96 } |
97 | 97 |
98 TEST_F(ProfileDestroyerTest, DelayOriginalProfileDestruction) { | 98 TEST_F(ProfileDestroyerTest, DelayOriginalProfileDestruction) { |
99 TestingOriginalDestructionProfile* original_profile = | 99 TestingOriginalDestructionProfile* original_profile = |
100 new TestingOriginalDestructionProfile; | 100 new TestingOriginalDestructionProfile; |
101 | 101 |
102 TestingOffTheRecordDestructionProfile* off_the_record_profile = | 102 TestingOffTheRecordDestructionProfile* off_the_record_profile = |
103 new TestingOffTheRecordDestructionProfile; | 103 new TestingOffTheRecordDestructionProfile; |
104 | 104 |
105 original_profile->SetOffTheRecordProfile(off_the_record_profile); | 105 original_profile->SetOffTheRecordProfile(off_the_record_profile); |
106 | 106 |
107 scoped_refptr<content::SiteInstance> instance1( | 107 scoped_refptr<content::SiteInstance> instance1( |
108 content::SiteInstance::Create(off_the_record_profile)); | 108 content::SiteInstance::Create(off_the_record_profile)); |
109 scoped_ptr<content::RenderProcessHost> render_process_host1; | 109 scoped_ptr<content::RenderProcessHost> render_process_host1; |
110 render_process_host1.reset(instance1->GetProcess()); | 110 render_process_host1.reset(instance1->GetProcess()); |
111 ASSERT_TRUE(render_process_host1.get() != NULL); | 111 ASSERT_TRUE(render_process_host1.get() != NULL); |
112 | 112 |
113 // Trying to destroy the original profile should be delayed until associated | 113 // Trying to destroy the original profile should be delayed until associated |
114 // off the record profile is released by all render process hosts. | 114 // off the record profile is released by all render process hosts. |
115 ProfileDestroyer::DestroyProfileWhenAppropriate(original_profile); | 115 ProfileDestroyer::DestroyProfileWhenAppropriate(original_profile); |
116 EXPECT_NE(TestingOriginalDestructionProfile::kNull, | 116 EXPECT_NE(TestingOriginalDestructionProfile::kNull, |
117 TestingOriginalDestructionProfile::living_instance_); | 117 TestingOriginalDestructionProfile::living_instance_); |
118 EXPECT_FALSE(original_profile->destroyed_otr_profile_); | 118 EXPECT_FALSE(original_profile->destroyed_otr_profile_); |
119 | 119 |
120 render_process_host1.release()->Cleanup(); | 120 render_process_host1.release()->Cleanup(); |
121 MessageLoop::current()->RunUntilIdle(); | 121 base::MessageLoop::current()->RunUntilIdle(); |
122 EXPECT_EQ(NULL, TestingOriginalDestructionProfile::living_instance_); | 122 EXPECT_EQ(NULL, TestingOriginalDestructionProfile::living_instance_); |
123 | 123 |
124 // And the same protection should apply to the main profile. | 124 // And the same protection should apply to the main profile. |
125 TestingOriginalDestructionProfile* main_profile = | 125 TestingOriginalDestructionProfile* main_profile = |
126 new TestingOriginalDestructionProfile; | 126 new TestingOriginalDestructionProfile; |
127 scoped_refptr<content::SiteInstance> instance2( | 127 scoped_refptr<content::SiteInstance> instance2( |
128 content::SiteInstance::Create(main_profile)); | 128 content::SiteInstance::Create(main_profile)); |
129 scoped_ptr<content::RenderProcessHost> render_process_host2; | 129 scoped_ptr<content::RenderProcessHost> render_process_host2; |
130 render_process_host2.reset(instance2->GetProcess()); | 130 render_process_host2.reset(instance2->GetProcess()); |
131 ASSERT_TRUE(render_process_host2.get() != NULL); | 131 ASSERT_TRUE(render_process_host2.get() != NULL); |
132 | 132 |
133 ProfileDestroyer::DestroyProfileWhenAppropriate(main_profile); | 133 ProfileDestroyer::DestroyProfileWhenAppropriate(main_profile); |
134 EXPECT_EQ(main_profile, TestingOriginalDestructionProfile::living_instance_); | 134 EXPECT_EQ(main_profile, TestingOriginalDestructionProfile::living_instance_); |
135 render_process_host2.release()->Cleanup(); | 135 render_process_host2.release()->Cleanup(); |
136 MessageLoop::current()->RunUntilIdle(); | 136 base::MessageLoop::current()->RunUntilIdle(); |
137 EXPECT_EQ(NULL, TestingOriginalDestructionProfile::living_instance_); | 137 EXPECT_EQ(NULL, TestingOriginalDestructionProfile::living_instance_); |
138 } | 138 } |
OLD | NEW |