 Chromium Code Reviews
 Chromium Code Reviews Issue 2902393002:
   [vr] Bail on unhandled code points.  (Closed)
    
  
    Issue 2902393002:
   [vr] Bail on unhandled code points.  (Closed) 
  | Index: chrome/browser/android/vr_shell/textures/url_bar_texture_unittest.cc | 
| diff --git a/chrome/browser/android/vr_shell/textures/url_bar_texture_unittest.cc b/chrome/browser/android/vr_shell/textures/url_bar_texture_unittest.cc | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..e77a7666ee4bbc33dc492d8b256dd50e77566720 | 
| --- /dev/null | 
| +++ b/chrome/browser/android/vr_shell/textures/url_bar_texture_unittest.cc | 
| @@ -0,0 +1,73 @@ | 
| +// Copyright 2017 The Chromium Authors. All rights reserved. | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| +#include "chrome/browser/android/vr_shell/textures/url_bar_texture.h" | 
| + | 
| +#include "base/bind.h" | 
| +#include "base/macros.h" | 
| +#include "testing/gtest/include/gtest/gtest.h" | 
| +#include "third_party/skia/include/core/SkSurface.h" | 
| +#include "ui/gfx/font_list.h" | 
| + | 
| +namespace vr_shell { | 
| + | 
| +namespace { | 
| + | 
| +static constexpr int kUrlWidth = 400; | 
| +static constexpr int kUrlHeight = 30; | 
| + | 
| +class TestUrlBarTexture : public UrlBarTexture { | 
| + public: | 
| + TestUrlBarTexture(); | 
| + ~TestUrlBarTexture() override {} | 
| + | 
| + void DrawURL(const GURL& gurl) { | 
| + unsupported_mode_ = UiUnsupportedMode::kMax; | 
| + SetURL(gurl); | 
| + sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul( | 
| + texture_size_.width(), texture_size_.height()); | 
| + DrawAndLayout(surface->getCanvas(), texture_size_); | 
| + } | 
| + | 
| + 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
 | 
| + SetForceFontFallbackFailureForTesting(force); | 
| + } | 
| + | 
| + // Reports the last unsupported mode that was encountered. Returns kMax if no | 
| + // unsupported mode was encountered. | 
| + UiUnsupportedMode unsupported_mode() const { return unsupported_mode_; } | 
| + | 
| + private: | 
| + void OnUnsupportedFeature(UiUnsupportedMode mode) { | 
| + unsupported_mode_ = mode; | 
| + } | 
| + | 
| + gfx::Size texture_size_; | 
| + gfx::Rect bounds_; | 
| + UiUnsupportedMode unsupported_mode_ = UiUnsupportedMode::kMax; | 
| +}; | 
| + | 
| +TestUrlBarTexture::TestUrlBarTexture() | 
| + : UrlBarTexture(base::Bind(&TestUrlBarTexture::OnUnsupportedFeature, | 
| + base::Unretained(this))), | 
| + texture_size_(kUrlWidth, kUrlHeight), | 
| + bounds_(kUrlWidth, kUrlHeight) { | 
| + gfx::FontList::SetDefaultFontDescription("Arial, Times New Roman, 15px"); | 
| +} | 
| + | 
| +} // namespace | 
| + | 
| +TEST(UrlBarTexture, WillFailOnUnhandledCodePoint) { | 
| + TestUrlBarTexture texture; | 
| + texture.DrawURL(GURL("https://foo.com")); | 
| + EXPECT_EQ(UiUnsupportedMode::kMax, texture.unsupported_mode()); | 
| + texture.SetForceFontFallbackFailure(true); | 
| + texture.DrawURL(GURL("https://bar.com")); | 
| + EXPECT_EQ(UiUnsupportedMode::kUnhandledCodePoint, texture.unsupported_mode()); | 
| + texture.SetForceFontFallbackFailure(false); | 
| + texture.DrawURL(GURL("https://baz.com")); | 
| + EXPECT_EQ(UiUnsupportedMode::kMax, texture.unsupported_mode()); | 
| +} | 
| + | 
| +} // namespace vr_shell |