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

Side by Side Diff: content/browser/linux_ipc_browsertest.cc

Issue 2833973003: Initialize FontConfigIPC when zygote is disabled so font fallback works. (Closed)
Patch Set: Make test TSan clean. Created 3 years, 7 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
« no previous file with comments | « no previous file | content/browser/renderer_host/render_process_host_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 <map>
6 #include <set>
7 #include <string>
8
9 #include "base/command_line.h"
10 #include "base/macros.h"
11 #include "base/synchronization/lock.h"
12 #include "content/browser/renderer_host/sandbox_ipc_linux.h"
13 #include "content/public/common/content_switches.h"
14 #include "content/public/test/content_browser_test.h"
15 #include "content/public/test/content_browser_test_utils.h"
16 #include "testing/gmock/include/gmock/gmock-matchers.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/gfx/test/fontconfig_util_linux.h"
20
21 namespace content {
22
23 class LinuxIPCBrowserTest : public ContentBrowserTest,
24 public SandboxIPCHandler::TestObserver,
25 public testing::WithParamInterface<std::string> {
26 public:
27 LinuxIPCBrowserTest() {
28 SetUpFontConfigForTest();
29 SandboxIPCHandler::SetObserverForTests(this);
30 }
31 ~LinuxIPCBrowserTest() override {}
32
33 protected:
34 void SetUpCommandLine(base::CommandLine* command_line) override {
35 ContentBrowserTest::SetUpCommandLine(command_line);
36 if (GetParam() == "no-zygote") {
37 command_line->AppendSwitch(switches::kNoZygote);
38 command_line->AppendSwitch(switches::kNoSandbox);
39 }
40 }
41
42 // Override the system fontconfig configuration with a test configuration so
43 // that the tested font fallback will work the same across systems.
44 void SetUpFontConfigForTest() {
45 gfx::SetUpFontconfig();
46 for (size_t i = 0; i < gfx::kNumSystemFontsForFontconfig; ++i) {
47 gfx::LoadFontIntoFontconfig(
48 base::FilePath(gfx::kSystemFontsForFontconfig[i]));
49 }
50 }
51
52 void OnFontOpen(int id) override {
53 base::AutoLock lock(lock_);
54 opened_fonts_.insert(font_names_[id]);
55 }
56
57 void OnGetFallbackFontForChar(UChar32 c, std::string name, int id) override {
58 base::AutoLock lock(lock_);
59 fallback_fonts_[c] = name;
60 font_names_[id] = name;
61 }
62
63 std::string FallbackFontName(UChar32 c) {
64 base::AutoLock lock(lock_);
65 return fallback_fonts_[c];
66 }
67
68 std::set<std::string> OpenedFonts() {
69 base::AutoLock lock(lock_);
70 return opened_fonts_;
71 }
72
73 // These variables are accessed on the IPC thread and the test thread.
74 // All accesses on the IPC thread should be before the renderer process
75 // completes navigation, and all accesses on the test thread should be after.
76 // However we still need a mutex for the accesses to be sequenced according to
77 // the C++ memory model.
78 base::Lock lock_;
79 std::map<UChar32, std::string> fallback_fonts_;
80 std::map<int, std::string> font_names_;
81 std::set<std::string> opened_fonts_;
82
83 DISALLOW_COPY_AND_ASSIGN(LinuxIPCBrowserTest);
84 };
85
86 // Tests that Linux IPC font fallback code runs round-trip when Zygote is
87 // disabled. It doesn't care what font is chosen, just that the IPC messages are
88 // flowing. This test assumes that U+65E5 (CJK "Sun" character) will trigger the
89 // font fallback codepath.
90 IN_PROC_BROWSER_TEST_P(LinuxIPCBrowserTest, FontFallbackIPCWorks) {
91 GURL test_url = GetTestUrl("font", "font_fallback.html");
92 EXPECT_TRUE(NavigateToURL(shell(), test_url));
93 EXPECT_THAT(FallbackFontName(U'\U000065E5'), testing::Ne(""));
94 EXPECT_THAT(OpenedFonts(),
95 testing::Contains(FallbackFontName(U'\U000065E5')));
96 }
97
98 INSTANTIATE_TEST_CASE_P(LinuxIPCBrowserTest,
99 LinuxIPCBrowserTest,
100 ::testing::Values("zygote", "no-zygote"));
101
102 } // namespace
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/render_process_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698