OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/compiler_specific.h" | 5 #include "base/compiler_specific.h" |
6 #include "base/memory/ptr_util.h" | 6 #include "base/memory/ptr_util.h" |
7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/search_engines/template_url_service_factory_test_util.h
" | 10 #include "chrome/browser/search_engines/template_url_service_factory_test_util.h
" |
| 11 #include "chrome/browser/search_engines/template_url_service_test_util.h" |
11 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h" | 12 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h" |
12 #include "chrome/browser/ui/search_engines/template_url_table_model.h" | 13 #include "chrome/browser/ui/search_engines/template_url_table_model.h" |
13 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
14 #include "components/search_engines/template_url.h" | 15 #include "components/search_engines/template_url.h" |
| 16 #include "components/search_engines/template_url_data.h" |
15 #include "components/search_engines/template_url_service.h" | 17 #include "components/search_engines/template_url_service.h" |
16 #include "components/sync_preferences/testing_pref_service_syncable.h" | 18 #include "components/sync_preferences/testing_pref_service_syncable.h" |
17 #include "content/public/test/test_browser_thread_bundle.h" | 19 #include "content/public/test/test_browser_thread_bundle.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "ui/base/models/table_model_observer.h" | 21 #include "ui/base/models/table_model_observer.h" |
20 | 22 |
21 using base::ASCIIToUTF16; | 23 using base::ASCIIToUTF16; |
22 | 24 |
23 static const base::string16 kA(ASCIIToUTF16("a")); | 25 static const base::string16 kA(ASCIIToUTF16("a")); |
24 static const base::string16 kA1(ASCIIToUTF16("a1")); | 26 static const base::string16 kA1(ASCIIToUTF16("a1")); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 ASSERT_EQ(removed_count, removed_count_); | 78 ASSERT_EQ(removed_count, removed_count_); |
77 ClearChangeCount(); | 79 ClearChangeCount(); |
78 } | 80 } |
79 | 81 |
80 void ClearChangeCount() { | 82 void ClearChangeCount() { |
81 model_changed_count_ = items_changed_count_ = added_count_ = | 83 model_changed_count_ = items_changed_count_ = added_count_ = |
82 removed_count_ = 0; | 84 removed_count_ = 0; |
83 } | 85 } |
84 | 86 |
85 void SimulateDefaultSearchIsManaged(const std::string& url) { | 87 void SimulateDefaultSearchIsManaged(const std::string& url) { |
86 util_.SetManagedDefaultSearchPreferences(true, | 88 TemplateURLData managed_engine; |
87 "managed", | 89 managed_engine.SetShortName(ASCIIToUTF16("managed")); |
88 "managed", | 90 managed_engine.SetKeyword(ASCIIToUTF16("managed")); |
89 url, | 91 managed_engine.SetURL(url); |
90 std::string(), | 92 SetManagedDefaultSearchPreferences(managed_engine, true, &profile_); |
91 std::string(), | |
92 std::string(), | |
93 std::string(), | |
94 std::string()); | |
95 } | 93 } |
96 | 94 |
97 TemplateURLTableModel* table_model() { return controller_->table_model(); } | 95 TemplateURLTableModel* table_model() { return controller_->table_model(); } |
98 KeywordEditorController* controller() { return controller_.get(); } | 96 KeywordEditorController* controller() { return controller_.get(); } |
99 const TemplateURLServiceFactoryTestUtil* util() const { return &util_; } | 97 const TemplateURLServiceFactoryTestUtil* util() const { return &util_; } |
100 | 98 |
101 int items_changed_count() const { return items_changed_count_; } | 99 int items_changed_count() const { return items_changed_count_; } |
102 int added_count() const { return added_count_; } | 100 int added_count() const { return added_count_; } |
103 int removed_count() const { return removed_count_; } | 101 int removed_count() const { return removed_count_; } |
104 | 102 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 data.SetKeyword(ASCIIToUTF16("a")); | 245 data.SetKeyword(ASCIIToUTF16("a")); |
248 TemplateURL* turl = util()->model()->Add(base::MakeUnique<TemplateURL>(data)); | 246 TemplateURL* turl = util()->model()->Add(base::MakeUnique<TemplateURL>(data)); |
249 | 247 |
250 // Table model should have updated. | 248 // Table model should have updated. |
251 VerifyChangeCount(1, 0, 0, 0); | 249 VerifyChangeCount(1, 0, 0, 0); |
252 | 250 |
253 // And should contain the newly added TemplateURL. | 251 // And should contain the newly added TemplateURL. |
254 ASSERT_EQ(original_row_count + 1, table_model()->RowCount()); | 252 ASSERT_EQ(original_row_count + 1, table_model()->RowCount()); |
255 ASSERT_GE(table_model()->IndexOfTemplateURL(turl), 0); | 253 ASSERT_GE(table_model()->IndexOfTemplateURL(turl), 0); |
256 } | 254 } |
OLD | NEW |