| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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/android/vr_shell/textures/url_bar_texture.h" | 5 #include "chrome/browser/android/vr_shell/textures/url_bar_texture.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/macros.h" |
| 6 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/android/vr_shell/textures/render_text_wrapper.h" | 11 #include "chrome/browser/android/vr_shell/textures/render_text_wrapper.h" |
| 9 #include "components/security_state/core/security_state.h" | 12 #include "components/security_state/core/security_state.h" |
| 10 #include "components/url_formatter/url_formatter.h" | 13 #include "components/url_formatter/url_formatter.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "third_party/skia/include/core/SkSurface.h" |
| 13 #include "ui/gfx/color_palette.h" | 17 #include "ui/gfx/color_palette.h" |
| 18 #include "ui/gfx/font_list.h" |
| 14 #include "ui/gfx/render_text.h" | 19 #include "ui/gfx/render_text.h" |
| 15 | 20 |
| 16 using security_state::SecurityLevel; | 21 using security_state::SecurityLevel; |
| 17 | 22 |
| 18 namespace vr_shell { | 23 namespace vr_shell { |
| 19 | 24 |
| 20 class MockRenderText : public vr_shell::RenderTextWrapper { | 25 static constexpr SkColor kEmphasizedColor = 0xFF000000; |
| 26 static constexpr SkColor kDeemphasizedColor = 0xFF5A5A5A; |
| 27 static const SkColor kSecureColor = gfx::kGoogleGreen700; |
| 28 static const SkColor kWarningColor = gfx::kGoogleRed700; |
| 29 static constexpr int kUrlWidth = 400; |
| 30 static constexpr int kUrlHeight = 30; |
| 31 |
| 32 class MockRenderText : public RenderTextWrapper { |
| 21 public: | 33 public: |
| 22 MockRenderText() : RenderTextWrapper(nullptr) {} | 34 MockRenderText() : RenderTextWrapper(nullptr) {} |
| 23 ~MockRenderText() override {} | 35 ~MockRenderText() override {} |
| 24 | 36 |
| 25 MOCK_METHOD1(SetColor, void(SkColor value)); | 37 MOCK_METHOD1(SetColor, void(SkColor value)); |
| 26 MOCK_METHOD2(ApplyColor, void(SkColor value, const gfx::Range& range)); | 38 MOCK_METHOD2(ApplyColor, void(SkColor value, const gfx::Range& range)); |
| 27 MOCK_METHOD2(SetStyle, void(gfx::TextStyle style, bool value)); | 39 MOCK_METHOD2(SetStyle, void(gfx::TextStyle style, bool value)); |
| 28 MOCK_METHOD3(ApplyStyle, | 40 MOCK_METHOD3(ApplyStyle, |
| 29 void(gfx::TextStyle style, bool value, const gfx::Range& range)); | 41 void(gfx::TextStyle style, bool value, const gfx::Range& range)); |
| 30 | 42 |
| 31 private: | 43 private: |
| 32 DISALLOW_COPY_AND_ASSIGN(MockRenderText); | 44 DISALLOW_COPY_AND_ASSIGN(MockRenderText); |
| 33 }; | 45 }; |
| 34 | 46 |
| 35 static constexpr SkColor kEmphasizedColor = 0xFF000000; | 47 class TestUrlBarTexture : public UrlBarTexture { |
| 36 static constexpr SkColor kDeemphasizedColor = 0xFF5A5A5A; | 48 public: |
| 37 static const SkColor kSecureColor = gfx::kGoogleGreen700; | 49 TestUrlBarTexture(); |
| 38 static const SkColor kWarningColor = gfx::kGoogleRed700; | 50 ~TestUrlBarTexture() override {} |
| 51 |
| 52 void DrawURL(const GURL& gurl) { |
| 53 unsupported_mode_ = UiUnsupportedMode::kCount; |
| 54 SetURL(gurl); |
| 55 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul( |
| 56 texture_size_.width(), texture_size_.height()); |
| 57 DrawAndLayout(surface->getCanvas(), texture_size_); |
| 58 } |
| 59 |
| 60 void SetForceFontFallbackFailure(bool force) { |
| 61 SetForceFontFallbackFailureForTesting(force); |
| 62 } |
| 63 |
| 64 // Reports the last unsupported mode that was encountered. Returns kCount if |
| 65 // no unsupported mode was encountered. |
| 66 UiUnsupportedMode unsupported_mode() const { return unsupported_mode_; } |
| 67 |
| 68 private: |
| 69 void OnUnsupportedFeature(UiUnsupportedMode mode) { |
| 70 unsupported_mode_ = mode; |
| 71 } |
| 72 |
| 73 gfx::Size texture_size_; |
| 74 gfx::Rect bounds_; |
| 75 UiUnsupportedMode unsupported_mode_ = UiUnsupportedMode::kCount; |
| 76 }; |
| 77 |
| 78 TestUrlBarTexture::TestUrlBarTexture() |
| 79 : UrlBarTexture(base::Bind(&TestUrlBarTexture::OnUnsupportedFeature, |
| 80 base::Unretained(this))), |
| 81 texture_size_(kUrlWidth, kUrlHeight), |
| 82 bounds_(kUrlWidth, kUrlHeight) { |
| 83 gfx::FontList::SetDefaultFontDescription("Arial, Times New Roman, 15px"); |
| 84 } |
| 39 | 85 |
| 40 class UrlEmphasisTest : public testing::Test { | 86 class UrlEmphasisTest : public testing::Test { |
| 41 protected: | 87 protected: |
| 42 void Verify(const std::string& url_string, | 88 void Verify(const std::string& url_string, |
| 43 SecurityLevel level, | 89 SecurityLevel level, |
| 44 const std::string& expected_string) { | 90 const std::string& expected_string) { |
| 45 GURL url(base::UTF8ToUTF16(url_string)); | 91 GURL url(base::UTF8ToUTF16(url_string)); |
| 46 url::Parsed parsed; | 92 url::Parsed parsed; |
| 47 const base::string16 formatted_url = url_formatter::FormatUrl( | 93 const base::string16 formatted_url = url_formatter::FormatUrl( |
| 48 url, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::NORMAL, | 94 url, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::NORMAL, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 "https://host.com/page"); | 133 "https://host.com/page"); |
| 88 } | 134 } |
| 89 | 135 |
| 90 TEST_F(UrlEmphasisTest, Data) { | 136 TEST_F(UrlEmphasisTest, Data) { |
| 91 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor)); | 137 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor)); |
| 92 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(0, 4))); | 138 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(0, 4))); |
| 93 Verify("data:text/html,lots of data", SecurityLevel::NONE, | 139 Verify("data:text/html,lots of data", SecurityLevel::NONE, |
| 94 "data:text/html,lots of data"); | 140 "data:text/html,lots of data"); |
| 95 } | 141 } |
| 96 | 142 |
| 143 TEST(UrlBarTextureTest, WillFailOnUnhandledCodePoint) { |
| 144 TestUrlBarTexture texture; |
| 145 texture.DrawURL(GURL("https://foo.com")); |
| 146 EXPECT_EQ(UiUnsupportedMode::kCount, texture.unsupported_mode()); |
| 147 texture.SetForceFontFallbackFailure(true); |
| 148 texture.DrawURL(GURL("https://bar.com")); |
| 149 EXPECT_EQ(UiUnsupportedMode::kUnhandledCodePoint, texture.unsupported_mode()); |
| 150 texture.SetForceFontFallbackFailure(false); |
| 151 texture.DrawURL(GURL("https://baz.com")); |
| 152 EXPECT_EQ(UiUnsupportedMode::kCount, texture.unsupported_mode()); |
| 153 } |
| 154 |
| 97 } // namespace vr_shell | 155 } // namespace vr_shell |
| OLD | NEW |