• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <gtest/gtest.h>
6 
7 #include "chrome/renderer/plugins/plugin_uma.h"
8 
9 class PluginUMATest : public testing::Test {
10  public:
ExpectPluginType(PluginUMAReporter::PluginType expected_plugin_type,const std::string & plugin_mime_type,const GURL & plugin_src)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,
17                                                               plugin_src));
18   }
19 };
20 
TEST_F(PluginUMATest,WindowsMediaPlayer)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"));
31 }
32 
TEST_F(PluginUMATest,Silverlight)33 TEST_F(PluginUMATest, Silverlight) {
34   ExpectPluginType(PluginUMAReporter::SILVERLIGHT,
35                    "application/x-silverlight",
36                    GURL("aaaa"));
37   ExpectPluginType(PluginUMAReporter::SILVERLIGHT,
38                    "application/x-silverlight-some-sufix",
39                    GURL("aaaa"));
40   ExpectPluginType(PluginUMAReporter::UNSUPPORTED_MIMETYPE,
41                    "some-prefix-application/x-silverlight",
42                    GURL("aaaa"));
43 }
44 
TEST_F(PluginUMATest,RealPlayer)45 TEST_F(PluginUMATest, RealPlayer) {
46   ExpectPluginType(
47       PluginUMAReporter::REALPLAYER, "audio/x-pn-realaudio", GURL("some url"));
48   ExpectPluginType(PluginUMAReporter::REALPLAYER,
49                    "audio/x-pn-realaudio-some-sufix",
50                    GURL("some url"));
51   ExpectPluginType(PluginUMAReporter::UNSUPPORTED_MIMETYPE,
52                    "some-prefix-audio/x-pn-realaudio",
53                    GURL("some url"));
54 }
55 
TEST_F(PluginUMATest,Java)56 TEST_F(PluginUMATest, Java) {
57   ExpectPluginType(
58       PluginUMAReporter::JAVA, "application/x-java-applet", GURL("some url"));
59   ExpectPluginType(PluginUMAReporter::JAVA,
60                    "application/x-java-applet-some-sufix",
61                    GURL("some url"));
62   ExpectPluginType(PluginUMAReporter::JAVA,
63                    "some-prefix-application/x-java-applet-sufix",
64                    GURL("some url"));
65 }
66 
TEST_F(PluginUMATest,QuickTime)67 TEST_F(PluginUMATest, QuickTime) {
68   ExpectPluginType(
69       PluginUMAReporter::QUICKTIME, "video/quicktime", GURL("some url"));
70   ExpectPluginType(PluginUMAReporter::UNSUPPORTED_MIMETYPE,
71                    "video/quicktime-sufix",
72                    GURL("some url"));
73   ExpectPluginType(PluginUMAReporter::UNSUPPORTED_MIMETYPE,
74                    "prefix-video/quicktime",
75                    GURL("some url"));
76 }
77 
TEST_F(PluginUMATest,BrowserPlugin)78 TEST_F(PluginUMATest, BrowserPlugin) {
79   ExpectPluginType(PluginUMAReporter::BROWSER_PLUGIN,
80                    "application/browser-plugin",
81                    GURL("some url"));
82   ExpectPluginType(PluginUMAReporter::UNSUPPORTED_MIMETYPE,
83                    "application/browser-plugin-sufix",
84                    GURL("some url"));
85   ExpectPluginType(PluginUMAReporter::UNSUPPORTED_MIMETYPE,
86                    "prefix-application/browser-plugin",
87                    GURL("some url"));
88 }
89 
TEST_F(PluginUMATest,ShockwaveFlash)90 TEST_F(PluginUMATest, ShockwaveFlash) {
91   ExpectPluginType(PluginUMAReporter::SHOCKWAVE_FLASH,
92                    "application/x-shockwave-flash",
93                    GURL("some url"));
94   ExpectPluginType(PluginUMAReporter::SHOCKWAVE_FLASH,
95                    "application/futuresplash",
96                    GURL("some url"));
97   ExpectPluginType(PluginUMAReporter::UNSUPPORTED_MIMETYPE,
98                    "application/x-futuresplash",
99                    GURL("some url"));
100   ExpectPluginType(PluginUMAReporter::UNSUPPORTED_MIMETYPE,
101                    "application/shockwave-flash",
102                    GURL("some url"));
103 }
104 
TEST_F(PluginUMATest,WidevineCdm)105 TEST_F(PluginUMATest, WidevineCdm) {
106 #if defined(ENABLE_PEPPER_CDMS)
107   ExpectPluginType(PluginUMAReporter::WIDEVINE_CDM,
108 #else
109   ExpectPluginType(PluginUMAReporter::UNSUPPORTED_MIMETYPE,
110 #endif
111                    "application/x-ppapi-widevine-cdm",
112                    GURL("some url"));
113   ExpectPluginType(PluginUMAReporter::UNSUPPORTED_MIMETYPE,
114                    "application/x-ppapi-widevine-cdm-sufix",
115                    GURL("some url"));
116   ExpectPluginType(PluginUMAReporter::UNSUPPORTED_MIMETYPE,
117                    "prefix-application/x-ppapi-widevine-cdm",
118                    GURL("some url"));
119 }
120 
TEST_F(PluginUMATest,BySrcExtension)121 TEST_F(PluginUMATest, BySrcExtension) {
122   ExpectPluginType(
123       PluginUMAReporter::QUICKTIME, std::string(), GURL("file://file.mov"));
124 
125   // When plugin's mime type is given, we don't check extension.
126   ExpectPluginType(PluginUMAReporter::UNSUPPORTED_MIMETYPE,
127                    "unknown-plugin",
128                    GURL("http://file.mov"));
129 
130   ExpectPluginType(PluginUMAReporter::WINDOWS_MEDIA_PLAYER,
131                    std::string(),
132                    GURL("file://file.asx"));
133   ExpectPluginType(
134       PluginUMAReporter::REALPLAYER, std::string(), GURL("file://file.rm"));
135   ExpectPluginType(PluginUMAReporter::QUICKTIME,
136                    std::string(),
137                    GURL("http://aaa/file.mov?x=aaaa&y=b#c"));
138   ExpectPluginType(PluginUMAReporter::QUICKTIME,
139                    std::string(),
140                    GURL("http://file.mov?x=aaaa&y=b#c"));
141   ExpectPluginType(PluginUMAReporter::SHOCKWAVE_FLASH,
142                    std::string(),
143                    GURL("http://file.swf?x=aaaa&y=b#c"));
144   ExpectPluginType(PluginUMAReporter::SHOCKWAVE_FLASH,
145                    std::string(),
146                    GURL("http://file.spl?x=aaaa&y=b#c"));
147 
148   ExpectPluginType(PluginUMAReporter::UNSUPPORTED_EXTENSION,
149                    std::string(),
150                    GURL("http://file.unknown_extension"));
151   ExpectPluginType(
152       PluginUMAReporter::UNSUPPORTED_EXTENSION, std::string(), GURL("http://"));
153   ExpectPluginType(
154       PluginUMAReporter::UNSUPPORTED_EXTENSION, std::string(), GURL("mov"));
155 }
156 
TEST_F(PluginUMATest,CaseSensitivity)157 TEST_F(PluginUMATest, CaseSensitivity) {
158   ExpectPluginType(
159       PluginUMAReporter::QUICKTIME, "video/QUICKTIME", GURL("http://file.aaa"));
160   ExpectPluginType(
161       PluginUMAReporter::QUICKTIME, std::string(), GURL("http://file.MoV"));
162 }
163