| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <gmock/gmock.h> | |
| 6 #include <gtest/gtest.h> | 5 #include <gtest/gtest.h> |
| 7 | 6 |
| 8 #include "chrome/renderer/plugins/plugin_uma.h" | 7 #include "chrome/renderer/plugins/plugin_uma.h" |
| 9 | 8 |
| 10 using ::testing::_; | 9 class PluginUMATest : public testing::Test { |
| 11 | |
| 12 class MockPluginUMASender : public MissingPluginReporter::UMASender { | |
| 13 public: | 10 public: |
| 14 MOCK_METHOD1(SendPluginUMA, void(MissingPluginReporter::PluginType)); | 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 } |
| 15 }; | 19 }; |
| 16 | 20 |
| 17 TEST(PluginUMATest, WindowsMediaPlayer) { | 21 TEST_F(PluginUMATest, WindowsMediaPlayer) { |
| 18 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | 22 ExpectPluginType(PluginUMAReporter::WINDOWS_MEDIA_PLAYER, |
| 19 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | 23 "application/x-mplayer2", |
| 20 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | 24 GURL("file://some_file.mov")); |
| 21 .Times(0); | 25 ExpectPluginType(PluginUMAReporter::OTHER, |
| 22 | 26 "application/x-mplayer2-some_sufix", |
| 23 EXPECT_CALL(*sender_mock, | 27 GURL("file://some_file.mov")); |
| 24 SendPluginUMA(MissingPluginReporter::WINDOWS_MEDIA_PLAYER)) | 28 ExpectPluginType(PluginUMAReporter::OTHER, |
| 25 .Times(1) | 29 "some-prefix-application/x-mplayer2", |
| 26 .RetiresOnSaturation(); | 30 GURL("file://some_file.mov")); |
| 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 } | 31 } |
| 45 | 32 |
| 46 TEST(PluginUMATest, Silverlight) { | 33 TEST_F(PluginUMATest, Silverlight) { |
| 47 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | 34 ExpectPluginType(PluginUMAReporter::SILVERLIGHT, |
| 48 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | 35 "application/x-silverlight", |
| 49 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | 36 GURL("aaaa")); |
| 50 .Times(0); | 37 ExpectPluginType(PluginUMAReporter::SILVERLIGHT, |
| 51 | 38 "application/x-silverlight-some-sufix", |
| 52 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::SILVERLIGHT)) | 39 GURL("aaaa")); |
| 53 .Times(1) | 40 ExpectPluginType(PluginUMAReporter::OTHER, |
| 54 .RetiresOnSaturation(); | 41 "some-prefix-application/x-silverlight", |
| 55 MissingPluginReporter::GetInstance()->ReportPluginMissing( | 42 GURL("aaaa")); |
| 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 } | 43 } |
| 73 | 44 |
| 74 TEST(PluginUMATest, RealPlayer) { | 45 TEST_F(PluginUMATest, RealPlayer) { |
| 75 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | 46 ExpectPluginType(PluginUMAReporter::REALPLAYER, |
| 76 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | 47 "audio/x-pn-realaudio", |
| 77 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | 48 GURL("some url")); |
| 78 .Times(0); | 49 ExpectPluginType(PluginUMAReporter::REALPLAYER, |
| 79 | 50 "audio/x-pn-realaudio-some-sufix", |
| 80 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::REALPLAYER)) | 51 GURL("some url")); |
| 81 .Times(1) | 52 ExpectPluginType(PluginUMAReporter::OTHER, |
| 82 .RetiresOnSaturation(); | 53 "some-prefix-audio/x-pn-realaudio", |
| 83 MissingPluginReporter::GetInstance()->ReportPluginMissing( | 54 GURL("some url")); |
| 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 } | 55 } |
| 101 | 56 |
| 102 TEST(PluginUMATest, Java) { | 57 TEST_F(PluginUMATest, Java) { |
| 103 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | 58 ExpectPluginType(PluginUMAReporter::JAVA, |
| 104 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | 59 "application/x-java-applet", |
| 105 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | 60 GURL("some url")); |
| 106 .Times(0); | 61 ExpectPluginType(PluginUMAReporter::JAVA, |
| 107 | 62 "application/x-java-applet-some-sufix", |
| 108 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::JAVA)) | 63 GURL("some url")); |
| 109 .Times(1) | 64 ExpectPluginType(PluginUMAReporter::JAVA, |
| 110 .RetiresOnSaturation(); | 65 "some-prefix-application/x-java-applet-sufix", |
| 111 MissingPluginReporter::GetInstance()->ReportPluginMissing( | 66 GURL("some url")); |
| 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 } | 67 } |
| 129 | 68 |
| 130 TEST(PluginUMATest, QuickTime) { | 69 TEST_F(PluginUMATest, QuickTime) { |
| 131 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | 70 ExpectPluginType(PluginUMAReporter::QUICKTIME, |
| 132 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | 71 "video/quicktime", |
| 133 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | 72 GURL("some url")); |
| 134 .Times(0); | 73 ExpectPluginType(PluginUMAReporter::OTHER, |
| 135 | 74 "video/quicktime-sufix", |
| 136 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::QUICKTIME)) | 75 GURL("some url")); |
| 137 .Times(1) | 76 ExpectPluginType(PluginUMAReporter::OTHER, |
| 138 .RetiresOnSaturation(); | 77 "prefix-video/quicktime", |
| 139 MissingPluginReporter::GetInstance()->ReportPluginMissing( | 78 GURL("some url")); |
| 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 } | 79 } |
| 157 | 80 |
| 158 TEST(PluginUMATest, BySrcExtension) { | 81 TEST_F(PluginUMATest, BySrcExtension) { |
| 159 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | 82 ExpectPluginType(PluginUMAReporter::QUICKTIME, |
| 160 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | 83 "", |
| 161 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | 84 GURL("file://file.mov")); |
| 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 | 85 |
| 171 // When plugin's mime type is given, we don't check extension. | 86 // When plugin's mime type is given, we don't check extension. |
| 172 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::OTHER)) | 87 ExpectPluginType(PluginUMAReporter::OTHER, |
| 173 .Times(1) | 88 "unknown-plugin", |
| 174 .RetiresOnSaturation(); | 89 GURL("http://file.mov")); |
| 175 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
| 176 "unknown-plugin", | |
| 177 GURL("http://file.mov")); | |
| 178 | 90 |
| 179 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::OTHER)) | 91 ExpectPluginType(PluginUMAReporter::OTHER, |
| 180 .Times(1) | 92 "", |
| 181 .RetiresOnSaturation(); | 93 GURL("http://file.unknown_extension")); |
| 182 MissingPluginReporter::GetInstance()->ReportPluginMissing( | 94 ExpectPluginType(PluginUMAReporter::QUICKTIME, |
| 183 "", | 95 "", |
| 184 GURL("http://file.unknown_extension")); | 96 GURL("http://aaa/file.mov?x=aaaa&y=b#c")); |
| 185 | 97 ExpectPluginType(PluginUMAReporter::QUICKTIME, |
| 186 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::QUICKTIME)) | 98 "", |
| 187 .Times(1) | 99 GURL("http://file.mov?x=aaaa&y=b#c")); |
| 188 .RetiresOnSaturation(); | 100 ExpectPluginType(PluginUMAReporter::OTHER, |
| 189 MissingPluginReporter::GetInstance()->ReportPluginMissing( | 101 "", |
| 190 "", | 102 GURL("http://")); |
| 191 GURL("http://aaa/file.mov?x=aaaa&y=b#c")); | 103 ExpectPluginType(PluginUMAReporter::OTHER, |
| 192 | 104 "", |
| 193 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::QUICKTIME)) | 105 GURL("mov")); |
| 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 } | 106 } |
| 214 | 107 |
| 215 TEST(PluginUMATest, CaseSensitivity) { | 108 TEST_F(PluginUMATest, CaseSensitivity) { |
| 216 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | 109 ExpectPluginType(PluginUMAReporter::QUICKTIME, |
| 217 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | 110 "video/QUICKTIME", |
| 218 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | 111 GURL("http://file.aaa")); |
| 219 .Times(0); | 112 ExpectPluginType(PluginUMAReporter::QUICKTIME, |
| 220 | 113 "", |
| 221 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::QUICKTIME)) | 114 GURL("http://file.MoV")); |
| 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 } | 115 } |
| 235 | |
| OLD | NEW |