Home | History | Annotate | Download | only in debugger
      1 // Copyright (c) 2011 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 <string>
      6 
      7 #include "base/memory/scoped_ptr.h"
      8 #include "base/string_number_conversions.h"
      9 #include "chrome/browser/debugger/devtools_remote.h"
     10 #include "chrome/browser/debugger/devtools_remote_message.h"
     11 #include "testing/gtest/include/gtest/gtest.h"
     12 
     13 class DevToolsRemoteMessageTest : public testing::Test {
     14  public:
     15   DevToolsRemoteMessageTest() : testing::Test() {}
     16 
     17  protected:
     18   virtual void SetUp() {
     19     testing::Test::SetUp();
     20   }
     21 };
     22 
     23 TEST_F(DevToolsRemoteMessageTest, ConstructInstanceManually) {
     24   DevToolsRemoteMessage::HeaderMap headers;
     25   std::string content = "{\"command\":\"ping\"}";
     26   headers[DevToolsRemoteMessageHeaders::kTool] = "DevToolsService";
     27   headers[DevToolsRemoteMessageHeaders::kContentLength] =
     28       base::IntToString(content.size());
     29 
     30   DevToolsRemoteMessage message(headers, content);
     31   ASSERT_STREQ("DevToolsService",
     32                message.GetHeaderWithEmptyDefault(
     33                    DevToolsRemoteMessageHeaders::kTool).c_str());
     34   ASSERT_STREQ("DevToolsService", message.tool().c_str());
     35   ASSERT_STREQ(content.c_str(), message.content().c_str());
     36   ASSERT_EQ(content.size(),
     37             static_cast<std::string::size_type>(message.content_length()));
     38   ASSERT_EQ(static_cast<DevToolsRemoteMessage::HeaderMap::size_type>(2),
     39             message.headers().size());
     40 }
     41 
     42 TEST_F(DevToolsRemoteMessageTest, ConstructWithBuilder) {
     43   std::string content = "Responsecontent";
     44   scoped_ptr<DevToolsRemoteMessage> message(
     45       DevToolsRemoteMessageBuilder::instance().Create(
     46           "V8Debugger",  // tool
     47           "2",           // destination
     48           content));     // content
     49 
     50   ASSERT_EQ(static_cast<DevToolsRemoteMessage::HeaderMap::size_type>(3),
     51             message->headers().size());
     52   ASSERT_STREQ(
     53       "V8Debugger",
     54       message->GetHeaderWithEmptyDefault(
     55           DevToolsRemoteMessageHeaders::kTool).c_str());
     56   ASSERT_STREQ(
     57       "V8Debugger",
     58       message->tool().c_str());
     59   ASSERT_STREQ(
     60       "2",
     61       message->GetHeaderWithEmptyDefault(
     62           DevToolsRemoteMessageHeaders::kDestination).c_str());
     63   ASSERT_STREQ(
     64       "2",
     65       message->destination().c_str());
     66   ASSERT_EQ(content.size(),
     67       static_cast<DevToolsRemoteMessage::HeaderMap::size_type>(
     68           message->content_length()));
     69   ASSERT_STREQ(content.c_str(), message->content().c_str());
     70 }
     71