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

Side by Side Diff: components/spellcheck/browser/feedback_sender_unittest.cc

Issue 2159283003: [WIP][DO NOT LAND] Componentize spellcheck Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
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 "components/spellcheck/browser/feedback_sender.h"
8 8
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <stdint.h> 10 #include <stdint.h>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/json/json_reader.h" 14 #include "base/json/json_reader.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/metrics/field_trial.h" 16 #include "base/metrics/field_trial.h"
17 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "chrome/common/chrome_switches.h" 20 //#include "chrome/common/chrome_switches.h"
21 #include "chrome/common/spellcheck_common.h" 21
22 #include "chrome/common/spellcheck_marker.h" 22 #include "components/spellcheck/common/spellcheck_common.h"
23 #include "chrome/common/spellcheck_result.h" 23 #include "components/spellcheck/common/spellcheck_marker.h"
24 #include "chrome/test/base/testing_profile.h" 24 #include "components/spellcheck/common/spellcheck_result.h"
25 //#include "chrome/test/base/testing_profile.h"
25 #include "components/variations/entropy_provider.h" 26 #include "components/variations/entropy_provider.h"
26 #include "content/public/test/test_browser_thread.h" 27 #include "content/public/test/test_browser_thread.h"
28 #include "content/public/common/content_switches.h"
27 #include "net/url_request/test_url_fetcher_factory.h" 29 #include "net/url_request/test_url_fetcher_factory.h"
28 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
29 31
30 namespace spellcheck { 32 namespace spellcheck {
31 33
32 namespace { 34 namespace {
33 35
34 const char kCountry[] = "USA"; 36 const char kCountry[] = "USA";
35 const char kLanguage[] = "en"; 37 const char kLanguage[] = "en";
36 const char kText[] = "Helllo world."; 38 const char kText[] = "Helllo world.";
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 feedback_->OnSpellcheckResults(kRendererProcessId, 136 feedback_->OnSpellcheckResults(kRendererProcessId,
135 base::UTF8ToUTF16(kText), 137 base::UTF8ToUTF16(kText),
136 std::vector<SpellCheckMarker>(), 138 std::vector<SpellCheckMarker>(),
137 &results); 139 &results);
138 return results[0].hash; 140 return results[0].hash;
139 } 141 }
140 142
141 void ExpireSession() { 143 void ExpireSession() {
142 feedback_->session_start_ = 144 feedback_->session_start_ =
143 base::Time::Now() - 145 base::Time::Now() -
144 base::TimeDelta::FromHours(chrome::spellcheck_common::kSessionHours); 146 base::TimeDelta::FromHours(spellcheck_common::kSessionHours);
145 } 147 }
146 148
147 bool UploadDataContains(const std::string& data) const { 149 bool UploadDataContains(const std::string& data) const {
148 const net::TestURLFetcher* fetcher = 150 const net::TestURLFetcher* fetcher =
149 fetchers_.GetFetcherByID(kUrlFetcherId); 151 fetchers_.GetFetcherByID(kUrlFetcherId);
150 return fetcher && CountOccurences(fetcher->upload_data(), data) > 0; 152 return fetcher && CountOccurences(fetcher->upload_data(), data) > 0;
151 } 153 }
152 154
153 bool UploadDataContains(const std::string& data, 155 bool UploadDataContains(const std::string& data,
154 int number_of_occurrences) const { 156 int number_of_occurrences) const {
(...skipping 20 matching lines...) Expand all
175 } 177 }
176 178
177 void AdjustUpdateTime(base::TimeDelta offset) { 179 void AdjustUpdateTime(base::TimeDelta offset) {
178 feedback_->last_salt_update_ += offset; 180 feedback_->last_salt_update_ += offset;
179 } 181 }
180 182
181 std::unique_ptr<MockFeedbackSender> feedback_; 183 std::unique_ptr<MockFeedbackSender> feedback_;
182 184
183 private: 185 private:
184 base::MessageLoop loop_; 186 base::MessageLoop loop_;
185 TestingProfile profile_; 187 // TestingProfile profile_;
186 content::TestBrowserThread ui_thread_; 188 content::TestBrowserThread ui_thread_;
187 std::unique_ptr<base::FieldTrialList> field_trial_list_; 189 std::unique_ptr<base::FieldTrialList> field_trial_list_;
188 scoped_refptr<base::FieldTrial> field_trial_; 190 scoped_refptr<base::FieldTrial> field_trial_;
189 net::TestURLFetcherFactory fetchers_; 191 net::TestURLFetcherFactory fetchers_;
190 }; 192 };
191 193
192 // Do not send data if there's no feedback. 194 // Do not send data if there's no feedback.
193 TEST_F(FeedbackSenderTest, NoFeedback) { 195 TEST_F(FeedbackSenderTest, NoFeedback) {
194 EXPECT_FALSE(IsUploadingData()); 196 EXPECT_FALSE(IsUploadingData());
195 feedback_->OnReceiveDocumentMarkers(kRendererProcessId, 197 feedback_->OnReceiveDocumentMarkers(kRendererProcessId,
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 "the chance to work hard at work worth doing."), 722 "the chance to work hard at work worth doing."),
721 std::vector<SpellCheckMarker>(), &results); 723 std::vector<SpellCheckMarker>(), &results);
722 feedback_->OnReceiveDocumentMarkers(kRendererProcessId, 724 feedback_->OnReceiveDocumentMarkers(kRendererProcessId,
723 std::vector<uint32_t>()); 725 std::vector<uint32_t>());
724 EXPECT_TRUE( 726 EXPECT_TRUE(
725 UploadDataContains(",\"originalText\":\"and away teh best prize\",")); 727 UploadDataContains(",\"originalText\":\"and away teh best prize\","));
726 EXPECT_TRUE(UploadDataContains(",\"misspelledStart\":9,")); 728 EXPECT_TRUE(UploadDataContains(",\"misspelledStart\":9,"));
727 } 729 }
728 730
729 } // namespace spellcheck 731 } // namespace spellcheck
OLDNEW
« no previous file with comments | « components/spellcheck/browser/feedback_sender.cc ('k') | components/spellcheck/browser/feedback_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698