Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: content/browser/speech/google_one_shot_remote_engine_unittest.cc

Issue 10581012: Move test_url_fetcher_factory.* from content/ to net/url_request (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove export annotations Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/message_loop.h" 5 #include "base/message_loop.h"
6 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "content/browser/speech/audio_buffer.h" 7 #include "content/browser/speech/audio_buffer.h"
8 #include "content/browser/speech/google_one_shot_remote_engine.h" 8 #include "content/browser/speech/google_one_shot_remote_engine.h"
9 #include "content/public/common/speech_recognition_error.h" 9 #include "content/public/common/speech_recognition_error.h"
10 #include "content/public/common/speech_recognition_result.h" 10 #include "content/public/common/speech_recognition_result.h"
11 #include "content/public/test/test_url_fetcher_factory.h" 11 #include "net/url_request/test_url_fetcher_factory.h"
12 #include "net/url_request/url_request_context_getter.h" 12 #include "net/url_request/url_request_context_getter.h"
13 #include "net/url_request/url_request_status.h" 13 #include "net/url_request/url_request_status.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 namespace speech { 16 namespace speech {
17 17
18 class GoogleOneShotRemoteEngineTest 18 class GoogleOneShotRemoteEngineTest
19 : public SpeechRecognitionEngineDelegate, 19 : public SpeechRecognitionEngineDelegate,
20 public testing::Test { 20 public testing::Test {
21 public: 21 public:
(...skipping 10 matching lines...) Expand all
32 result_ = result; 32 result_ = result;
33 } 33 }
34 34
35 virtual void OnSpeechRecognitionEngineError( 35 virtual void OnSpeechRecognitionEngineError(
36 const content::SpeechRecognitionError& error) OVERRIDE { 36 const content::SpeechRecognitionError& error) OVERRIDE {
37 error_ = error.code; 37 error_ = error.code;
38 } 38 }
39 39
40 protected: 40 protected:
41 MessageLoop message_loop_; 41 MessageLoop message_loop_;
42 TestURLFetcherFactory url_fetcher_factory_; 42 net::TestURLFetcherFactory url_fetcher_factory_;
43 content::SpeechRecognitionErrorCode error_; 43 content::SpeechRecognitionErrorCode error_;
44 content::SpeechRecognitionResult result_; 44 content::SpeechRecognitionResult result_;
45 }; 45 };
46 46
47 void GoogleOneShotRemoteEngineTest::CreateAndTestRequest( 47 void GoogleOneShotRemoteEngineTest::CreateAndTestRequest(
48 bool success, const std::string& http_response) { 48 bool success, const std::string& http_response) {
49 GoogleOneShotRemoteEngine client(NULL); 49 GoogleOneShotRemoteEngine client(NULL);
50 unsigned char dummy_audio_buffer_data[2] = {'\0', '\0'}; 50 unsigned char dummy_audio_buffer_data[2] = {'\0', '\0'};
51 scoped_refptr<AudioChunk> dummy_audio_chunk( 51 scoped_refptr<AudioChunk> dummy_audio_chunk(
52 new AudioChunk(&dummy_audio_buffer_data[0], 52 new AudioChunk(&dummy_audio_buffer_data[0],
53 sizeof(dummy_audio_buffer_data), 53 sizeof(dummy_audio_buffer_data),
54 2 /* bytes per sample */)); 54 2 /* bytes per sample */));
55 client.set_delegate(this); 55 client.set_delegate(this);
56 client.StartRecognition(); 56 client.StartRecognition();
57 client.TakeAudioChunk(*dummy_audio_chunk); 57 client.TakeAudioChunk(*dummy_audio_chunk);
58 client.AudioChunksEnded(); 58 client.AudioChunksEnded();
59 TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0); 59 net::TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
60 ASSERT_TRUE(fetcher); 60 ASSERT_TRUE(fetcher);
61 61
62 fetcher->set_url(fetcher->GetOriginalURL()); 62 fetcher->set_url(fetcher->GetOriginalURL());
63 net::URLRequestStatus status; 63 net::URLRequestStatus status;
64 status.set_status(success ? net::URLRequestStatus::SUCCESS : 64 status.set_status(success ? net::URLRequestStatus::SUCCESS :
65 net::URLRequestStatus::FAILED); 65 net::URLRequestStatus::FAILED);
66 fetcher->set_status(status); 66 fetcher->set_status(status);
67 fetcher->set_response_code(success ? 200 : 500); 67 fetcher->set_response_code(success ? 200 : 500);
68 fetcher->SetResponseString(http_response); 68 fetcher->SetResponseString(http_response);
69 69
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 EXPECT_EQ(0U, result_.hypotheses.size()); 114 EXPECT_EQ(0U, result_.hypotheses.size());
115 115
116 // Malformed JSON case. 116 // Malformed JSON case.
117 CreateAndTestRequest(true, "{\"status\":0,\"hypotheses\":" 117 CreateAndTestRequest(true, "{\"status\":0,\"hypotheses\":"
118 "[{\"unknownkey\":\"hello\"}]}"); 118 "[{\"unknownkey\":\"hello\"}]}");
119 EXPECT_EQ(error_, content::SPEECH_RECOGNITION_ERROR_NETWORK); 119 EXPECT_EQ(error_, content::SPEECH_RECOGNITION_ERROR_NETWORK);
120 EXPECT_EQ(0U, result_.hypotheses.size()); 120 EXPECT_EQ(0U, result_.hypotheses.size());
121 } 121 }
122 122
123 } // namespace speech 123 } // namespace speech
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698