1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include "base/string_number_conversions.h"
#include "chrome/browser/debugger/devtools_remote.h"
#include "chrome/browser/debugger/devtools_remote_message.h"
#include "testing/gtest/include/gtest/gtest.h"
class DevToolsRemoteMessageTest : public testing::Test {
public:
DevToolsRemoteMessageTest() : testing::Test() {
}
protected:
virtual void SetUp() {
testing::Test::SetUp();
}
};
TEST_F(DevToolsRemoteMessageTest, ConstructInstanceManually) {
DevToolsRemoteMessage::HeaderMap headers;
std::string content = "{\"command\":\"ping\"}";
headers[DevToolsRemoteMessageHeaders::kTool] = "DevToolsService";
headers[DevToolsRemoteMessageHeaders::kContentLength] =
base::IntToString(content.size());
DevToolsRemoteMessage message(headers, content);
ASSERT_STREQ("DevToolsService",
message.GetHeaderWithEmptyDefault(
DevToolsRemoteMessageHeaders::kTool).c_str());
ASSERT_STREQ("DevToolsService", message.tool().c_str());
ASSERT_STREQ(content.c_str(), message.content().c_str());
ASSERT_EQ(content.size(),
static_cast<std::string::size_type>(message.content_length()));
ASSERT_EQ(static_cast<DevToolsRemoteMessage::HeaderMap::size_type>(2),
message.headers().size());
}
TEST_F(DevToolsRemoteMessageTest, ConstructWithBuilder) {
std::string content = "Responsecontent";
testing::internal::scoped_ptr<DevToolsRemoteMessage> message(
DevToolsRemoteMessageBuilder::instance().Create(
"V8Debugger", // tool
"2", // destination
content)); // content
ASSERT_EQ(static_cast<DevToolsRemoteMessage::HeaderMap::size_type>(3),
message->headers().size());
ASSERT_STREQ(
"V8Debugger",
message->GetHeaderWithEmptyDefault(
DevToolsRemoteMessageHeaders::kTool).c_str());
ASSERT_STREQ(
"V8Debugger",
message->tool().c_str());
ASSERT_STREQ(
"2",
message->GetHeaderWithEmptyDefault(
DevToolsRemoteMessageHeaders::kDestination).c_str());
ASSERT_STREQ(
"2",
message->destination().c_str());
ASSERT_EQ(content.size(),
static_cast<DevToolsRemoteMessage::HeaderMap::size_type>(
message->content_length()));
ASSERT_STREQ(content.c_str(), message->content().c_str());
}
|