| 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 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 static const SkColor kEmphasizedColor = 0xFF000000; | 29 static const SkColor kEmphasizedColor = 0xFF000000; |
| 30 static const SkColor kDeemphasizedColor = 0xFF5A5A5A; | 30 static const SkColor kDeemphasizedColor = 0xFF5A5A5A; |
| 31 static const SkColor kSecureColor = gfx::kGoogleGreen700; | 31 static const SkColor kSecureColor = gfx::kGoogleGreen700; |
| 32 static const SkColor kWarningColor = gfx::kGoogleRed700; | 32 static const SkColor kWarningColor = gfx::kGoogleRed700; |
| 33 | 33 |
| 34 static const SkColor kIncognitoDeemphasizedColor = 0xFF878787; | 34 static const SkColor kIncognitoDeemphasizedColor = 0xFF878787; |
| 35 static const SkColor kIncognitoEmphasizedColor = 0xFFEDEDED; | 35 static const SkColor kIncognitoEmphasizedColor = 0xFFEDEDED; |
| 36 static const SkColor kIncognitoSecureColor = 0xFFEDEDED; | 36 static const SkColor kIncognitoSecureColor = 0xFFEDEDED; |
| 37 static const SkColor kIncognitoWarningColor = 0xFFEDEDED; | 37 static const SkColor kIncognitoWarningColor = 0xFFEDEDED; |
| 38 | 38 |
| 39 static constexpr int kUrlWidth = 400; | 39 static constexpr int kUrlWidthPixels = 1024; |
| 40 static constexpr int kUrlHeight = 30; | |
| 41 | 40 |
| 42 class TestUrlBarTexture : public UrlBarTexture { | 41 class TestUrlBarTexture : public UrlBarTexture { |
| 43 public: | 42 public: |
| 44 TestUrlBarTexture(); | 43 TestUrlBarTexture(); |
| 45 ~TestUrlBarTexture() override {} | 44 ~TestUrlBarTexture() override {} |
| 46 | 45 |
| 47 void DrawURL(const GURL& gurl) { | 46 void DrawURL(const GURL& gurl) { |
| 48 unsupported_mode_ = UiUnsupportedMode::kCount; | 47 unsupported_mode_ = UiUnsupportedMode::kCount; |
| 49 ToolbarState state(gurl, SecurityLevel::HTTP_SHOW_WARNING, | 48 ToolbarState state(gurl, SecurityLevel::DANGEROUS, |
| 50 &toolbar::kHttpsInvalidIcon, | 49 &toolbar::kHttpsInvalidIcon, |
| 51 base::UTF8ToUTF16("Not secure"), true); | 50 base::UTF8ToUTF16("Not secure"), true); |
| 52 ASSERT_TRUE(state.should_display_url); | 51 ASSERT_TRUE(state.should_display_url); |
| 53 SetToolbarState(state); | 52 SetToolbarState(state); |
| 53 gfx::Size texture_size = GetPreferredTextureSize(kUrlWidthPixels); |
| 54 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul( | 54 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul( |
| 55 texture_size_.width(), texture_size_.height()); | 55 texture_size.width(), texture_size.height()); |
| 56 DrawAndLayout(surface->getCanvas(), texture_size_); | 56 DrawAndLayout(surface->getCanvas(), texture_size); |
| 57 } | 57 } |
| 58 | 58 |
| 59 static void TestUrlStyling(const base::string16& formatted_url, | 59 static void TestUrlStyling(const base::string16& formatted_url, |
| 60 const url::Parsed& parsed, | 60 const url::Parsed& parsed, |
| 61 security_state::SecurityLevel security_level, | 61 security_state::SecurityLevel security_level, |
| 62 vr_shell::RenderTextWrapper* render_text, | 62 vr_shell::RenderTextWrapper* render_text, |
| 63 const ColorScheme& color_scheme) { | 63 const ColorScheme& color_scheme) { |
| 64 ApplyUrlStyling(formatted_url, parsed, security_level, render_text, | 64 ApplyUrlStyling(formatted_url, parsed, security_level, render_text, |
| 65 color_scheme); | 65 color_scheme); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void SetForceFontFallbackFailure(bool force) { | 68 void SetForceFontFallbackFailure(bool force) { |
| 69 SetForceFontFallbackFailureForTesting(force); | 69 SetForceFontFallbackFailureForTesting(force); |
| 70 } | 70 } |
| 71 | 71 |
| 72 size_t GetNumberOfFontFallbacksForURL(const GURL& gurl) { | 72 size_t GetNumberOfFontFallbacksForURL(const GURL& gurl) { |
| 73 url::Parsed parsed; | 73 url::Parsed parsed; |
| 74 const base::string16 text = url_formatter::FormatUrl( | 74 const base::string16 text = url_formatter::FormatUrl( |
| 75 gurl, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::NORMAL, | 75 gurl, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::NORMAL, |
| 76 &parsed, nullptr, nullptr); | 76 &parsed, nullptr, nullptr); |
| 77 | 77 |
| 78 gfx::Size texture_size = GetPreferredTextureSize(kUrlWidthPixels); |
| 78 gfx::FontList font_list; | 79 gfx::FontList font_list; |
| 79 if (!GetFontList(kUrlHeight, text, &font_list)) | 80 if (!GetFontList(texture_size.height(), text, &font_list)) |
| 80 return 0; | 81 return 0; |
| 81 | 82 |
| 82 return font_list.GetFonts().size(); | 83 return font_list.GetFonts().size(); |
| 83 } | 84 } |
| 84 | 85 |
| 85 // Reports the last unsupported mode that was encountered. Returns kCount if | 86 // Reports the last unsupported mode that was encountered. Returns kCount if |
| 86 // no unsupported mode was encountered. | 87 // no unsupported mode was encountered. |
| 87 UiUnsupportedMode unsupported_mode() const { return unsupported_mode_; } | 88 UiUnsupportedMode unsupported_mode() const { return unsupported_mode_; } |
| 88 | 89 |
| 89 gfx::RenderText* url_render_text() { return url_render_text_.get(); } | 90 gfx::RenderText* url_render_text() { return url_render_text_.get(); } |
| 90 const base::string16& url_text() { return url_text_; } | 91 const base::string16& url_text() { return url_text_; } |
| 91 | 92 |
| 92 private: | 93 private: |
| 93 void OnUnsupportedFeature(UiUnsupportedMode mode) { | 94 void OnUnsupportedFeature(UiUnsupportedMode mode) { |
| 94 unsupported_mode_ = mode; | 95 unsupported_mode_ = mode; |
| 95 } | 96 } |
| 96 | 97 |
| 97 gfx::Size texture_size_; | |
| 98 gfx::Rect bounds_; | |
| 99 UiUnsupportedMode unsupported_mode_ = UiUnsupportedMode::kCount; | 98 UiUnsupportedMode unsupported_mode_ = UiUnsupportedMode::kCount; |
| 100 }; | 99 }; |
| 101 | 100 |
| 102 TestUrlBarTexture::TestUrlBarTexture() | 101 TestUrlBarTexture::TestUrlBarTexture() |
| 103 : UrlBarTexture(false, | 102 : UrlBarTexture(false, |
| 104 base::Bind(&TestUrlBarTexture::OnUnsupportedFeature, | 103 base::Bind(&TestUrlBarTexture::OnUnsupportedFeature, |
| 105 base::Unretained(this))), | 104 base::Unretained(this))) { |
| 106 texture_size_(kUrlWidth, kUrlHeight), | |
| 107 bounds_(kUrlWidth, kUrlHeight) { | |
| 108 gfx::FontList::SetDefaultFontDescription("Arial, Times New Roman, 15px"); | 105 gfx::FontList::SetDefaultFontDescription("Arial, Times New Roman, 15px"); |
| 109 } | 106 } |
| 110 | 107 |
| 111 class MockRenderText : public RenderTextWrapper { | 108 class MockRenderText : public RenderTextWrapper { |
| 112 public: | 109 public: |
| 113 MockRenderText() : RenderTextWrapper(nullptr) {} | 110 MockRenderText() : RenderTextWrapper(nullptr) {} |
| 114 ~MockRenderText() override {} | 111 ~MockRenderText() override {} |
| 115 | 112 |
| 116 MOCK_METHOD1(SetColor, void(SkColor value)); | 113 MOCK_METHOD1(SetColor, void(SkColor value)); |
| 117 MOCK_METHOD2(ApplyColor, void(SkColor value, const gfx::Range& range)); | 114 MOCK_METHOD2(ApplyColor, void(SkColor value, const gfx::Range& range)); |
| 118 MOCK_METHOD2(SetStyle, void(gfx::TextStyle style, bool value)); | 115 MOCK_METHOD2(SetStyle, void(gfx::TextStyle style, bool value)); |
| 119 MOCK_METHOD3(ApplyStyle, | 116 MOCK_METHOD3(ApplyStyle, |
| 120 void(gfx::TextStyle style, bool value, const gfx::Range& range)); | 117 void(gfx::TextStyle style, bool value, const gfx::Range& range)); |
| 118 MOCK_METHOD1(SetStrikeThicknessFactor, void(SkScalar)); |
| 121 | 119 |
| 122 private: | 120 private: |
| 123 DISALLOW_COPY_AND_ASSIGN(MockRenderText); | 121 DISALLOW_COPY_AND_ASSIGN(MockRenderText); |
| 124 }; | 122 }; |
| 125 | 123 |
| 126 class UrlEmphasisTest : public testing::Test { | 124 class UrlEmphasisTest : public testing::Test { |
| 127 protected: | 125 protected: |
| 128 void Verify(const std::string& url_string, | 126 void Verify(const std::string& url_string, |
| 129 SecurityLevel level, | 127 SecurityLevel level, |
| 130 const std::string& expected_string) { | 128 const std::string& expected_string) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 EXPECT_CALL(mock_, SetColor(kIncognitoDeemphasizedColor)); | 179 EXPECT_CALL(mock_, SetColor(kIncognitoDeemphasizedColor)); |
| 182 EXPECT_CALL(mock_, ApplyColor(kIncognitoEmphasizedColor, gfx::Range(0, 8))); | 180 EXPECT_CALL(mock_, ApplyColor(kIncognitoEmphasizedColor, gfx::Range(0, 8))); |
| 183 Verify("http://host.com/page", SecurityLevel::HTTP_SHOW_WARNING, | 181 Verify("http://host.com/page", SecurityLevel::HTTP_SHOW_WARNING, |
| 184 "host.com/page"); | 182 "host.com/page"); |
| 185 } | 183 } |
| 186 | 184 |
| 187 TEST_F(UrlEmphasisTest, DangerousHttpsHost) { | 185 TEST_F(UrlEmphasisTest, DangerousHttpsHost) { |
| 188 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor)); | 186 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor)); |
| 189 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(8, 16))); | 187 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(8, 16))); |
| 190 EXPECT_CALL(mock_, ApplyColor(kWarningColor, gfx::Range(0, 5))); | 188 EXPECT_CALL(mock_, ApplyColor(kWarningColor, gfx::Range(0, 5))); |
| 189 EXPECT_CALL(mock_, SetStrikeThicknessFactor(testing::_)); |
| 191 EXPECT_CALL(mock_, | 190 EXPECT_CALL(mock_, |
| 192 ApplyStyle(gfx::TextStyle::STRIKE, true, gfx::Range(0, 5))); | 191 ApplyStyle(gfx::TextStyle::STRIKE, true, gfx::Range(0, 5))); |
| 193 EXPECT_CALL(mock_, SetColor(kIncognitoDeemphasizedColor)); | 192 EXPECT_CALL(mock_, SetColor(kIncognitoDeemphasizedColor)); |
| 194 EXPECT_CALL(mock_, ApplyColor(kIncognitoEmphasizedColor, gfx::Range(8, 16))); | 193 EXPECT_CALL(mock_, ApplyColor(kIncognitoEmphasizedColor, gfx::Range(8, 16))); |
| 195 EXPECT_CALL(mock_, ApplyColor(kIncognitoWarningColor, gfx::Range(0, 5))); | 194 EXPECT_CALL(mock_, ApplyColor(kIncognitoWarningColor, gfx::Range(0, 5))); |
| 195 EXPECT_CALL(mock_, SetStrikeThicknessFactor(testing::_)); |
| 196 EXPECT_CALL(mock_, | 196 EXPECT_CALL(mock_, |
| 197 ApplyStyle(gfx::TextStyle::STRIKE, true, gfx::Range(0, 5))); | 197 ApplyStyle(gfx::TextStyle::STRIKE, true, gfx::Range(0, 5))); |
| 198 Verify("https://host.com/page", SecurityLevel::DANGEROUS, | 198 Verify("https://host.com/page", SecurityLevel::DANGEROUS, |
| 199 "https://host.com/page"); | 199 "https://host.com/page"); |
| 200 } | 200 } |
| 201 | 201 |
| 202 TEST_F(UrlEmphasisTest, Data) { | 202 TEST_F(UrlEmphasisTest, Data) { |
| 203 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor)); | 203 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor)); |
| 204 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(0, 4))); | 204 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(0, 4))); |
| 205 EXPECT_CALL(mock_, SetColor(kIncognitoDeemphasizedColor)); | 205 EXPECT_CALL(mock_, SetColor(kIncognitoDeemphasizedColor)); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 EXPECT_EQ(UiUnsupportedMode::kCount, texture.unsupported_mode()); | 286 EXPECT_EQ(UiUnsupportedMode::kCount, texture.unsupported_mode()); |
| 287 } | 287 } |
| 288 | 288 |
| 289 TEST(UrlBarTexture, EmptyURL) { | 289 TEST(UrlBarTexture, EmptyURL) { |
| 290 TestUrlBarTexture texture; | 290 TestUrlBarTexture texture; |
| 291 texture.DrawURL(GURL()); | 291 texture.DrawURL(GURL()); |
| 292 EXPECT_EQ(UiUnsupportedMode::kCount, texture.unsupported_mode()); | 292 EXPECT_EQ(UiUnsupportedMode::kCount, texture.unsupported_mode()); |
| 293 } | 293 } |
| 294 | 294 |
| 295 } // namespace vr_shell | 295 } // namespace vr_shell |
| OLD | NEW |