Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: extensions/common/permissions/usb_device_permission_unittest.cc

Issue 2601803003: Introduce kiosk.autolaunched feature session type (Closed)
Patch Set: . Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 <memory> 5 #include <memory>
6 6
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "device/usb/mock_usb_device.h" 8 #include "device/usb/mock_usb_device.h"
9 #include "device/usb/usb_descriptors.h" 9 #include "device/usb/usb_descriptors.h"
10 #include "extensions/common/extension_builder.h" 10 #include "extensions/common/extension_builder.h"
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 std::unique_ptr<UsbDevicePermission::CheckParam> param = 178 std::unique_ptr<UsbDevicePermission::CheckParam> param =
179 UsbDevicePermission::CheckParam::ForDeviceWithAnyInterfaceClass( 179 UsbDevicePermission::CheckParam::ForDeviceWithAnyInterfaceClass(
180 app.get(), 0x02ad, 0x138c, 180 app.get(), 0x02ad, 0x138c,
181 UsbDevicePermissionData::SPECIAL_VALUE_UNSPECIFIED); 181 UsbDevicePermissionData::SPECIAL_VALUE_UNSPECIFIED);
182 182
183 // Interface class permission should be ignored when not in kiosk session. 183 // Interface class permission should be ignored when not in kiosk session.
184 EXPECT_FALSE(permission_data.Check(param.get())); 184 EXPECT_FALSE(permission_data.Check(param.get()));
185 } 185 }
186 186
187 { 187 {
188 std::unique_ptr<base::AutoReset<FeatureSessionType>> scoped_session_type_( 188 std::unique_ptr<base::AutoReset<FeatureSessionType>> scoped_session_type(
189 ScopedCurrentFeatureSessionType(FeatureSessionType::KIOSK)); 189 ScopedCurrentFeatureSessionType(FeatureSessionType::KIOSK));
190 ScopedCurrentChannel channel(version_info::Channel::DEV); 190 ScopedCurrentChannel channel(version_info::Channel::DEV);
191 191
192 std::unique_ptr<UsbDevicePermission::CheckParam> param = 192 std::unique_ptr<UsbDevicePermission::CheckParam> param =
193 UsbDevicePermission::CheckParam::ForDeviceWithAnyInterfaceClass( 193 UsbDevicePermission::CheckParam::ForDeviceWithAnyInterfaceClass(
194 app.get(), 0x02ad, 0x138c, 194 app.get(), 0x02ad, 0x138c,
195 UsbDevicePermissionData::SPECIAL_VALUE_UNSPECIFIED); 195 UsbDevicePermissionData::SPECIAL_VALUE_UNSPECIFIED);
196 196
197 // |ForDeviceWithAnyInterfaceClass| creates check param that matches any 197 // |ForDeviceWithAnyInterfaceClass| creates check param that matches any
198 // interfaceClass permission property - needed in cases where set of 198 // interfaceClass permission property - needed in cases where set of
(...skipping 19 matching lines...) Expand all
218 { 218 {
219 std::unique_ptr<UsbDevicePermission::CheckParam> param = 219 std::unique_ptr<UsbDevicePermission::CheckParam> param =
220 UsbDevicePermission::CheckParam::ForDeviceWithAnyInterfaceClass( 220 UsbDevicePermission::CheckParam::ForDeviceWithAnyInterfaceClass(
221 app.get(), 0x02ad, 0x138c, 221 app.get(), 0x02ad, 0x138c,
222 UsbDevicePermissionData::SPECIAL_VALUE_UNSPECIFIED); 222 UsbDevicePermissionData::SPECIAL_VALUE_UNSPECIFIED);
223 223
224 EXPECT_FALSE(permission_data.Check(param.get())); 224 EXPECT_FALSE(permission_data.Check(param.get()));
225 } 225 }
226 226
227 { 227 {
228 std::unique_ptr<base::AutoReset<FeatureSessionType>> scoped_session_type_( 228 std::unique_ptr<base::AutoReset<FeatureSessionType>> scoped_session_type(
229 ScopedCurrentFeatureSessionType(FeatureSessionType::KIOSK)); 229 ScopedCurrentFeatureSessionType(FeatureSessionType::KIOSK));
230 ScopedCurrentChannel channel(version_info::Channel::DEV); 230 ScopedCurrentChannel channel(version_info::Channel::DEV);
231 231
232 std::unique_ptr<UsbDevicePermission::CheckParam> param = 232 std::unique_ptr<UsbDevicePermission::CheckParam> param =
233 UsbDevicePermission::CheckParam::ForDeviceWithAnyInterfaceClass( 233 UsbDevicePermission::CheckParam::ForDeviceWithAnyInterfaceClass(
234 app.get(), 0x02ad, 0x138c, 234 app.get(), 0x02ad, 0x138c,
235 UsbDevicePermissionData::SPECIAL_VALUE_UNSPECIFIED); 235 UsbDevicePermissionData::SPECIAL_VALUE_UNSPECIFIED);
236 236
237 EXPECT_TRUE(permission_data.Check(param.get())); 237 EXPECT_TRUE(permission_data.Check(param.get()));
238 } 238 }
239 239
240 { 240 {
241 std::unique_ptr<base::AutoReset<FeatureSessionType>> scoped_session_type_( 241 std::unique_ptr<base::AutoReset<FeatureSessionType>> scoped_session_type(
242 ScopedCurrentFeatureSessionType(FeatureSessionType::KIOSK)); 242 ScopedCurrentFeatureSessionType(FeatureSessionType::KIOSK));
243 ScopedCurrentChannel channel(version_info::Channel::DEV); 243 ScopedCurrentChannel channel(version_info::Channel::DEV);
244 244
245 std::unique_ptr<UsbDevicePermission::CheckParam> param = 245 std::unique_ptr<UsbDevicePermission::CheckParam> param =
246 UsbDevicePermission::CheckParam::ForDeviceWithAnyInterfaceClass( 246 UsbDevicePermission::CheckParam::ForDeviceWithAnyInterfaceClass(
247 app.get(), 0x138c, 0x138c, 247 app.get(), 0x138c, 0x138c,
248 UsbDevicePermissionData::SPECIAL_VALUE_UNSPECIFIED); 248 UsbDevicePermissionData::SPECIAL_VALUE_UNSPECIFIED);
249 249
250 EXPECT_FALSE(permission_data.Check(param.get())); 250 EXPECT_FALSE(permission_data.Check(param.get()));
251 } 251 }
(...skipping 13 matching lines...) Expand all
265 265
266 { 266 {
267 std::unique_ptr<UsbDevicePermission::CheckParam> param = 267 std::unique_ptr<UsbDevicePermission::CheckParam> param =
268 UsbDevicePermission::CheckParam::ForHidDevice(app.get(), 0x02ad, 268 UsbDevicePermission::CheckParam::ForHidDevice(app.get(), 0x02ad,
269 0x138c); 269 0x138c);
270 270
271 EXPECT_FALSE(permission_data.Check(param.get())); 271 EXPECT_FALSE(permission_data.Check(param.get()));
272 } 272 }
273 273
274 { 274 {
275 std::unique_ptr<base::AutoReset<FeatureSessionType>> scoped_session_type_( 275 std::unique_ptr<base::AutoReset<FeatureSessionType>> scoped_session_type(
276 ScopedCurrentFeatureSessionType(FeatureSessionType::KIOSK)); 276 ScopedCurrentFeatureSessionType(FeatureSessionType::KIOSK));
277 ScopedCurrentChannel channel(version_info::Channel::DEV); 277 ScopedCurrentChannel channel(version_info::Channel::DEV);
278 278
279 std::unique_ptr<UsbDevicePermission::CheckParam> param = 279 std::unique_ptr<UsbDevicePermission::CheckParam> param =
280 UsbDevicePermission::CheckParam::ForHidDevice(app.get(), 0x02ad, 280 UsbDevicePermission::CheckParam::ForHidDevice(app.get(), 0x02ad,
281 0x138c); 281 0x138c);
282 282
283 EXPECT_TRUE(permission_data.Check(param.get())); 283 EXPECT_TRUE(permission_data.Check(param.get()));
284 } 284 }
285 285
286 { 286 {
287 std::unique_ptr<base::AutoReset<FeatureSessionType>> scoped_session_type_( 287 std::unique_ptr<base::AutoReset<FeatureSessionType>> scoped_session_type(
288 ScopedCurrentFeatureSessionType(FeatureSessionType::KIOSK)); 288 ScopedCurrentFeatureSessionType(FeatureSessionType::KIOSK));
289 ScopedCurrentChannel channel(version_info::Channel::DEV); 289 ScopedCurrentChannel channel(version_info::Channel::DEV);
290 290
291 std::unique_ptr<UsbDevicePermission::CheckParam> param = 291 std::unique_ptr<UsbDevicePermission::CheckParam> param =
292 UsbDevicePermission::CheckParam::ForHidDevice(app.get(), 0x138c, 292 UsbDevicePermission::CheckParam::ForHidDevice(app.get(), 0x138c,
293 0x138c); 293 0x138c);
294 294
295 EXPECT_FALSE(permission_data.Check(param.get())); 295 EXPECT_FALSE(permission_data.Check(param.get()));
296 } 296 }
297 } 297 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 { 368 {
369 scoped_refptr<device::MockUsbDevice> device = 369 scoped_refptr<device::MockUsbDevice> device =
370 CreateTestUsbDevice(0x02ad, 0x138c, 0x9, std::vector<uint8_t>()); 370 CreateTestUsbDevice(0x02ad, 0x138c, 0x9, std::vector<uint8_t>());
371 std::unique_ptr<UsbDevicePermission::CheckParam> param = 371 std::unique_ptr<UsbDevicePermission::CheckParam> param =
372 UsbDevicePermission::CheckParam::ForUsbDevice(app.get(), device.get()); 372 UsbDevicePermission::CheckParam::ForUsbDevice(app.get(), device.get());
373 373
374 EXPECT_FALSE(permission_data.Check(param.get())); 374 EXPECT_FALSE(permission_data.Check(param.get()));
375 } 375 }
376 376
377 { 377 {
378 std::unique_ptr<base::AutoReset<FeatureSessionType>> scoped_session_type_( 378 std::unique_ptr<base::AutoReset<FeatureSessionType>> scoped_session_type(
379 ScopedCurrentFeatureSessionType(FeatureSessionType::KIOSK)); 379 ScopedCurrentFeatureSessionType(FeatureSessionType::KIOSK));
380 ScopedCurrentChannel channel(version_info::Channel::DEV); 380 ScopedCurrentChannel channel(version_info::Channel::DEV);
381 381
382 scoped_refptr<device::MockUsbDevice> device = 382 scoped_refptr<device::MockUsbDevice> device =
383 CreateTestUsbDevice(0x02ad, 0x138c, 0x9, std::vector<uint8_t>()); 383 CreateTestUsbDevice(0x02ad, 0x138c, 0x9, std::vector<uint8_t>());
384 std::unique_ptr<UsbDevicePermission::CheckParam> param = 384 std::unique_ptr<UsbDevicePermission::CheckParam> param =
385 UsbDevicePermission::CheckParam::ForUsbDevice(app.get(), device.get()); 385 UsbDevicePermission::CheckParam::ForUsbDevice(app.get(), device.get());
386 386
387 EXPECT_TRUE(permission_data.Check(param.get())); 387 EXPECT_TRUE(permission_data.Check(param.get()));
388 } 388 }
389 { 389 {
390 std::unique_ptr<base::AutoReset<FeatureSessionType>> scoped_session_type_( 390 std::unique_ptr<base::AutoReset<FeatureSessionType>> scoped_session_type(
391 ScopedCurrentFeatureSessionType(FeatureSessionType::KIOSK)); 391 ScopedCurrentFeatureSessionType(FeatureSessionType::KIOSK));
392 ScopedCurrentChannel channel(version_info::Channel::DEV); 392 ScopedCurrentChannel channel(version_info::Channel::DEV);
393 393
394 scoped_refptr<device::MockUsbDevice> device = 394 scoped_refptr<device::MockUsbDevice> device =
395 CreateTestUsbDevice(0x02ad, 0x138c, 0x3, std::vector<uint8_t>()); 395 CreateTestUsbDevice(0x02ad, 0x138c, 0x3, std::vector<uint8_t>());
396 std::unique_ptr<UsbDevicePermission::CheckParam> param = 396 std::unique_ptr<UsbDevicePermission::CheckParam> param =
397 UsbDevicePermission::CheckParam::ForUsbDevice(app.get(), device.get()); 397 UsbDevicePermission::CheckParam::ForUsbDevice(app.get(), device.get());
398 398
399 EXPECT_FALSE(permission_data.Check(param.get())); 399 EXPECT_FALSE(permission_data.Check(param.get()));
400 } 400 }
401 } 401 }
402 402
403 TEST(USBDevicePermissionTest, IgnoreNullDeviceClass) { 403 TEST(USBDevicePermissionTest, IgnoreNullDeviceClass) {
404 std::unique_ptr<base::Value> permission_data_value = 404 std::unique_ptr<base::Value> permission_data_value =
405 DictionaryBuilder().Set("interfaceClass", 0).Build(); 405 DictionaryBuilder().Set("interfaceClass", 0).Build();
406 UsbDevicePermissionData permission_data; 406 UsbDevicePermissionData permission_data;
407 EXPECT_TRUE(permission_data.FromValue(permission_data_value.get())); 407 EXPECT_TRUE(permission_data.FromValue(permission_data_value.get()));
408 408
409 scoped_refptr<const Extension> app = 409 scoped_refptr<const Extension> app =
410 CreateTestApp(std::move(permission_data_value)); 410 CreateTestApp(std::move(permission_data_value));
411 411
412 { 412 {
413 std::unique_ptr<base::AutoReset<FeatureSessionType>> scoped_session_type_( 413 std::unique_ptr<base::AutoReset<FeatureSessionType>> scoped_session_type(
414 ScopedCurrentFeatureSessionType(FeatureSessionType::KIOSK)); 414 ScopedCurrentFeatureSessionType(FeatureSessionType::KIOSK));
415 ScopedCurrentChannel channel(version_info::Channel::DEV); 415 ScopedCurrentChannel channel(version_info::Channel::DEV);
416 416
417 scoped_refptr<device::MockUsbDevice> device = 417 scoped_refptr<device::MockUsbDevice> device =
418 CreateTestUsbDevice(0x02ad, 0x138c, 0, std::vector<uint8_t>()); 418 CreateTestUsbDevice(0x02ad, 0x138c, 0, std::vector<uint8_t>());
419 std::unique_ptr<UsbDevicePermission::CheckParam> param = 419 std::unique_ptr<UsbDevicePermission::CheckParam> param =
420 UsbDevicePermission::CheckParam::ForUsbDevice(app.get(), device.get()); 420 UsbDevicePermission::CheckParam::ForUsbDevice(app.get(), device.get());
421 421
422 EXPECT_FALSE(permission_data.Check(param.get())); 422 EXPECT_FALSE(permission_data.Check(param.get()));
423 } 423 }
(...skipping 13 matching lines...) Expand all
437 CreateTestUsbDevice(0x02ad, 0x138c, 0, {2, 3}); 437 CreateTestUsbDevice(0x02ad, 0x138c, 0, {2, 3});
438 std::unique_ptr<UsbDevicePermission::CheckParam> param = 438 std::unique_ptr<UsbDevicePermission::CheckParam> param =
439 UsbDevicePermission::CheckParam::ForUsbDevice(app.get(), device.get()); 439 UsbDevicePermission::CheckParam::ForUsbDevice(app.get(), device.get());
440 440
441 EXPECT_FALSE(permission_data.Check(param.get())); 441 EXPECT_FALSE(permission_data.Check(param.get()));
442 } 442 }
443 443
444 { 444 {
445 // Interface should match inactive configuration when none of configurations 445 // Interface should match inactive configuration when none of configurations
446 // is active. 446 // is active.
447 std::unique_ptr<base::AutoReset<FeatureSessionType>> scoped_session_type_( 447 std::unique_ptr<base::AutoReset<FeatureSessionType>> scoped_session_type(
448 ScopedCurrentFeatureSessionType(FeatureSessionType::KIOSK)); 448 ScopedCurrentFeatureSessionType(FeatureSessionType::KIOSK));
449 ScopedCurrentChannel channel(version_info::Channel::DEV); 449 ScopedCurrentChannel channel(version_info::Channel::DEV);
450 450
451 scoped_refptr<device::MockUsbDevice> device = 451 scoped_refptr<device::MockUsbDevice> device =
452 CreateTestUsbDevice(0x02ad, 0x138c, 0, {2, 3}); 452 CreateTestUsbDevice(0x02ad, 0x138c, 0, {2, 3});
453 std::unique_ptr<UsbDevicePermission::CheckParam> param = 453 std::unique_ptr<UsbDevicePermission::CheckParam> param =
454 UsbDevicePermission::CheckParam::ForUsbDevice(app.get(), device.get()); 454 UsbDevicePermission::CheckParam::ForUsbDevice(app.get(), device.get());
455 455
456 EXPECT_TRUE(permission_data.Check(param.get())); 456 EXPECT_TRUE(permission_data.Check(param.get()));
457 } 457 }
458 458
459 { 459 {
460 std::unique_ptr<base::AutoReset<FeatureSessionType>> scoped_session_type_( 460 std::unique_ptr<base::AutoReset<FeatureSessionType>> scoped_session_type(
461 ScopedCurrentFeatureSessionType(FeatureSessionType::KIOSK)); 461 ScopedCurrentFeatureSessionType(FeatureSessionType::KIOSK));
462 ScopedCurrentChannel channel(version_info::Channel::DEV); 462 ScopedCurrentChannel channel(version_info::Channel::DEV);
463 463
464 scoped_refptr<device::MockUsbDevice> device = 464 scoped_refptr<device::MockUsbDevice> device =
465 CreateTestUsbDevice(0x02ad, 0x138c, 0, {2, 3}); 465 CreateTestUsbDevice(0x02ad, 0x138c, 0, {2, 3});
466 device->ActiveConfigurationChanged(kUsbConfigWithInterfaces); 466 device->ActiveConfigurationChanged(kUsbConfigWithInterfaces);
467 std::unique_ptr<UsbDevicePermission::CheckParam> param = 467 std::unique_ptr<UsbDevicePermission::CheckParam> param =
468 UsbDevicePermission::CheckParam::ForUsbDevice(app.get(), device.get()); 468 UsbDevicePermission::CheckParam::ForUsbDevice(app.get(), device.get());
469 469
470 EXPECT_TRUE(permission_data.Check(param.get())); 470 EXPECT_TRUE(permission_data.Check(param.get()));
471 } 471 }
472 472
473 { 473 {
474 // Interface should match inactive configuration when another configuration 474 // Interface should match inactive configuration when another configuration
475 // is active. 475 // is active.
476 std::unique_ptr<base::AutoReset<FeatureSessionType>> scoped_session_type_( 476 std::unique_ptr<base::AutoReset<FeatureSessionType>> scoped_session_type(
477 ScopedCurrentFeatureSessionType(FeatureSessionType::KIOSK)); 477 ScopedCurrentFeatureSessionType(FeatureSessionType::KIOSK));
478 ScopedCurrentChannel channel(version_info::Channel::DEV); 478 ScopedCurrentChannel channel(version_info::Channel::DEV);
479 479
480 scoped_refptr<device::MockUsbDevice> device = 480 scoped_refptr<device::MockUsbDevice> device =
481 CreateTestUsbDevice(0x02ad, 0x138c, 0, {2, 3}); 481 CreateTestUsbDevice(0x02ad, 0x138c, 0, {2, 3});
482 device->ActiveConfigurationChanged(kUsbConfigWithoutInterfaces); 482 device->ActiveConfigurationChanged(kUsbConfigWithoutInterfaces);
483 std::unique_ptr<UsbDevicePermission::CheckParam> param = 483 std::unique_ptr<UsbDevicePermission::CheckParam> param =
484 UsbDevicePermission::CheckParam::ForUsbDevice(app.get(), device.get()); 484 UsbDevicePermission::CheckParam::ForUsbDevice(app.get(), device.get());
485 485
486 EXPECT_TRUE(permission_data.Check(param.get())); 486 EXPECT_TRUE(permission_data.Check(param.get()));
487 } 487 }
488 488
489 { 489 {
490 std::unique_ptr<base::AutoReset<FeatureSessionType>> scoped_session_type_( 490 std::unique_ptr<base::AutoReset<FeatureSessionType>> scoped_session_type(
491 ScopedCurrentFeatureSessionType(FeatureSessionType::KIOSK)); 491 ScopedCurrentFeatureSessionType(FeatureSessionType::KIOSK));
492 ScopedCurrentChannel channel(version_info::Channel::DEV); 492 ScopedCurrentChannel channel(version_info::Channel::DEV);
493 493
494 scoped_refptr<device::MockUsbDevice> device = 494 scoped_refptr<device::MockUsbDevice> device =
495 CreateTestUsbDevice(0x02ad, 0x138c, 0, {4, 5}); 495 CreateTestUsbDevice(0x02ad, 0x138c, 0, {4, 5});
496 std::unique_ptr<UsbDevicePermission::CheckParam> param = 496 std::unique_ptr<UsbDevicePermission::CheckParam> param =
497 UsbDevicePermission::CheckParam::ForUsbDevice(app.get(), device.get()); 497 UsbDevicePermission::CheckParam::ForUsbDevice(app.get(), device.get());
498 498
499 EXPECT_FALSE(permission_data.Check(param.get())); 499 EXPECT_FALSE(permission_data.Check(param.get()));
500 } 500 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 .Set("vendorId", 0x02ad) 588 .Set("vendorId", 0x02ad)
589 .Set("productId", 0x128c) 589 .Set("productId", 0x128c)
590 .Set("interfaceId", 3) 590 .Set("interfaceId", 3)
591 .Set("interfaceClass", 7) 591 .Set("interfaceClass", 7)
592 .Build(); 592 .Build();
593 UsbDevicePermissionData permission_data; 593 UsbDevicePermissionData permission_data;
594 ASSERT_FALSE(permission_data.FromValue(permission_data_value.get())); 594 ASSERT_FALSE(permission_data.FromValue(permission_data_value.get()));
595 } 595 }
596 596
597 } // namespace extensions 597 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/features/simple_feature_unittest.cc ('k') | tools/json_schema_compiler/feature_compiler.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698