OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/font_family_cache.h" | 5 #include "chrome/browser/font_family_cache.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/test/base/testing_pref_service_syncable.h" | 8 #include "chrome/test/base/testing_pref_service_syncable.h" |
9 #include "chrome/test/base/testing_profile.h" | 9 #include "chrome/test/base/testing_profile.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); | 36 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); |
37 | 37 |
38 std::string font1("font 1"); | 38 std::string font1("font 1"); |
39 std::string font2("font 2"); | 39 std::string font2("font 2"); |
40 std::string map_name("webkit.webprefs.fonts.pictograph"); | 40 std::string map_name("webkit.webprefs.fonts.pictograph"); |
41 std::string script("Zzyxca"); | 41 std::string script("Zzyxca"); |
42 std::string pref_name(map_name + '.' + script); | 42 std::string pref_name(map_name + '.' + script); |
43 std::string pref_name2(map_name + '.' + "adsf"); | 43 std::string pref_name2(map_name + '.' + "adsf"); |
44 | 44 |
45 // Registers 2 preferences, and sets the first one. | 45 // Registers 2 preferences, and sets the first one. |
46 prefs->registry()->RegisterStringPref( | 46 prefs->registry()->RegisterStringPref(pref_name.c_str(), std::string()); |
47 pref_name.c_str(), | 47 prefs->registry()->RegisterStringPref(pref_name2.c_str(), std::string()); |
48 std::string(), | |
49 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
50 prefs->registry()->RegisterStringPref( | |
51 pref_name2.c_str(), | |
52 std::string(), | |
53 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
54 prefs->SetString(pref_name.c_str(), font1.c_str()); | 48 prefs->SetString(pref_name.c_str(), font1.c_str()); |
55 | 49 |
56 // Check that the right preference is returned. | 50 // Check that the right preference is returned. |
57 std::string result = base::UTF16ToUTF8( | 51 std::string result = base::UTF16ToUTF8( |
58 cache.FetchAndCacheFont(script.c_str(), map_name.c_str())); | 52 cache.FetchAndCacheFont(script.c_str(), map_name.c_str())); |
59 EXPECT_EQ(font1, result); | 53 EXPECT_EQ(font1, result); |
60 EXPECT_EQ(1, cache.fetch_font_count_); | 54 EXPECT_EQ(1, cache.fetch_font_count_); |
61 | 55 |
62 // Check that the second access uses the cache. | 56 // Check that the second access uses the cache. |
63 result = base::UTF16ToUTF8( | 57 result = base::UTF16ToUTF8( |
64 cache.FetchAndCacheFont(script.c_str(), map_name.c_str())); | 58 cache.FetchAndCacheFont(script.c_str(), map_name.c_str())); |
65 EXPECT_EQ(font1, result); | 59 EXPECT_EQ(font1, result); |
66 EXPECT_EQ(1, cache.fetch_font_count_); | 60 EXPECT_EQ(1, cache.fetch_font_count_); |
67 | 61 |
68 // Changing another preference should have no effect. | 62 // Changing another preference should have no effect. |
69 prefs->SetString(pref_name2.c_str(), "katy perry"); | 63 prefs->SetString(pref_name2.c_str(), "katy perry"); |
70 result = base::UTF16ToUTF8( | 64 result = base::UTF16ToUTF8( |
71 cache.FetchAndCacheFont(script.c_str(), map_name.c_str())); | 65 cache.FetchAndCacheFont(script.c_str(), map_name.c_str())); |
72 EXPECT_EQ(font1, result); | 66 EXPECT_EQ(font1, result); |
73 EXPECT_EQ(1, cache.fetch_font_count_); | 67 EXPECT_EQ(1, cache.fetch_font_count_); |
74 | 68 |
75 // Changing the preferences invalidates the cache. | 69 // Changing the preferences invalidates the cache. |
76 prefs->SetString(pref_name.c_str(), font2.c_str()); | 70 prefs->SetString(pref_name.c_str(), font2.c_str()); |
77 result = base::UTF16ToUTF8( | 71 result = base::UTF16ToUTF8( |
78 cache.FetchAndCacheFont(script.c_str(), map_name.c_str())); | 72 cache.FetchAndCacheFont(script.c_str(), map_name.c_str())); |
79 EXPECT_EQ(font2, result); | 73 EXPECT_EQ(font2, result); |
80 EXPECT_EQ(2, cache.fetch_font_count_); | 74 EXPECT_EQ(2, cache.fetch_font_count_); |
81 } | 75 } |
OLD | NEW |