Chromium Code Reviews| 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 #include "base/memory/ptr_util.h" | 6 #include "base/memory/ptr_util.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/android/vr_shell/textures/render_text_wrapper.h" | 8 #include "chrome/browser/android/vr_shell/textures/render_text_wrapper.h" |
| 9 #include "components/security_state/core/security_state.h" | 9 #include "components/security_state/core/security_state.h" |
| 10 #include "components/url_formatter/url_formatter.h" | 10 #include "components/url_formatter/url_formatter.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 MOCK_METHOD1(SetColor, void(SkColor value)); | 25 MOCK_METHOD1(SetColor, void(SkColor value)); |
| 26 MOCK_METHOD2(ApplyColor, void(SkColor value, const gfx::Range& range)); | 26 MOCK_METHOD2(ApplyColor, void(SkColor value, const gfx::Range& range)); |
| 27 MOCK_METHOD2(SetStyle, void(gfx::TextStyle style, bool value)); | 27 MOCK_METHOD2(SetStyle, void(gfx::TextStyle style, bool value)); |
| 28 MOCK_METHOD3(ApplyStyle, | 28 MOCK_METHOD3(ApplyStyle, |
| 29 void(gfx::TextStyle style, bool value, const gfx::Range& range)); | 29 void(gfx::TextStyle style, bool value, const gfx::Range& range)); |
| 30 | 30 |
| 31 private: | 31 private: |
| 32 DISALLOW_COPY_AND_ASSIGN(MockRenderText); | 32 DISALLOW_COPY_AND_ASSIGN(MockRenderText); |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 static constexpr SkColor kEmphasizedColor = 0xFF000000; | 35 static const SkColor kEmphasizedColor = 0xFF000000; |
| 36 static constexpr SkColor kDeemphasizedColor = 0xFF5A5A5A; | 36 static const SkColor kDeemphasizedColor = 0xFF5A5A5A; |
| 37 static const SkColor kSecureColor = gfx::kGoogleGreen700; | 37 static const SkColor kSecureColor = gfx::kGoogleGreen700; |
| 38 static const SkColor kWarningColor = gfx::kGoogleRed700; | 38 static const SkColor kWarningColor = gfx::kGoogleRed700; |
| 39 | 39 |
| 40 static const SkColor kIncognitoDeemphasizedColor = 0xFFE6E6E6; | |
|
amp
2017/05/27 00:47:47
Are these redefining constants in the color scheme
Ian Vollick
2017/05/27 01:29:12
I had commented on the same thing on the patch tha
| |
| 41 static const SkColor kIncognitoEmphasizedColor = 0xFFFFFFFF; | |
| 42 static const SkColor kIncognitoSecureColor = 0xFFE6E6E6; | |
| 43 static const SkColor kIncognitoWarningColor = 0xFFE6E6E6; | |
| 44 | |
| 40 class UrlEmphasisTest : public testing::Test { | 45 class UrlEmphasisTest : public testing::Test { |
| 41 protected: | 46 protected: |
| 42 void Verify(const std::string& url_string, | 47 void Verify(const std::string& url_string, |
| 43 SecurityLevel level, | 48 SecurityLevel level, |
| 44 const std::string& expected_string) { | 49 const std::string& expected_string) { |
| 45 GURL url(base::UTF8ToUTF16(url_string)); | 50 GURL url(base::UTF8ToUTF16(url_string)); |
| 46 url::Parsed parsed; | 51 url::Parsed parsed; |
| 47 const base::string16 formatted_url = url_formatter::FormatUrl( | 52 const base::string16 formatted_url = url_formatter::FormatUrl( |
| 48 url, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::NORMAL, | 53 url, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::NORMAL, |
| 49 &parsed, nullptr, nullptr); | 54 &parsed, nullptr, nullptr); |
| 50 EXPECT_EQ(formatted_url, base::UTF8ToUTF16(expected_string)); | 55 EXPECT_EQ(formatted_url, base::UTF8ToUTF16(expected_string)); |
| 51 UrlBarTexture::ApplyUrlStyling(formatted_url, parsed, level, &mock_); | 56 UrlBarTexture::ApplyUrlStyling( |
| 57 formatted_url, parsed, level, &mock_, | |
| 58 ColorScheme::GetColorScheme(ColorScheme::kModeNormal)); | |
| 59 UrlBarTexture::ApplyUrlStyling( | |
| 60 formatted_url, parsed, level, &mock_, | |
| 61 ColorScheme::GetColorScheme(ColorScheme::kModeIncognito)); | |
| 52 } | 62 } |
| 53 | 63 |
| 54 testing::InSequence in_sequence_; | 64 testing::InSequence in_sequence_; |
| 55 MockRenderText mock_; | 65 MockRenderText mock_; |
| 56 }; | 66 }; |
| 57 | 67 |
| 58 TEST_F(UrlEmphasisTest, SecureHttpsHost) { | 68 TEST_F(UrlEmphasisTest, SecureHttpsHost) { |
| 59 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor)); | 69 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor)); |
| 60 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(8, 16))); | 70 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(8, 16))); |
| 61 EXPECT_CALL(mock_, ApplyColor(kSecureColor, gfx::Range(0, 5))); | 71 EXPECT_CALL(mock_, ApplyColor(kSecureColor, gfx::Range(0, 5))); |
| 72 EXPECT_CALL(mock_, SetColor(kIncognitoDeemphasizedColor)); | |
| 73 EXPECT_CALL(mock_, ApplyColor(kIncognitoEmphasizedColor, gfx::Range(8, 16))); | |
| 74 EXPECT_CALL(mock_, ApplyColor(kIncognitoSecureColor, gfx::Range(0, 5))); | |
| 62 Verify("https://host.com/page", SecurityLevel::SECURE, | 75 Verify("https://host.com/page", SecurityLevel::SECURE, |
| 63 "https://host.com/page"); | 76 "https://host.com/page"); |
| 64 } | 77 } |
| 65 | 78 |
| 66 TEST_F(UrlEmphasisTest, NotSecureHttpsHost) { | 79 TEST_F(UrlEmphasisTest, NotSecureHttpsHost) { |
| 67 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor)); | 80 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor)); |
| 68 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(8, 16))); | 81 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(8, 16))); |
| 82 EXPECT_CALL(mock_, SetColor(kIncognitoDeemphasizedColor)); | |
| 83 EXPECT_CALL(mock_, ApplyColor(kIncognitoEmphasizedColor, gfx::Range(8, 16))); | |
| 69 Verify("https://host.com/page", SecurityLevel::HTTP_SHOW_WARNING, | 84 Verify("https://host.com/page", SecurityLevel::HTTP_SHOW_WARNING, |
| 70 "https://host.com/page"); | 85 "https://host.com/page"); |
| 71 } | 86 } |
| 72 | 87 |
| 73 TEST_F(UrlEmphasisTest, NotSecureHttpHost) { | 88 TEST_F(UrlEmphasisTest, NotSecureHttpHost) { |
| 74 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor)); | 89 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor)); |
| 75 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(0, 8))); | 90 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(0, 8))); |
| 91 EXPECT_CALL(mock_, SetColor(kIncognitoDeemphasizedColor)); | |
| 92 EXPECT_CALL(mock_, ApplyColor(kIncognitoEmphasizedColor, gfx::Range(0, 8))); | |
| 76 Verify("http://host.com/page", SecurityLevel::HTTP_SHOW_WARNING, | 93 Verify("http://host.com/page", SecurityLevel::HTTP_SHOW_WARNING, |
| 77 "host.com/page"); | 94 "host.com/page"); |
| 78 } | 95 } |
| 79 | 96 |
| 80 TEST_F(UrlEmphasisTest, DangerousHttpsHost) { | 97 TEST_F(UrlEmphasisTest, DangerousHttpsHost) { |
| 81 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor)); | 98 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor)); |
| 82 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(8, 16))); | 99 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(8, 16))); |
| 83 EXPECT_CALL(mock_, ApplyColor(kWarningColor, gfx::Range(0, 5))); | 100 EXPECT_CALL(mock_, ApplyColor(kWarningColor, gfx::Range(0, 5))); |
| 84 EXPECT_CALL(mock_, ApplyStyle(gfx::TextStyle::DIAGONAL_STRIKE, true, | 101 EXPECT_CALL(mock_, ApplyStyle(gfx::TextStyle::DIAGONAL_STRIKE, true, |
| 85 gfx::Range(0, 5))); | 102 gfx::Range(0, 5))); |
| 103 EXPECT_CALL(mock_, SetColor(kIncognitoDeemphasizedColor)); | |
| 104 EXPECT_CALL(mock_, ApplyColor(kIncognitoEmphasizedColor, gfx::Range(8, 16))); | |
| 105 EXPECT_CALL(mock_, ApplyColor(kIncognitoWarningColor, gfx::Range(0, 5))); | |
| 106 EXPECT_CALL(mock_, ApplyStyle(gfx::TextStyle::DIAGONAL_STRIKE, true, | |
| 107 gfx::Range(0, 5))); | |
| 86 Verify("https://host.com/page", SecurityLevel::DANGEROUS, | 108 Verify("https://host.com/page", SecurityLevel::DANGEROUS, |
| 87 "https://host.com/page"); | 109 "https://host.com/page"); |
| 88 } | 110 } |
| 89 | 111 |
| 90 TEST_F(UrlEmphasisTest, Data) { | 112 TEST_F(UrlEmphasisTest, Data) { |
| 91 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor)); | 113 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor)); |
| 92 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(0, 4))); | 114 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(0, 4))); |
| 115 EXPECT_CALL(mock_, SetColor(kIncognitoDeemphasizedColor)); | |
| 116 EXPECT_CALL(mock_, ApplyColor(kIncognitoEmphasizedColor, gfx::Range(0, 4))); | |
| 93 Verify("data:text/html,lots of data", SecurityLevel::NONE, | 117 Verify("data:text/html,lots of data", SecurityLevel::NONE, |
| 94 "data:text/html,lots of data"); | 118 "data:text/html,lots of data"); |
| 95 } | 119 } |
| 96 | 120 |
| 97 } // namespace vr_shell | 121 } // namespace vr_shell |
| OLD | NEW |