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

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

Issue 7524033: Add a scoper object for URLFetcher::Factory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years, 4 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) 2011 The Chromium Authors. All rights reserved. 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 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/utf_string_conversions.h" 5 #include "base/utf_string_conversions.h"
6 #include "content/browser/speech/speech_recognition_request.h" 6 #include "content/browser/speech/speech_recognition_request.h"
7 #include "content/common/test_url_fetcher_factory.h" 7 #include "content/test/test_url_fetcher_factory.h"
8 #include "net/url_request/url_request_context_getter.h" 8 #include "net/url_request/url_request_context_getter.h"
9 #include "net/url_request/url_request_status.h" 9 #include "net/url_request/url_request_status.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 namespace speech_input { 12 namespace speech_input {
13 13
14 class SpeechRecognitionRequestTest : public SpeechRecognitionRequestDelegate, 14 class SpeechRecognitionRequestTest : public SpeechRecognitionRequestDelegate,
15 public testing::Test { 15 public testing::Test {
16 public: 16 public:
17 SpeechRecognitionRequestTest() : error_(false) { } 17 SpeechRecognitionRequestTest() : error_(false) { }
18 18
19 // Creates a speech recognition request and invokes it's URL fetcher delegate 19 // Creates a speech recognition request and invokes it's URL fetcher delegate
20 // with the given test data. 20 // with the given test data.
21 void CreateAndTestRequest(bool success, const std::string& http_response); 21 void CreateAndTestRequest(bool success, const std::string& http_response);
22 22
23 // SpeechRecognitionRequestDelegate methods. 23 // SpeechRecognitionRequestDelegate methods.
24 virtual void SetRecognitionResult(bool error, 24 virtual void SetRecognitionResult(bool error,
25 const SpeechInputResultArray& result) { 25 const SpeechInputResultArray& result) {
26 error_ = error; 26 error_ = error;
27 result_ = result; 27 result_ = result;
28 } 28 }
29 29
30 // testing::Test methods.
31 virtual void SetUp() {
32 URLFetcher::set_factory(&url_fetcher_factory_);
33 }
34
35 virtual void TearDown() {
36 URLFetcher::set_factory(NULL);
37 }
38
39 protected: 30 protected:
40 MessageLoop message_loop_; 31 MessageLoop message_loop_;
41 TestURLFetcherFactory url_fetcher_factory_; 32 TestURLFetcherFactory url_fetcher_factory_;
42 bool error_; 33 bool error_;
43 SpeechInputResultArray result_; 34 SpeechInputResultArray result_;
44 }; 35 };
45 36
46 void SpeechRecognitionRequestTest::CreateAndTestRequest( 37 void SpeechRecognitionRequestTest::CreateAndTestRequest(
47 bool success, const std::string& http_response) { 38 bool success, const std::string& http_response) {
48 SpeechRecognitionRequest request(NULL, this); 39 SpeechRecognitionRequest request(NULL, this);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 EXPECT_TRUE(error_); 81 EXPECT_TRUE(error_);
91 EXPECT_EQ(0U, result_.size()); 82 EXPECT_EQ(0U, result_.size());
92 83
93 // Malformed JSON case. 84 // Malformed JSON case.
94 CreateAndTestRequest(true, "{\"hypotheses\":[{\"unknownkey\":\"hello\"}]}"); 85 CreateAndTestRequest(true, "{\"hypotheses\":[{\"unknownkey\":\"hello\"}]}");
95 EXPECT_TRUE(error_); 86 EXPECT_TRUE(error_);
96 EXPECT_EQ(0U, result_.size()); 87 EXPECT_EQ(0U, result_.size());
97 } 88 }
98 89
99 } // namespace speech_input 90 } // namespace speech_input
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698