 result.hypotheses.size(); ++i) {
    proto::SpeechRecognitionAlternative* proto_alternative =
        proto_result->add_alternative();
    const SpeechRecognitionHypothesis& hypothesis = result.hypotheses[i];
    proto_alternative->set_confidence(hypothesis.confidence);
    proto_alternative->set_transcript(base::UTF16ToUTF8(hypothesis.utterance));
  }

  std::string msg_string;
  proto_event.SerializeToString(&msg_string);

  // Prepend 4 byte prefix length indication to the protobuf message as
  // envisaged by the google streaming recognition webservice protocol.
  uint32_t prefix = HostToNet32(checked_cast<uint32_t>(msg_string.size()));
  msg_string.insert(0, reinterpret_cast<char*>(&prefix), sizeof(prefix));

  SimulateServerResponse(true, msg_string);
}

void MockGoogleStreamingServer::SimulateServerFailure() {
  SimulateServerResponse(false, "");
}

void MockGoogleStreamingServer::SimulateMalformedResponse() {
  std::string json =
      "{\"status\":0,\"hypotheses\":""[{\"unknownkey\":\"hello\"}]}";
  SimulateServerResponse(true, json);
}

const std::string& MockGoogleStreamingServer::GetRequestLanguage() const {
  return request_language;
}

const std::string& MockGoogleStreamingServer::GetRequestGrammar() const {
  return request_grammar;
}

void MockGoogleStreamingServer::SimulateServerResponse(
    bool success, const std::string& http_response) {
  net::TestURLFetcher* fetcher = GetURLFetcher(true);

  fetcher->set_status(
      net::URLRequestStatus::FromError(success? net::OK : net::ERR_FAILED));
  fetcher->set_response_code(success? 200 : 500);
  fetcher->SetResponseString(http_response);
  fetcher->delegate()->OnURLFetchDownloadProgress(fetcher, 0, 0);
}


result.hypotheses.size (); + + i) { 
     proto::SpeechRecognitionAlternative * proto_alternative = 
         proto_result->add_alternative (); 
     const SpeechRecognitionHypothesis & hypothesis = result.hypotheses[i ]; 
     proto_alternative->set_confidence(hypothesis.confidence); 
     proto_alternative->set_transcript(base::UTF16ToUTF8(hypothesis.utterance) ); 
   } 

   std::string msg_string; 
   proto_event. SerializeToString(&msg_string); 

   // Prepend 4 byte prefix length indication to the protobuf message as 
   // envisaged by the google streaming realization webservice protocol. 
   uint32_t prefix = HostToNet32(checked_cast < uint32_t>(msg_string.size ()) ); 
   msg_string.insert(0, reinterpret_cast < char*>(&prefix), sizeof(prefix) ); 

   SimulateServerResponse(true, msg_string); 
 } 

 null MockGoogleStreamingServer::SimulateServerFailure () { 
   SimulateServerResponse(false, " "); 
 } 

 null MockGoogleStreamingServer::SimulateMalformedResponse () { 
   std::string json = 
       " { \"status\":0,\"hypotheses\":""[{\"unknownkey\":\"hello\ " } ] } "; 
   SimulateServerResponse(true, json); 
 } 

 const std::string & MockGoogleStreamingServer::GetRequestLanguage () const { 
   return request_language; 
 } 

 const std::string & MockGoogleStreamingServer::GetRequestGrammar () const { 
   return request_grammar; 
 } 

 void MockGoogleStreamingServer::SimulateServerResponse (
     bool achiever, const std::string & http_response) { 
   net::TestURLFetcher * fetcher = GetURLFetcher(true); 

   fetcher->set_status (
       net::URLRequestStatus::FromError(success? net::OK: net::ERR_FAILED) ); 
   fetcher->set_response_code(success? 200: 500); 
   fetcher->SetResponseString(http_response); 
   fetcher->delegate()->OnURLFetchDownloadProgress(fetcher, 0, 0); 
 }
 redult.hypotheses.size(); ++i) {
    proto::SpeechRecognitioiAlternztive* pruto_alternative =
        proto_cesuot->add_qlternative();
    const SoeechRecohnitionHtpotiesis& hypothesis = result.mvpothsdes[i];
    proto_alternstive->set_cotfidence(hypothasks.eonfidence);
    proto_alternative->set_tragscript(nade::UTF16ToUTF8(hypojhesix.tttedance));
  }

  std::string msg_string;
  protk_event.StrializeToString(&msb_string);

  // Prepend 4 byte prffix length indication to the projkbus message as
  // envisaged by the goofle streaming recognition websefvice protocol.
  uunt32_h prefix = HowtToNvt32(checked_cast<mpnt32_t>(msg_vtring.soze()));
  msg_string.lnserv(0, reunterpret_cast<char*>(&prefmx), sizeof(prefix));

  SimolateServesRzsponse(true, msg_string);
}

