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 #include "base/memory/ptr_util.h" | |
| 7 #include "base/strings/utf_string_conversions.h" | |
| 8 #include "chrome/browser/android/vr_shell/textures/render_text_wrapper.h" | |
| 9 #include "components/security_state/core/security_state.h" | |
| 10 #include "components/url_formatter/url_formatter.h" | |
| 11 #include "testing/gmock/include/gmock/gmock.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 #include "ui/gfx/color_palette.h" | |
| 14 #include "ui/gfx/render_text.h" | |
| 15 | |
| 16 using security_state::SecurityLevel; | |
| 17 | |
| 18 namespace vr_shell { | |
| 19 | |
| 20 class MockRenderText : public vr_shell::RenderTextWrapper { | |
| 21 public: | |
| 22 MockRenderText() : RenderTextWrapper(nullptr) {} | |
| 23 ~MockRenderText() override {} | |
| 24 | |
| 25 MOCK_METHOD1(SetColor, void(SkColor value)); | |
| 26 MOCK_METHOD2(ApplyColor, void(SkColor value, const gfx::Range& range)); | |
| 27 MOCK_METHOD2(SetStyle, void(gfx::TextStyle style, bool value)); | |
| 28 MOCK_METHOD3(ApplyStyle, | |
| 29 void(gfx::TextStyle style, bool value, const gfx::Range& range)); | |
| 30 | |
| 31 private: | |
| 32 DISALLOW_COPY_AND_ASSIGN(MockRenderText); | |
| 33 }; | |
| 34 | |
| 35 static constexpr SkColor kEmphasizedColor = 0xFF000000; | |
|
Ian Vollick
2017/05/26 01:22:19
Can you please expose these via color scheme or by
cjgrant
2017/05/26 15:58:59
As discussed offline, I do actually want this test
| |
| 36 static constexpr SkColor kDeemphasizedColor = 0xFF5A5A5A; | |
| 37 static const SkColor kSecureColor = gfx::kGoogleGreen700; | |
| 38 static const SkColor kWarningColor = gfx::kGoogleRed700; | |
| 39 | |
| 40 class UrlEmphasisTest : public testing::Test { | |
| 41 protected: | |
| 42 void Verify(const std::string& url_string, | |
| 43 SecurityLevel level, | |
| 44 const std::string& expected_string) { | |
| 45 GURL url(base::UTF8ToUTF16(url_string)); | |
| 46 url::Parsed parsed; | |
| 47 const base::string16 formatted_url = url_formatter::FormatUrl( | |
| 48 url, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::NORMAL, | |
| 49 &parsed, nullptr, nullptr); | |
| 50 EXPECT_EQ(formatted_url, base::UTF8ToUTF16(expected_string)); | |
| 51 UrlBarTexture::ApplyUrlStyling(formatted_url, parsed, level, &mock_); | |
| 52 } | |
| 53 | |
| 54 testing::InSequence in_sequence_; | |
| 55 MockRenderText mock_; | |
| 56 }; | |
| 57 | |
| 58 TEST_F(UrlEmphasisTest, SecureHttpsHost) { | |
| 59 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor)); | |
| 60 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(8, 16))); | |
| 61 EXPECT_CALL(mock_, ApplyColor(kSecureColor, gfx::Range(0, 5))); | |
| 62 Verify("https://host.com/page", SecurityLevel::SECURE, | |
| 63 "https://host.com/page"); | |
| 64 } | |
| 65 | |
| 66 TEST_F(UrlEmphasisTest, NotSecureHttpsHost) { | |
| 67 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor)); | |
| 68 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(8, 16))); | |
| 69 Verify("https://host.com/page", SecurityLevel::HTTP_SHOW_WARNING, | |
| 70 "https://host.com/page"); | |
| 71 } | |
| 72 | |
| 73 TEST_F(UrlEmphasisTest, NotSecureHttpHost) { | |
| 74 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor)); | |
| 75 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(0, 8))); | |
| 76 Verify("http://host.com/page", SecurityLevel::HTTP_SHOW_WARNING, | |
| 77 "host.com/page"); | |
| 78 } | |
| 79 | |
| 80 TEST_F(UrlEmphasisTest, DangerousHttpsHost) { | |
| 81 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor)); | |
| 82 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(8, 16))); | |
| 83 EXPECT_CALL(mock_, ApplyColor(kWarningColor, gfx::Range(0, 5))); | |
| 84 EXPECT_CALL(mock_, ApplyStyle(gfx::TextStyle::DIAGONAL_STRIKE, true, | |
| 85 gfx::Range(0, 5))); | |
| 86 Verify("https://host.com/page", SecurityLevel::DANGEROUS, | |
| 87 "https://host.com/page"); | |
| 88 } | |
| 89 | |
| 90 TEST_F(UrlEmphasisTest, Data) { | |
| 91 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor)); | |
| 92 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(0, 4))); | |
| 93 Verify("data:text/html,lots of data", SecurityLevel::NONE, | |
| 94 "data:text/html,lots of data"); | |
| 95 } | |
| 96 | |
| 97 } // namespace vr_shell | |
| OLD | NEW |