| 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" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #import "testing/gtest_mac.h" |
| 12 #include "testing/platform_test.h" | 13 #include "testing/platform_test.h" |
| 13 | 14 |
| 14 // A helper for NSNotifications. Makes a note that it's been called back. | 15 // A helper for NSNotifications. Makes a note that it's been called back. |
| 15 @interface SearchEngineListHelper : NSObject { | 16 @interface SearchEngineListHelper : NSObject { |
| 16 @public | 17 @public |
| 17 BOOL sawNotification_; | 18 BOOL sawNotification_; |
| 18 } | 19 } |
| 19 @end | 20 @end |
| 20 | 21 |
| 21 @implementation SearchEngineListHelper | 22 @implementation SearchEngineListHelper |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 // Still should only have 2 engines and not these newly added ones. | 97 // Still should only have 2 engines and not these newly added ones. |
| 97 EXPECT_EQ([[model_ searchEngines] count], 2U); | 98 EXPECT_EQ([[model_ searchEngines] count], 2U); |
| 98 | 99 |
| 99 // Since keyword3 is not in the default list, the 2nd index in the default | 100 // Since keyword3 is not in the default list, the 2nd index in the default |
| 100 // keyword list should be keyword4. Test for http://crbug.com/21898. | 101 // keyword list should be keyword4. Test for http://crbug.com/21898. |
| 101 template_model_->SetDefaultSearchProvider(t_url); | 102 template_model_->SetDefaultSearchProvider(t_url); |
| 102 EXPECT_EQ([[model_ searchEngines] count], 3U); | 103 EXPECT_EQ([[model_ searchEngines] count], 3U); |
| 103 EXPECT_EQ([model_ defaultIndex], 2U); | 104 EXPECT_EQ([model_ defaultIndex], 2U); |
| 104 | 105 |
| 105 NSString* defaultString = [[model_ searchEngines] objectAtIndex:2]; | 106 NSString* defaultString = [[model_ searchEngines] objectAtIndex:2]; |
| 106 EXPECT_TRUE([@"google4" isEqualToString:defaultString]); | 107 EXPECT_NSEQ(@"google4", defaultString); |
| 107 } | 108 } |
| 108 | 109 |
| 109 // Make sure that when the back-end model changes that we get a notification. | 110 // Make sure that when the back-end model changes that we get a notification. |
| 110 TEST_F(SearchEngineListModelTest, Notification) { | 111 TEST_F(SearchEngineListModelTest, Notification) { |
| 111 // Add one more item to force a notification. | 112 // Add one more item to force a notification. |
| 112 TemplateURL* t_url = new TemplateURL(); | 113 TemplateURL* t_url = new TemplateURL(); |
| 113 t_url->SetURL("http://www.google3.com/foo/bar", 0, 0); | 114 t_url->SetURL("http://www.google3.com/foo/bar", 0, 0); |
| 114 t_url->set_keyword(L"keyword3"); | 115 t_url->set_keyword(L"keyword3"); |
| 115 t_url->set_short_name(L"google3"); | 116 t_url->set_short_name(L"google3"); |
| 116 t_url->set_show_in_default_list(true); | 117 t_url->set_show_in_default_list(true); |
| 117 template_model_->Add(t_url); | 118 template_model_->Add(t_url); |
| 118 | 119 |
| 119 EXPECT_TRUE(notification_helper_.get()->sawNotification_); | 120 EXPECT_TRUE(notification_helper_.get()->sawNotification_); |
| 120 } | 121 } |
| OLD | NEW |