| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/scoped_nsobject.h" | 5 #include "base/scoped_nsobject.h" |
| 6 #include "chrome/browser/cocoa/browser_test_helper.h" | 6 #include "chrome/browser/cocoa/browser_test_helper.h" |
| 7 #import "chrome/browser/cocoa/search_engine_list_model.h" | 7 #import "chrome/browser/cocoa/search_engine_list_model.h" |
| 8 #include "chrome/browser/profile.h" | 8 #include "chrome/browser/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_model.h" | 10 #include "chrome/browser/search_engines/template_url_model.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 sawNotification_ = YES; | 23 sawNotification_ = YES; |
| 24 } | 24 } |
| 25 @end | 25 @end |
| 26 | 26 |
| 27 class SearchEngineListModelTest : public PlatformTest { | 27 class SearchEngineListModelTest : public PlatformTest { |
| 28 public: | 28 public: |
| 29 SearchEngineListModelTest() { | 29 SearchEngineListModelTest() { |
| 30 // Build a fake set of template urls. | 30 // Build a fake set of template urls. |
| 31 template_model_.reset(new TemplateURLModel(helper_.profile())); | 31 template_model_.reset(new TemplateURLModel(helper_.profile())); |
| 32 TemplateURL* t_url = new TemplateURL(); | 32 TemplateURL* t_url = new TemplateURL(); |
| 33 t_url->SetURL(L"http://www.google.com/foo/bar", 0, 0); | 33 t_url->SetURL(L"http://www.google.com/?q={searchTerms}", 0, 0); |
| 34 t_url->set_keyword(L"keyword"); | 34 t_url->set_keyword(L"keyword"); |
| 35 t_url->set_short_name(L"google"); | 35 t_url->set_short_name(L"google"); |
| 36 t_url->set_show_in_default_list(true); | 36 t_url->set_show_in_default_list(true); |
| 37 template_model_->Add(t_url); | 37 template_model_->Add(t_url); |
| 38 t_url = new TemplateURL(); | 38 t_url = new TemplateURL(); |
| 39 t_url->SetURL(L"http://www.google2.com/foo/bar", 0, 0); | 39 t_url->SetURL(L"http://www.google2.com/?q={searchTerms}", 0, 0); |
| 40 t_url->set_keyword(L"keyword2"); | 40 t_url->set_keyword(L"keyword2"); |
| 41 t_url->set_short_name(L"google2"); | 41 t_url->set_short_name(L"google2"); |
| 42 t_url->set_show_in_default_list(true); | 42 t_url->set_show_in_default_list(true); |
| 43 template_model_->Add(t_url); | 43 template_model_->Add(t_url); |
| 44 EXPECT_EQ(template_model_->GetTemplateURLs().size(), 2U); | 44 EXPECT_EQ(template_model_->GetTemplateURLs().size(), 2U); |
| 45 | 45 |
| 46 model_.reset([[SearchEngineListModel alloc] | 46 model_.reset([[SearchEngineListModel alloc] |
| 47 initWithModel:template_model_.get()]); | 47 initWithModel:template_model_.get()]); |
| 48 notification_helper_.reset([[SearchEngineListHelper alloc] init]); | 48 notification_helper_.reset([[SearchEngineListHelper alloc] init]); |
| 49 [[NSNotificationCenter defaultCenter] | 49 [[NSNotificationCenter defaultCenter] |
| (...skipping 13 matching lines...) Expand all Loading... |
| 63 scoped_nsobject<SearchEngineListHelper> notification_helper_; | 63 scoped_nsobject<SearchEngineListHelper> notification_helper_; |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 TEST_F(SearchEngineListModelTest, Init) { | 66 TEST_F(SearchEngineListModelTest, Init) { |
| 67 scoped_nsobject<SearchEngineListModel> model( | 67 scoped_nsobject<SearchEngineListModel> model( |
| 68 [[SearchEngineListModel alloc] initWithModel:template_model_.get()]); | 68 [[SearchEngineListModel alloc] initWithModel:template_model_.get()]); |
| 69 } | 69 } |
| 70 | 70 |
| 71 TEST_F(SearchEngineListModelTest, Engines) { | 71 TEST_F(SearchEngineListModelTest, Engines) { |
| 72 NSArray* engines = [model_ searchEngines]; | 72 NSArray* engines = [model_ searchEngines]; |
| 73 // TODO(pinkerton): because the templates we create aren't truly parsable, | 73 EXPECT_EQ([engines count], 2U); |
| 74 // they won't pass the "displayable" test and thus we don't get any results. | |
| 75 EXPECT_EQ([engines count], /* 2U */ 0U); | |
| 76 } | 74 } |
| 77 | 75 |
| 78 TEST_F(SearchEngineListModelTest, Default) { | 76 TEST_F(SearchEngineListModelTest, Default) { |
| 79 EXPECT_EQ([model_ defaultIndex], 0U); | 77 EXPECT_EQ([model_ defaultIndex], 0U); |
| 80 | 78 |
| 81 [model_ setDefaultIndex:1]; | 79 [model_ setDefaultIndex:1]; |
| 82 EXPECT_EQ([model_ defaultIndex], 1U); | 80 EXPECT_EQ([model_ defaultIndex], 1U); |
| 81 |
| 82 // Add two more URLs, neither of which are shown in the default list. |
| 83 TemplateURL* t_url = new TemplateURL(); |
| 84 t_url->SetURL(L"http://www.google3.com/?q={searchTerms}", 0, 0); |
| 85 t_url->set_keyword(L"keyword3"); |
| 86 t_url->set_short_name(L"google3 not eligible"); |
| 87 t_url->set_show_in_default_list(false); |
| 88 template_model_->Add(t_url); |
| 89 t_url = new TemplateURL(); |
| 90 t_url->SetURL(L"http://www.google4.com/?q={searchTerms}", 0, 0); |
| 91 t_url->set_keyword(L"keyword4"); |
| 92 t_url->set_short_name(L"google4"); |
| 93 t_url->set_show_in_default_list(false); |
| 94 template_model_->Add(t_url); |
| 95 |
| 96 // Still should only have 2 engines and not these newly added ones. |
| 97 EXPECT_EQ([[model_ searchEngines] count], 2U); |
| 98 |
| 99 // Since keyword3 is not in the default list, the 2nd index in the default |
| 100 // key word list should be keyword4. Test for http://crbug.com/21898. |
| 101 template_model_->SetDefaultSearchProvider(t_url); |
| 102 EXPECT_EQ([[model_ searchEngines] count], 3U); |
| 103 EXPECT_EQ([model_ defaultIndex], 2U); |
| 104 |
| 105 NSString* defaultString = [[model_ searchEngines] objectAtIndex:2]; |
| 106 EXPECT_TRUE([@"google4" isEqualToString:defaultString]); |
| 83 } | 107 } |
| 84 | 108 |
| 85 // Make sure that when the back-end model changes that we get a notification. | 109 // Make sure that when the back-end model changes that we get a notification. |
| 86 TEST_F(SearchEngineListModelTest, Notification) { | 110 TEST_F(SearchEngineListModelTest, Notification) { |
| 87 // Add one more item to force a notification. | 111 // Add one more item to force a notification. |
| 88 TemplateURL* t_url = new TemplateURL(); | 112 TemplateURL* t_url = new TemplateURL(); |
| 89 t_url->SetURL(L"http://www.google3.com/foo/bar", 0, 0); | 113 t_url->SetURL(L"http://www.google3.com/foo/bar", 0, 0); |
| 90 t_url->set_keyword(L"keyword3"); | 114 t_url->set_keyword(L"keyword3"); |
| 91 t_url->set_short_name(L"google3"); | 115 t_url->set_short_name(L"google3"); |
| 92 t_url->set_show_in_default_list(true); | 116 t_url->set_show_in_default_list(true); |
| 93 template_model_->Add(t_url); | 117 template_model_->Add(t_url); |
| 94 | 118 |
| 95 EXPECT_TRUE(notification_helper_.get()->sawNotification_); | 119 EXPECT_TRUE(notification_helper_.get()->sawNotification_); |
| 96 } | 120 } |
| OLD | NEW |