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

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

Issue 12546016: Remove the Extensions URLRequestContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: compile gdi. Created 7 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) 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 #include <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/metrics/field_trial.h" 12 #include "base/metrics/field_trial.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/spellchecker/feedback_sender.h" 16 #include "chrome/browser/spellchecker/feedback_sender.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.h" 23 #include "content/public/test/test_browser_thread_bundle.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 static const int kMisspellingLength = 6; 31 static const int kMisspellingLength = 6;
32 static const int kMisspellingStart = 0; 32 static const int kMisspellingStart = 0;
33 static const int kRendererProcessId = 0; 33 static const int kRendererProcessId = 0;
(...skipping 18 matching lines...) Expand all
52 pos = haystack.find(needle, pos + needle.length())) { 52 pos = haystack.find(needle, pos + needle.length())) {
53 ++number_of_occurrences; 53 ++number_of_occurrences;
54 } 54 }
55 return number_of_occurrences; 55 return number_of_occurrences;
56 } 56 }
57 57
58 } // namespace 58 } // namespace
59 59
60 class FeedbackSenderTest : public testing::Test { 60 class FeedbackSenderTest : public testing::Test {
61 public: 61 public:
62 FeedbackSenderTest() : ui_thread_(content::BrowserThread::UI, &loop_) { 62 FeedbackSenderTest() {
63 63
64 // The command-line switch and the field trial are temporary. 64 // The command-line switch and the field trial are temporary.
65 // TODO(rouslan): Remove the command-line switch and the field trial. 65 // TODO(rouslan): Remove the command-line switch and the field trial.
66 // http://crbug.com/247726 66 // http://crbug.com/247726
67 CommandLine::ForCurrentProcess()->AppendSwitch( 67 CommandLine::ForCurrentProcess()->AppendSwitch(
68 switches::kEnableSpellingServiceFeedback); 68 switches::kEnableSpellingServiceFeedback);
69 field_trial_list_.reset( 69 field_trial_list_.reset(
70 new base::FieldTrialList(new metrics::SHA1EntropyProvider("foo"))); 70 new base::FieldTrialList(new metrics::SHA1EntropyProvider("foo")));
71 field_trial_ = base::FieldTrialList::CreateFieldTrial( 71 field_trial_ = base::FieldTrialList::CreateFieldTrial(
72 kFeedbackFieldTrialName, kFeedbackFieldTrialEnabledGroupName); 72 kFeedbackFieldTrialName, kFeedbackFieldTrialEnabledGroupName);
73 field_trial_->group(); 73 field_trial_->group();
74 74
75 feedback_.reset(new FeedbackSender(NULL, kLanguage, kCountry)); 75 feedback_.reset(new FeedbackSender(NULL, kLanguage, kCountry));
76 } 76 }
77 virtual ~FeedbackSenderTest() {} 77 virtual ~FeedbackSenderTest() {}
78 78
79 private: 79 private:
80 content::TestBrowserThreadBundle thread_bundle_;
80 TestingProfile profile_; 81 TestingProfile profile_;
81 base::MessageLoop loop_;
82 content::TestBrowserThread ui_thread_;
83 scoped_ptr<base::FieldTrialList> field_trial_list_; 82 scoped_ptr<base::FieldTrialList> field_trial_list_;
84 scoped_refptr<base::FieldTrial> field_trial_; 83 scoped_refptr<base::FieldTrial> field_trial_;
85 net::TestURLFetcherFactory fetchers_; 84 net::TestURLFetcherFactory fetchers_;
86 85
87 protected: 86 protected:
88 uint32 AddPendingFeedback() { 87 uint32 AddPendingFeedback() {
89 std::vector<SpellCheckResult> results(1, BuildSpellCheckResult()); 88 std::vector<SpellCheckResult> results(1, BuildSpellCheckResult());
90 feedback_->OnSpellcheckResults( 89 feedback_->OnSpellcheckResults(
91 &results, kRendererProcessId, kText, std::vector<SpellCheckMarker>()); 90 &results, kRendererProcessId, kText, std::vector<SpellCheckMarker>());
92 return results[0].hash; 91 return results[0].hash;
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 uint32 select_hash = AddPendingFeedback(); 488 uint32 select_hash = AddPendingFeedback();
490 feedback_->SelectedSuggestion(select_hash, 0); 489 feedback_->SelectedSuggestion(select_hash, 0);
491 feedback_->AddedToDictionary(add_to_dict_hash); 490 feedback_->AddedToDictionary(add_to_dict_hash);
492 feedback_->OnReceiveDocumentMarkers(kRendererProcessId, 491 feedback_->OnReceiveDocumentMarkers(kRendererProcessId,
493 std::vector<uint32>()); 492 std::vector<uint32>());
494 EXPECT_TRUE(UploadDataContains("SELECT", 1)); 493 EXPECT_TRUE(UploadDataContains("SELECT", 1));
495 EXPECT_TRUE(UploadDataContains("ADD_TO_DICT", 2)); 494 EXPECT_TRUE(UploadDataContains("ADD_TO_DICT", 2));
496 } 495 }
497 496
498 } // namespace spellcheck 497 } // namespace spellcheck
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698