| Index: ipc/ipc_channel_reader_unittest.cc
 | 
| diff --git a/ipc/ipc_channel_reader_unittest.cc b/ipc/ipc_channel_reader_unittest.cc
 | 
| index 1107cc73eeb936f064ad109ae4cc3c759f63fd86..fbb73f9443ee727fac89e29e7481f690ccb0c4df 100644
 | 
| --- a/ipc/ipc_channel_reader_unittest.cc
 | 
| +++ b/ipc/ipc_channel_reader_unittest.cc
 | 
| @@ -12,65 +12,15 @@
 | 
|  #include <set>
 | 
|  
 | 
|  #include "base/run_loop.h"
 | 
| -#include "ipc/attachment_broker.h"
 | 
|  #include "ipc/brokerable_attachment.h"
 | 
|  #include "ipc/ipc_channel_reader.h"
 | 
| -#include "ipc/placeholder_brokerable_attachment.h"
 | 
|  #include "testing/gtest/include/gtest/gtest.h"
 | 
|  
 | 
| -// Whether IPC::Message::FindNext() can determine message size for
 | 
| -// partial messages. The condition is from FindNext() implementation.
 | 
| -#if USE_ATTACHMENT_BROKER
 | 
| -#define MESSAGE_FINDNEXT_PARTIAL 0
 | 
| -#else
 | 
| -#define MESSAGE_FINDNEXT_PARTIAL 1
 | 
| -#endif
 | 
| -
 | 
