Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/files/scoped_temp_dir.h" | |
| 6 #include "base/strings/string_split.h" | |
| 7 #include "base/strings/string_util.h" | |
| 8 #include "base/strings/utf_string_conversions.h" | |
| 9 #include "base/time/time.h" | |
| 10 #include "chrome/browser/search_engines/default_search_manager.h" | |
| 11 #include "chrome/browser/search_engines/template_url.h" | |
| 12 #include "chrome/test/base/testing_profile.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 // Checks that the two TemplateURLs are similar. It does not check the id, the | |
| 18 // date_created or the last_modified time. Neither pointer should be NULL. | |
| 19 void ExpectSimilar(const TemplateURLData* expected, | |
| 20 const TemplateURLData* actual) { | |
| 21 ASSERT_TRUE(expected != NULL); | |
|
erikwright (departed)
2014/04/23 14:18:01
Don't use ASSERT in a helper function. Many develo
Cait (Slow)
2014/04/23 19:10:05
Done.
| |
| 22 ASSERT_TRUE(actual != NULL); | |
| 23 EXPECT_EQ(expected->short_name, actual->short_name); | |
| 24 EXPECT_EQ(expected->keyword(), actual->keyword()); | |
| 25 EXPECT_EQ(expected->url(), actual->url()); | |
| 26 EXPECT_EQ(expected->suggestions_url, actual->suggestions_url); | |
| 27 EXPECT_EQ(expected->favicon_url, actual->favicon_url); | |
| 28 EXPECT_EQ(expected->alternate_urls, actual->alternate_urls); | |
| 29 EXPECT_EQ(expected->show_in_default_list, actual->show_in_default_list); | |
| 30 EXPECT_EQ(expected->safe_for_autoreplace, actual->safe_for_autoreplace); | |
| 31 EXPECT_EQ(expected->input_encodings, actual->input_encodings); | |
| 32 EXPECT_EQ(expected->search_terms_replacement_key, | |
| 33 actual->search_terms_replacement_key); | |
| 34 } | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 38 class DefaultSearchManagerTest : public testing::Test { | |
| 39 public: | |
| 40 DefaultSearchManagerTest() {}; | |
| 41 | |
| 42 virtual void SetUp() OVERRIDE { | |
| 43 // Make unique temp directory. | |
| 44 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
| 45 profile_.reset(new TestingProfile(temp_dir_.path())); | |
|
erikwright (departed)
2014/04/23 14:18:01
I believe there is also a TestingPrefService which
Cait (Slow)
2014/04/23 19:10:05
Done.
| |
| 46 } | |
| 47 | |
| 48 virtual void TearDown() { profile_.reset(); } | |
| 49 | |
| 50 Profile* profile() const { return profile_.get(); } | |
| 51 | |
| 52 private: | |
| 53 base::ScopedTempDir temp_dir_; | |
| 54 scoped_ptr<Profile> profile_; | |
| 55 DISALLOW_COPY_AND_ASSIGN(DefaultSearchManagerTest); | |
| 56 }; | |
| 57 | |
| 58 TEST_F(DefaultSearchManagerTest, PrefSaving) { | |
| 59 DefaultSearchManager manager; | |
| 60 TemplateURLData data; | |
| 61 data.short_name = base::UTF8ToUTF16("name1"); | |
| 62 data.SetKeyword(base::UTF8ToUTF16("key1")); | |
| 63 data.SetURL("http://foo1/{searchTerms}"); | |
| 64 data.suggestions_url = "http://sugg1"; | |
| 65 data.alternate_urls.push_back( "http://foo1/alt"); | |
| 66 data.favicon_url = GURL("http://icon1"); | |
| 67 data.safe_for_autoreplace = true; | |
| 68 data.show_in_default_list = true; | |
| 69 base::SplitString("UTF-8;UTF-16", ';', &data.input_encodings); | |
| 70 data.date_created = base::Time(); | |
| 71 data.last_modified = base::Time(); | |
| 72 | |
| 73 manager.SaveToPrefService(profile()->GetPrefs(), &data); | |
| 74 TemplateURLData read_data; | |
| 75 manager.ReadFromPrefService(profile()->GetPrefs(), &read_data); | |
| 76 ExpectSimilar(&data, &read_data); | |
| 77 } | |
| OLD | NEW |