Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: chrome/browser/ui/browser_unittest.cc

Issue 9420036: Also delay regular profile destruction... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/ui/browser.h" 5 #include "chrome/browser/ui/browser.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 "content/public/browser/render_process_host.h"
9 #include "content/public/browser/site_instance.h"
10 8
11 typedef BrowserWithTestWindowTest BrowserTest; 9 typedef BrowserWithTestWindowTest BrowserTest;
12 10
13 class TestingOffTheRecordDestructionProfile : public TestingProfile {
14 public:
15 TestingOffTheRecordDestructionProfile() : destroyed_profile_(false) {
16 set_incognito(true);
17 }
18 virtual void DestroyOffTheRecordProfile() OVERRIDE {
19 destroyed_profile_ = true;
20 }
21 bool destroyed_profile_;
22
23 DISALLOW_COPY_AND_ASSIGN(TestingOffTheRecordDestructionProfile);
24 };
25
26 class BrowserTestOffTheRecord : public BrowserTest {
27 public:
28 BrowserTestOffTheRecord() : off_the_record_profile_(NULL) {}
29
30 protected:
31 virtual TestingProfile* CreateProfile() OVERRIDE {
32 if (off_the_record_profile_ == NULL)
33 off_the_record_profile_ = new TestingOffTheRecordDestructionProfile();
34 return off_the_record_profile_;
35 }
36 TestingOffTheRecordDestructionProfile* off_the_record_profile_;
37
38 DISALLOW_COPY_AND_ASSIGN(BrowserTestOffTheRecord);
39 };
40
41 // Various assertions around setting show state. 11 // Various assertions around setting show state.
42 TEST_F(BrowserTest, GetSavedWindowShowState) { 12 TEST_F(BrowserTest, GetSavedWindowShowState) {
43 // Default show state is SHOW_STATE_DEFAULT. 13 // Default show state is SHOW_STATE_DEFAULT.
44 EXPECT_EQ(ui::SHOW_STATE_DEFAULT, browser()->GetSavedWindowShowState()); 14 EXPECT_EQ(ui::SHOW_STATE_DEFAULT, browser()->GetSavedWindowShowState());
45 15
46 // Explicitly specifying a state should stick though. 16 // Explicitly specifying a state should stick though.
47 browser()->set_show_state(ui::SHOW_STATE_MAXIMIZED); 17 browser()->set_show_state(ui::SHOW_STATE_MAXIMIZED);
48 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, browser()->GetSavedWindowShowState()); 18 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, browser()->GetSavedWindowShowState());
49 browser()->set_show_state(ui::SHOW_STATE_NORMAL); 19 browser()->set_show_state(ui::SHOW_STATE_NORMAL);
50 EXPECT_EQ(ui::SHOW_STATE_NORMAL, browser()->GetSavedWindowShowState()); 20 EXPECT_EQ(ui::SHOW_STATE_NORMAL, browser()->GetSavedWindowShowState());
51 browser()->set_show_state(ui::SHOW_STATE_MINIMIZED); 21 browser()->set_show_state(ui::SHOW_STATE_MINIMIZED);
52 EXPECT_EQ(ui::SHOW_STATE_MINIMIZED, browser()->GetSavedWindowShowState()); 22 EXPECT_EQ(ui::SHOW_STATE_MINIMIZED, browser()->GetSavedWindowShowState());
53 browser()->set_show_state(ui::SHOW_STATE_FULLSCREEN); 23 browser()->set_show_state(ui::SHOW_STATE_FULLSCREEN);
54 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, browser()->GetSavedWindowShowState()); 24 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, browser()->GetSavedWindowShowState());
55 } 25 }
56
57 TEST_F(BrowserTestOffTheRecord, DelayProfileDestruction) {
58 scoped_refptr<content::SiteInstance> instance1(
59 static_cast<content::SiteInstance*>(
60 content::SiteInstance::Create(off_the_record_profile_)));
61 scoped_ptr<content::RenderProcessHost> render_process_host1;
62 render_process_host1.reset(instance1->GetProcess());
63 ASSERT_TRUE(render_process_host1.get() != NULL);
64
65 scoped_refptr<content::SiteInstance> instance2(
66 static_cast<content::SiteInstance*>(
67 content::SiteInstance::Create(off_the_record_profile_)));
68 scoped_ptr<content::RenderProcessHost> render_process_host2;
69 render_process_host2.reset(instance2->GetProcess());
70 ASSERT_TRUE(render_process_host2.get() != NULL);
71
72 // destroying the browser should not destroy the off the record profile...
73 set_browser(NULL);
74 EXPECT_FALSE(off_the_record_profile_->destroyed_profile_);
75
76 // until we destroy the render process host holding on to it...
77 render_process_host1.release()->Cleanup();
78
79 // And asynchronicity kicked in properly.
80 MessageLoop::current()->RunAllPending();
81 EXPECT_FALSE(off_the_record_profile_->destroyed_profile_);
82
83 // I meant, ALL the render process hosts... :-)
84 render_process_host2.release()->Cleanup();
85 MessageLoop::current()->RunAllPending();
86 EXPECT_TRUE(off_the_record_profile_->destroyed_profile_);
87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698