[Cronet] Delay StartNetLog and StopNetLog until native request context is initialized
[chromium-blink-merge.git] / chrome / browser / devtools / device / webrtc / devtools_bridge_instances_request_unittest.cc
blob3b9710fbbd2c0e0e74a8b5eafd9453d5c477bfe3
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"
16 namespace {
18 class MockDelegate : public DevToolsBridgeInstancesRequest::Delegate {
19 public:
20 DevToolsBridgeInstancesRequest::InstanceList instances;
22 void OnDevToolsBridgeInstancesRequestSucceeded(
23 const DevToolsBridgeInstancesRequest::InstanceList& result) override {
24 instances = result;
27 void OnDevToolsBridgeInstancesRequestFailed() override {}
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);
39 } // namespace
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));
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);