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

Side by Side Diff: trunk/src/chrome/browser/spellchecker/feedback_sender_unittest.cc

Issue 23551005: Revert 219709 "Remove the Extensions URLRequestContext." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 3 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 // Unit tests for |FeedbackSender| object. 5 // Unit tests for |FeedbackSender| object.
6 6
7 #include "chrome/browser/spellchecker/feedback_sender.h" 7 #include "chrome/browser/spellchecker/feedback_sender.h"
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/json/json_reader.h" 11 #include "base/json/json_reader.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/metrics/field_trial.h" 13 #include "base/metrics/field_trial.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/metrics/entropy_provider.h" 18 #include "chrome/common/metrics/entropy_provider.h"
19 #include "chrome/common/spellcheck_common.h" 19 #include "chrome/common/spellcheck_common.h"
20 #include "chrome/common/spellcheck_marker.h" 20 #include "chrome/common/spellcheck_marker.h"
21 #include "chrome/common/spellcheck_result.h" 21 #include "chrome/common/spellcheck_result.h"
22 #include "chrome/test/base/testing_profile.h" 22 #include "chrome/test/base/testing_profile.h"
23 #include "content/public/test/test_browser_thread_bundle.h" 23 #include "content/public/test/test_browser_thread.h"
24 #include "net/url_request/test_url_fetcher_factory.h" 24 #include "net/url_request/test_url_fetcher_factory.h"
25 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
26 26
27 namespace spellcheck { 27 namespace spellcheck {
28 28
29 namespace { 29 namespace {
30 30
31 const char kCountry[] = "USA"; 31 const char kCountry[] = "USA";
32 const char kLanguage[] = "en"; 32 const char kLanguage[] = "en";
33 const char kText[] = "Helllo world."; 33 const char kText[] = "Helllo world.";
(...skipping 20 matching lines...) Expand all
54 ++number_of_occurrences; 54 ++number_of_occurrences;
55 } 55 }
56 return number_of_occurrences; 56 return number_of_occurrences;
57 } 57 }
58 58
59 } // namespace 59 } // namespace
60 60
61 // A test fixture to help keep tests simple. 61 // A test fixture to help keep tests simple.
62 class FeedbackSenderTest : public testing::Test { 62 class FeedbackSenderTest : public testing::Test {
63 public: 63 public:
64 FeedbackSenderTest() { 64 FeedbackSenderTest() : ui_thread_(content::BrowserThread::UI, &loop_) {
65 // The command-line switch and the field trial are temporary. 65 // The command-line switch and the field trial are temporary.
66 // TODO(rouslan): Remove the command-line switch and the field trial. 66 // TODO(rouslan): Remove the command-line switch and the field trial.
67 // http://crbug.com/247726 67 // http://crbug.com/247726
68 CommandLine::ForCurrentProcess()->AppendSwitch( 68 CommandLine::ForCurrentProcess()->AppendSwitch(
69 switches::kEnableSpellingServiceFeedback); 69 switches::kEnableSpellingServiceFeedback);
70 field_trial_list_.reset( 70 field_trial_list_.reset(
71 new base::FieldTrialList(new metrics::SHA1EntropyProvider("foo"))); 71 new base::FieldTrialList(new metrics::SHA1EntropyProvider("foo")));
72 field_trial_ = base::FieldTrialList::CreateFieldTrial( 72 field_trial_ = base::FieldTrialList::CreateFieldTrial(
73 kFeedbackFieldTrialName, kFeedbackFieldTrialEnabledGroupName); 73 kFeedbackFieldTrialName, kFeedbackFieldTrialEnabledGroupName);
74 field_trial_->group(); 74 field_trial_->group();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 118
119 std::string GetUploadData() const { 119 std::string GetUploadData() const {
120 const net::TestURLFetcher* fetcher = 120 const net::TestURLFetcher* fetcher =
121 fetchers_.GetFetcherByID(kUrlFetcherId); 121 fetchers_.GetFetcherByID(kUrlFetcherId);
122 return fetcher ? fetcher->upload_data() : std::string(); 122 return fetcher ? fetcher->upload_data() : std::string();
123 } 123 }
124 124
125 scoped_ptr<spellcheck::FeedbackSender> feedback_; 125 scoped_ptr<spellcheck::FeedbackSender> feedback_;
126 126
127 private: 127 private:
128 content::TestBrowserThreadBundle thread_bundle_;
129 TestingProfile profile_; 128 TestingProfile profile_;
129 base::MessageLoop loop_;
130 content::TestBrowserThread ui_thread_;
130 scoped_ptr<base::FieldTrialList> field_trial_list_; 131 scoped_ptr<base::FieldTrialList> field_trial_list_;
131 scoped_refptr<base::FieldTrial> field_trial_; 132 scoped_refptr<base::FieldTrial> field_trial_;
132 net::TestURLFetcherFactory fetchers_; 133 net::TestURLFetcherFactory fetchers_;
133 }; 134 };
134 135
135 // Do not send data if there's no feedback. 136 // Do not send data if there's no feedback.
136 TEST_F(FeedbackSenderTest, NoFeedback) { 137 TEST_F(FeedbackSenderTest, NoFeedback) {
137 EXPECT_FALSE(IsUploadingData()); 138 EXPECT_FALSE(IsUploadingData());
138 feedback_->OnReceiveDocumentMarkers(kRendererProcessId, 139 feedback_->OnReceiveDocumentMarkers(kRendererProcessId,
139 std::vector<uint32>()); 140 std::vector<uint32>());
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 feedback_->OnSpellcheckResults(kRendererProcessId, 518 feedback_->OnSpellcheckResults(kRendererProcessId,
518 UTF8ToUTF16(kText), 519 UTF8ToUTF16(kText),
519 std::vector<SpellCheckMarker>(), 520 std::vector<SpellCheckMarker>(),
520 &results); 521 &results);
521 feedback_->OnReceiveDocumentMarkers(kRendererProcessId, 522 feedback_->OnReceiveDocumentMarkers(kRendererProcessId,
522 std::vector<uint32>()); 523 std::vector<uint32>());
523 EXPECT_FALSE(IsUploadingData()); 524 EXPECT_FALSE(IsUploadingData());
524 } 525 }
525 526
526 } // namespace spellcheck 527 } // namespace spellcheck
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698