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" |
11 | 11 |
12 class TestingOffTheRecordDestructionProfile : public TestingProfile { | 12 class TestingOffTheRecordDestructionProfile : public TestingProfile { |
13 public: | 13 public: |
14 TestingOffTheRecordDestructionProfile() | 14 TestingOffTheRecordDestructionProfile() |
15 : TestingProfile(base::FilePath(), | 15 : TestingProfile(base::FilePath(), |
16 NULL, | 16 NULL, |
17 scoped_refptr<ExtensionSpecialStoragePolicy>() | 17 scoped_refptr<ExtensionSpecialStoragePolicy>() |
18 scoped_ptr<PrefServiceSyncable>(), | 18 scoped_ptr<PrefServiceSyncable>(), |
19 true, | 19 true, |
20 TestingFactories()), | 20 TestingFactories()), |
21 destroyed_otr_profile_(false) { | 21 destroyed_otr_profile_(false) { |
22 set_incognito(true); | 22 set_incognito(true); |
23 } | 23 } |
24 virtual void DestroyOffTheRecordProfile() OVERRIDE { | 24 virtual void DestroyOffTheRecordProfile() override { |
25 destroyed_otr_profile_ = true; | 25 destroyed_otr_profile_ = true; |
26 } | 26 } |
27 bool destroyed_otr_profile_; | 27 bool destroyed_otr_profile_; |
28 | 28 |
29 DISALLOW_COPY_AND_ASSIGN(TestingOffTheRecordDestructionProfile); | 29 DISALLOW_COPY_AND_ASSIGN(TestingOffTheRecordDestructionProfile); |
30 }; | 30 }; |
31 | 31 |
32 class TestingOriginalDestructionProfile : public TestingProfile { | 32 class TestingOriginalDestructionProfile : public TestingProfile { |
33 public: | 33 public: |
34 TestingOriginalDestructionProfile() : destroyed_otr_profile_(false) { | 34 TestingOriginalDestructionProfile() : destroyed_otr_profile_(false) { |
35 DCHECK_EQ(kNull, living_instance_); | 35 DCHECK_EQ(kNull, living_instance_); |
36 living_instance_ = this; | 36 living_instance_ = this; |
37 } | 37 } |
38 virtual ~TestingOriginalDestructionProfile() { | 38 virtual ~TestingOriginalDestructionProfile() { |
39 DCHECK_EQ(this, living_instance_); | 39 DCHECK_EQ(this, living_instance_); |
40 living_instance_ = NULL; | 40 living_instance_ = NULL; |
41 } | 41 } |
42 virtual void DestroyOffTheRecordProfile() OVERRIDE { | 42 virtual void DestroyOffTheRecordProfile() override { |
43 SetOffTheRecordProfile(NULL); | 43 SetOffTheRecordProfile(NULL); |
44 destroyed_otr_profile_ = true; | 44 destroyed_otr_profile_ = true; |
45 } | 45 } |
46 bool destroyed_otr_profile_; | 46 bool destroyed_otr_profile_; |
47 static TestingOriginalDestructionProfile* living_instance_; | 47 static TestingOriginalDestructionProfile* living_instance_; |
48 | 48 |
49 // This is to avoid type casting in DCHECK_EQ & EXPECT_NE. | 49 // This is to avoid type casting in DCHECK_EQ & EXPECT_NE. |
50 static const TestingOriginalDestructionProfile* kNull; | 50 static const TestingOriginalDestructionProfile* kNull; |
51 | 51 |
52 DISALLOW_COPY_AND_ASSIGN(TestingOriginalDestructionProfile); | 52 DISALLOW_COPY_AND_ASSIGN(TestingOriginalDestructionProfile); |
53 }; | 53 }; |
54 const TestingOriginalDestructionProfile* | 54 const TestingOriginalDestructionProfile* |
55 TestingOriginalDestructionProfile::kNull = NULL; | 55 TestingOriginalDestructionProfile::kNull = NULL; |
56 | 56 |
57 TestingOriginalDestructionProfile* | 57 TestingOriginalDestructionProfile* |
58 TestingOriginalDestructionProfile::living_instance_ = NULL; | 58 TestingOriginalDestructionProfile::living_instance_ = NULL; |
59 | 59 |
60 class ProfileDestroyerTest : public BrowserWithTestWindowTest { | 60 class ProfileDestroyerTest : public BrowserWithTestWindowTest { |
61 public: | 61 public: |
62 ProfileDestroyerTest() : off_the_record_profile_(NULL) {} | 62 ProfileDestroyerTest() : off_the_record_profile_(NULL) {} |
63 | 63 |
64 protected: | 64 protected: |
65 virtual TestingProfile* CreateProfile() OVERRIDE { | 65 virtual TestingProfile* CreateProfile() override { |
66 if (off_the_record_profile_ == NULL) | 66 if (off_the_record_profile_ == NULL) |
67 off_the_record_profile_ = new TestingOffTheRecordDestructionProfile(); | 67 off_the_record_profile_ = new TestingOffTheRecordDestructionProfile(); |
68 return off_the_record_profile_; | 68 return off_the_record_profile_; |
69 } | 69 } |
70 TestingOffTheRecordDestructionProfile* off_the_record_profile_; | 70 TestingOffTheRecordDestructionProfile* off_the_record_profile_; |
71 | 71 |
72 DISALLOW_COPY_AND_ASSIGN(ProfileDestroyerTest); | 72 DISALLOW_COPY_AND_ASSIGN(ProfileDestroyerTest); |
73 }; | 73 }; |
74 | 74 |
75 TEST_F(ProfileDestroyerTest, DelayProfileDestruction) { | 75 TEST_F(ProfileDestroyerTest, DelayProfileDestruction) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 scoped_ptr<content::RenderProcessHost> render_process_host2; | 136 scoped_ptr<content::RenderProcessHost> render_process_host2; |
137 render_process_host2.reset(instance2->GetProcess()); | 137 render_process_host2.reset(instance2->GetProcess()); |
138 ASSERT_TRUE(render_process_host2.get() != NULL); | 138 ASSERT_TRUE(render_process_host2.get() != NULL); |
139 | 139 |
140 ProfileDestroyer::DestroyProfileWhenAppropriate(main_profile); | 140 ProfileDestroyer::DestroyProfileWhenAppropriate(main_profile); |
141 EXPECT_EQ(main_profile, TestingOriginalDestructionProfile::living_instance_); | 141 EXPECT_EQ(main_profile, TestingOriginalDestructionProfile::living_instance_); |
142 render_process_host2.release()->Cleanup(); | 142 render_process_host2.release()->Cleanup(); |
143 base::MessageLoop::current()->RunUntilIdle(); | 143 base::MessageLoop::current()->RunUntilIdle(); |
144 EXPECT_EQ(NULL, TestingOriginalDestructionProfile::living_instance_); | 144 EXPECT_EQ(NULL, TestingOriginalDestructionProfile::living_instance_); |
145 } | 145 } |
OLD | NEW |