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/webrtc/devtools_bridge_instances_request.h"
7 #include "base/files/file_util.h"
8 #include "base/json/json_reader.h"
9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/path_service.h"
12 #include "base/values.h"
13 #include "chrome/common/chrome_paths.h"
14 #include "testing/gtest/include/gtest/gtest.h"
18 class MockDelegate
: public DevToolsBridgeInstancesRequest::Delegate
{
20 DevToolsBridgeInstancesRequest::InstanceList instances
;
22 void OnDevToolsBridgeInstancesRequestSucceeded(
23 const DevToolsBridgeInstancesRequest::InstanceList
& result
) override
{
27 void OnDevToolsBridgeInstancesRequestFailed() override
{}
30 base::FilePath
GetTestFilePath(const std::string
& file_name
) {
32 if (!PathService::Get(chrome::DIR_TEST_DATA
, &path
))
33 return base::FilePath();
34 return path
.AppendASCII("devtools")
35 .AppendASCII("webrtc_device_provider")
36 .AppendASCII(file_name
);
41 TEST(DevToolsBridgeInstancesRequestTest
, ParseResponse
) {
43 ASSERT_TRUE(base::ReadFileToString(
44 GetTestFilePath("devtools_bridge_instances_response.json"), &input
));
45 base::JSONReader reader
;
46 scoped_ptr
<base::Value
> root(reader
.ReadToValue(input
));
47 ASSERT_TRUE(root
.get()) << reader
.GetErrorMessage();
48 EXPECT_TRUE(root
->IsType(base::Value::TYPE_DICTIONARY
));
50 const base::DictionaryValue
* dictionary
= NULL
;
51 ASSERT_TRUE(root
->GetAsDictionary(&dictionary
));
53 MockDelegate delegate
;
55 delegate
.instances
.resize(10);
57 DevToolsBridgeInstancesRequest(&delegate
).OnGCDAPIFlowComplete(*dictionary
);
59 ASSERT_TRUE(delegate
.instances
.size() == 1);
60 ASSERT_EQ("ab911465-83c7-e335-ea64-cb656868cbe0", delegate
.instances
[0].id
);