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
3 // found in the LICENSE file.
5 #include "chrome/browser/devtools/device/adb/adb_device_provider.h"
6 #include "chrome/browser/devtools/device/adb/mock_adb_server.h"
7 #include "chrome/browser/devtools/device/devtools_android_bridge.h"
8 #include "chrome/browser/devtools/devtools_target_impl.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/test/base/in_process_browser_test.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/test/test_utils.h"
14 using content::BrowserThread
;
16 static scoped_refptr
<DevToolsAndroidBridge::RemoteBrowser
>
17 FindBrowserByDisplayName(DevToolsAndroidBridge::RemoteBrowsers browsers
,
18 const std::string
& name
) {
19 for (DevToolsAndroidBridge::RemoteBrowsers::iterator it
= browsers
.begin();
20 it
!= browsers
.end(); ++it
)
21 if ((*it
)->display_name() == name
)
26 class AdbClientSocketTest
: public InProcessBrowserTest
,
27 public DevToolsAndroidBridge::DeviceListListener
{
31 Profile
* profile
= browser()->profile();
32 android_bridge_
= DevToolsAndroidBridge::Factory::GetForProfile(profile
);
33 AndroidDeviceManager::DeviceProviders device_providers
;
34 device_providers
.push_back(new AdbDeviceProvider());
35 android_bridge_
->set_device_providers_for_test(device_providers
);
36 android_bridge_
->AddDeviceListListener(this);
37 content::RunMessageLoop();
40 void DeviceListChanged(
41 const DevToolsAndroidBridge::RemoteDevices
& devices
) override
{
43 android_bridge_
->RemoveDeviceListListener(this);
44 base::MessageLoop::current()->Quit();
48 ASSERT_EQ(2U, devices_
.size());
50 scoped_refptr
<DevToolsAndroidBridge::RemoteDevice
> connected
=
51 devices_
[0]->is_connected() ? devices_
[0] : devices_
[1];
53 scoped_refptr
<DevToolsAndroidBridge::RemoteDevice
> not_connected
=
54 devices_
[0]->is_connected() ? devices_
[1] : devices_
[0];
56 ASSERT_TRUE(connected
->is_connected());
57 ASSERT_FALSE(not_connected
->is_connected());
59 ASSERT_EQ(720, connected
->screen_size().width());
60 ASSERT_EQ(1184, connected
->screen_size().height());
62 ASSERT_EQ("01498B321301A00A", connected
->serial());
63 ASSERT_EQ("Nexus 6", connected
->model());
65 ASSERT_EQ("01498B2B0D01300E", not_connected
->serial());
66 ASSERT_EQ("Offline", not_connected
->model());
68 const DevToolsAndroidBridge::RemoteBrowsers
& browsers
=
69 connected
->browsers();
70 ASSERT_EQ(4U, browsers
.size());
72 scoped_refptr
<DevToolsAndroidBridge::RemoteBrowser
> chrome
=
73 FindBrowserByDisplayName(browsers
, "Chrome");
74 ASSERT_TRUE(chrome
.get());
76 scoped_refptr
<DevToolsAndroidBridge::RemoteBrowser
> chrome_beta
=
77 FindBrowserByDisplayName(browsers
, "Chrome Beta");
78 ASSERT_TRUE(chrome_beta
.get());
80 scoped_refptr
<DevToolsAndroidBridge::RemoteBrowser
> chromium
=
81 FindBrowserByDisplayName(browsers
, "Chromium");
82 ASSERT_FALSE(chromium
.get());
84 scoped_refptr
<DevToolsAndroidBridge::RemoteBrowser
> webview
=
85 FindBrowserByDisplayName(browsers
, "WebView in com.sample.feed");
86 ASSERT_TRUE(webview
.get());
88 scoped_refptr
<DevToolsAndroidBridge::RemoteBrowser
> noprocess
=
89 FindBrowserByDisplayName(browsers
, "Noprocess");
90 ASSERT_TRUE(noprocess
.get());
92 ASSERT_EQ("32.0.1679.0", chrome
->version());
93 ASSERT_EQ("31.0.1599.0", chrome_beta
->version());
94 ASSERT_EQ("4.0", webview
->version());
96 ASSERT_EQ("Test User", chrome
->user());
97 ASSERT_EQ("Test User : 2", chrome_beta
->user());
98 ASSERT_EQ("Test User", webview
->user());
100 DevToolsAndroidBridge::RemotePages chrome_pages
=
102 DevToolsAndroidBridge::RemotePages chrome_beta_pages
=
103 chrome_beta
->pages();
104 DevToolsAndroidBridge::RemotePages webview_pages
=
107 ASSERT_EQ(1U, chrome_pages
.size());
108 ASSERT_EQ(1U, chrome_beta_pages
.size());
109 ASSERT_EQ(2U, webview_pages
.size());
111 scoped_ptr
<DevToolsTargetImpl
> chrome_target(
112 android_bridge_
->CreatePageTarget(chrome_pages
[0]));
113 scoped_ptr
<DevToolsTargetImpl
> chrome_beta_target(
114 android_bridge_
->CreatePageTarget(chrome_beta_pages
[0]));
115 scoped_ptr
<DevToolsTargetImpl
> webview_target_0(
116 android_bridge_
->CreatePageTarget(webview_pages
[0]));
117 scoped_ptr
<DevToolsTargetImpl
> webview_target_1(
118 android_bridge_
->CreatePageTarget(webview_pages
[1]));
120 // Check that we have non-empty description for webview pages.
121 ASSERT_EQ(0U, chrome_target
->GetDescription().size());
122 ASSERT_EQ(0U, chrome_beta_target
->GetDescription().size());
123 ASSERT_NE(0U, webview_target_0
->GetDescription().size());
124 ASSERT_NE(0U, webview_target_1
->GetDescription().size());
126 ASSERT_EQ(GURL("http://www.chromium.org/"),
127 chrome_target
->GetURL());
128 ASSERT_EQ("The Chromium Projects",
129 chrome_target
->GetTitle());
133 DevToolsAndroidBridge
* android_bridge_
;
134 DevToolsAndroidBridge::RemoteDevices devices_
;
137 IN_PROC_BROWSER_TEST_F(AdbClientSocketTest
, TestFlushWithoutSize
) {
138 StartMockAdbServer(FlushWithoutSize
);
144 IN_PROC_BROWSER_TEST_F(AdbClientSocketTest
, TestFlushWithSize
) {
145 StartMockAdbServer(FlushWithSize
);
151 IN_PROC_BROWSER_TEST_F(AdbClientSocketTest
, TestFlushWithData
) {
152 StartMockAdbServer(FlushWithData
);