OLD | NEW |
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/containers/scoped_ptr_hash_map.h" | 7 #include "base/containers/scoped_ptr_hash_map.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/devtools/device/adb/mock_adb_server.h" | 9 #include "chrome/browser/devtools/device/adb/mock_adb_server.h" |
10 #include "chrome/browser/devtools/device/devtools_android_bridge.h" | 10 #include "chrome/browser/devtools/device/devtools_android_bridge.h" |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 scoped_refptr<UsbDeviceProvider> provider = | 579 scoped_refptr<UsbDeviceProvider> provider = |
580 new UsbDeviceProvider(browser()->profile()); | 580 new UsbDeviceProvider(browser()->profile()); |
581 | 581 |
582 AndroidDeviceManager::DeviceProviders providers; | 582 AndroidDeviceManager::DeviceProviders providers; |
583 providers.push_back(provider); | 583 providers.push_back(provider); |
584 adb_bridge_->set_device_providers_for_test(providers); | 584 adb_bridge_->set_device_providers_for_test(providers); |
585 runner_ = new content::MessageLoopRunner; | 585 runner_ = new content::MessageLoopRunner; |
586 } | 586 } |
587 | 587 |
588 void ScheduleDeviceCountRequest(const base::Closure& request) { | 588 void ScheduleDeviceCountRequest(const base::Closure& request) { |
589 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 589 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
590 scheduler_invoked_++; | 590 scheduler_invoked_++; |
591 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, request); | 591 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, request); |
592 } | 592 } |
593 | 593 |
594 virtual void SetUpService() { | 594 virtual void SetUpService() { |
595 UsbService::SetInstanceForTest(new MockUsbService()); | 595 UsbService::SetInstanceForTest(new MockUsbService()); |
596 } | 596 } |
597 | 597 |
598 void TearDownOnMainThread() override { | 598 void TearDownOnMainThread() override { |
599 scoped_refptr<content::MessageLoopRunner> runner = | 599 scoped_refptr<content::MessageLoopRunner> runner = |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 ++invoked_; | 683 ++invoked_; |
684 adb_bridge_->RemoveDeviceCountListener(this); | 684 adb_bridge_->RemoveDeviceCountListener(this); |
685 Shutdown(); | 685 Shutdown(); |
686 } | 686 } |
687 | 687 |
688 void Shutdown() { | 688 void Shutdown() { |
689 ShutdownOnUIThread(); | 689 ShutdownOnUIThread(); |
690 }; | 690 }; |
691 | 691 |
692 void ShutdownOnUIThread() { | 692 void ShutdownOnUIThread() { |
693 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 693 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
694 if (reposts_left_-- == 0) { | 694 if (reposts_left_-- == 0) { |
695 base::MessageLoop::current()->Quit(); | 695 base::MessageLoop::current()->Quit(); |
696 } else { | 696 } else { |
697 BrowserThread::PostTask( | 697 BrowserThread::PostTask( |
698 BrowserThread::FILE, | 698 BrowserThread::FILE, |
699 FROM_HERE, | 699 FROM_HERE, |
700 base::Bind(&MockCountListener::ShutdownOnFileThread, | 700 base::Bind(&MockCountListener::ShutdownOnFileThread, |
701 base::Unretained(this))); | 701 base::Unretained(this))); |
702 } | 702 } |
703 } | 703 } |
704 | 704 |
705 void ShutdownOnFileThread() { | 705 void ShutdownOnFileThread() { |
706 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 706 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
707 BrowserThread::PostTask(BrowserThread::UI, | 707 BrowserThread::PostTask(BrowserThread::UI, |
708 FROM_HERE, | 708 FROM_HERE, |
709 base::Bind(&MockCountListener::ShutdownOnUIThread, | 709 base::Bind(&MockCountListener::ShutdownOnUIThread, |
710 base::Unretained(this))); | 710 base::Unretained(this))); |
711 } | 711 } |
712 | 712 |
713 DevToolsAndroidBridge* adb_bridge_; | 713 DevToolsAndroidBridge* adb_bridge_; |
714 int reposts_left_; | 714 int reposts_left_; |
715 int invoked_; | 715 int invoked_; |
716 }; | 716 }; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
861 runner_->Run(); | 861 runner_->Run(); |
862 EXPECT_EQ(2, listener.invoked_); | 862 EXPECT_EQ(2, listener.invoked_); |
863 EXPECT_EQ(listener.invoked_ - 1, scheduler_invoked_); | 863 EXPECT_EQ(listener.invoked_ - 1, scheduler_invoked_); |
864 } | 864 } |
865 | 865 |
866 IN_PROC_BROWSER_TEST_F(AndroidUsbTraitsTest, TestDeviceCounting) { | 866 IN_PROC_BROWSER_TEST_F(AndroidUsbTraitsTest, TestDeviceCounting) { |
867 MockCountListenerForCheckingTraits listener(adb_bridge_); | 867 MockCountListenerForCheckingTraits listener(adb_bridge_); |
868 adb_bridge_->AddDeviceCountListener(&listener); | 868 adb_bridge_->AddDeviceCountListener(&listener); |
869 runner_->Run(); | 869 runner_->Run(); |
870 } | 870 } |
OLD | NEW |