1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/test/chromedriver/chrome/adb.h"
11 #include "chrome/test/chromedriver/chrome/device_manager.h"
12 #include "chrome/test/chromedriver/chrome/status.h"
13 #include "testing/gtest/include/gtest/gtest.h"
17 class FakeAdb
: public Adb
{
20 ~FakeAdb() override
{}
22 Status
GetDevices(std::vector
<std::string
>* devices
) override
{
23 devices
->push_back("a");
24 devices
->push_back("b");
28 Status
ForwardPort(const std::string
& device_serial
,
30 const std::string
& remote_abstract
) override
{
34 Status
SetCommandLineFile(const std::string
& device_serial
,
35 const std::string
& command_line_file
,
36 const std::string
& exec_name
,
37 const std::string
& args
) override
{
41 Status
CheckAppInstalled(const std::string
& device_serial
,
42 const std::string
& package
) override
{
46 Status
ClearAppData(const std::string
& device_serial
,
47 const std::string
& package
) override
{
51 Status
SetDebugApp(const std::string
& device_serial
,
52 const std::string
& package
) override
{
56 Status
Launch(const std::string
& device_serial
,
57 const std::string
& package
,
58 const std::string
& activity
) override
{
62 Status
ForceStop(const std::string
& device_serial
,
63 const std::string
& package
) override
{
67 Status
GetPidByName(const std::string
& device_serial
,
68 const std::string
& process_name
,
70 *pid
= 0; // avoid uninit error crbug.com/393231
77 TEST(DeviceManager
, AcquireDevice
) {
79 DeviceManager
device_manager(&adb
);
80 scoped_ptr
<Device
> device1
;
81 scoped_ptr
<Device
> device2
;
82 scoped_ptr
<Device
> device3
;
83 ASSERT_TRUE(device_manager
.AcquireDevice(&device1
).IsOk());
84 ASSERT_TRUE(device_manager
.AcquireDevice(&device2
).IsOk());
85 ASSERT_FALSE(device_manager
.AcquireDevice(&device3
).IsOk());
87 ASSERT_TRUE(device_manager
.AcquireDevice(&device3
).IsOk());
88 ASSERT_FALSE(device_manager
.AcquireDevice(&device1
).IsOk());
91 TEST(DeviceManager
, AcquireSpecificDevice
) {
93 DeviceManager
device_manager(&adb
);
94 scoped_ptr
<Device
> device1
;
95 scoped_ptr
<Device
> device2
;
96 scoped_ptr
<Device
> device3
;
97 ASSERT_TRUE(device_manager
.AcquireSpecificDevice("a", &device1
).IsOk());
98 ASSERT_FALSE(device_manager
.AcquireSpecificDevice("a", &device2
).IsOk());
99 ASSERT_TRUE(device_manager
.AcquireSpecificDevice("b", &device3
).IsOk());
101 ASSERT_TRUE(device_manager
.AcquireSpecificDevice("a", &device2
).IsOk());
102 ASSERT_FALSE(device_manager
.AcquireSpecificDevice("a", &device1
).IsOk());
103 ASSERT_FALSE(device_manager
.AcquireSpecificDevice("b", &device1
).IsOk());
106 TEST(Device
, StartStopApp
) {
108 DeviceManager
device_manager(&adb
);
109 scoped_ptr
<Device
> device1
;
110 ASSERT_TRUE(device_manager
.AcquireDevice(&device1
).IsOk());
111 ASSERT_TRUE(device1
->TearDown().IsOk());
112 ASSERT_TRUE(device1
->SetUp("a.chrome.package", "", "", "", false, 0).IsOk());
113 ASSERT_FALSE(device1
->SetUp("a.chrome.package", "", "", "", false, 0).IsOk());
114 ASSERT_TRUE(device1
->TearDown().IsOk());
115 ASSERT_FALSE(device1
->SetUp(
116 "a.chrome.package", "an.activity", "", "", false, 0).IsOk());
117 ASSERT_FALSE(device1
->SetUp("a.package", "", "", "", false, 0).IsOk());
118 ASSERT_TRUE(device1
->SetUp(
119 "a.package", "an.activity", "", "", false, 0).IsOk());
120 ASSERT_TRUE(device1
->TearDown().IsOk());
121 ASSERT_TRUE(device1
->TearDown().IsOk());
122 ASSERT_TRUE(device1
->SetUp(
123 "a.package", "an.activity", "a.process", "", false, 0).IsOk());
124 ASSERT_TRUE(device1
->TearDown().IsOk());