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

Side by Side Diff: chrome/browser/devtools/device/usb/android_usb_browsertest.cc

Issue 625113002: replace OVERRIDE and FINAL with override and final in chrome/browser/[a-i]* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix newly added OVERRIDEs Created 6 years, 2 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/devtools/device/devtools_android_bridge.h" 8 #include "chrome/browser/devtools/device/devtools_android_bridge.h"
9 #include "chrome/browser/devtools/device/usb/android_usb_device.h" 9 #include "chrome/browser/devtools/device/usb/android_usb_device.h"
10 #include "chrome/browser/devtools/device/usb/usb_device_provider.h" 10 #include "chrome/browser/devtools/device/usb/usb_device_provider.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 class MockUsbDevice; 107 class MockUsbDevice;
108 108
109 template <class T> 109 template <class T>
110 class MockUsbDeviceHandle : public UsbDeviceHandle { 110 class MockUsbDeviceHandle : public UsbDeviceHandle {
111 public: 111 public:
112 explicit MockUsbDeviceHandle(MockUsbDevice<T>* device) 112 explicit MockUsbDeviceHandle(MockUsbDevice<T>* device)
113 : device_(device), 113 : device_(device),
114 remaining_body_length_(0), 114 remaining_body_length_(0),
115 next_local_socket_(0) {} 115 next_local_socket_(0) {}
116 116
117 virtual scoped_refptr<UsbDevice> GetDevice() const OVERRIDE { 117 virtual scoped_refptr<UsbDevice> GetDevice() const override {
118 return device_; 118 return device_;
119 } 119 }
120 120
121 virtual void Close() OVERRIDE { device_ = NULL; } 121 virtual void Close() override { device_ = NULL; }
122 122
123 bool ClaimInterface(int interface_number) { 123 bool ClaimInterface(int interface_number) {
124 if (device_->claimed_interfaces_.find(interface_number) != 124 if (device_->claimed_interfaces_.find(interface_number) !=
125 device_->claimed_interfaces_.end()) 125 device_->claimed_interfaces_.end())
126 return false; 126 return false;
127 127
128 device_->claimed_interfaces_.insert(interface_number); 128 device_->claimed_interfaces_.insert(interface_number);
129 return true; 129 return true;
130 } 130 }
131 131
132 bool ReleaseInterface(int interface_number) { 132 bool ReleaseInterface(int interface_number) {
133 if (device_->claimed_interfaces_.find(interface_number) == 133 if (device_->claimed_interfaces_.find(interface_number) ==
134 device_->claimed_interfaces_.end()) 134 device_->claimed_interfaces_.end())
135 return false; 135 return false;
136 136
137 device_->claimed_interfaces_.erase(interface_number); 137 device_->claimed_interfaces_.erase(interface_number);
138 return true; 138 return true;
139 } 139 }
140 140
141 virtual bool SetInterfaceAlternateSetting(int interface_number, 141 virtual bool SetInterfaceAlternateSetting(int interface_number,
142 int alternate_setting) OVERRIDE { 142 int alternate_setting) override {
143 return true; 143 return true;
144 } 144 }
145 145
146 virtual bool ResetDevice() OVERRIDE { return true; } 146 virtual bool ResetDevice() override { return true; }
147 virtual bool GetStringDescriptor(uint8_t string_id, base::string16* content) { 147 virtual bool GetStringDescriptor(uint8_t string_id, base::string16* content) {
148 return false; 148 return false;
149 } 149 }
150 150
151 // Async IO. Can be called on any thread. 151 // Async IO. Can be called on any thread.
152 virtual void ControlTransfer(UsbEndpointDirection direction, 152 virtual void ControlTransfer(UsbEndpointDirection direction,
153 TransferRequestType request_type, 153 TransferRequestType request_type,
154 TransferRecipient recipient, 154 TransferRecipient recipient,
155 uint8 request, 155 uint8 request,
156 uint16 value, 156 uint16 value,
157 uint16 index, 157 uint16 index,
158 net::IOBuffer* buffer, 158 net::IOBuffer* buffer,
159 size_t length, 159 size_t length,
160 unsigned int timeout, 160 unsigned int timeout,
161 const UsbTransferCallback& callback) OVERRIDE {} 161 const UsbTransferCallback& callback) override {}
162 162
163 virtual void BulkTransfer(UsbEndpointDirection direction, 163 virtual void BulkTransfer(UsbEndpointDirection direction,
164 uint8 endpoint, 164 uint8 endpoint,
165 net::IOBuffer* buffer, 165 net::IOBuffer* buffer,
166 size_t length, 166 size_t length,
167 unsigned int timeout, 167 unsigned int timeout,
168 const UsbTransferCallback& callback) OVERRIDE { 168 const UsbTransferCallback& callback) override {
169 if (direction == device::USB_DIRECTION_OUTBOUND) { 169 if (direction == device::USB_DIRECTION_OUTBOUND) {
170 if (remaining_body_length_ == 0) { 170 if (remaining_body_length_ == 0) {
171 std::vector<uint32> header(6); 171 std::vector<uint32> header(6);
172 memcpy(&header[0], buffer->data(), length); 172 memcpy(&header[0], buffer->data(), length);
173 current_message_ = new AdbMessage(header[0], header[1], header[2], ""); 173 current_message_ = new AdbMessage(header[0], header[1], header[2], "");
174 remaining_body_length_ = header[3]; 174 remaining_body_length_ = header[3];
175 uint32 magic = header[5]; 175 uint32 magic = header[5];
176 if ((current_message_->command ^ 0xffffffff) != magic) { 176 if ((current_message_->command ^ 0xffffffff) != magic) {
177 DCHECK(false) << "Header checksum error"; 177 DCHECK(false) << "Header checksum error";
178 return; 178 return;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 device::USB_TRANSFER_COMPLETED, 289 device::USB_TRANSFER_COMPLETED,
290 query.buffer, 290 query.buffer,
291 query.size)); 291 query.size));
292 } 292 }
293 293
294 virtual void InterruptTransfer(UsbEndpointDirection direction, 294 virtual void InterruptTransfer(UsbEndpointDirection direction,
295 uint8 endpoint, 295 uint8 endpoint,
296 net::IOBuffer* buffer, 296 net::IOBuffer* buffer,
297 size_t length, 297 size_t length,
298 unsigned int timeout, 298 unsigned int timeout,
299 const UsbTransferCallback& callback) OVERRIDE { 299 const UsbTransferCallback& callback) override {
300 } 300 }
301 301
302 virtual void IsochronousTransfer( 302 virtual void IsochronousTransfer(
303 UsbEndpointDirection direction, 303 UsbEndpointDirection direction,
304 uint8 endpoint, 304 uint8 endpoint,
305 net::IOBuffer* buffer, 305 net::IOBuffer* buffer,
306 size_t length, 306 size_t length,
307 unsigned int packets, 307 unsigned int packets,
308 unsigned int packet_length, 308 unsigned int packet_length,
309 unsigned int timeout, 309 unsigned int timeout,
310 const UsbTransferCallback& callback) OVERRIDE {} 310 const UsbTransferCallback& callback) override {}
311 311
312 protected: 312 protected:
313 virtual ~MockUsbDeviceHandle() {} 313 virtual ~MockUsbDeviceHandle() {}
314 314
315 struct Query { 315 struct Query {
316 UsbTransferCallback callback; 316 UsbTransferCallback callback;
317 scoped_refptr<net::IOBuffer> buffer; 317 scoped_refptr<net::IOBuffer> buffer;
318 size_t size; 318 size_t size;
319 319
320 Query(UsbTransferCallback callback, 320 Query(UsbTransferCallback callback,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 interface_desc.alternate_setting = 0; 352 interface_desc.alternate_setting = 0;
353 interface_desc.interface_class = T::kClass; 353 interface_desc.interface_class = T::kClass;
354 interface_desc.interface_subclass = T::kSubclass; 354 interface_desc.interface_subclass = T::kSubclass;
355 interface_desc.interface_protocol = T::kProtocol; 355 interface_desc.interface_protocol = T::kProtocol;
356 interface_desc.endpoints.push_back(bulk_in); 356 interface_desc.endpoints.push_back(bulk_in);
357 interface_desc.endpoints.push_back(bulk_out); 357 interface_desc.endpoints.push_back(bulk_out);
358 358
359 config_desc_.interfaces.push_back(interface_desc); 359 config_desc_.interfaces.push_back(interface_desc);
360 } 360 }
361 361
362 virtual scoped_refptr<UsbDeviceHandle> Open() OVERRIDE { 362 virtual scoped_refptr<UsbDeviceHandle> Open() override {
363 return new MockUsbDeviceHandle<T>(this); 363 return new MockUsbDeviceHandle<T>(this);
364 } 364 }
365 365
366 virtual const UsbConfigDescriptor& GetConfiguration() OVERRIDE { 366 virtual const UsbConfigDescriptor& GetConfiguration() override {
367 return config_desc_; 367 return config_desc_;
368 } 368 }
369 369
370 virtual bool GetManufacturer(base::string16* manufacturer) OVERRIDE { 370 virtual bool GetManufacturer(base::string16* manufacturer) override {
371 *manufacturer = base::UTF8ToUTF16(kDeviceManufacturer); 371 *manufacturer = base::UTF8ToUTF16(kDeviceManufacturer);
372 return true; 372 return true;
373 } 373 }
374 374
375 virtual bool GetProduct(base::string16* product) OVERRIDE { 375 virtual bool GetProduct(base::string16* product) override {
376 *product = base::UTF8ToUTF16(kDeviceModel); 376 *product = base::UTF8ToUTF16(kDeviceModel);
377 return true; 377 return true;
378 } 378 }
379 379
380 virtual bool GetSerialNumber(base::string16* serial) OVERRIDE { 380 virtual bool GetSerialNumber(base::string16* serial) override {
381 *serial = base::UTF8ToUTF16(kDeviceSerial); 381 *serial = base::UTF8ToUTF16(kDeviceSerial);
382 return true; 382 return true;
383 } 383 }
384 384
385 virtual bool Close(scoped_refptr<UsbDeviceHandle> handle) OVERRIDE { 385 virtual bool Close(scoped_refptr<UsbDeviceHandle> handle) override {
386 return true; 386 return true;
387 } 387 }
388 388
389 #if defined(OS_CHROMEOS) 389 #if defined(OS_CHROMEOS)
390 // On ChromeOS, if an interface of a claimed device is not claimed, the 390 // On ChromeOS, if an interface of a claimed device is not claimed, the
391 // permission broker can change the owner of the device so that the unclaimed 391 // permission broker can change the owner of the device so that the unclaimed
392 // interfaces can be used. If this argument is missing, permission broker will 392 // interfaces can be used. If this argument is missing, permission broker will
393 // not be used and this method fails if the device is claimed. 393 // not be used and this method fails if the device is claimed.
394 virtual void RequestUsbAccess( 394 virtual void RequestUsbAccess(
395 int interface_id, 395 int interface_id,
396 const base::Callback<void(bool success)>& callback) OVERRIDE { 396 const base::Callback<void(bool success)>& callback) override {
397 callback.Run(true); 397 callback.Run(true);
398 } 398 }
399 #endif // OS_CHROMEOS 399 #endif // OS_CHROMEOS
400 400
401 std::set<int> claimed_interfaces_; 401 std::set<int> claimed_interfaces_;
402 402
403 protected: 403 protected:
404 virtual ~MockUsbDevice() {} 404 virtual ~MockUsbDevice() {}
405 405
406 private: 406 private:
407 UsbConfigDescriptor config_desc_; 407 UsbConfigDescriptor config_desc_;
408 }; 408 };
409 409
410 class MockUsbService : public UsbService { 410 class MockUsbService : public UsbService {
411 public: 411 public:
412 MockUsbService() { 412 MockUsbService() {
413 devices_.push_back(new MockUsbDevice<AndroidTraits>()); 413 devices_.push_back(new MockUsbDevice<AndroidTraits>());
414 } 414 }
415 415
416 virtual ~MockUsbService() {} 416 virtual ~MockUsbService() {}
417 417
418 virtual scoped_refptr<UsbDevice> GetDeviceById(uint32 unique_id) OVERRIDE { 418 virtual scoped_refptr<UsbDevice> GetDeviceById(uint32 unique_id) override {
419 NOTIMPLEMENTED(); 419 NOTIMPLEMENTED();
420 return NULL; 420 return NULL;
421 } 421 }
422 422
423 virtual void GetDevices( 423 virtual void GetDevices(
424 std::vector<scoped_refptr<UsbDevice> >* devices) OVERRIDE { 424 std::vector<scoped_refptr<UsbDevice> >* devices) override {
425 STLClearObject(devices); 425 STLClearObject(devices);
426 std::copy(devices_.begin(), devices_.end(), back_inserter(*devices)); 426 std::copy(devices_.begin(), devices_.end(), back_inserter(*devices));
427 } 427 }
428 428
429 std::vector<scoped_refptr<UsbDevice> > devices_; 429 std::vector<scoped_refptr<UsbDevice> > devices_;
430 }; 430 };
431 431
432 class MockUsbServiceForCheckingTraits : public UsbService { 432 class MockUsbServiceForCheckingTraits : public UsbService {
433 public: 433 public:
434 MockUsbServiceForCheckingTraits() : step_(0) {} 434 MockUsbServiceForCheckingTraits() : step_(0) {}
435 435
436 virtual ~MockUsbServiceForCheckingTraits() {} 436 virtual ~MockUsbServiceForCheckingTraits() {}
437 437
438 virtual scoped_refptr<UsbDevice> GetDeviceById(uint32 unique_id) OVERRIDE { 438 virtual scoped_refptr<UsbDevice> GetDeviceById(uint32 unique_id) override {
439 NOTIMPLEMENTED(); 439 NOTIMPLEMENTED();
440 return NULL; 440 return NULL;
441 } 441 }
442 442
443 virtual void GetDevices( 443 virtual void GetDevices(
444 std::vector<scoped_refptr<UsbDevice> >* devices) OVERRIDE { 444 std::vector<scoped_refptr<UsbDevice> >* devices) override {
445 STLClearObject(devices); 445 STLClearObject(devices);
446 // This switch should be kept in sync with 446 // This switch should be kept in sync with
447 // AndroidUsbBrowserTest::DeviceCountChanged. 447 // AndroidUsbBrowserTest::DeviceCountChanged.
448 switch (step_) { 448 switch (step_) {
449 case 0: 449 case 0:
450 // No devices. 450 // No devices.
451 break; 451 break;
452 case 1: 452 case 1:
453 // Android device. 453 // Android device.
454 devices->push_back(new MockUsbDevice<AndroidTraits>()); 454 devices->push_back(new MockUsbDevice<AndroidTraits>());
(...skipping 15 matching lines...) Expand all
470 int step_; 470 int step_;
471 }; 471 };
472 472
473 class DevToolsAndroidBridgeWarmUp 473 class DevToolsAndroidBridgeWarmUp
474 : public DevToolsAndroidBridge::DeviceCountListener { 474 : public DevToolsAndroidBridge::DeviceCountListener {
475 public: 475 public:
476 DevToolsAndroidBridgeWarmUp(base::Closure closure, 476 DevToolsAndroidBridgeWarmUp(base::Closure closure,
477 scoped_refptr<DevToolsAndroidBridge> adb_bridge) 477 scoped_refptr<DevToolsAndroidBridge> adb_bridge)
478 : closure_(closure), adb_bridge_(adb_bridge) {} 478 : closure_(closure), adb_bridge_(adb_bridge) {}
479 479
480 virtual void DeviceCountChanged(int count) OVERRIDE { 480 virtual void DeviceCountChanged(int count) override {
481 adb_bridge_->RemoveDeviceCountListener(this); 481 adb_bridge_->RemoveDeviceCountListener(this);
482 closure_.Run(); 482 closure_.Run();
483 } 483 }
484 484
485 base::Closure closure_; 485 base::Closure closure_;
486 scoped_refptr<DevToolsAndroidBridge> adb_bridge_; 486 scoped_refptr<DevToolsAndroidBridge> adb_bridge_;
487 }; 487 };
488 488
489 class AndroidUsbDiscoveryTest : public InProcessBrowserTest { 489 class AndroidUsbDiscoveryTest : public InProcessBrowserTest {
490 protected: 490 protected:
491 AndroidUsbDiscoveryTest() 491 AndroidUsbDiscoveryTest()
492 : scheduler_invoked_(0) { 492 : scheduler_invoked_(0) {
493 } 493 }
494 virtual void SetUpOnMainThread() OVERRIDE { 494 virtual void SetUpOnMainThread() override {
495 scoped_refptr<content::MessageLoopRunner> runner = 495 scoped_refptr<content::MessageLoopRunner> runner =
496 new content::MessageLoopRunner; 496 new content::MessageLoopRunner;
497 497
498 BrowserThread::PostTaskAndReply( 498 BrowserThread::PostTaskAndReply(
499 BrowserThread::FILE, 499 BrowserThread::FILE,
500 FROM_HERE, 500 FROM_HERE,
501 base::Bind(&AndroidUsbDiscoveryTest::SetUpService, this), 501 base::Bind(&AndroidUsbDiscoveryTest::SetUpService, this),
502 runner->QuitClosure()); 502 runner->QuitClosure());
503 runner->Run(); 503 runner->Run();
504 504
(...skipping 15 matching lines...) Expand all
520 void ScheduleDeviceCountRequest(const base::Closure& request) { 520 void ScheduleDeviceCountRequest(const base::Closure& request) {
521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
522 scheduler_invoked_++; 522 scheduler_invoked_++;
523 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, request); 523 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, request);
524 } 524 }
525 525
526 virtual void SetUpService() { 526 virtual void SetUpService() {
527 UsbService::SetInstanceForTest(new MockUsbService()); 527 UsbService::SetInstanceForTest(new MockUsbService());
528 } 528 }
529 529
530 virtual void TearDownOnMainThread() OVERRIDE { 530 virtual void TearDownOnMainThread() override {
531 scoped_refptr<content::MessageLoopRunner> runner = 531 scoped_refptr<content::MessageLoopRunner> runner =
532 new content::MessageLoopRunner; 532 new content::MessageLoopRunner;
533 UsbService* service = NULL; 533 UsbService* service = NULL;
534 BrowserThread::PostTaskAndReply( 534 BrowserThread::PostTaskAndReply(
535 BrowserThread::FILE, 535 BrowserThread::FILE,
536 FROM_HERE, 536 FROM_HERE,
537 base::Bind(&UsbService::SetInstanceForTest, service), 537 base::Bind(&UsbService::SetInstanceForTest, service),
538 runner->QuitClosure()); 538 runner->QuitClosure());
539 runner->Run(); 539 runner->Run();
540 } 540 }
541 541
542 scoped_refptr<content::MessageLoopRunner> runner_; 542 scoped_refptr<content::MessageLoopRunner> runner_;
543 scoped_refptr<DevToolsAndroidBridge> adb_bridge_; 543 scoped_refptr<DevToolsAndroidBridge> adb_bridge_;
544 int scheduler_invoked_; 544 int scheduler_invoked_;
545 }; 545 };
546 546
547 class AndroidUsbCountTest : public AndroidUsbDiscoveryTest { 547 class AndroidUsbCountTest : public AndroidUsbDiscoveryTest {
548 protected: 548 protected:
549 virtual void SetUpOnMainThread() OVERRIDE { 549 virtual void SetUpOnMainThread() override {
550 AndroidUsbDiscoveryTest::SetUpOnMainThread(); 550 AndroidUsbDiscoveryTest::SetUpOnMainThread();
551 DevToolsAndroidBridgeWarmUp warmup(runner_->QuitClosure(), adb_bridge_); 551 DevToolsAndroidBridgeWarmUp warmup(runner_->QuitClosure(), adb_bridge_);
552 adb_bridge_->AddDeviceCountListener(&warmup); 552 adb_bridge_->AddDeviceCountListener(&warmup);
553 runner_->Run(); 553 runner_->Run();
554 runner_ = new content::MessageLoopRunner; 554 runner_ = new content::MessageLoopRunner;
555 } 555 }
556 }; 556 };
557 557
558 class AndroidUsbTraitsTest : public AndroidUsbDiscoveryTest { 558 class AndroidUsbTraitsTest : public AndroidUsbDiscoveryTest {
559 protected: 559 protected:
560 virtual void SetUpService() OVERRIDE { 560 virtual void SetUpService() override {
561 UsbService::SetInstanceForTest(new MockUsbServiceForCheckingTraits()); 561 UsbService::SetInstanceForTest(new MockUsbServiceForCheckingTraits());
562 } 562 }
563 }; 563 };
564 564
565 class MockListListener : public DevToolsAndroidBridge::DeviceListListener { 565 class MockListListener : public DevToolsAndroidBridge::DeviceListListener {
566 public: 566 public:
567 MockListListener(scoped_refptr<DevToolsAndroidBridge> adb_bridge, 567 MockListListener(scoped_refptr<DevToolsAndroidBridge> adb_bridge,
568 const base::Closure& callback) 568 const base::Closure& callback)
569 : adb_bridge_(adb_bridge), 569 : adb_bridge_(adb_bridge),
570 callback_(callback) { 570 callback_(callback) {
571 } 571 }
572 572
573 virtual void DeviceListChanged( 573 virtual void DeviceListChanged(
574 const DevToolsAndroidBridge::RemoteDevices& devices) OVERRIDE { 574 const DevToolsAndroidBridge::RemoteDevices& devices) override {
575 if (devices.size() > 0) { 575 if (devices.size() > 0) {
576 if (devices[0]->is_connected()) { 576 if (devices[0]->is_connected()) {
577 ASSERT_EQ(kDeviceModel, devices[0]->model()); 577 ASSERT_EQ(kDeviceModel, devices[0]->model());
578 ASSERT_EQ(kDeviceSerial, devices[0]->serial()); 578 ASSERT_EQ(kDeviceSerial, devices[0]->serial());
579 adb_bridge_->RemoveDeviceListListener(this); 579 adb_bridge_->RemoveDeviceListListener(this);
580 callback_.Run(); 580 callback_.Run();
581 } 581 }
582 } 582 }
583 } 583 }
584 584
585 scoped_refptr<DevToolsAndroidBridge> adb_bridge_; 585 scoped_refptr<DevToolsAndroidBridge> adb_bridge_;
586 base::Closure callback_; 586 base::Closure callback_;
587 }; 587 };
588 588
589 class MockCountListener : public DevToolsAndroidBridge::DeviceCountListener { 589 class MockCountListener : public DevToolsAndroidBridge::DeviceCountListener {
590 public: 590 public:
591 explicit MockCountListener(scoped_refptr<DevToolsAndroidBridge> adb_bridge) 591 explicit MockCountListener(scoped_refptr<DevToolsAndroidBridge> adb_bridge)
592 : adb_bridge_(adb_bridge), 592 : adb_bridge_(adb_bridge),
593 reposts_left_(10), 593 reposts_left_(10),
594 invoked_(0) { 594 invoked_(0) {
595 } 595 }
596 596
597 virtual void DeviceCountChanged(int count) OVERRIDE { 597 virtual void DeviceCountChanged(int count) override {
598 ++invoked_; 598 ++invoked_;
599 adb_bridge_->RemoveDeviceCountListener(this); 599 adb_bridge_->RemoveDeviceCountListener(this);
600 Shutdown(); 600 Shutdown();
601 } 601 }
602 602
603 void Shutdown() { 603 void Shutdown() {
604 ShutdownOnUIThread(); 604 ShutdownOnUIThread();
605 }; 605 };
606 606
607 void ShutdownOnUIThread() { 607 void ShutdownOnUIThread() {
(...skipping 23 matching lines...) Expand all
631 }; 631 };
632 632
633 class MockCountListenerWithReAdd : public MockCountListener { 633 class MockCountListenerWithReAdd : public MockCountListener {
634 public: 634 public:
635 explicit MockCountListenerWithReAdd( 635 explicit MockCountListenerWithReAdd(
636 scoped_refptr<DevToolsAndroidBridge> adb_bridge) 636 scoped_refptr<DevToolsAndroidBridge> adb_bridge)
637 : MockCountListener(adb_bridge), 637 : MockCountListener(adb_bridge),
638 readd_count_(2) { 638 readd_count_(2) {
639 } 639 }
640 640
641 virtual void DeviceCountChanged(int count) OVERRIDE { 641 virtual void DeviceCountChanged(int count) override {
642 ++invoked_; 642 ++invoked_;
643 adb_bridge_->RemoveDeviceCountListener(this); 643 adb_bridge_->RemoveDeviceCountListener(this);
644 if (readd_count_ > 0) { 644 if (readd_count_ > 0) {
645 readd_count_--; 645 readd_count_--;
646 adb_bridge_->AddDeviceCountListener(this); 646 adb_bridge_->AddDeviceCountListener(this);
647 adb_bridge_->RemoveDeviceCountListener(this); 647 adb_bridge_->RemoveDeviceCountListener(this);
648 adb_bridge_->AddDeviceCountListener(this); 648 adb_bridge_->AddDeviceCountListener(this);
649 } else { 649 } else {
650 Shutdown(); 650 Shutdown();
651 } 651 }
652 } 652 }
653 653
654 int readd_count_; 654 int readd_count_;
655 }; 655 };
656 656
657 class MockCountListenerWithReAddWhileQueued : public MockCountListener { 657 class MockCountListenerWithReAddWhileQueued : public MockCountListener {
658 public: 658 public:
659 MockCountListenerWithReAddWhileQueued( 659 MockCountListenerWithReAddWhileQueued(
660 scoped_refptr<DevToolsAndroidBridge> adb_bridge) 660 scoped_refptr<DevToolsAndroidBridge> adb_bridge)
661 : MockCountListener(adb_bridge), 661 : MockCountListener(adb_bridge),
662 readded_(false) { 662 readded_(false) {
663 } 663 }
664 664
665 virtual void DeviceCountChanged(int count) OVERRIDE { 665 virtual void DeviceCountChanged(int count) override {
666 ++invoked_; 666 ++invoked_;
667 if (!readded_) { 667 if (!readded_) {
668 readded_ = true; 668 readded_ = true;
669 base::MessageLoop::current()->PostTask( 669 base::MessageLoop::current()->PostTask(
670 FROM_HERE, 670 FROM_HERE,
671 base::Bind(&MockCountListenerWithReAddWhileQueued::ReAdd, 671 base::Bind(&MockCountListenerWithReAddWhileQueued::ReAdd,
672 base::Unretained(this))); 672 base::Unretained(this)));
673 } else { 673 } else {
674 adb_bridge_->RemoveDeviceCountListener(this); 674 adb_bridge_->RemoveDeviceCountListener(this);
675 Shutdown(); 675 Shutdown();
676 } 676 }
677 } 677 }
678 678
679 void ReAdd() { 679 void ReAdd() {
680 adb_bridge_->RemoveDeviceCountListener(this); 680 adb_bridge_->RemoveDeviceCountListener(this);
681 adb_bridge_->AddDeviceCountListener(this); 681 adb_bridge_->AddDeviceCountListener(this);
682 } 682 }
683 683
684 bool readded_; 684 bool readded_;
685 }; 685 };
686 686
687 class MockCountListenerForCheckingTraits : public MockCountListener { 687 class MockCountListenerForCheckingTraits : public MockCountListener {
688 public: 688 public:
689 MockCountListenerForCheckingTraits( 689 MockCountListenerForCheckingTraits(
690 scoped_refptr<DevToolsAndroidBridge> adb_bridge) 690 scoped_refptr<DevToolsAndroidBridge> adb_bridge)
691 : MockCountListener(adb_bridge), 691 : MockCountListener(adb_bridge),
692 step_(0) { 692 step_(0) {
693 } 693 }
694 virtual void DeviceCountChanged(int count) OVERRIDE { 694 virtual void DeviceCountChanged(int count) override {
695 switch (step_) { 695 switch (step_) {
696 case 0: 696 case 0:
697 // Check for 0 devices when no devices present. 697 // Check for 0 devices when no devices present.
698 EXPECT_EQ(0, count); 698 EXPECT_EQ(0, count);
699 break; 699 break;
700 case 1: 700 case 1:
701 // Check for 1 device when only android device present. 701 // Check for 1 device when only android device present.
702 EXPECT_EQ(1, count); 702 EXPECT_EQ(1, count);
703 break; 703 break;
704 case 2: 704 case 2:
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 runner_->Run(); 764 runner_->Run();
765 EXPECT_EQ(2, listener.invoked_); 765 EXPECT_EQ(2, listener.invoked_);
766 EXPECT_EQ(listener.invoked_ - 1, scheduler_invoked_); 766 EXPECT_EQ(listener.invoked_ - 1, scheduler_invoked_);
767 } 767 }
768 768
769 IN_PROC_BROWSER_TEST_F(AndroidUsbTraitsTest, TestDeviceCounting) { 769 IN_PROC_BROWSER_TEST_F(AndroidUsbTraitsTest, TestDeviceCounting) {
770 MockCountListenerForCheckingTraits listener(adb_bridge_); 770 MockCountListenerForCheckingTraits listener(adb_bridge_);
771 adb_bridge_->AddDeviceCountListener(&listener); 771 adb_bridge_->AddDeviceCountListener(&listener);
772 runner_->Run(); 772 runner_->Run();
773 } 773 }
OLDNEW
« no previous file with comments | « chrome/browser/devtools/device/self_device_provider.h ('k') | chrome/browser/devtools/device/usb/android_usb_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698