Fix IPCChannelMojoErrorTest.SendFailWithPendingMessages

The test has been broken since MojoBootstrap was introduced.
The change makes it impossible to inject failure from the ChannelMojo
subclass.

This change uses large data as pending message to trigger failure,
instead of overloading IPC::ChannelMojo functions.

R=viettrungluu@chromium.org
BUG=417439

Review URL: https://codereview.chromium.org/598093006

Cr-Commit-Position: refs/heads/master@{#296565}


CrOS-Libchrome-Original-Commit: be6c4ccb1377a0ffd5b31ef9b56b70474a126833
diff --git a/ipc/mojo/ipc_channel_mojo_unittest.cc b/ipc/mojo/ipc_channel_mojo_unittest.cc
index 6626747..e1adecd 100644
--- a/ipc/mojo/ipc_channel_mojo_unittest.cc
+++ b/ipc/mojo/ipc_channel_mojo_unittest.cc
@@ -158,52 +158,16 @@
   return 0;
 }
 
-// Close given handle before use to simulate an error.
-class ErraticChannelMojo : public IPC::ChannelMojo {
- public:
-  ErraticChannelMojo(IPC::ChannelMojoHost* host,
-                     const IPC::ChannelHandle& channel_handle,
-                     IPC::Channel::Mode mode,
-                     IPC::Listener* listener,
-                     scoped_refptr<base::TaskRunner> runner)
-      : ChannelMojo(host, channel_handle, mode, listener) {}
-
-  virtual void OnConnected(mojo::ScopedMessagePipeHandle pipe) {
-    MojoClose(pipe.get().value());
-    OnConnected(pipe.Pass());
-  }
-};
-
-// Exists to create ErraticChannelMojo.
-class ErraticChannelFactory : public IPC::ChannelFactory {
- public:
-  explicit ErraticChannelFactory(IPC::ChannelMojoHost* host,
-                                 const IPC::ChannelHandle& handle,
-                                 base::TaskRunner* runner)
-      : host_(host), handle_(handle), runner_(runner) {}
-
-  virtual std::string GetName() const OVERRIDE {
-    return "";
-  }
-
-  virtual scoped_ptr<IPC::Channel> BuildChannel(
-      IPC::Listener* listener) OVERRIDE {
-    return scoped_ptr<IPC::Channel>(new ErraticChannelMojo(
-        host_, handle_, IPC::Channel::MODE_SERVER, listener, runner_));
-  }
-
- private:
-  IPC::ChannelMojoHost* host_;
-  IPC::ChannelHandle handle_;
-  scoped_refptr<base::TaskRunner> runner_;
-};
-
 class ListenerExpectingErrors : public IPC::Listener {
  public:
   ListenerExpectingErrors()
       : has_error_(false) {
   }
 
+  virtual void OnChannelConnected(int32 peer_pid) OVERRIDE {
+    base::MessageLoop::current()->Quit();
+  }
+
   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE {
     return true;
   }
@@ -226,8 +190,7 @@
       const IPC::ChannelHandle& handle,
       base::TaskRunner* runner) OVERRIDE {
     host_.reset(new IPC::ChannelMojoHost(task_runner()));
-    return scoped_ptr<IPC::ChannelFactory>(
-        new ErraticChannelFactory(host_.get(), handle, runner));
+    return IPC::ChannelMojo::CreateServerFactory(host_.get(), handle);
   }
 
   virtual bool DidStartClient() OVERRIDE {
@@ -266,8 +229,7 @@
   return 0;
 }
 
-// https://crbug.com/417439
-TEST_F(IPCChannelMojoErrorTest, DISABLED_SendFailWithPendingMessages) {
+TEST_F(IPCChannelMojoErrorTest, SendFailWithPendingMessages) {
   Init("IPCChannelMojoErraticTestClient");
 
   // Set up IPC channel and start client.
@@ -275,10 +237,13 @@
   CreateChannel(&listener);
   ASSERT_TRUE(ConnectChannel());
 
+  // This matches a value in mojo/system/constants.h
+  const int kMaxMessageNumBytes = 4 * 1024 * 1024;
+  std::string overly_large_data(kMaxMessageNumBytes, '*');
   // This messages are queued as pending.
-  for (size_t i = 0; i < 2; ++i) {
+  for (size_t i = 0; i < 10; ++i) {
     IPC::TestChannelListener::SendOneMessage(
-        sender(), "hello from parent");
+        sender(), overly_large_data.c_str());
   }
 
   ASSERT_TRUE(StartClient());