| 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" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 class TestingFontFamilyCache : public FontFamilyCache { | 14 class TestingFontFamilyCache : public FontFamilyCache { |
| 15 public: | 15 public: |
| 16 explicit TestingFontFamilyCache(Profile* profile) | 16 explicit TestingFontFamilyCache(Profile* profile) |
| 17 : FontFamilyCache(profile), fetch_font_count_(0) {} | 17 : FontFamilyCache(profile), fetch_font_count_(0) {} |
| 18 virtual ~TestingFontFamilyCache() {} | 18 virtual ~TestingFontFamilyCache() {} |
| 19 virtual base::string16 FetchFont(const char* script, | 19 virtual base::string16 FetchFont(const char* script, |
| 20 const char* map_name) OVERRIDE { | 20 const char* map_name) override { |
| 21 ++fetch_font_count_; | 21 ++fetch_font_count_; |
| 22 return FontFamilyCache::FetchFont(script, map_name); | 22 return FontFamilyCache::FetchFont(script, map_name); |
| 23 } | 23 } |
| 24 | 24 |
| 25 int fetch_font_count_; | 25 int fetch_font_count_; |
| 26 | 26 |
| 27 private: | 27 private: |
| 28 DISALLOW_COPY_AND_ASSIGN(TestingFontFamilyCache); | 28 DISALLOW_COPY_AND_ASSIGN(TestingFontFamilyCache); |
| 29 }; | 29 }; |
| 30 | 30 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 EXPECT_EQ(font1, result); | 73 EXPECT_EQ(font1, result); |
| 74 EXPECT_EQ(1, cache.fetch_font_count_); | 74 EXPECT_EQ(1, cache.fetch_font_count_); |
| 75 | 75 |
| 76 // Changing the preferences invalidates the cache. | 76 // Changing the preferences invalidates the cache. |
| 77 prefs->SetString(pref_name.c_str(), font2.c_str()); | 77 prefs->SetString(pref_name.c_str(), font2.c_str()); |
| 78 result = base::UTF16ToUTF8( | 78 result = base::UTF16ToUTF8( |
| 79 cache.FetchAndCacheFont(script.c_str(), map_name.c_str())); | 79 cache.FetchAndCacheFont(script.c_str(), map_name.c_str())); |
| 80 EXPECT_EQ(font2, result); | 80 EXPECT_EQ(font2, result); |
| 81 EXPECT_EQ(2, cache.fetch_font_count_); | 81 EXPECT_EQ(2, cache.fetch_font_count_); |
| 82 } | 82 } |
| OLD | NEW |