Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: chrome/browser/android/vr_shell/textures/url_bar_texture_unittest.cc

Issue 2911943002: [vr] Add incognito coloring (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "chrome/browser/android/vr_shell/textures/render_text_wrapper.h" 11 #include "chrome/browser/android/vr_shell/textures/render_text_wrapper.h"
12 #include "components/security_state/core/security_state.h" 12 #include "components/security_state/core/security_state.h"
13 #include "components/url_formatter/url_formatter.h" 13 #include "components/url_formatter/url_formatter.h"
14 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/skia/include/core/SkSurface.h" 16 #include "third_party/skia/include/core/SkSurface.h"
17 #include "ui/gfx/color_palette.h" 17 #include "ui/gfx/color_palette.h"
18 #include "ui/gfx/font_list.h" 18 #include "ui/gfx/font_list.h"
19 #include "ui/gfx/render_text.h" 19 #include "ui/gfx/render_text.h"
20 20
21 using security_state::SecurityLevel; 21 using security_state::SecurityLevel;
22 22
23 namespace vr_shell { 23 namespace vr_shell {
24 24
25 static constexpr SkColor kEmphasizedColor = 0xFF000000; 25 static const SkColor kEmphasizedColor = 0xFF000000;
26 static constexpr SkColor kDeemphasizedColor = 0xFF5A5A5A; 26 static const SkColor kDeemphasizedColor = 0xFF5A5A5A;
27 static const SkColor kSecureColor = gfx::kGoogleGreen700; 27 static const SkColor kSecureColor = gfx::kGoogleGreen700;
28 static const SkColor kWarningColor = gfx::kGoogleRed700; 28 static const SkColor kWarningColor = gfx::kGoogleRed700;
29
30 static const SkColor kIncognitoDeemphasizedColor = 0xFFE6E6E6;
31 static const SkColor kIncognitoEmphasizedColor = 0xFFFFFFFF;
32 static const SkColor kIncognitoSecureColor = 0xFFE6E6E6;
33 static const SkColor kIncognitoWarningColor = 0xFFE6E6E6;
34
29 static constexpr int kUrlWidth = 400; 35 static constexpr int kUrlWidth = 400;
30 static constexpr int kUrlHeight = 30; 36 static constexpr int kUrlHeight = 30;
31 37
32 class MockRenderText : public RenderTextWrapper {
33 public:
34 MockRenderText() : RenderTextWrapper(nullptr) {}
35 ~MockRenderText() override {}
36
37 MOCK_METHOD1(SetColor, void(SkColor value));
38 MOCK_METHOD2(ApplyColor, void(SkColor value, const gfx::Range& range));
39 MOCK_METHOD2(SetStyle, void(gfx::TextStyle style, bool value));
40 MOCK_METHOD3(ApplyStyle,
41 void(gfx::TextStyle style, bool value, const gfx::Range& range));
42
43 private:
44 DISALLOW_COPY_AND_ASSIGN(MockRenderText);
45 };
46
47 class TestUrlBarTexture : public UrlBarTexture { 38 class TestUrlBarTexture : public UrlBarTexture {
48 public: 39 public:
49 TestUrlBarTexture(); 40 TestUrlBarTexture();
50 ~TestUrlBarTexture() override {} 41 ~TestUrlBarTexture() override {}
51 42
52 void DrawURL(const GURL& gurl) { 43 void DrawURL(const GURL& gurl) {
53 unsupported_mode_ = UiUnsupportedMode::kCount; 44 unsupported_mode_ = UiUnsupportedMode::kCount;
54 SetURL(gurl); 45 SetURL(gurl);
55 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul( 46 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(
56 texture_size_.width(), texture_size_.height()); 47 texture_size_.width(), texture_size_.height());
(...skipping 19 matching lines...) Expand all
76 }; 67 };
77 68
78 TestUrlBarTexture::TestUrlBarTexture() 69 TestUrlBarTexture::TestUrlBarTexture()
79 : UrlBarTexture(base::Bind(&TestUrlBarTexture::OnUnsupportedFeature, 70 : UrlBarTexture(base::Bind(&TestUrlBarTexture::OnUnsupportedFeature,
80 base::Unretained(this))), 71 base::Unretained(this))),
81 texture_size_(kUrlWidth, kUrlHeight), 72 texture_size_(kUrlWidth, kUrlHeight),
82 bounds_(kUrlWidth, kUrlHeight) { 73 bounds_(kUrlWidth, kUrlHeight) {
83 gfx::FontList::SetDefaultFontDescription("Arial, Times New Roman, 15px"); 74 gfx::FontList::SetDefaultFontDescription("Arial, Times New Roman, 15px");
84 } 75 }
85 76
77 class MockRenderText : public RenderTextWrapper {
78 public:
79 MockRenderText() : RenderTextWrapper(nullptr) {}
80 ~MockRenderText() override {}
81
82 MOCK_METHOD1(SetColor, void(SkColor value));
83 MOCK_METHOD2(ApplyColor, void(SkColor value, const gfx::Range& range));
84 MOCK_METHOD2(SetStyle, void(gfx::TextStyle style, bool value));
85 MOCK_METHOD3(ApplyStyle,
86 void(gfx::TextStyle style, bool value, const gfx::Range& range));
87
88 private:
89 DISALLOW_COPY_AND_ASSIGN(MockRenderText);
90 };
91
86 class UrlEmphasisTest : public testing::Test { 92 class UrlEmphasisTest : public testing::Test {
87 protected: 93 protected:
88 void Verify(const std::string& url_string, 94 void Verify(const std::string& url_string,
89 SecurityLevel level, 95 SecurityLevel level,
90 const std::string& expected_string) { 96 const std::string& expected_string) {
91 GURL url(base::UTF8ToUTF16(url_string)); 97 GURL url(base::UTF8ToUTF16(url_string));
92 url::Parsed parsed; 98 url::Parsed parsed;
93 const base::string16 formatted_url = url_formatter::FormatUrl( 99 const base::string16 formatted_url = url_formatter::FormatUrl(
94 url, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::NORMAL, 100 url, url_formatter::kFormatUrlOmitAll, net::UnescapeRule::NORMAL,
95 &parsed, nullptr, nullptr); 101 &parsed, nullptr, nullptr);
96 EXPECT_EQ(formatted_url, base::UTF8ToUTF16(expected_string)); 102 EXPECT_EQ(formatted_url, base::UTF8ToUTF16(expected_string));
97 UrlBarTexture::ApplyUrlStyling(formatted_url, parsed, level, &mock_); 103 UrlBarTexture::ApplyUrlStyling(
104 formatted_url, parsed, level, &mock_,
105 ColorScheme::GetColorScheme(ColorScheme::kModeNormal));
106 UrlBarTexture::ApplyUrlStyling(
107 formatted_url, parsed, level, &mock_,
108 ColorScheme::GetColorScheme(ColorScheme::kModeIncognito));
98 } 109 }
99 110
100 testing::InSequence in_sequence_; 111 testing::InSequence in_sequence_;
101 MockRenderText mock_; 112 MockRenderText mock_;
102 }; 113 };
103 114
104 TEST_F(UrlEmphasisTest, SecureHttpsHost) { 115 TEST_F(UrlEmphasisTest, SecureHttpsHost) {
105 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor)); 116 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor));
106 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(8, 16))); 117 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(8, 16)));
107 EXPECT_CALL(mock_, ApplyColor(kSecureColor, gfx::Range(0, 5))); 118 EXPECT_CALL(mock_, ApplyColor(kSecureColor, gfx::Range(0, 5)));
119 EXPECT_CALL(mock_, SetColor(kIncognitoDeemphasizedColor));
120 EXPECT_CALL(mock_, ApplyColor(kIncognitoEmphasizedColor, gfx::Range(8, 16)));
121 EXPECT_CALL(mock_, ApplyColor(kIncognitoSecureColor, gfx::Range(0, 5)));
108 Verify("https://host.com/page", SecurityLevel::SECURE, 122 Verify("https://host.com/page", SecurityLevel::SECURE,
109 "https://host.com/page"); 123 "https://host.com/page");
110 } 124 }
111 125
112 TEST_F(UrlEmphasisTest, NotSecureHttpsHost) { 126 TEST_F(UrlEmphasisTest, NotSecureHttpsHost) {
113 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor)); 127 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor));
114 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(8, 16))); 128 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(8, 16)));
129 EXPECT_CALL(mock_, SetColor(kIncognitoDeemphasizedColor));
130 EXPECT_CALL(mock_, ApplyColor(kIncognitoEmphasizedColor, gfx::Range(8, 16)));
115 Verify("https://host.com/page", SecurityLevel::HTTP_SHOW_WARNING, 131 Verify("https://host.com/page", SecurityLevel::HTTP_SHOW_WARNING,
116 "https://host.com/page"); 132 "https://host.com/page");
117 } 133 }
118 134
119 TEST_F(UrlEmphasisTest, NotSecureHttpHost) { 135 TEST_F(UrlEmphasisTest, NotSecureHttpHost) {
120 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor)); 136 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor));
121 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(0, 8))); 137 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(0, 8)));
138 EXPECT_CALL(mock_, SetColor(kIncognitoDeemphasizedColor));
139 EXPECT_CALL(mock_, ApplyColor(kIncognitoEmphasizedColor, gfx::Range(0, 8)));
122 Verify("http://host.com/page", SecurityLevel::HTTP_SHOW_WARNING, 140 Verify("http://host.com/page", SecurityLevel::HTTP_SHOW_WARNING,
123 "host.com/page"); 141 "host.com/page");
124 } 142 }
125 143
126 TEST_F(UrlEmphasisTest, DangerousHttpsHost) { 144 TEST_F(UrlEmphasisTest, DangerousHttpsHost) {
127 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor)); 145 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor));
128 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(8, 16))); 146 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(8, 16)));
129 EXPECT_CALL(mock_, ApplyColor(kWarningColor, gfx::Range(0, 5))); 147 EXPECT_CALL(mock_, ApplyColor(kWarningColor, gfx::Range(0, 5)));
130 EXPECT_CALL(mock_, ApplyStyle(gfx::TextStyle::DIAGONAL_STRIKE, true, 148 EXPECT_CALL(mock_, ApplyStyle(gfx::TextStyle::DIAGONAL_STRIKE, true,
131 gfx::Range(0, 5))); 149 gfx::Range(0, 5)));
150 EXPECT_CALL(mock_, SetColor(kIncognitoDeemphasizedColor));
151 EXPECT_CALL(mock_, ApplyColor(kIncognitoEmphasizedColor, gfx::Range(8, 16)));
152 EXPECT_CALL(mock_, ApplyColor(kIncognitoWarningColor, gfx::Range(0, 5)));
153 EXPECT_CALL(mock_, ApplyStyle(gfx::TextStyle::DIAGONAL_STRIKE, true,
154 gfx::Range(0, 5)));
132 Verify("https://host.com/page", SecurityLevel::DANGEROUS, 155 Verify("https://host.com/page", SecurityLevel::DANGEROUS,
133 "https://host.com/page"); 156 "https://host.com/page");
134 } 157 }
135 158
136 TEST_F(UrlEmphasisTest, Data) { 159 TEST_F(UrlEmphasisTest, Data) {
137 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor)); 160 EXPECT_CALL(mock_, SetColor(kDeemphasizedColor));
138 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(0, 4))); 161 EXPECT_CALL(mock_, ApplyColor(kEmphasizedColor, gfx::Range(0, 4)));
162 EXPECT_CALL(mock_, SetColor(kIncognitoDeemphasizedColor));
163 EXPECT_CALL(mock_, ApplyColor(kIncognitoEmphasizedColor, gfx::Range(0, 4)));
139 Verify("data:text/html,lots of data", SecurityLevel::NONE, 164 Verify("data:text/html,lots of data", SecurityLevel::NONE,
140 "data:text/html,lots of data"); 165 "data:text/html,lots of data");
141 } 166 }
142 167
143 TEST(UrlBarTextureTest, WillFailOnUnhandledCodePoint) { 168 TEST(UrlBarTextureTest, WillFailOnUnhandledCodePoint) {
144 TestUrlBarTexture texture; 169 TestUrlBarTexture texture;
145 texture.DrawURL(GURL("https://foo.com")); 170 texture.DrawURL(GURL("https://foo.com"));
146 EXPECT_EQ(UiUnsupportedMode::kCount, texture.unsupported_mode()); 171 EXPECT_EQ(UiUnsupportedMode::kCount, texture.unsupported_mode());
147 texture.SetForceFontFallbackFailure(true); 172 texture.SetForceFontFallbackFailure(true);
148 texture.DrawURL(GURL("https://bar.com")); 173 texture.DrawURL(GURL("https://bar.com"));
149 EXPECT_EQ(UiUnsupportedMode::kUnhandledCodePoint, texture.unsupported_mode()); 174 EXPECT_EQ(UiUnsupportedMode::kUnhandledCodePoint, texture.unsupported_mode());
150 texture.SetForceFontFallbackFailure(false); 175 texture.SetForceFontFallbackFailure(false);
151 texture.DrawURL(GURL("https://baz.com")); 176 texture.DrawURL(GURL("https://baz.com"));
152 EXPECT_EQ(UiUnsupportedMode::kCount, texture.unsupported_mode()); 177 EXPECT_EQ(UiUnsupportedMode::kCount, texture.unsupported_mode());
153 } 178 }
154 179
155 } // namespace vr_shell 180 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698