OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include <gmock/gmock.h> | |
6 #include <gtest/gtest.h> | |
7 | |
8 #include "chrome/renderer/plugin_uma.h" | |
9 | |
10 using ::testing::_; | |
11 | |
12 class MockPluginUMASender : public MissingPluginReporter::UMASender { | |
13 public: | |
14 MOCK_METHOD1(SendPluginUMA, void(MissingPluginReporter::PluginType)); | |
15 }; | |
16 | |
17 TEST(PluginUMATest, WindowsMediaPlayer) { | |
18 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | |
19 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | |
20 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | |
21 .Times(0); | |
22 | |
23 EXPECT_CALL(*sender_mock, | |
24 SendPluginUMA(MissingPluginReporter::WINDOWS_MEDIA_PLAYER)) | |
25 .Times(1) | |
26 .RetiresOnSaturation(); | |
27 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
28 "application/x-mplayer2", | |
29 GURL("file://some_file.mov")); | |
30 | |
31 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::OTHER)) | |
32 .Times(1) | |
33 .RetiresOnSaturation(); | |
34 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
35 "application/x-mplayer2-some_sufix", | |
36 GURL("file://some_file.mov")); | |
37 | |
38 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::OTHER)) | |
39 .Times(1) | |
40 .RetiresOnSaturation(); | |
41 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
42 "some-prefix-application/x-mplayer2", | |
43 GURL("file://some_file.mov")); | |
44 } | |
45 | |
46 TEST(PluginUMATest, Silverlight) { | |
47 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | |
48 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | |
49 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | |
50 .Times(0); | |
51 | |
52 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::SILVERLIGHT)) | |
53 .Times(1) | |
54 .RetiresOnSaturation(); | |
55 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
56 "application/x-silverlight", | |
57 GURL("aaaa")); | |
58 | |
59 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::SILVERLIGHT)) | |
60 .Times(1) | |
61 .RetiresOnSaturation(); | |
62 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
63 "application/x-silverlight-some-sufix", | |
64 GURL("aaaa")); | |
65 | |
66 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::OTHER)) | |
67 .Times(1) | |
68 .RetiresOnSaturation(); | |
69 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
70 "some-prefix-application/x-silverlight", | |
71 GURL("aaaa")); | |
72 } | |
73 | |
74 TEST(PluginUMATest, RealPlayer) { | |
75 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | |
76 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | |
77 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | |
78 .Times(0); | |
79 | |
80 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::REALPLAYER)) | |
81 .Times(1) | |
82 .RetiresOnSaturation(); | |
83 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
84 "audio/x-pn-realaudio", | |
85 GURL("some url")); | |
86 | |
87 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::REALPLAYER)) | |
88 .Times(1) | |
89 .RetiresOnSaturation(); | |
90 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
91 "audio/x-pn-realaudio-some-sufix", | |
92 GURL("some url")); | |
93 | |
94 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::OTHER)) | |
95 .Times(1) | |
96 .RetiresOnSaturation(); | |
97 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
98 "some-prefix-audio/x-pn-realaudio", | |
99 GURL("some url")); | |
100 } | |
101 | |
102 TEST(PluginUMATest, Java) { | |
103 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | |
104 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | |
105 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | |
106 .Times(0); | |
107 | |
108 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::JAVA)) | |
109 .Times(1) | |
110 .RetiresOnSaturation(); | |
111 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
112 "application/x-java-applet", | |
113 GURL("some url")); | |
114 | |
115 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::JAVA)) | |
116 .Times(1) | |
117 .RetiresOnSaturation(); | |
118 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
119 "application/x-java-applet-some-sufix", | |
120 GURL("some url")); | |
121 | |
122 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::JAVA)) | |
123 .Times(1) | |
124 .RetiresOnSaturation(); | |
125 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
126 "some-prefix-application/x-java-applet-sufix", | |
127 GURL("some url")); | |
128 } | |
129 | |
130 TEST(PluginUMATest, QuickTime) { | |
131 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | |
132 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | |
133 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | |
134 .Times(0); | |
135 | |
136 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::QUICKTIME)) | |
137 .Times(1) | |
138 .RetiresOnSaturation(); | |
139 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
140 "video/quicktime", | |
141 GURL("some url")); | |
142 | |
143 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::OTHER)) | |
144 .Times(1) | |
145 .RetiresOnSaturation(); | |
146 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
147 "video/quicktime-sufix", | |
148 GURL("some url")); | |
149 | |
150 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::OTHER)) | |
151 .Times(1) | |
152 .RetiresOnSaturation(); | |
153 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
154 "prefix-video/quicktime", | |
155 GURL("some url")); | |
156 } | |
157 | |
158 TEST(PluginUMATest, BySrcExtension) { | |
159 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | |
160 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | |
161 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | |
162 .Times(0); | |
163 | |
164 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::QUICKTIME)) | |
165 .Times(1) | |
166 .RetiresOnSaturation(); | |
167 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
168 "", | |
169 GURL("file://file.mov")); | |
170 | |
171 // When plugin's mime type is given, we don't check extension. | |
172 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::OTHER)) | |
173 .Times(1) | |
174 .RetiresOnSaturation(); | |
175 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
176 "unknown-plugin", | |
177 GURL("http://file.mov")); | |
178 | |
179 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::OTHER)) | |
180 .Times(1) | |
181 .RetiresOnSaturation(); | |
182 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
183 "", | |
184 GURL("http://file.unknown_extension")); | |
185 | |
186 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::QUICKTIME)) | |
187 .Times(1) | |
188 .RetiresOnSaturation(); | |
189 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
190 "", | |
191 GURL("http://aaa/file.mov?x=aaaa&y=b#c")); | |
192 | |
193 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::QUICKTIME)) | |
194 .Times(1) | |
195 .RetiresOnSaturation(); | |
196 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
197 "", | |
198 GURL("http://file.mov?x=aaaa&y=b#c")); | |
199 | |
200 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::OTHER)) | |
201 .Times(1) | |
202 .RetiresOnSaturation(); | |
203 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
204 "", | |
205 GURL("http://")); | |
206 | |
207 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::OTHER)) | |
208 .Times(1) | |
209 .RetiresOnSaturation(); | |
210 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
211 "", | |
212 GURL("mov")); | |
213 } | |
214 | |
215 TEST(PluginUMATest, CaseSensitivity) { | |
216 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | |
217 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | |
218 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | |
219 .Times(0); | |
220 | |
221 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::QUICKTIME)) | |
222 .Times(1) | |
223 .RetiresOnSaturation(); | |
224 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
225 "video/QUICKTIME", | |
226 GURL("http://file.aaa")); | |
227 | |
228 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::QUICKTIME)) | |
229 .Times(1) | |
230 .RetiresOnSaturation(); | |
231 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
232 "", | |
233 GURL("http://file.MoV")); | |
234 } | |
235 | |
OLD | NEW |