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

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: Addressed comments, fixed bug Created 8 years, 8 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() {}
Peter Kasting 2012/03/30 20:31:13 Nit: It would be nice while here to move these inl
GeorgeY 2012/04/02 21:57:43 Sure
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 111
109 void KeywordEditorControllerTest::Init(bool simulate_load_failure) { 112 void KeywordEditorControllerTest::Init(bool simulate_load_failure) {
110 ClearChangeCount(); 113 ClearChangeCount();
111 114
112 // If init is called twice, make sure that the controller is destroyed before 115 // If init is called twice, make sure that the controller is destroyed before
113 // the profile is. 116 // the profile is.
114 controller_.reset(); 117 controller_.reset();
115 profile_.reset(new TestingProfile()); 118 profile_.reset(new TestingProfile());
116 profile_->CreateTemplateURLService(); 119 profile_->CreateTemplateURLService();
117 120
121 WebDataServiceFactory::GetInstance()->SetTestingFactory(profile_.get(), NULL);
122
118 model_ = TemplateURLServiceFactory::GetForProfile(profile_.get()); 123 model_ = TemplateURLServiceFactory::GetForProfile(profile_.get());
119 if (simulate_load_failure) 124 if (simulate_load_failure)
120 model_->OnWebDataServiceRequestDone(0, NULL); 125 model_->OnWebDataServiceRequestDone(0, NULL);
121 126
122 controller_.reset(new KeywordEditorController(profile_.get())); 127 controller_.reset(new KeywordEditorController(profile_.get()));
123 controller_->table_model()->SetObserver(this); 128 controller_->table_model()->SetObserver(this);
124 } 129 }
125 130
126 // Tests adding a TemplateURL. 131 // Tests adding a TemplateURL.
127 TEST_F(KeywordEditorControllerTest, Add) { 132 TEST_F(KeywordEditorControllerTest, Add) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 turl->set_short_name(ASCIIToUTF16("b")); 257 turl->set_short_name(ASCIIToUTF16("b"));
253 model_->Add(turl); 258 model_->Add(turl);
254 259
255 // Table model should have updated. 260 // Table model should have updated.
256 VerifyChangeCount(1, 0, 0, 0); 261 VerifyChangeCount(1, 0, 0, 0);
257 262
258 // And should contain the newly added TemplateURL. 263 // And should contain the newly added TemplateURL.
259 ASSERT_EQ(1, table_model()->RowCount()); 264 ASSERT_EQ(1, table_model()->RowCount());
260 ASSERT_EQ(0, table_model()->IndexOfTemplateURL(turl)); 265 ASSERT_EQ(0, table_model()->IndexOfTemplateURL(turl));
261 } 266 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698