|  namespace IPC {
 | 
|  namespace internal {
 | 
|  
 | 
|  namespace {
 | 
|  
 | 
| -#if USE_ATTACHMENT_BROKER
 | 
| -
 | 
| -class MockAttachment : public BrokerableAttachment {
 | 
| - public:
 | 
| -  MockAttachment() {}
 | 
| -  MockAttachment(BrokerableAttachment::AttachmentId id)
 | 
| -      : BrokerableAttachment(id) {}
 | 
| -
 | 
| -#if defined(OS_POSIX)
 | 
| -  base::PlatformFile TakePlatformFile() override {
 | 
| -    return base::PlatformFile();
 | 
| -  }
 | 
| -#endif  // OS_POSIX
 | 
| -
 | 
| -  BrokerableType GetBrokerableType() const override { return WIN_HANDLE; }
 | 
| -
 | 
| - private:
 | 
| -  ~MockAttachment() override {}
 | 
| -};
 | 
| -
 | 
| -class MockAttachmentBroker : public AttachmentBroker {
 | 
| - public:
 | 
| -  typedef std::set<scoped_refptr<BrokerableAttachment>> AttachmentSet;
 | 
| -
 | 
| -  bool SendAttachmentToProcess(
 | 
| -      const scoped_refptr<BrokerableAttachment>& attachment,
 | 
| -      base::ProcessId destination_process) override {
 | 
| -    return false;
 | 
| -  }
 | 
| -
 | 
| -  bool OnMessageReceived(const Message& message) override { return false; }
 | 
| -
 | 
| -  void AddAttachment(scoped_refptr<BrokerableAttachment> attachment) {
 | 
| -    get_attachments()->push_back(attachment);
 | 
| -    NotifyObservers(attachment->GetIdentifier());
 | 
| -  }
 | 
| -};
 | 
| -
 | 
| -#endif  // USE_ATTACHMENT_BROKER
 | 
| -
 | 
|  class MockChannelReader : public ChannelReader {
 | 
|   public:
 | 
|    MockChannelReader()
 | 
| @@ -99,19 +49,8 @@ class MockChannelReader : public ChannelReader {
 | 
|  
 | 
|    base::ProcessId GetSenderPID() override { return base::kNullProcessId; }
 | 
|  
 | 
| -  bool IsAttachmentBrokerEndpoint() override { return false; }
 | 
| -
 | 
| -  AttachmentBroker* GetAttachmentBroker() override { return broker_; }
 | 
| -
 | 
| -  // This instance takes ownership of |m|.
 | 
| -  void AddMessageForDispatch(Message* m) {
 | 
| -    get_queued_messages()->push_back(m);
 | 
| -  }
 | 
| -
 | 
|    Message* get_last_dispatched_message() { return last_dispatched_message_; }
 | 
|  
 | 
| -  void set_broker(AttachmentBroker* broker) { broker_ = broker; }
 | 
| -
 | 
|    void AppendData(const void* data, size_t size) {
 | 
|      data_.append(static_cast<const char*>(data), size);
 | 
|    }
 | 
| @@ -122,7 +61,6 @@ class MockChannelReader : public ChannelReader {
 | 
|  
 | 
|   private:
 | 
|    Message* last_dispatched_message_;
 | 
| -  AttachmentBroker* broker_;
 | 
|    std::string data_;
 | 
|  };
 | 
|  
 | 
| @@ -137,52 +75,6 @@ const size_t LargePayloadSize = Channel::kMaximumReadBufferSize * 3 / 2;
 | 
|  
 | 
|  }  // namespace
 | 
|  
 | 
| -#if USE_ATTACHMENT_BROKER
 | 
| -
 | 
| -TEST(ChannelReaderTest, AttachmentAlreadyBrokered) {
 | 
| -  MockAttachmentBroker broker;
 | 
| -  MockChannelReader reader;
 | 
| -  reader.set_broker(&broker);
 | 
| -  scoped_refptr<MockAttachment> attachment(new MockAttachment);
 | 
| -  broker.AddAttachment(attachment);
 | 
| -
 | 
| -  Message* m = new Message;
 | 
| -  PlaceholderBrokerableAttachment* needs_brokering_attachment =
 | 
| -      new PlaceholderBrokerableAttachment(attachment->GetIdentifier());
 | 
| -  EXPECT_TRUE(m->WriteAttachment(needs_brokering_attachment));
 | 
| -  reader.AddMessageForDispatch(m);
 | 
| -  EXPECT_EQ(ChannelReader::DISPATCH_FINISHED, reader.DispatchMessages());
 | 
| -  EXPECT_EQ(m, reader.get_last_dispatched_message());
 | 
| -}
 | 
| -
 | 
| -TEST(ChannelReaderTest, AttachmentNotYetBrokered) {
 | 
| -  std::unique_ptr<base::MessageLoop> message_loop(new base::MessageLoopForIO());
 | 
| -
 | 
| -  MockAttachmentBroker broker;
 | 
| -  MockChannelReader reader;
 | 
| -  reader.set_broker(&broker);
 | 
| -  scoped_refptr<MockAttachment> attachment(new MockAttachment);
 | 
| -
 | 
| -  Message* m = new Message;
 | 
| -  PlaceholderBrokerableAttachment* needs_brokering_attachment =
 | 
| -      new PlaceholderBrokerableAttachment(attachment->GetIdentifier());
 | 
| -  EXPECT_TRUE(m->WriteAttachment(needs_brokering_attachment));
 | 
| -  reader.AddMessageForDispatch(m);
 | 
| -  EXPECT_EQ(ChannelReader::DISPATCH_WAITING_ON_BROKER,
 | 
| -            reader.DispatchMessages());
 | 
| -  EXPECT_EQ(nullptr, reader.get_last_dispatched_message());
 | 
| -
 | 
| -  broker.AddAttachment(attachment);
 | 
| -  base::RunLoop run_loop;
 | 
| -  run_loop.RunUntilIdle();
 | 
| -
 | 
| -  EXPECT_EQ(m, reader.get_last_dispatched_message());
 | 
| -}
 | 
| -
 | 
| -#endif  // USE_ATTACHMENT_BROKER
 | 
| -
 | 
| -#if !USE_ATTACHMENT_BROKER
 | 
| -
 | 
|  // We can determine message size from its header (and hence resize the buffer)
 | 
|  // only when attachment broker is not used, see IPC::Message::FindNext().
 | 
|  
 | 
| @@ -227,8 +119,6 @@ TEST(ChannelReaderTest, InvalidMessageSize) {
 | 
|    EXPECT_LE(reader.input_overflow_buf_.capacity(), capacity_before);
 | 
|  }
 | 
|  
 | 
| -#endif  // !USE_ATTACHMENT_BROKER
 | 
| -
 | 
|  TEST(ChannelReaderTest, TrimBuffer) {
 | 
|    // ChannelReader uses std::string as a buffer, and calls reserve()
 | 
|    // to trim it to kMaximumReadBufferSize. However, an implementation
 | 
| @@ -274,13 +164,9 @@ TEST(ChannelReaderTest, TrimBuffer) {
 | 
|      EXPECT_EQ(ChannelReader::DISPATCH_FINISHED,
 | 
|                reader.ProcessIncomingMessages());
 | 
|  
 | 
| -#if MESSAGE_FINDNEXT_PARTIAL
 | 
|      // We determined message size for the message from its header, so
 | 
|      // we resized the buffer to fit.
 | 
|      EXPECT_GE(reader.input_overflow_buf_.capacity(), message.size());
 | 
| -#else
 | 
| -    // We couldn't determine message size, so we didn't resize the buffer.
 | 
| -#endif
 | 
|  
 | 
|      // Write and process payload
 | 
|      reader.AppendData(message.payload(), message.payload_size());
 | 
| @@ -309,15 +195,9 @@ TEST(ChannelReaderTest, TrimBuffer) {
 | 
|      EXPECT_EQ(ChannelReader::DISPATCH_FINISHED,
 | 
|                reader.ProcessIncomingMessages());
 | 
|  
 | 
| -#if MESSAGE_FINDNEXT_PARTIAL
 | 
|      // We determined message size for the second (partial) message, so
 | 
|      // we resized the buffer to fit.
 | 
|      EXPECT_GE(reader.input_overflow_buf_.capacity(), message1.size());
 | 
| -#else
 | 
| -    // We couldn't determine message size for the second (partial) message,
 | 
| -    // so we trimmed the buffer.
 | 
| -    EXPECT_EQ(reader.input_overflow_buf_.capacity(), trimmed_buffer_size);
 | 
| -#endif
 | 
|    }
 | 
|  
 | 
|    // Buffer resized appropriately if next message is larger than the first.
 | 
| @@ -339,15 +219,9 @@ TEST(ChannelReaderTest, TrimBuffer) {
 | 
|      EXPECT_EQ(ChannelReader::DISPATCH_FINISHED,
 | 
|                reader.ProcessIncomingMessages());
 | 
|  
 | 
| -#if MESSAGE_FINDNEXT_PARTIAL
 | 
|      // We determined message size for the second (partial) message, and
 | 
|      // resized the buffer to fit it.
 | 
|      EXPECT_GE(reader.input_overflow_buf_.capacity(), message2.size());
 | 
| -#else
 | 
| -    // We couldn't determine message size for the second (partial) message,
 | 
| -    // so we trimmed the buffer.
 | 
| -    EXPECT_EQ(reader.input_overflow_buf_.capacity(), trimmed_buffer_size);
 | 
| -#endif
 | 
|    }
 | 
|  
 | 
|    // Buffer is not trimmed if we've just resized it to accommodate large
 | 
| @@ -368,14 +242,9 @@ TEST(ChannelReaderTest, TrimBuffer) {
 | 
|      EXPECT_EQ(ChannelReader::DISPATCH_FINISHED,
 | 
|                reader.ProcessIncomingMessages());
 | 
|  
 | 
| -#if MESSAGE_FINDNEXT_PARTIAL
 | 
|      // We determined message size for the second (partial) message, so
 | 
|      // we resized the buffer to fit.
 | 
|      EXPECT_GE(reader.input_overflow_buf_.capacity(), message2.size());
 | 
| -#else
 | 
| -    // We couldn't determine size for the second (partial) message, and
 | 
| -    // first message was small, so we did nothing.
 | 
| -#endif
 | 
|    }
 | 
|  }
 | 
|  
 | 
| 
 |