Roll src/third_party/WebKit bf18a82:a9cee16 (svn 185297:185304)
[chromium-blink-merge.git] / chrome / test / chromedriver / chrome / device_manager_unittest.cc
blobbe6f2793251f6923a7a3ca7c6fa510a69be12537
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.
5 #include <string>
6 #include <vector>
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"
15 namespace {
17 class FakeAdb : public Adb {
18 public:
19 FakeAdb() {}
20 ~FakeAdb() override {}
22 Status GetDevices(std::vector<std::string>* devices) override {
23 devices->push_back("a");
24 devices->push_back("b");
25 return Status(kOk);
28 Status ForwardPort(const std::string& device_serial,
29 int local_port,
30 const std::string& remote_abstract) override {
31 return Status(kOk);
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 {
38 return Status(kOk);
41 Status CheckAppInstalled(const std::string& device_serial,
42 const std::string& package) override {
43 return Status(kOk);
46 Status ClearAppData(const std::string& device_serial,
47 const std::string& package) override {
48 return Status(kOk);
51 Status SetDebugApp(const std::string& device_serial,
52 const std::string& package) override {
53 return Status(kOk);
56 Status Launch(const std::string& device_serial,
57 const std::string& package,
58 const std::string& activity) override {
59 return Status(kOk);
62 Status ForceStop(const std::string& device_serial,
63 const std::string& package) override {
64 return Status(kOk);
67 Status GetPidByName(const std::string& device_serial,
68 const std::string& process_name,
69 int* pid) override {
70 *pid = 0; // avoid uninit error crbug.com/393231
71 return Status(kOk);
75 } // namespace
77 TEST(DeviceManager, AcquireDevice) {
78 FakeAdb adb;
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());
86 device1.reset(NULL);
87 ASSERT_TRUE(device_manager.AcquireDevice(&device3).IsOk());
88 ASSERT_FALSE(device_manager.AcquireDevice(&device1).IsOk());
91 TEST(DeviceManager, AcquireSpecificDevice) {
92 FakeAdb adb;
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());
100 device1.reset(NULL);
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) {
107 FakeAdb adb;
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());