blob: b2a38b9495c2db284d72854266f8dc0b30468f70 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/site_instance.h"
typedef BrowserWithTestWindowTest BrowserTest;
class TestingOffTheRecordDestructionProfile : public TestingProfile {
public:
TestingOffTheRecordDestructionProfile() : destroyed_profile_(false) {
set_incognito(true);
}
virtual void DestroyOffTheRecordProfile() OVERRIDE {
destroyed_profile_ = true;
}
bool destroyed_profile_;
DISALLOW_COPY_AND_ASSIGN(TestingOffTheRecordDestructionProfile);
};
class BrowserTestOffTheRecord : public BrowserTest {
public:
BrowserTestOffTheRecord() : off_the_record_profile_(NULL) {}
protected:
virtual TestingProfile* CreateProfile() OVERRIDE {
if (off_the_record_profile_ == NULL)
off_the_record_profile_ = new TestingOffTheRecordDestructionProfile();
return off_the_record_profile_;
}
TestingOffTheRecordDestructionProfile* off_the_record_profile_;
DISALLOW_COPY_AND_ASSIGN(BrowserTestOffTheRecord);
};
// Various assertions around setting show state.
TEST_F(BrowserTest, GetSavedWindowShowState) {
// Default show state is SHOW_STATE_DEFAULT.
EXPECT_EQ(ui::SHOW_STATE_DEFAULT, browser()->GetSavedWindowShowState());
// Explicitly specifying a state should stick though.
browser()->set_show_state(ui::SHOW_STATE_MAXIMIZED);
EXPECT_EQ(ui::SHOW_STATE_MAXIMIZED, browser()->GetSavedWindowShowState());
browser()->set_show_state(ui::SHOW_STATE_NORMAL);
EXPECT_EQ(ui::SHOW_STATE_NORMAL, browser()->GetSavedWindowShowState());
browser()->set_show_state(ui::SHOW_STATE_MINIMIZED);
EXPECT_EQ(ui::SHOW_STATE_MINIMIZED, browser()->GetSavedWindowShowState());
browser()->set_show_state(ui::SHOW_STATE_FULLSCREEN);
EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, browser()->GetSavedWindowShowState());
}
TEST_F(BrowserTestOffTheRecord, DelayProfileDestruction) {
scoped_refptr<content::SiteInstance> instance1(
static_cast<content::SiteInstance*>(
content::SiteInstance::Create(off_the_record_profile_)));
scoped_ptr<content::RenderProcessHost> render_process_host1;
render_process_host1.reset(instance1->GetProcess());
ASSERT_TRUE(render_process_host1.get() != NULL);
scoped_refptr<content::SiteInstance> instance2(
static_cast<content::SiteInstance*>(
content::SiteInstance::Create(off_the_record_profile_)));
scoped_ptr<content::RenderProcessHost> render_process_host2;
render_process_host2.reset(instance2->GetProcess());
ASSERT_TRUE(render_process_host2.get() != NULL);
// destroying the browser should not destroy the off the record profile...
set_browser(NULL);
EXPECT_FALSE(off_the_record_profile_->destroyed_profile_);
// until we destroy the render process host holding on to it...
render_process_host1.release()->Cleanup();
// And asynchronicity kicked in properly.
MessageLoop::current()->RunAllPending();
EXPECT_FALSE(off_the_record_profile_->destroyed_profile_);
// I meant, ALL the render process hosts... :-)
render_process_host2.release()->Cleanup();
MessageLoop::current()->RunAllPending();
EXPECT_TRUE(off_the_record_profile_->destroyed_profile_);
}
|