| 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 <map> |
| 6 #include <set> |
| 7 #include <string> |
| 8 |
| 9 #include "base/command_line.h" |
| 10 #include "base/macros.h" |
| 11 #include "content/browser/renderer_host/sandbox_ipc_linux.h" |
| 12 #include "content/public/common/content_switches.h" |
| 13 #include "content/public/test/content_browser_test.h" |
| 14 #include "content/public/test/content_browser_test_utils.h" |
| 15 #include "testing/gmock/include/gmock/gmock-matchers.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "ui/gfx/test/fontconfig_util_linux.h" |
| 19 |
| 20 namespace content { |
| 21 |
| 22 class LinuxIPCBrowserTest : public ContentBrowserTest, |
| 23 public SandboxIPCHandler::TestObserver, |
| 24 public testing::WithParamInterface<std::string> { |
| 25 public: |
| 26 LinuxIPCBrowserTest() { |
| 27 SetUpFontConfigForTest(); |
| 28 SandboxIPCHandler::SetObserverForTests(this); |
| 29 } |
| 30 ~LinuxIPCBrowserTest() override {} |
| 31 |
| 32 protected: |
| 33 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 34 ContentBrowserTest::SetUpCommandLine(command_line); |
| 35 if (GetParam() == "no-zygote") { |
| 36 command_line->AppendSwitch(switches::kNoZygote); |
| 37 command_line->AppendSwitch(switches::kNoSandbox); |
| 38 } |
| 39 } |
| 40 |
| 41 // Override the system fontconfig configuration with a test configuration so |
| 42 // that the tested font fallback will work the same across systems. |
| 43 void SetUpFontConfigForTest() { |
| 44 gfx::SetUpFontconfig(); |
| 45 for (size_t i = 0; i < gfx::kNumSystemFontsForFontconfig; ++i) { |
| 46 gfx::LoadFontIntoFontconfig( |
| 47 base::FilePath(gfx::kSystemFontsForFontconfig[i])); |
| 48 } |
| 49 } |
| 50 |
| 51 void OnFontOpen(int id) override { opened_fonts.insert(font_names[id]); }; |
| 52 |
| 53 void OnGetFallbackFontForChar(UChar32 c, std::string name, int id) override { |
| 54 fallback_fonts[c] = name; |
| 55 font_names[id] = name; |
| 56 } |
| 57 |
| 58 std::map<UChar32, std::string> fallback_fonts; |
| 59 std::map<int, std::string> font_names; |
| 60 std::set<std::string> opened_fonts; |
| 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(LinuxIPCBrowserTest); |
| 63 }; |
| 64 |
| 65 // Tests that Linux IPC font fallback code runs round-trip when Zygote is |
| 66 // disabled. It doesn't care what font is chosen, just that the IPC messages are |
| 67 // flowing. This test assumes that U+65E5 (CJK "Sun" character) will trigger the |
| 68 // font fallback codepath. |
| 69 IN_PROC_BROWSER_TEST_P(LinuxIPCBrowserTest, FontFallbackIPCWorks) { |
| 70 GURL test_url = GetTestUrl("font", "font_fallback.html"); |
| 71 EXPECT_TRUE(NavigateToURL(shell(), test_url)); |
| 72 EXPECT_THAT(fallback_fonts[U'\U000065E5'], testing::Ne("")); |
| 73 EXPECT_THAT(opened_fonts, testing::Contains(fallback_fonts[U'\U000065E5'])); |
| 74 } |
| 75 |
| 76 INSTANTIATE_TEST_CASE_P(LinuxIPCBrowserTest, |
| 77 LinuxIPCBrowserTest, |
| 78 ::testing::Values("zygote", "no-zygote")); |
| 79 |
| 80 } // namespace |
| OLD | NEW |