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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
// Copyright (c) 2011 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/renderer_host/accelerated_plugin_view_mac.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
@interface UnderlayCountingWindow : NSWindow {
@private
int underlayCount_;
}
@property (readonly, nonatomic) int underlayCount;
- (void)underlaySurfaceAdded;
- (void)underlaySurfaceRemoved;
@end
@implementation UnderlayCountingWindow
@synthesize underlayCount = underlayCount_;
- (void)underlaySurfaceAdded {
++underlayCount_;
}
- (void)underlaySurfaceRemoved {
--underlayCount_;
}
@end
class AcceleratedPluginViewTest : public PlatformTest {
protected:
AcceleratedPluginViewTest() {}
UnderlayCountingWindow* StubUnderlayWindow() {
UnderlayCountingWindow* window = [[[UnderlayCountingWindow alloc]
initWithContentRect:NSMakeRect(20, 20, 300, 200)
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO] autorelease];
[window orderFront:nil];
return window;
}
AcceleratedPluginView* StubAcceleratedPluginView() {
// It truns out the rwhv and the plugin handle are not necessary for
// this test, and AcceleratedPluginView doesn't crash without them.
AcceleratedPluginView* view = [[[AcceleratedPluginView alloc]
initWithRenderWidgetHostViewMac:NULL
pluginHandle:0] autorelease];
return view;
}
private:
DISALLOW_COPY_AND_ASSIGN(AcceleratedPluginViewTest);
};
TEST_F(AcceleratedPluginViewTest, Basic) {
}
TEST_F(AcceleratedPluginViewTest, BasicAdding) {
AcceleratedPluginView* view = StubAcceleratedPluginView();
UnderlayCountingWindow* window = StubUnderlayWindow();
EXPECT_EQ(0, [window underlayCount]);
[[window contentView] addSubview:view];
EXPECT_EQ(1, [window underlayCount]);
[view removeFromSuperview];
EXPECT_EQ(0, [window underlayCount]);
}
TEST_F(AcceleratedPluginViewTest, MoveBetweenWindows) {
AcceleratedPluginView* view = StubAcceleratedPluginView();
UnderlayCountingWindow* window1 = StubUnderlayWindow();
UnderlayCountingWindow* window2 = StubUnderlayWindow();
EXPECT_EQ(0, [window1 underlayCount]);
EXPECT_EQ(0, [window2 underlayCount]);
[[window1 contentView] addSubview:view];
EXPECT_EQ(1, [window1 underlayCount]);
EXPECT_EQ(0, [window2 underlayCount]);
[[window2 contentView] addSubview:view];
EXPECT_EQ(0, [window1 underlayCount]);
EXPECT_EQ(1, [window2 underlayCount]);
}
TEST_F(AcceleratedPluginViewTest, HiddenWhenAdding) {
AcceleratedPluginView* view = StubAcceleratedPluginView();
[view setHidden:YES];
UnderlayCountingWindow* window = StubUnderlayWindow();
EXPECT_EQ(0, [window underlayCount]);
[[window contentView] addSubview:view];
EXPECT_EQ(0, [window underlayCount]);
[view setHidden:NO];
EXPECT_EQ(1, [window underlayCount]);
[view setHidden:YES];
EXPECT_EQ(0, [window underlayCount]);
[view removeFromSuperview];
EXPECT_EQ(0, [window underlayCount]);
}
TEST_F(AcceleratedPluginViewTest, HiddenAfterAdding) {
AcceleratedPluginView* view = StubAcceleratedPluginView();
UnderlayCountingWindow* window = StubUnderlayWindow();
EXPECT_EQ(0, [window underlayCount]);
[[window contentView] addSubview:view];
EXPECT_EQ(1, [window underlayCount]);
[view setHidden:YES];
EXPECT_EQ(0, [window underlayCount]);
[view setHidden:NO];
EXPECT_EQ(1, [window underlayCount]);
[view removeFromSuperview];
EXPECT_EQ(0, [window underlayCount]);
}
TEST_F(AcceleratedPluginViewTest, MoveBetweenWindowsWithHiding) {
AcceleratedPluginView* view = StubAcceleratedPluginView();
[view setHidden:YES];
UnderlayCountingWindow* window1 = StubUnderlayWindow();
UnderlayCountingWindow* window2 = StubUnderlayWindow();
EXPECT_EQ(0, [window1 underlayCount]);
EXPECT_EQ(0, [window2 underlayCount]);
[[window1 contentView] addSubview:view];
EXPECT_EQ(0, [window1 underlayCount]);
EXPECT_EQ(0, [window2 underlayCount]);
[view setHidden:NO];
EXPECT_EQ(1, [window1 underlayCount]);
EXPECT_EQ(0, [window2 underlayCount]);
// Move view while it's visible.
[[window2 contentView] addSubview:view];
EXPECT_EQ(0, [window1 underlayCount]);
EXPECT_EQ(1, [window2 underlayCount]);
[view setHidden:YES];
EXPECT_EQ(0, [window1 underlayCount]);
EXPECT_EQ(0, [window2 underlayCount]);
// Move view while it's hidden.
[[window1 contentView] addSubview:view];
EXPECT_EQ(0, [window1 underlayCount]);
EXPECT_EQ(0, [window2 underlayCount]);
[view setHidden:NO];
EXPECT_EQ(1, [window1 underlayCount]);
EXPECT_EQ(0, [window2 underlayCount]);
}
|