Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
|
ddorwin
2013/04/04 19:09:50
same
xhwang
2013/04/04 23:10:33
Done.
| |
| 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 void ExpectPluginType(PluginUMAReporter::PluginType expected_plugin_type, |
|
Bernhard Bauer
2013/04/04 21:14:31
This should be in an anonymous namespace.
Of cour
xhwang
2013/04/04 23:10:33
Done.
| |
| 11 | 10 const std::string& plugin_mime_type, |
| 12 class MockPluginUMASender : public MissingPluginReporter::UMASender { | 11 const GURL& plugin_src) { |
| 13 public: | 12 EXPECT_EQ(expected_plugin_type, |
| 14 MOCK_METHOD1(SendPluginUMA, void(MissingPluginReporter::PluginType)); | 13 PluginUMAReporter::GetInstance()->GetPluginType(plugin_mime_type, |
| 15 }; | 14 plugin_src)); |
| 15 } | |
| 16 | 16 |
| 17 TEST(PluginUMATest, WindowsMediaPlayer) { | 17 TEST(PluginUMATest, WindowsMediaPlayer) { |
| 18 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | 18 ExpectPluginType(PluginUMAReporter::WINDOWS_MEDIA_PLAYER, |
| 19 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | 19 "application/x-mplayer2", |
| 20 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | 20 GURL("file://some_file.mov")); |
| 21 .Times(0); | 21 ExpectPluginType(PluginUMAReporter::OTHER, |
| 22 | 22 "application/x-mplayer2-some_sufix", |
| 23 EXPECT_CALL(*sender_mock, | 23 GURL("file://some_file.mov")); |
| 24 SendPluginUMA(MissingPluginReporter::WINDOWS_MEDIA_PLAYER)) | 24 ExpectPluginType(PluginUMAReporter::OTHER, |
| 25 .Times(1) | 25 "some-prefix-application/x-mplayer2", |
| 26 .RetiresOnSaturation(); | 26 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 } | 27 } |
| 45 | 28 |
| 46 TEST(PluginUMATest, Silverlight) { | 29 TEST(PluginUMATest, Silverlight) { |
| 47 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | 30 ExpectPluginType(PluginUMAReporter::SILVERLIGHT, |
| 48 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | 31 "application/x-silverlight", |
| 49 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | 32 GURL("aaaa")); |
| 50 .Times(0); | 33 ExpectPluginType(PluginUMAReporter::SILVERLIGHT, |
| 51 | 34 "application/x-silverlight-some-sufix", |
| 52 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::SILVERLIGHT)) | 35 GURL("aaaa")); |
| 53 .Times(1) | 36 ExpectPluginType(PluginUMAReporter::OTHER, |
| 54 .RetiresOnSaturation(); | 37 "some-prefix-application/x-silverlight", |
| 55 MissingPluginReporter::GetInstance()->ReportPluginMissing( | 38 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 } | 39 } |
| 73 | 40 |
| 74 TEST(PluginUMATest, RealPlayer) { | 41 TEST(PluginUMATest, RealPlayer) { |
| 75 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | 42 ExpectPluginType(PluginUMAReporter::REALPLAYER, |
| 76 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | 43 "audio/x-pn-realaudio", |
| 77 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | 44 GURL("some url")); |
| 78 .Times(0); | 45 ExpectPluginType(PluginUMAReporter::REALPLAYER, |
| 79 | 46 "audio/x-pn-realaudio-some-sufix", |
| 80 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::REALPLAYER)) | 47 GURL("some url")); |
| 81 .Times(1) | 48 ExpectPluginType(PluginUMAReporter::OTHER, |
| 82 .RetiresOnSaturation(); | 49 "some-prefix-audio/x-pn-realaudio", |
| 83 MissingPluginReporter::GetInstance()->ReportPluginMissing( | 50 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 } | 51 } |
| 101 | 52 |
| 102 TEST(PluginUMATest, Java) { | 53 TEST(PluginUMATest, Java) { |
| 103 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | 54 ExpectPluginType(PluginUMAReporter::JAVA, |
| 104 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | 55 "application/x-java-applet", |
| 105 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | 56 GURL("some url")); |
| 106 .Times(0); | 57 ExpectPluginType(PluginUMAReporter::JAVA, |
| 107 | 58 "application/x-java-applet-some-sufix", |
| 108 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::JAVA)) | 59 GURL("some url")); |
| 109 .Times(1) | 60 ExpectPluginType(PluginUMAReporter::JAVA, |
| 110 .RetiresOnSaturation(); | 61 "some-prefix-application/x-java-applet-sufix", |
| 111 MissingPluginReporter::GetInstance()->ReportPluginMissing( | 62 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 } | 63 } |
| 129 | 64 |
| 130 TEST(PluginUMATest, QuickTime) { | 65 TEST(PluginUMATest, QuickTime) { |
| 131 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | 66 ExpectPluginType(PluginUMAReporter::QUICKTIME, |
| 132 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | 67 "video/quicktime", |
| 133 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | 68 GURL("some url")); |
| 134 .Times(0); | 69 ExpectPluginType(PluginUMAReporter::OTHER, |
| 135 | 70 "video/quicktime-sufix", |
| 136 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::QUICKTIME)) | 71 GURL("some url")); |
| 137 .Times(1) | 72 ExpectPluginType(PluginUMAReporter::OTHER, |
| 138 .RetiresOnSaturation(); | 73 "prefix-video/quicktime", |
| 139 MissingPluginReporter::GetInstance()->ReportPluginMissing( | 74 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 } | 75 } |
| 157 | 76 |
| 158 TEST(PluginUMATest, BySrcExtension) { | 77 TEST(PluginUMATest, BySrcExtension) { |
| 159 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | 78 ExpectPluginType(PluginUMAReporter::QUICKTIME, |
| 160 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | 79 "", |
| 161 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | 80 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 | 81 |
| 171 // When plugin's mime type is given, we don't check extension. | 82 // When plugin's mime type is given, we don't check extension. |
| 172 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::OTHER)) | 83 ExpectPluginType(PluginUMAReporter::OTHER, |
| 173 .Times(1) | 84 "unknown-plugin", |
| 174 .RetiresOnSaturation(); | 85 GURL("http://file.mov")); |
| 175 MissingPluginReporter::GetInstance()->ReportPluginMissing( | |
| 176 "unknown-plugin", | |
| 177 GURL("http://file.mov")); | |
| 178 | 86 |
| 179 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::OTHER)) | 87 ExpectPluginType(PluginUMAReporter::OTHER, |
| 180 .Times(1) | 88 "", |
| 181 .RetiresOnSaturation(); | 89 GURL("http://file.unknown_extension")); |
| 182 MissingPluginReporter::GetInstance()->ReportPluginMissing( | 90 ExpectPluginType(PluginUMAReporter::QUICKTIME, |
| 183 "", | 91 "", |
| 184 GURL("http://file.unknown_extension")); | 92 GURL("http://aaa/file.mov?x=aaaa&y=b#c")); |
| 185 | 93 ExpectPluginType(PluginUMAReporter::QUICKTIME, |
| 186 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::QUICKTIME)) | 94 "", |
| 187 .Times(1) | 95 GURL("http://file.mov?x=aaaa&y=b#c")); |
| 188 .RetiresOnSaturation(); | 96 ExpectPluginType(PluginUMAReporter::OTHER, |
| 189 MissingPluginReporter::GetInstance()->ReportPluginMissing( | 97 "", |
| 190 "", | 98 GURL("http://")); |
| 191 GURL("http://aaa/file.mov?x=aaaa&y=b#c")); | 99 ExpectPluginType(PluginUMAReporter::OTHER, |
| 192 | 100 "", |
| 193 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::QUICKTIME)) | 101 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 } | 102 } |
| 214 | 103 |
| 215 TEST(PluginUMATest, CaseSensitivity) { | 104 TEST(PluginUMATest, CaseSensitivity) { |
| 216 MockPluginUMASender* sender_mock = new MockPluginUMASender(); | 105 ExpectPluginType(PluginUMAReporter::QUICKTIME, |
| 217 MissingPluginReporter::GetInstance()->SetUMASender(sender_mock); | 106 "video/QUICKTIME", |
| 218 EXPECT_CALL(*sender_mock, SendPluginUMA(_)) | 107 GURL("http://file.aaa")); |
| 219 .Times(0); | 108 ExpectPluginType(PluginUMAReporter::QUICKTIME, |
| 220 | 109 "", |
| 221 EXPECT_CALL(*sender_mock, SendPluginUMA(MissingPluginReporter::QUICKTIME)) | 110 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 } | 111 } |
| 235 | |
| OLD | NEW |