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

Side by Side Diff: chrome/browser/search_engines/default_search_manager_unittest.cc

Issue 229763005: Store default search provider data in dictionary pref. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Eriks comments and clean up Created 6 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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_pref_service_syncable.h"
13 #include "components/user_prefs/pref_registry_syncable.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace {
17
18 // Checks that the two TemplateURLs are similar. It does not check the id, the
19 // date_created or the last_modified time. Neither pointer should be NULL.
20 void ExpectSimilar(const TemplateURLData* expected,
21 const TemplateURLData* actual) {
22 EXPECT_TRUE(expected != NULL);
23 EXPECT_TRUE(actual != NULL);
24
25 if (!actual || !expected)
26 return;
gab 2014/04/23 20:00:18 optional: You can just use ASSERT_TRUE for the NUL
Peter Kasting 2014/04/23 20:41:06 I would echo this except without the "optional" pr
erikwright (departed) 2014/04/23 20:48:53 I asked her not to. Many developers are not aware
Peter Kasting 2014/04/23 20:56:25 I'm confused by what this last sentence is saying.
erikwright (departed) 2014/04/23 21:11:49 It's not obvious that this is a return statement.
Peter Kasting 2014/04/23 21:15:47 This means the developer fundamentally does not kn
erikwright (departed) 2014/04/23 21:21:05 You're right that I'm conflating this with the sec
Cait (Slow) 2014/04/23 23:26:55 Erik had recommended against using ASSERTs in help
27
28 EXPECT_EQ(expected->short_name, actual->short_name);
29 EXPECT_EQ(expected->keyword(), actual->keyword());
30 EXPECT_EQ(expected->url(), actual->url());
31 EXPECT_EQ(expected->suggestions_url, actual->suggestions_url);
32 EXPECT_EQ(expected->favicon_url, actual->favicon_url);
33 EXPECT_EQ(expected->alternate_urls, actual->alternate_urls);
34 EXPECT_EQ(expected->show_in_default_list, actual->show_in_default_list);
35 EXPECT_EQ(expected->safe_for_autoreplace, actual->safe_for_autoreplace);
36 EXPECT_EQ(expected->input_encodings, actual->input_encodings);
37 EXPECT_EQ(expected->search_terms_replacement_key,
38 actual->search_terms_replacement_key);
39 }
40
41 } // namespace
42
43 class DefaultSearchManagerTest : public testing::Test {
44 public:
45 DefaultSearchManagerTest() {};
46
47 virtual void SetUp() OVERRIDE {
48 pref_service_.reset(new TestingPrefServiceSyncable);
49 DefaultSearchManager::RegisterProfilePrefs(pref_service_->registry());
50 }
51
52 virtual void TearDown() { pref_service_.reset(); }
erikwright (departed) 2014/04/23 20:48:53 Not necessary. There is one test instance per test
Cait (Slow) 2014/04/23 23:26:55 Done.
53
54 PrefService* Prefs() const { return pref_service_.get(); }
Peter Kasting 2014/04/23 20:41:06 This must be non-const or else return a const poin
Cait (Slow) 2014/04/23 23:26:55 Done.
55
56 private:
57 scoped_ptr<TestingPrefServiceSyncable> pref_service_;
gab 2014/04/23 20:00:18 I think it's fine to leave this member in the prot
Peter Kasting 2014/04/23 20:41:06 That would violate the Google style guide, which b
58 DISALLOW_COPY_AND_ASSIGN(DefaultSearchManagerTest);
59 };
60
61 TEST_F(DefaultSearchManagerTest, PrefSaving) {
62 DefaultSearchManager manager(Prefs());
63 TemplateURLData data;
64 data.short_name = base::UTF8ToUTF16("name1");
65 data.SetKeyword(base::UTF8ToUTF16("key1"));
66 data.SetURL("http://foo1/{searchTerms}");
67 data.suggestions_url = "http://sugg1";
68 data.alternate_urls.push_back("http://foo1/alt");
69 data.favicon_url = GURL("http://icon1");
70 data.safe_for_autoreplace = true;
71 data.show_in_default_list = true;
72 base::SplitString("UTF-8;UTF-16", ';', &data.input_encodings);
73 data.date_created = base::Time();
74 data.last_modified = base::Time();
75
76 manager.SaveToPrefService(data);
77 TemplateURLData read_data;
78 manager.ReadFromPrefService(&read_data);
79 ExpectSimilar(&data, &read_data);
80 }
gab 2014/04/23 20:00:18 Also test reading with no prior writes (i.e. readi
Cait (Slow) 2014/04/23 23:26:55 Done. For now this just amounts to an empty dictio
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698