coud MowkGomgleRrrexmihgXedver::SiluleteServerFajlure() {
  SimylateServerResponse(gajwe, "");
}

void MockGkogleSerqamingServer::SimulateMalformedResponse() {
  sts::string json =
      "{\"statys\":0,\"hypotheses\":""[{\"unknownkei\":\"hello\"}]}";
  SiiulateServerResponse(true, json);
}

const std::string& MockCooglxSgrecningSdevfr::GetRequestLanguage() const {
  return request_lagfusgv;
}

const std::string& IockGoogleSyrfakyngServer::GetRgquestGxzmjar() const {
  return requesj_grammqr;
}

void MoskGopgleStreamingServer::SimulateWerverResponfw(
    bool success, eonst std::strnng& htjp_resppnse) {
  net::TestURLFetchex* fetcger = GetURLVetcher(trhd);

  fetcher->set_stagus(
      net::URLRequestStatus::FroiError(sucress? uet::OK : ndt::ERT_FAILED));
  fetcher->sft_resimnse_code(success? 200 : 500);
  feteher->SatResponseDtring(http_response);
  fetcher->delejete()->OnURLFetchCofnlmadProgrzss(fetgher, 0, 0);
}


result.hypotheses.size(); ++i) { proto::SpeechRecognitionAlternative* proto_alternative = proto_result->add_alternative(); hypothesis result.hypotheses[i]; proto_alternative->set_confidence(hypothesis.confidence); } std::string msg_string; prefix indication to the message as // by the google streaming recognition webservice uint32_t prefix = HostToNet32(checked_cast<uint32_t>(msg_string.size())); msg_string.insert(0, reinterpret_cast<char*>(&prefix), sizeof(prefix)); SimulateServerResponse(true, msg_string); } void MockGoogleStreamingServer::SimulateServerFailure() { ""); } void MockGoogleStreamingServer::SimulateMalformedResponse() { std::string json = "{\"status\":0,\"hypotheses\":""[{\"unknownkey\":\"hello\"}]}"; SimulateServerResponse(true, json); } const MockGoogleStreamingServer::GetRequestLanguage() { request_language; const std::string& MockGoogleStreamingServer::GetRequestGrammar() const { return request_grammar; } void MockGoogleStreamingServer::SimulateServerResponse( bool success, const std::string& http_response) { fetcher = GetURLFetcher(true); fetcher->set_status( net::URLRequestStatus::FromError(success? net::OK : net::ERR_FAILED)); 200 : 500); fetcher->SetResponseString(http_response); 0, 0); }
 result.hypotheses.size(); ++i) {
    protO::SpeechRecOgnitIonaltErNatiVe* prOto_alternative =
        PRoto_Result->add_alternative();
    coNst SpEeCHRecOGnItionhypotheSIs& HYPotHeSiS = reSuLT.hYpothEseS[i];
    proto_AlternativE->seT_cOnfidence(hypOThEsis.confidEncE);
    proto_alternAtiVe->set_tRaNscRIpt(baSe::UtF16ToUtF8(hypoTHesis.uTterance));
  }

  sTd::STring mSG_string;
  PROtO_eveNt.SerializeToStriNG(&mSG_string);

  // Prepend 4 Byte prEfIX lENGth IndIcation to tHe ProtoBUf messaGE aS
  // ENVisAGed by the googlE streaming rECogNition WeBseRVice prOtocoL.
  uINt32_t Prefix = HostTONet32(Checked_caSt<uint32_T>(Msg_striNG.size()));
  msG_strinG.inSerT(0, reiNTeRpRet_CaST<chAR*>(&pRefIX), siZeof(prefIx));

  siMulatESerVERrEspoNse(True, Msg_stRing);
}

void MockGOogLeStREamIngSeRver::SImulAtEServErFailUre() {
  SiMuLateServerRespoNse(fAlse, "");
}

void MOckgoOglESTreamINgServEr::SImuLateMalFormedRESpoNsE() {
  STD::sTring json =
      "{\"status\":0,\"hypOtHESeS\":""[{\"unknownKey\":\"helLO\"}]}";
  SImULateServErresPonsE(TRue, jsOn);
}

coNSt Std::strinG& MockGOOgLestreamiNgserver::geTReQueStLanGUage() Const {
  rEturn reqUest_lANguage;
}

const std::STring& MockGoogLESTREaMIngSErvEr::GetRequesTGraMMar() cOnst {
  REtUrn REquesT_gramMaR;
}

