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

Side by Side Diff: chrome/browser/ui/search_engines/keyword_editor_controller_unittest.cc

Issue 9834056: Moved WebDataService to ProfileKeyedService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: removed unchanged file Created 8 years, 9 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/message_loop.h" 5 #include "base/message_loop.h"
6 #include "base/string16.h" 6 #include "base/string16.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/search_engines/template_url.h" 9 #include "chrome/browser/search_engines/template_url.h"
10 #include "chrome/browser/search_engines/template_url_service.h" 10 #include "chrome/browser/search_engines/template_url_service.h"
11 #include "chrome/browser/search_engines/template_url_service_factory.h" 11 #include "chrome/browser/search_engines/template_url_service_factory.h"
12 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h" 12 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h"
13 #include "chrome/browser/ui/search_engines/template_url_table_model.h" 13 #include "chrome/browser/ui/search_engines/template_url_table_model.h"
14 #include "chrome/browser/webdata/web_data_service_factory.h"
14 #include "chrome/common/chrome_notification_types.h" 15 #include "chrome/common/chrome_notification_types.h"
15 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
16 #include "chrome/test/base/testing_pref_service.h" 17 #include "chrome/test/base/testing_pref_service.h"
17 #include "chrome/test/base/testing_profile.h" 18 #include "chrome/test/base/testing_profile.h"
18 #include "content/public/browser/notification_details.h" 19 #include "content/public/browser/notification_details.h"
19 #include "content/public/browser/notification_source.h" 20 #include "content/public/browser/notification_source.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 #include "ui/base/models/table_model_observer.h" 22 #include "ui/base/models/table_model_observer.h"
22 23
23 static const string16 kA(ASCIIToUTF16("a")); 24 static const string16 kA(ASCIIToUTF16("a"));
24 static const string16 kA1(ASCIIToUTF16("a1")); 25 static const string16 kA1(ASCIIToUTF16("a1"));
25 static const string16 kB(ASCIIToUTF16("b")); 26 static const string16 kB(ASCIIToUTF16("b"));
26 static const string16 kB1(ASCIIToUTF16("b1")); 27 static const string16 kB1(ASCIIToUTF16("b1"));
27 28
28 // Base class for keyword editor tests. Creates a profile containing an 29 // Base class for keyword editor tests. Creates a profile containing an
29 // empty TemplateURLService. 30 // empty TemplateURLService.
30 class KeywordEditorControllerTest : public testing::Test, 31 class KeywordEditorControllerTest : public testing::Test,
31 public ui::TableModelObserver { 32 public ui::TableModelObserver {
32 public: 33 public:
34 KeywordEditorControllerTest() {}
35
33 // Initializes all of the state. 36 // Initializes all of the state.
34 void Init(bool simulate_load_failure); 37 void Init(bool simulate_load_failure);
35 38
36 virtual void SetUp() { 39 virtual void SetUp() {
37 Init(false); 40 Init(false);
38 } 41 }
39 42
40 virtual void OnModelChanged() { 43 virtual void OnModelChanged() {
41 model_changed_count_++; 44 model_changed_count_++;
42 } 45 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 model_->Observe( 90 model_->Observe(
88 chrome::NOTIFICATION_PREF_CHANGED, 91 chrome::NOTIFICATION_PREF_CHANGED,
89 content::Source<PrefService>(profile_->GetTestingPrefService()), 92 content::Source<PrefService>(profile_->GetTestingPrefService()),
90 content::Details<std::string>(NULL)); 93 content::Details<std::string>(NULL));
91 } 94 }
92 95
93 TemplateURLTableModel* table_model() const { 96 TemplateURLTableModel* table_model() const {
94 return controller_->table_model(); 97 return controller_->table_model();
95 } 98 }
96 99
100 // Build no service.
101 static scoped_refptr<RefcountedProfileKeyedService> BuildNull(
102 Profile* profile) {
103 return NULL;
104 }
105
97 protected: 106 protected:
98 MessageLoopForUI message_loop_; 107 MessageLoopForUI message_loop_;
99 scoped_ptr<TestingProfile> profile_; 108 scoped_ptr<TestingProfile> profile_;
100 scoped_ptr<KeywordEditorController> controller_; 109 scoped_ptr<KeywordEditorController> controller_;
101 TemplateURLService* model_; 110 TemplateURLService* model_;
102 111
103 int model_changed_count_; 112 int model_changed_count_;
104 int items_changed_count_; 113 int items_changed_count_;
105 int added_count_; 114 int added_count_;
106 int removed_count_; 115 int removed_count_;
107 }; 116 };
108 117
109 void KeywordEditorControllerTest::Init(bool simulate_load_failure) { 118 void KeywordEditorControllerTest::Init(bool simulate_load_failure) {
110 ClearChangeCount(); 119 ClearChangeCount();
111 120
112 // If init is called twice, make sure that the controller is destroyed before 121 // If init is called twice, make sure that the controller is destroyed before
113 // the profile is. 122 // the profile is.
114 controller_.reset(); 123 controller_.reset();
115 profile_.reset(new TestingProfile()); 124 profile_.reset(new TestingProfile());
116 profile_->CreateTemplateURLService(); 125 profile_->CreateTemplateURLService();
117 126
127 WebDataServiceFactory::GetInstance()->SetTestingFactory(
128 profile_.get(), KeywordEditorControllerTest::BuildNull);
129
118 model_ = TemplateURLServiceFactory::GetForProfile(profile_.get()); 130 model_ = TemplateURLServiceFactory::GetForProfile(profile_.get());
119 if (simulate_load_failure) 131 if (simulate_load_failure)
120 model_->OnWebDataServiceRequestDone(0, NULL); 132 model_->OnWebDataServiceRequestDone(0, NULL);
121 133
122 controller_.reset(new KeywordEditorController(profile_.get())); 134 controller_.reset(new KeywordEditorController(profile_.get()));
123 controller_->table_model()->SetObserver(this); 135 controller_->table_model()->SetObserver(this);
124 } 136 }
125 137
126 // Tests adding a TemplateURL. 138 // Tests adding a TemplateURL.
127 TEST_F(KeywordEditorControllerTest, Add) { 139 TEST_F(KeywordEditorControllerTest, Add) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 turl->set_short_name(ASCIIToUTF16("b")); 264 turl->set_short_name(ASCIIToUTF16("b"));
253 model_->Add(turl); 265 model_->Add(turl);
254 266
255 // Table model should have updated. 267 // Table model should have updated.
256 VerifyChangeCount(1, 0, 0, 0); 268 VerifyChangeCount(1, 0, 0, 0);
257 269
258 // And should contain the newly added TemplateURL. 270 // And should contain the newly added TemplateURL.
259 ASSERT_EQ(1, table_model()->RowCount()); 271 ASSERT_EQ(1, table_model()->RowCount());
260 ASSERT_EQ(0, table_model()->IndexOfTemplateURL(turl)); 272 ASSERT_EQ(0, table_model()->IndexOfTemplateURL(turl));
261 } 273 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698