Chromium Code Reviews| 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> | 5 #include <gmock/gmock.h> |
| 6 #include <gtest/gtest.h> | 6 #include <gtest/gtest.h> |
| 7 | 7 |
| 8 #include "chrome/renderer/plugins/plugin_uma.h" | 8 #include "chrome/renderer/plugins/plugin_uma.h" |
| 9 | 9 |
| 10 using ::testing::_; | 10 using ::testing::_; |
| 11 | 11 |
| 12 class MockPluginUMASender : public MissingPluginReporter::UMASender { | 12 class MockPluginUMASender : public PluginUMAReporter::UMASender { |
| 13 public: | 13 public: |
| 14 MOCK_METHOD1(SendPluginUMA, void(MissingPluginReporter::PluginType)); | 14 MOCK_METHOD2(SendPluginUMA, void(PluginUMAReporter::ReportType, |
| 15 PluginUMAReporter::PluginType)); | |
| 15 }; | 16 }; |
| 16 | 17 |
| 17 TEST(PluginUMATest, WindowsMediaPlayer) { | 18 class PluginUMATest : public testing::Test { |
| 18 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | 19 public: |
| 19 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | 20 PluginUMATest() : sender_mock_(new MockPluginUMASender()) { |
| 20 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | 21 PluginUMAReporter::GetInstance()->SetUMASender(sender_mock_); |
| 21 .Times(0); | 22 EXPECT_CALL(*sender_mock_, SendPluginUMA(_, _)) |
| 23 .Times(0); | |
| 24 } | |
| 22 | 25 |
| 23 EXPECT_CALL(*sender_mock, | 26 void ExpectUMAReport(PluginUMAReporter::PluginType plugin_type, |
| 24 SendPluginUMA(MissingPluginReporter::WINDOWS_MEDIA_PLAYER)) | 27 const std::string& plugin_mime_type, |
| 25 .Times(1) | 28 const GURL& plugin_src) { |
| 26 .RetiresOnSaturation(); | 29 EXPECT_CALL(*sender_mock_, SendPluginUMA(PluginUMAReporter::MISSING_PLUGIN, |
| 27 MissingPluginReporter::GetInstance()->ReportPluginMissing( | 30 plugin_type)) |
| 28 "application/x-mplayer2", | 31 .Times(1) |
| 29 GURL("file://some_file.mov")); | 32 .RetiresOnSaturation(); |
| 33 PluginUMAReporter::GetInstance()->ReportPluginMissing( | |
| 34 plugin_mime_type, plugin_src); | |
| 30 | 35 |
| 31 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::OTHER)) | 36 EXPECT_CALL(*sender_mock_, SendPluginUMA(PluginUMAReporter::DISABLED_PLUGIN, |
|
xhwang
2013/04/03 18:50:45
DISABLED_PLUGIN is tested here!
| |
| 32 .Times(1) | 37 plugin_type)) |
| 33 .RetiresOnSaturation(); | 38 .Times(1) |
| 34 MissingPluginReporter::GetInstance()->ReportPluginMissing( | 39 .RetiresOnSaturation(); |
| 35 "application/x-mplayer2-some_sufix", | 40 PluginUMAReporter::GetInstance()->ReportPluginDisabled( |
| 36 GURL("file://some_file.mov")); | 41 plugin_mime_type, plugin_src); |
| 42 } | |
| 37 | 43 |
| 38 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::OTHER)) | 44 private: |
| 39 .Times(1) | 45 MockPluginUMASender* sender_mock_; |
| 40 .RetiresOnSaturation(); | 46 }; |
| 41 MissingPluginReporter::GetInstance()->ReportPluginMissing( | 47 |
| 42 "some-prefix-application/x-mplayer2", | 48 TEST_F(PluginUMATest, WindowsMediaPlayer) { |
| 43 GURL("file://some_file.mov")); | 49 ExpectUMAReport(PluginUMAReporter::WINDOWS_MEDIA_PLAYER, |
|
Bernhard Bauer
2013/04/03 19:08:42
Thanks for this cleanup! We could probably go a bi
xhwang
2013/04/04 17:28:38
Done.
| |
| 50 "application/x-mplayer2", | |
| 51 GURL("file://some_file.mov")); | |
| 52 ExpectUMAReport(PluginUMAReporter::OTHER, | |
| 53 "application/x-mplayer2-some_sufix", | |
| 54 GURL("file://some_file.mov")); | |
| 55 ExpectUMAReport(PluginUMAReporter::OTHER, | |
| 56 "some-prefix-application/x-mplayer2", | |
| 57 GURL("file://some_file.mov")); | |
| 44 } | 58 } |
| 45 | 59 |
| 46 TEST(PluginUMATest, Silverlight) { | 60 TEST_F(PluginUMATest, Silverlight) { |
| 47 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | 61 ExpectUMAReport(PluginUMAReporter::SILVERLIGHT, |
| 48 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | 62 "application/x-silverlight", |
| 49 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | 63 GURL("aaaa")); |
| 50 .Times(0); | 64 ExpectUMAReport(PluginUMAReporter::SILVERLIGHT, |
| 51 | 65 "application/x-silverlight-some-sufix", |
| 52 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::SILVERLIGHT)) | 66 GURL("aaaa")); |
| 53 .Times(1) | 67 ExpectUMAReport(PluginUMAReporter::OTHER, |
| 54 .RetiresOnSaturation(); | 68 "some-prefix-application/x-silverlight", |
| 55 MissingPluginReporter::GetInstance()->ReportPluginMissing( | 69 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 } | 70 } |
| 73 | 71 |
| 74 TEST(PluginUMATest, RealPlayer) { | 72 TEST_F(PluginUMATest, RealPlayer) { |
| 75 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | 73 ExpectUMAReport(PluginUMAReporter::REALPLAYER, |
| 76 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | 74 "audio/x-pn-realaudio", |
| 77 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | 75 GURL("some url")); |
| 78 .Times(0); | 76 ExpectUMAReport(PluginUMAReporter::REALPLAYER, |
| 79 | 77 "audio/x-pn-realaudio-some-sufix", |
| 80 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::REALPLAYER)) | 78 GURL("some url")); |
| 81 .Times(1) | 79 ExpectUMAReport(PluginUMAReporter::OTHER, |
| 82 .RetiresOnSaturation(); | 80 "some-prefix-audio/x-pn-realaudio", |
| 83 MissingPluginReporter::GetInstance()->ReportPluginMissing( | 81 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 } | 82 } |
| 101 | 83 |
| 102 TEST(PluginUMATest, Java) { | 84 TEST_F(PluginUMATest, Java) { |
| 103 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | 85 ExpectUMAReport(PluginUMAReporter::JAVA, |
| 104 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | 86 "application/x-java-applet", |
| 105 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | 87 GURL("some url")); |
| 106 .Times(0); | 88 ExpectUMAReport(PluginUMAReporter::JAVA, |
| 107 | 89 "application/x-java-applet-some-sufix", |
| 108 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::JAVA)) | 90 GURL("some url")); |
| 109 .Times(1) | 91 ExpectUMAReport(PluginUMAReporter::JAVA, |
| 110 .RetiresOnSaturation(); | 92 "some-prefix-application/x-java-applet-sufix", |
| 111 MissingPluginReporter::GetInstance()->ReportPluginMissing( | 93 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 } | 94 } |
| 129 | 95 |
| 130 TEST(PluginUMATest, QuickTime) { | 96 TEST_F(PluginUMATest, QuickTime) { |
| 131 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | 97 ExpectUMAReport(PluginUMAReporter::QUICKTIME, |
| 132 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | 98 "video/quicktime", |
| 133 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | 99 GURL("some url")); |
| 134 .Times(0); | 100 ExpectUMAReport(PluginUMAReporter::OTHER, |
| 135 | 101 "video/quicktime-sufix", |
| 136 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::QUICKTIME)) | 102 GURL("some url")); |
| 137 .Times(1) | 103 ExpectUMAReport(PluginUMAReporter::OTHER, |
| 138 .RetiresOnSaturation(); | 104 "prefix-video/quicktime", |
| 139 MissingPluginReporter::GetInstance()->ReportPluginMissing( | 105 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 } | 106 } |
| 157 | 107 |
| 158 TEST(PluginUMATest, BySrcExtension) { | 108 TEST_F(PluginUMATest, BySrcExtension) { |
| 159 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | 109 ExpectUMAReport(PluginUMAReporter::QUICKTIME, |
| 160 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | 110 "", |
| 161 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | 111 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 | 112 |
| 171 // When plugin's mime type is given, we don't check extension. | 113 // When plugin's mime type is given, we don't check extension. |
| 172 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::OTHER)) | 114 ExpectUMAReport(PluginUMAReporter::OTHER, |
| 173 .Times(1) | 115 "unknown-plugin", |
| 174 .RetiresOnSaturation(); | 116 GURL("http://file.mov")); |
| 175 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
| 176 "unknown-plugin", | |
| 177 GURL("http://file.mov")); | |
| 178 | 117 |
| 179 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::OTHER)) | 118 ExpectUMAReport(PluginUMAReporter::OTHER, |
| 180 .Times(1) | 119 "", |
| 181 .RetiresOnSaturation(); | 120 GURL("http://file.unknown_extension")); |
| 182 MissingPluginReporter::GetInstance()->ReportPluginMissing( | 121 ExpectUMAReport(PluginUMAReporter::QUICKTIME, |
| 183 "", | 122 "", |
| 184 GURL("http://file.unknown_extension")); | 123 GURL("http://aaa/file.mov?x=aaaa&y=b#c")); |
| 185 | 124 ExpectUMAReport(PluginUMAReporter::QUICKTIME, |
| 186 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::QUICKTIME)) | 125 "", |
| 187 .Times(1) | 126 GURL("http://file.mov?x=aaaa&y=b#c")); |
| 188 .RetiresOnSaturation(); | 127 ExpectUMAReport(PluginUMAReporter::OTHER, |
| 189 MissingPluginReporter::GetInstance()->ReportPluginMissing( | 128 "", |
| 190 "", | 129 GURL("http://")); |
| 191 GURL("http://aaa/file.mov?x=aaaa&y=b#c")); | 130 ExpectUMAReport(PluginUMAReporter::OTHER, |
| 192 | 131 "", |
| 193 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::QUICKTIME)) | 132 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 } | 133 } |
| 214 | 134 |
| 215 TEST(PluginUMATest, CaseSensitivity) { | 135 TEST_F(PluginUMATest, CaseSensitivity) { |
| 216 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | 136 ExpectUMAReport(PluginUMAReporter::QUICKTIME, |
| 217 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | 137 "video/QUICKTIME", |
| 218 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | 138 GURL("http://file.aaa")); |
| 219 .Times(0); | 139 ExpectUMAReport(PluginUMAReporter::QUICKTIME, |
| 220 | 140 "", |
| 221 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::QUICKTIME)) | 141 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 } | 142 } |
| 235 | |
| OLD | NEW |