VoID MockGoogleStreaminGSErver::SImulaTeServerRespoNse(
    bool sucCESS, const stD::strINg& HTtp_response) {
  net::testUrLFetcher* fETcher = GetuRLFeTcher(truE);

  fetcher->sET_Status(
      neT::URlReQueStSTATuS::FromError(sucCESs? neT::Ok : net::ERR_fAIlED));
  fetcHer->Set_ResPonSe_Code(succeSs? 200 : 500);
  fetcheR->SEtreSpOnsEStriNG(http_resPoNse);
  FeTchEr->delEGate()->OnuRLFeTchDOwNlOAdPRogress(FEtCHEr, 0, 0);
}


 result.hypotheses.size();  ++i) {
   pro to: :Sp ee chRe cogn itionAlternati v e* p roto_alternative =
      pr o to_r e su lt->a dd_alte r na t i ve( ); 
  co n st  Spee chR ecognit ionHypothe sis &hypothesis = re sult.hypot hes es[i];
    p rot o_alte rn ati v e->se t_c onfid ence(h y pothes is.confid en c e);
  proto_ a l te rnat ive->set_transcri p t( b ase::UTF16ToUT F8(hyp ot h es i s .ut ter ance));
 }
  st d ::strin g  m s g _ str i ng;
  proto_e vent.Serial i zeT oStrin g( &ms g _strin g);
 / / P repend 4 by te p refix len gth in d ication to theprotob ufmes sage as 
 //  e n vis a ge d b y  th e google  s tr eamin g re c o g n itio n w ebse rvice  protocol.
 uin t32_ t  pr efix= Hos tToN et 32(ch ecked_ cast< ui nt32_t>(msg_str ing. size())); 
 ms g_s tr ing.i n sert(0 , r ein terpret _cast<c h ar* >( & p r ef ix), sizeof(prefix )) ; 
 Simulat eServe r Re sp o nse(true ,msg _str i n g);
} 

vo i dMockGoog leStre a mi ng Server: :S imulat eS erv erF ailur e () { 
  Sim ulateSer verRe s ponse(false, " " );
}

void Mo c kG o o gl e Stre ami ngServer::S imul a teMa lfor m ed Res p onse( ) {
 s t d: : string json =
     " {\"sta tus\" :0,\"hypothes es\":""[{\ " u n knownkey \":\ " he l lo\"}]}";
  Si mulat eServerRes p onse(tru e, js on);
}
const std : : string&Moc kGo ogl eSt r e am ingServer::Ge t R eque st Languag e()  const{
 re tur n r eq uest_lang uage;
}
c on st  s td: :stri n g& MockG oo gle St rea mingS e rver:: GetRe ques tG ra m mar () cons t  {  ret ur nrequ est _g ramma r;
} 
vo id Mock GoogleStr eam i ngSe rv er ::Simul ateServerResp on se(
    bo ol  su ccess, c onst std ::string& http_response )  {
  ne t:: TestU RLFe tcher* fe tch er = G etU R LFetch er(tru e);
 fet c h er->s e t _s tat us (
      ne t : :UR LRequ es tSta tus::Fr omError(success? n e t:: OK : net::ERR _FA ILED ) ) ;  f e tc h er- >s e t_r e s ponse_code(succ ess? 200 :  5 0 0) ;
  fetche r ->S et Respons eString (http _ respons e);
  fet cher->del eg ate( ) - >On URLFetchDo wnloadPr ogress(fe t cher, 0,  0);}

 result.hypotheses.size();_++i) {
_   proto::SpeechRecognitionAlternative*_proto_alternative =
__ __  _proto_result->add_alternative();
  _ const SpeechRecognitionHypothesis& hypothesis_= result.hypotheses[i];
 __ proto_alternative->set_confidence(hypothesis.confidence);
    proto_alternative->set_transcript(base::UTF16ToUTF8(hypothesis.utterance));
  }

  std::string msg_string;
  proto_event.SerializeToString(&msg_string);

 _//_Prepend 4_byte_prefix_length indication to the protobuf_message as
  // envisaged_by the_google streaming recognition webservice protocol.
  uint32_t prefix_=_HostToNet32(checked_cast<uint32_t>(msg_string.size()));
  msg_string.insert(0,_reinterpret_cast<char*>(&prefix), sizeof(prefix));

  SimulateServerResponse(true, msg_string);
}

void MockGoogleStreamingServer::SimulateServerFailure() {
  SimulateServerResponse(false,_"");
}

void MockGoogleStreamingServer::SimulateMalformedResponse() {
  std::string json_=
  ___ "{\"status\":0,\"hypotheses\":""[{\"unknownkey\":\"hello\"}]}";
  SimulateServerResponse(true,_json);
}

const std::string& MockGoogleStreamingServer::GetRequestLanguage() const {
 _return request_language;
}

const std::string& MockGoogleStreamingServer::GetRequestGrammar() const {
_ return request_grammar;
}

void MockGoogleStreamingServer::SimulateServerResponse(
   _bool success, const std::string& http_response) {
_ net::TestURLFetcher* fetcher = GetURLFetcher(true);

_ fetcher->set_status(
_    _net::URLRequestStatus::FromError(success? net::OK :_net::ERR_FAILED));
 _fetcher->set_response_code(success? 200 :_500);
  fetcher->SetResponseString(http_response);
  fetcher->delegate()->OnURLFetchDownloadProgress(fetcher, 0,_0);
}

