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.
5 #include <gtest/gtest.h>
7 #include "chrome/renderer/plugins/plugin_uma.h"
9 class PluginUMATest
: public testing::Test
{
11 static void ExpectPluginType(
12 PluginUMAReporter::PluginType expected_plugin_type
,
13 const std::string
& plugin_mime_type
,
14 const GURL
& plugin_src
) {
15 EXPECT_EQ(expected_plugin_type
,
16 PluginUMAReporter::GetInstance()->GetPluginType(plugin_mime_type
,
21 TEST_F(PluginUMATest
, WindowsMediaPlayer
) {
22 ExpectPluginType(PluginUMAReporter::WINDOWS_MEDIA_PLAYER
,
23 "application/x-mplayer2",
24 GURL("file://some_file.mov"));
25 ExpectPluginType(PluginUMAReporter::UNSUPPORTED_MIMETYPE
,
26 "application/x-mplayer2-some_sufix",
27 GURL("file://some_file.mov"));
28 ExpectPluginType(PluginUMAReporter::UNSUPPORTED_MIMETYPE
,
29 "some-prefix-application/x-mplayer2",
30 GURL("file://some_file.mov"));
33 TEST_F(PluginUMATest
, Silverlight
) {
34 ExpectPluginType(PluginUMAReporter::SILVERLIGHT
,
35 "application/x-silverlight",
37 ExpectPluginType(PluginUMAReporter::SILVERLIGHT
,
38 "application/x-silverlight-some-sufix",
40 ExpectPluginType(PluginUMAReporter::UNSUPPORTED_MIMETYPE
,
41 "some-prefix-application/x-silverlight",
45 TEST_F(PluginUMATest
, RealPlayer
) {
47 PluginUMAReporter::REALPLAYER
, "audio/x-pn-realaudio", GURL("some url"));
48 ExpectPluginType(PluginUMAReporter::REALPLAYER
,
49 "audio/x-pn-realaudio-some-sufix",
51 ExpectPluginType(PluginUMAReporter::UNSUPPORTED_MIMETYPE
,
52 "some-prefix-audio/x-pn-realaudio",
56 TEST_F(PluginUMATest
, Java
) {
58 PluginUMAReporter::JAVA
, "application/x-java-applet", GURL("some url"));
59 ExpectPluginType(PluginUMAReporter::JAVA
,
60 "application/x-java-applet-some-sufix",
62 ExpectPluginType(PluginUMAReporter::JAVA
,
63 "some-prefix-application/x-java-applet-sufix",
67 TEST_F(PluginUMATest
, QuickTime
) {
69 PluginUMAReporter::QUICKTIME
, "video/quicktime", GURL("some url"));
70 ExpectPluginType(PluginUMAReporter::UNSUPPORTED_MIMETYPE
,
71 "video/quicktime-sufix",
73 ExpectPluginType(PluginUMAReporter::UNSUPPORTED_MIMETYPE
,
74 "prefix-video/quicktime",
78 TEST_F(PluginUMATest
, BrowserPlugin
) {
79 ExpectPluginType(PluginUMAReporter::BROWSER_PLUGIN
,
80 "application/browser-plugin",
82 ExpectPluginType(PluginUMAReporter::UNSUPPORTED_MIMETYPE
,
83 "application/browser-plugin-sufix",
85 ExpectPluginType(PluginUMAReporter::UNSUPPORTED_MIMETYPE
,
86 "prefix-application/browser-plugin",
90 TEST_F(PluginUMATest
, ShockwaveFlash
) {
91 ExpectPluginType(PluginUMAReporter::SHOCKWAVE_FLASH
,
92 "application/x-shockwave-flash",
94 ExpectPluginType(PluginUMAReporter::SHOCKWAVE_FLASH
,
95 "application/futuresplash",
97 ExpectPluginType(PluginUMAReporter::UNSUPPORTED_MIMETYPE
,
98 "application/x-futuresplash",
100 ExpectPluginType(PluginUMAReporter::UNSUPPORTED_MIMETYPE
,
101 "application/shockwave-flash",
105 TEST_F(PluginUMATest
, WidevineCdm
) {
106 #if defined(ENABLE_PEPPER_CDMS)
107 ExpectPluginType(PluginUMAReporter::WIDEVINE_CDM
,
109 ExpectPluginType(PluginUMAReporter::UNSUPPORTED_MIMETYPE
,
111 "application/x-ppapi-widevine-cdm",
113 ExpectPluginType(PluginUMAReporter::UNSUPPORTED_MIMETYPE
,
114 "application/x-ppapi-widevine-cdm-sufix",
116 ExpectPluginType(PluginUMAReporter::UNSUPPORTED_MIMETYPE
,
117 "prefix-application/x-ppapi-widevine-cdm",
121 TEST_F(PluginUMATest
, BySrcExtension
) {
123 PluginUMAReporter::QUICKTIME
, std::string(), GURL("file://file.mov"));
125 // When plugin's mime type is given, we don't check extension.
126 ExpectPluginType(PluginUMAReporter::UNSUPPORTED_MIMETYPE
,
128 GURL("http://file.mov"));
130 ExpectPluginType(PluginUMAReporter::WINDOWS_MEDIA_PLAYER
,
132 GURL("file://file.asx"));
134 PluginUMAReporter::REALPLAYER
, std::string(), GURL("file://file.rm"));
135 ExpectPluginType(PluginUMAReporter::QUICKTIME
,
137 GURL("http://aaa/file.mov?x=aaaa&y=b#c"));
138 ExpectPluginType(PluginUMAReporter::QUICKTIME
,
140 GURL("http://file.mov?x=aaaa&y=b#c"));
141 ExpectPluginType(PluginUMAReporter::SHOCKWAVE_FLASH
,
143 GURL("http://file.swf?x=aaaa&y=b#c"));
144 ExpectPluginType(PluginUMAReporter::SHOCKWAVE_FLASH
,
146 GURL("http://file.spl?x=aaaa&y=b#c"));
148 ExpectPluginType(PluginUMAReporter::UNSUPPORTED_EXTENSION
,
150 GURL("http://file.unknown_extension"));
152 PluginUMAReporter::UNSUPPORTED_EXTENSION
, std::string(), GURL("http://"));
154 PluginUMAReporter::UNSUPPORTED_EXTENSION
, std::string(), GURL("mov"));
157 TEST_F(PluginUMATest
, CaseSensitivity
) {
159 PluginUMAReporter::QUICKTIME
, "video/QUICKTIME", GURL("http://file.aaa"));
161 PluginUMAReporter::QUICKTIME
, std::string(), GURL("http://file.MoV"));