Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 "chrome/browser/android/vr_shell/textures/url_bar_texture.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/macros.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 #include "third_party/skia/include/core/SkSurface.h" | |
| 11 #include "ui/gfx/font_list.h" | |
| 12 | |
| 13 namespace vr_shell { | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 static constexpr int kUrlWidth = 400; | |
| 18 static constexpr int kUrlHeight = 30; | |
| 19 | |
| 20 class TestUrlBarTexture : public UrlBarTexture { | |
| 21 public: | |
| 22 TestUrlBarTexture(); | |
| 23 ~TestUrlBarTexture() override {} | |
| 24 | |
| 25 void DrawURL(const GURL& gurl) { | |
| 26 unsupported_mode_ = UiUnsupportedMode::kMax; | |
| 27 SetURL(gurl); | |
| 28 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul( | |
| 29 texture_size_.width(), texture_size_.height()); | |
| 30 DrawAndLayout(surface->getCanvas(), texture_size_); | |
| 31 } | |
| 32 | |
| 33 void SetForceFontFallbackFailure(bool force) { | |
|
cjgrant
2017/05/26 18:52:00
I'm not suggesting a change in this CL, but am cur
Ian Vollick
2017/05/26 20:20:28
In this case, I wonder if we can make the static f
| |
| 34 SetForceFontFallbackFailureForTesting(force); | |
| 35 } | |
| 36 | |
| 37 // Reports the last unsupported mode that was encountered. Returns kMax if no | |
| 38 // unsupported mode was encountered. | |
| 39 UiUnsupportedMode unsupported_mode() const { return unsupported_mode_; } | |
| 40 | |
| 41 private: | |
| 42 void OnUnsupportedFeature(UiUnsupportedMode mode) { | |
| 43 unsupported_mode_ = mode; | |
| 44 } | |
| 45 | |
| 46 gfx::Size texture_size_; | |
| 47 gfx::Rect bounds_; | |
| 48 UiUnsupportedMode unsupported_mode_ = UiUnsupportedMode::kMax; | |
| 49 }; | |
| 50 | |
| 51 TestUrlBarTexture::TestUrlBarTexture() | |
| 52 : UrlBarTexture(base::Bind(&TestUrlBarTexture::OnUnsupportedFeature, | |
| 53 base::Unretained(this))), | |
| 54 texture_size_(kUrlWidth, kUrlHeight), | |
| 55 bounds_(kUrlWidth, kUrlHeight) { | |
| 56 gfx::FontList::SetDefaultFontDescription("Arial, Times New Roman, 15px"); | |
| 57 } | |
| 58 | |
| 59 } // namespace | |
| 60 | |
| 61 TEST(UrlBarTexture, WillFailOnUnhandledCodePoint) { | |
| 62 TestUrlBarTexture texture; | |
| 63 texture.DrawURL(GURL("https://foo.com")); | |
| 64 EXPECT_EQ(UiUnsupportedMode::kMax, texture.unsupported_mode()); | |
| 65 texture.SetForceFontFallbackFailure(true); | |
| 66 texture.DrawURL(GURL("https://bar.com")); | |
| 67 EXPECT_EQ(UiUnsupportedMode::kUnhandledCodePoint, texture.unsupported_mode()); | |
| 68 texture.SetForceFontFallbackFailure(false); | |
| 69 texture.DrawURL(GURL("https://baz.com")); | |
| 70 EXPECT_EQ(UiUnsupportedMode::kMax, texture.unsupported_mode()); | |
| 71 } | |
| 72 | |
| 73 } // namespace vr_shell | |
| OLD | NEW |