| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/devtools/device/webrtc/devtools_bridge_instances_reques
t.h" | |
| 6 | |
| 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" | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 class MockDelegate : public DevToolsBridgeInstancesRequest::Delegate { | |
| 19 public: | |
| 20 DevToolsBridgeInstancesRequest::InstanceList instances; | |
| 21 | |
| 22 void OnDevToolsBridgeInstancesRequestSucceeded( | |
| 23 const DevToolsBridgeInstancesRequest::InstanceList& result) override { | |
| 24 instances = result; | |
| 25 } | |
| 26 | |
| 27 void OnDevToolsBridgeInstancesRequestFailed() override {} | |
| 28 }; | |
| 29 | |
| 30 base::FilePath GetTestFilePath(const std::string& file_name) { | |
| 31 base::FilePath path; | |
| 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); | |
| 37 } | |
| 38 | |
| 39 } // namespace | |
| 40 | |
| 41 TEST(DevToolsBridgeInstancesRequestTest, ParseResponse) { | |
| 42 std::string input; | |
| 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)); | |
| 49 | |
| 50 const base::DictionaryValue* dictionary = NULL; | |
| 51 ASSERT_TRUE(root->GetAsDictionary(&dictionary)); | |
| 52 | |
| 53 MockDelegate delegate; | |
| 54 | |
| 55 delegate.instances.resize(10); | |
| 56 | |
| 57 DevToolsBridgeInstancesRequest(&delegate).OnGCDAPIFlowComplete(*dictionary); | |
| 58 | |
| 59 ASSERT_TRUE(delegate.instances.size() == 1); | |
| 60 ASSERT_EQ("ab911465-83c7-e335-ea64-cb656868cbe0", delegate.instances[0].id); | |
| 61 } | |
| OLD | NEW |