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/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 | |
11 class TestingOffTheRecordDestructionProfile : public TestingProfile { | |
12 public: | |
13 TestingOffTheRecordDestructionProfile() : destroyed_profile_(false) { | |
14 set_incognito(true); | |
15 } | |
16 virtual void DestroyOffTheRecordProfile() OVERRIDE { | |
17 destroyed_profile_ = true; | |
18 } | |
19 bool destroyed_profile_; | |
20 | |
21 DISALLOW_COPY_AND_ASSIGN(TestingOffTheRecordDestructionProfile); | |
22 }; | |
23 | |
24 class BrowserTestOffTheRecord : public BrowserWithTestWindowTest { | |
25 public: | |
26 BrowserTestOffTheRecord() : off_the_record_profile_(NULL) {} | |
27 | |
28 protected: | |
29 virtual TestingProfile* CreateProfile() OVERRIDE { | |
30 if (off_the_record_profile_ == NULL) | |
31 off_the_record_profile_ = new TestingOffTheRecordDestructionProfile(); | |
32 return off_the_record_profile_; | |
33 } | |
34 TestingOffTheRecordDestructionProfile* off_the_record_profile_; | |
35 | |
36 DISALLOW_COPY_AND_ASSIGN(BrowserTestOffTheRecord); | |
37 }; | |
38 | 8 |
39 // Various assertions around setting show state. | 9 // Various assertions around setting show state. |
40 TEST_F(BrowserWithTestWindowTest, GetSavedWindowShowState) { | 10 TEST_F(BrowserWithTestWindowTest, GetSavedWindowShowState) { |
41 // Default show state is SHOW_STATE_DEFAULT. | 11 // Default show state is SHOW_STATE_DEFAULT. |
42 EXPECT_EQ(ui::SHOW_STATE_DEFAULT, browser()->GetSavedWindowShowState()); | 12 EXPECT_EQ(ui::SHOW_STATE_DEFAULT, browser()->GetSavedWindowShowState()); |
43 | 13 |
44 // Explicitly specifying a state should stick though. | 14 // Explicitly specifying a state should stick though. |
45 browser()->set_show_state(ui::SHOW_STATE_MAXIMIZED); | 15 browser()->set_show_state(ui::SHOW_STATE_MAXIMIZED); |
46 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, browser()->GetSavedWindowShowState()); | 16 EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, browser()->GetSavedWindowShowState()); |
47 browser()->set_show_state(ui::SHOW_STATE_NORMAL); | 17 browser()->set_show_state(ui::SHOW_STATE_NORMAL); |
48 EXPECT_EQ(ui::SHOW_STATE_NORMAL, browser()->GetSavedWindowShowState()); | 18 EXPECT_EQ(ui::SHOW_STATE_NORMAL, browser()->GetSavedWindowShowState()); |
49 browser()->set_show_state(ui::SHOW_STATE_MINIMIZED); | 19 browser()->set_show_state(ui::SHOW_STATE_MINIMIZED); |
50 EXPECT_EQ(ui::SHOW_STATE_MINIMIZED, browser()->GetSavedWindowShowState()); | 20 EXPECT_EQ(ui::SHOW_STATE_MINIMIZED, browser()->GetSavedWindowShowState()); |
51 browser()->set_show_state(ui::SHOW_STATE_FULLSCREEN); | 21 browser()->set_show_state(ui::SHOW_STATE_FULLSCREEN); |
52 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, browser()->GetSavedWindowShowState()); | 22 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, browser()->GetSavedWindowShowState()); |
53 } | 23 } |
54 | |
55 TEST_F(BrowserTestOffTheRecord, DelayProfileDestruction) { | |
56 scoped_refptr<content::SiteInstance> instance1( | |
57 static_cast<content::SiteInstance*>( | |
58 content::SiteInstance::Create(off_the_record_profile_))); | |
59 scoped_ptr<content::RenderProcessHost> render_process_host1; | |
60 render_process_host1.reset(instance1->GetProcess()); | |
61 ASSERT_TRUE(render_process_host1.get() != NULL); | |
62 | |
63 scoped_refptr<content::SiteInstance> instance2( | |
64 static_cast<content::SiteInstance*>( | |
65 content::SiteInstance::Create(off_the_record_profile_))); | |
66 scoped_ptr<content::RenderProcessHost> render_process_host2; | |
67 render_process_host2.reset(instance2->GetProcess()); | |
68 ASSERT_TRUE(render_process_host2.get() != NULL); | |
69 | |
70 // destroying the browser should not destroy the off the record profile... | |
71 set_browser(NULL); | |
72 EXPECT_FALSE(off_the_record_profile_->destroyed_profile_); | |
73 | |
74 // until we destroy the render process host holding on to it... | |
75 render_process_host1.release()->Cleanup(); | |
76 | |
77 // And asynchronicity kicked in properly. | |
78 MessageLoop::current()->RunAllPending(); | |
79 EXPECT_FALSE(off_the_record_profile_->destroyed_profile_); | |
80 | |
81 // I meant, ALL the render process hosts... :-) | |
82 render_process_host2.release()->Cleanup(); | |
83 MessageLoop::current()->RunAllPending(); | |
84 EXPECT_TRUE(off_the_record_profile_->destroyed_profile_); | |
85 } | |
OLD | NEW |