| OLD | NEW |
| 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 "components/spellcheck/browser/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/memory/ptr_util.h" |
| 15 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 16 #include "base/metrics/field_trial.h" | 17 #include "base/metrics/field_trial.h" |
| 17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/values.h" | 20 #include "base/values.h" |
| 20 #include "components/spellcheck/common/spellcheck_common.h" | 21 #include "components/spellcheck/common/spellcheck_common.h" |
| 21 #include "components/spellcheck/common/spellcheck_marker.h" | 22 #include "components/spellcheck/common/spellcheck_marker.h" |
| 22 #include "components/spellcheck/common/spellcheck_result.h" | 23 #include "components/spellcheck/common/spellcheck_result.h" |
| 23 #include "components/spellcheck/common/spellcheck_switches.h" | 24 #include "components/spellcheck/common/spellcheck_switches.h" |
| 24 #include "components/variations/entropy_provider.h" | 25 #include "components/variations/entropy_provider.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 spellcheck::switches::kEnableSpellingFeedbackFieldTrial); | 114 spellcheck::switches::kEnableSpellingFeedbackFieldTrial); |
| 114 feedback_.reset(new MockFeedbackSender(NULL, kLanguage, kCountry)); | 115 feedback_.reset(new MockFeedbackSender(NULL, kLanguage, kCountry)); |
| 115 feedback_->StartFeedbackCollection(); | 116 feedback_->StartFeedbackCollection(); |
| 116 } | 117 } |
| 117 | 118 |
| 118 // Enables the "SpellingServiceFeedback.Enabled" field trial. | 119 // Enables the "SpellingServiceFeedback.Enabled" field trial. |
| 119 void EnableFieldTrial() { | 120 void EnableFieldTrial() { |
| 120 // The field trial is temporary. | 121 // The field trial is temporary. |
| 121 // TODO(rouslan): Remove the field trial. http://crbug.com/247726 | 122 // TODO(rouslan): Remove the field trial. http://crbug.com/247726 |
| 122 field_trial_list_.reset( | 123 field_trial_list_.reset( |
| 123 new base::FieldTrialList(new metrics::SHA1EntropyProvider("foo"))); | 124 new base::FieldTrialList( |
| 125 base::MakeUnique<metrics::SHA1EntropyProvider>("foo"))); |
| 124 field_trial_ = base::FieldTrialList::CreateFieldTrial( | 126 field_trial_ = base::FieldTrialList::CreateFieldTrial( |
| 125 kFeedbackFieldTrialName, kFeedbackFieldTrialEnabledGroupName); | 127 kFeedbackFieldTrialName, kFeedbackFieldTrialEnabledGroupName); |
| 126 field_trial_->group(); | 128 field_trial_->group(); |
| 127 feedback_.reset(new MockFeedbackSender(NULL, kLanguage, kCountry)); | 129 feedback_.reset(new MockFeedbackSender(NULL, kLanguage, kCountry)); |
| 128 feedback_->StartFeedbackCollection(); | 130 feedback_->StartFeedbackCollection(); |
| 129 } | 131 } |
| 130 | 132 |
| 131 uint32_t AddPendingFeedback() { | 133 uint32_t AddPendingFeedback() { |
| 132 std::vector<SpellCheckResult> results(1, BuildSpellCheckResult()); | 134 std::vector<SpellCheckResult> results(1, BuildSpellCheckResult()); |
| 133 feedback_->OnSpellcheckResults(kRendererProcessId, | 135 feedback_->OnSpellcheckResults(kRendererProcessId, |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 "the chance to work hard at work worth doing."), | 720 "the chance to work hard at work worth doing."), |
| 719 std::vector<SpellCheckMarker>(), &results); | 721 std::vector<SpellCheckMarker>(), &results); |
| 720 feedback_->OnReceiveDocumentMarkers(kRendererProcessId, | 722 feedback_->OnReceiveDocumentMarkers(kRendererProcessId, |
| 721 std::vector<uint32_t>()); | 723 std::vector<uint32_t>()); |
| 722 EXPECT_TRUE( | 724 EXPECT_TRUE( |
| 723 UploadDataContains(",\"originalText\":\"and away teh best prize\",")); | 725 UploadDataContains(",\"originalText\":\"and away teh best prize\",")); |
| 724 EXPECT_TRUE(UploadDataContains(",\"misspelledStart\":9,")); | 726 EXPECT_TRUE(UploadDataContains(",\"misspelledStart\":9,")); |
| 725 } | 727 } |
| 726 | 728 |
| 727 } // namespace spellcheck | 729 } // namespace spellcheck |
| OLD | NEW |