| OLD | NEW |
| 1 // Copyright (c) 2010 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 "app/table_model_observer.h" | 5 #include "app/table_model_observer.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/keyword_editor_controller.h" | 9 #include "chrome/browser/search_engines/keyword_editor_controller.h" |
| 10 #include "chrome/browser/search_engines/template_url.h" | 10 #include "chrome/browser/search_engines/template_url.h" |
| 11 #include "chrome/browser/search_engines/template_url_model.h" | 11 #include "chrome/browser/search_engines/template_url_model.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 return; | 130 return; |
| 131 | 131 |
| 132 // Verify the TableModel has the new data. | 132 // Verify the TableModel has the new data. |
| 133 ASSERT_EQ(1, table_model()->RowCount()); | 133 ASSERT_EQ(1, table_model()->RowCount()); |
| 134 | 134 |
| 135 // Verify the TemplateURLModel has the new entry. | 135 // Verify the TemplateURLModel has the new entry. |
| 136 ASSERT_EQ(1U, model_->GetTemplateURLs().size()); | 136 ASSERT_EQ(1U, model_->GetTemplateURLs().size()); |
| 137 | 137 |
| 138 // Verify the entry is what we added. | 138 // Verify the entry is what we added. |
| 139 const TemplateURL* turl = model_->GetTemplateURLs()[0]; | 139 const TemplateURL* turl = model_->GetTemplateURLs()[0]; |
| 140 EXPECT_EQ(L"a", turl->short_name()); | 140 EXPECT_EQ(ASCIIToUTF16("a"), turl->short_name()); |
| 141 EXPECT_EQ(L"b", turl->keyword()); | 141 EXPECT_EQ(ASCIIToUTF16("b"), turl->keyword()); |
| 142 ASSERT_TRUE(turl->url() != NULL); | 142 ASSERT_TRUE(turl->url() != NULL); |
| 143 EXPECT_EQ("http://c", turl->url()->url()); | 143 EXPECT_EQ("http://c", turl->url()->url()); |
| 144 } | 144 } |
| 145 | 145 |
| 146 // Tests modifying a TemplateURL. | 146 // Tests modifying a TemplateURL. |
| 147 TEST_F(KeywordEditorControllerTest, Modify) { | 147 TEST_F(KeywordEditorControllerTest, Modify) { |
| 148 controller_->AddTemplateURL(kA, kB, "http://c"); | 148 controller_->AddTemplateURL(kA, kB, "http://c"); |
| 149 ClearChangeCount(); | 149 ClearChangeCount(); |
| 150 | 150 |
| 151 // Modify the entry. | 151 // Modify the entry. |
| 152 const TemplateURL* turl = model_->GetTemplateURLs()[0]; | 152 const TemplateURL* turl = model_->GetTemplateURLs()[0]; |
| 153 controller_->ModifyTemplateURL(turl, kA1, kB1, "http://c1"); | 153 controller_->ModifyTemplateURL(turl, kA1, kB1, "http://c1"); |
| 154 | 154 |
| 155 // Make sure it was updated appropriately. | 155 // Make sure it was updated appropriately. |
| 156 VerifyChangeCount(0, 1, 0, 0); | 156 VerifyChangeCount(0, 1, 0, 0); |
| 157 EXPECT_EQ(L"a1", turl->short_name()); | 157 EXPECT_EQ(ASCIIToUTF16("a1"), turl->short_name()); |
| 158 EXPECT_EQ(L"b1", turl->keyword()); | 158 EXPECT_EQ(ASCIIToUTF16("b1"), turl->keyword()); |
| 159 ASSERT_TRUE(turl->url() != NULL); | 159 ASSERT_TRUE(turl->url() != NULL); |
| 160 EXPECT_EQ("http://c1", turl->url()->url()); | 160 EXPECT_EQ("http://c1", turl->url()->url()); |
| 161 } | 161 } |
| 162 | 162 |
| 163 // Tests making a TemplateURL the default search provider. | 163 // Tests making a TemplateURL the default search provider. |
| 164 TEST_F(KeywordEditorControllerTest, MakeDefault) { | 164 TEST_F(KeywordEditorControllerTest, MakeDefault) { |
| 165 controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}"); | 165 controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}"); |
| 166 ClearChangeCount(); | 166 ClearChangeCount(); |
| 167 | 167 |
| 168 const TemplateURL* turl = model_->GetTemplateURLs()[0]; | 168 const TemplateURL* turl = model_->GetTemplateURLs()[0]; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 179 EXPECT_EQ(-1, new_default); | 179 EXPECT_EQ(-1, new_default); |
| 180 } | 180 } |
| 181 | 181 |
| 182 // Tests that a TemplateURL can't be made the default if the default search | 182 // Tests that a TemplateURL can't be made the default if the default search |
| 183 // provider is managed via policy. | 183 // provider is managed via policy. |
| 184 TEST_F(KeywordEditorControllerTest, CannotSetDefaultWhileManaged) { | 184 TEST_F(KeywordEditorControllerTest, CannotSetDefaultWhileManaged) { |
| 185 controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}"); | 185 controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}"); |
| 186 controller_->AddTemplateURL(kA1, kB1, "http://d{searchTerms}"); | 186 controller_->AddTemplateURL(kA1, kB1, "http://d{searchTerms}"); |
| 187 ClearChangeCount(); | 187 ClearChangeCount(); |
| 188 | 188 |
| 189 const TemplateURL* turl1 = model_->GetTemplateURLForKeyword(L"b"); | 189 const TemplateURL* turl1 = |
| 190 model_->GetTemplateURLForKeyword(ASCIIToUTF16("b")); |
| 190 ASSERT_TRUE(turl1 != NULL); | 191 ASSERT_TRUE(turl1 != NULL); |
| 191 const TemplateURL* turl2 = model_->GetTemplateURLForKeyword(L"b1"); | 192 const TemplateURL* turl2 = |
| 193 model_->GetTemplateURLForKeyword(ASCIIToUTF16("b1")); |
| 192 ASSERT_TRUE(turl2 != NULL); | 194 ASSERT_TRUE(turl2 != NULL); |
| 193 | 195 |
| 194 EXPECT_TRUE(controller_->CanMakeDefault(turl1)); | 196 EXPECT_TRUE(controller_->CanMakeDefault(turl1)); |
| 195 EXPECT_TRUE(controller_->CanMakeDefault(turl2)); | 197 EXPECT_TRUE(controller_->CanMakeDefault(turl2)); |
| 196 | 198 |
| 197 SimulateDefaultSearchIsManaged(turl2->url()->url()); | 199 SimulateDefaultSearchIsManaged(turl2->url()->url()); |
| 198 EXPECT_TRUE(model_->is_default_search_managed()); | 200 EXPECT_TRUE(model_->is_default_search_managed()); |
| 199 | 201 |
| 200 EXPECT_FALSE(controller_->CanMakeDefault(turl1)); | 202 EXPECT_FALSE(controller_->CanMakeDefault(turl1)); |
| 201 EXPECT_FALSE(controller_->CanMakeDefault(turl2)); | 203 EXPECT_FALSE(controller_->CanMakeDefault(turl2)); |
| 202 } | 204 } |
| 203 | 205 |
| 204 // Tests that a TemplateURL can't be edited if it is the managed default search | 206 // Tests that a TemplateURL can't be edited if it is the managed default search |
| 205 // provider. | 207 // provider. |
| 206 TEST_F(KeywordEditorControllerTest, EditManagedDefault) { | 208 TEST_F(KeywordEditorControllerTest, EditManagedDefault) { |
| 207 controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}"); | 209 controller_->AddTemplateURL(kA, kB, "http://c{searchTerms}"); |
| 208 controller_->AddTemplateURL(kA1, kB1, "http://d{searchTerms}"); | 210 controller_->AddTemplateURL(kA1, kB1, "http://d{searchTerms}"); |
| 209 ClearChangeCount(); | 211 ClearChangeCount(); |
| 210 | 212 |
| 211 const TemplateURL* turl1 = model_->GetTemplateURLForKeyword(L"b"); | 213 const TemplateURL* turl1 = |
| 214 model_->GetTemplateURLForKeyword(ASCIIToUTF16("b")); |
| 212 ASSERT_TRUE(turl1 != NULL); | 215 ASSERT_TRUE(turl1 != NULL); |
| 213 const TemplateURL* turl2 = model_->GetTemplateURLForKeyword(L"b1"); | 216 const TemplateURL* turl2 = |
| 217 model_->GetTemplateURLForKeyword(ASCIIToUTF16("b1")); |
| 214 ASSERT_TRUE(turl2 != NULL); | 218 ASSERT_TRUE(turl2 != NULL); |
| 215 | 219 |
| 216 EXPECT_TRUE(controller_->CanEdit(turl1)); | 220 EXPECT_TRUE(controller_->CanEdit(turl1)); |
| 217 EXPECT_TRUE(controller_->CanEdit(turl2)); | 221 EXPECT_TRUE(controller_->CanEdit(turl2)); |
| 218 | 222 |
| 219 // Simulate setting a managed default. This will add another template URL to | 223 // Simulate setting a managed default. This will add another template URL to |
| 220 // the model. | 224 // the model. |
| 221 SimulateDefaultSearchIsManaged(turl2->url()->url()); | 225 SimulateDefaultSearchIsManaged(turl2->url()->url()); |
| 222 EXPECT_TRUE(model_->is_default_search_managed()); | 226 EXPECT_TRUE(model_->is_default_search_managed()); |
| 223 EXPECT_TRUE(controller_->CanEdit(turl1)); | 227 EXPECT_TRUE(controller_->CanEdit(turl1)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 234 | 238 |
| 235 // This should not result in a crash. | 239 // This should not result in a crash. |
| 236 int new_default = controller_->MakeDefaultTemplateURL(0); | 240 int new_default = controller_->MakeDefaultTemplateURL(0); |
| 237 EXPECT_EQ(0, new_default); | 241 EXPECT_EQ(0, new_default); |
| 238 } | 242 } |
| 239 | 243 |
| 240 // Mutates the TemplateURLModel and make sure table model is updating | 244 // Mutates the TemplateURLModel and make sure table model is updating |
| 241 // appropriately. | 245 // appropriately. |
| 242 TEST_F(KeywordEditorControllerTest, MutateTemplateURLModel) { | 246 TEST_F(KeywordEditorControllerTest, MutateTemplateURLModel) { |
| 243 TemplateURL* turl = new TemplateURL(); | 247 TemplateURL* turl = new TemplateURL(); |
| 244 turl->set_keyword(L"a"); | 248 turl->set_keyword(ASCIIToUTF16("a")); |
| 245 turl->set_short_name(L"b"); | 249 turl->set_short_name(ASCIIToUTF16("b")); |
| 246 model_->Add(turl); | 250 model_->Add(turl); |
| 247 | 251 |
| 248 // Table model should have updated. | 252 // Table model should have updated. |
| 249 VerifyChangeCount(1, 0, 0, 0); | 253 VerifyChangeCount(1, 0, 0, 0); |
| 250 | 254 |
| 251 // And should contain the newly added TemplateURL. | 255 // And should contain the newly added TemplateURL. |
| 252 ASSERT_EQ(1, table_model()->RowCount()); | 256 ASSERT_EQ(1, table_model()->RowCount()); |
| 253 ASSERT_EQ(0, table_model()->IndexOfTemplateURL(turl)); | 257 ASSERT_EQ(0, table_model()->IndexOfTemplateURL(turl)); |
| 254 } | 258 } |
| OLD | NEW |