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

Unified Diff: chrome/browser/ui/cocoa/search_engine_list_model_unittest.mm

Issue 6339002: [Mac] Consolidate all files relating to preferences in a subdir of c/b/ui/coc... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/search_engine_list_model_unittest.mm
===================================================================
--- chrome/browser/ui/cocoa/search_engine_list_model_unittest.mm (revision 71447)
+++ chrome/browser/ui/cocoa/search_engine_list_model_unittest.mm (working copy)
@@ -1,152 +0,0 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/scoped_nsobject.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/search_engines/template_url.h"
-#include "chrome/browser/search_engines/template_url_model.h"
-#include "chrome/browser/ui/cocoa/browser_test_helper.h"
-#import "chrome/browser/ui/cocoa/search_engine_list_model.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#import "testing/gtest_mac.h"
-#include "testing/platform_test.h"
-
-// A helper for NSNotifications. Makes a note that it's been called back.
-@interface SearchEngineListHelper : NSObject {
- @public
- BOOL sawNotification_;
-}
-@end
-
-@implementation SearchEngineListHelper
-- (void)entryChanged:(NSNotification*)notify {
- sawNotification_ = YES;
-}
-@end
-
-class SearchEngineListModelTest : public PlatformTest {
- public:
- SearchEngineListModelTest() {
- // Build a fake set of template urls.
- template_model_.reset(new TemplateURLModel(helper_.profile()));
- TemplateURL* t_url = new TemplateURL();
- t_url->SetURL("http://www.google.com/?q={searchTerms}", 0, 0);
- t_url->set_keyword(L"keyword");
- t_url->set_short_name(L"google");
- t_url->set_show_in_default_list(true);
- template_model_->Add(t_url);
- t_url = new TemplateURL();
- t_url->SetURL("http://www.google2.com/?q={searchTerms}", 0, 0);
- t_url->set_keyword(L"keyword2");
- t_url->set_short_name(L"google2");
- t_url->set_show_in_default_list(true);
- template_model_->Add(t_url);
- EXPECT_EQ(template_model_->GetTemplateURLs().size(), 2U);
-
- model_.reset([[SearchEngineListModel alloc]
- initWithModel:template_model_.get()]);
- notification_helper_.reset([[SearchEngineListHelper alloc] init]);
- [[NSNotificationCenter defaultCenter]
- addObserver:notification_helper_.get()
- selector:@selector(entryChanged:)
- name:kSearchEngineListModelChangedNotification
- object:nil];
- }
- ~SearchEngineListModelTest() {
- [[NSNotificationCenter defaultCenter]
- removeObserver:notification_helper_.get()];
- }
-
- BrowserTestHelper helper_;
- scoped_ptr<TemplateURLModel> template_model_;
- scoped_nsobject<SearchEngineListModel> model_;
- scoped_nsobject<SearchEngineListHelper> notification_helper_;
-};
-
-TEST_F(SearchEngineListModelTest, Init) {
- scoped_nsobject<SearchEngineListModel> model(
- [[SearchEngineListModel alloc] initWithModel:template_model_.get()]);
-}
-
-TEST_F(SearchEngineListModelTest, Engines) {
- NSArray* engines = [model_ searchEngines];
- EXPECT_EQ([engines count], 2U);
-}
-
-TEST_F(SearchEngineListModelTest, Default) {
- EXPECT_EQ([model_ defaultIndex], -1);
-
- [model_ setDefaultIndex:1];
- EXPECT_EQ([model_ defaultIndex], 1);
-
- // Add two more URLs, neither of which are shown in the default list.
- TemplateURL* t_url = new TemplateURL();
- t_url->SetURL("http://www.google3.com/?q={searchTerms}", 0, 0);
- t_url->set_keyword(L"keyword3");
- t_url->set_short_name(L"google3 not eligible");
- t_url->set_show_in_default_list(false);
- template_model_->Add(t_url);
- t_url = new TemplateURL();
- t_url->SetURL("http://www.google4.com/?q={searchTerms}", 0, 0);
- t_url->set_keyword(L"keyword4");
- t_url->set_short_name(L"google4");
- t_url->set_show_in_default_list(false);
- template_model_->Add(t_url);
-
- // Still should only have 2 engines and not these newly added ones.
- EXPECT_EQ([[model_ searchEngines] count], 2U);
-
- // Since keyword3 is not in the default list, the 2nd index in the default
- // keyword list should be keyword4. Test for http://crbug.com/21898.
- template_model_->SetDefaultSearchProvider(t_url);
- EXPECT_EQ([[model_ searchEngines] count], 3U);
- EXPECT_EQ([model_ defaultIndex], 2);
-
- NSString* defaultString = [[model_ searchEngines] objectAtIndex:2];
- EXPECT_NSEQ(@"google4", defaultString);
-}
-
-TEST_F(SearchEngineListModelTest, DefaultChosenFromUI) {
- EXPECT_EQ([model_ defaultIndex], -1);
-
- [model_ setDefaultIndex:1];
- EXPECT_EQ([model_ defaultIndex], 1);
-
- // Add two more URLs, the first one not shown in the default list.
- TemplateURL* t_url = new TemplateURL();
- t_url->SetURL("http://www.google3.com/?q={searchTerms}", 0, 0);
- t_url->set_keyword(L"keyword3");
- t_url->set_short_name(L"google3 not eligible");
- t_url->set_show_in_default_list(false);
- template_model_->Add(t_url);
- t_url = new TemplateURL();
- t_url->SetURL("http://www.google4.com/?q={searchTerms}", 0, 0);
- t_url->set_keyword(L"keyword4");
- t_url->set_short_name(L"google4");
- t_url->set_show_in_default_list(true);
- template_model_->Add(t_url);
-
- // We should have 3 engines.
- EXPECT_EQ([[model_ searchEngines] count], 3U);
-
- // Simulate the UI setting the default to the third entry.
- [model_ setDefaultIndex:2];
- EXPECT_EQ([model_ defaultIndex], 2);
-
- // The default search provider should be google4.
- EXPECT_EQ(template_model_->GetDefaultSearchProvider(), t_url);
-}
-
-// Make sure that when the back-end model changes that we get a notification.
-TEST_F(SearchEngineListModelTest, Notification) {
- // Add one more item to force a notification.
- TemplateURL* t_url = new TemplateURL();
- t_url->SetURL("http://www.google3.com/foo/bar", 0, 0);
- t_url->set_keyword(L"keyword3");
- t_url->set_short_name(L"google3");
- t_url->set_show_in_default_list(true);
- template_model_->Add(t_url);
-
- EXPECT_TRUE(notification_helper_.get()->sawNotification_);
-}

Powered by Google App Engine
This is Rietveld 408576698