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

Unified Diff: content/browser/linux_ipc_browsertest.cc

Issue 2833973003: Initialize FontConfigIPC when zygote is disabled so font fallback works. (Closed)
Patch Set: Add browser test. 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/linux_ipc_browsertest.cc
diff --git a/content/browser/linux_ipc_browsertest.cc b/content/browser/linux_ipc_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0857998375d87f0d1d92c5a0415b7ed5a081efa8
--- /dev/null
+++ b/content/browser/linux_ipc_browsertest.cc
@@ -0,0 +1,80 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <map>
+#include <set>
+#include <string>
+
+#include "base/command_line.h"
+#include "base/macros.h"
+#include "content/browser/renderer_host/sandbox_ipc_linux.h"
+#include "content/public/common/content_switches.h"
+#include "content/public/test/content_browser_test.h"
+#include "content/public/test/content_browser_test_utils.h"
+#include "testing/gmock/include/gmock/gmock-matchers.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/gfx/test/fontconfig_util_linux.h"
+
+namespace content {
+
+class LinuxIPCBrowserTest : public ContentBrowserTest,
+ public SandboxIPCHandler::TestObserver,
+ public testing::WithParamInterface<std::string> {
+ public:
+ LinuxIPCBrowserTest() {
+ SetUpFontConfigForTest();
+ SandboxIPCHandler::SetObserverForTests(this);
+ }
+ ~LinuxIPCBrowserTest() override {}
+
+ protected:
+ void SetUpCommandLine(base::CommandLine* command_line) override {
+ ContentBrowserTest::SetUpCommandLine(command_line);
+ if (GetParam() == "no-zygote") {
+ command_line->AppendSwitch(switches::kNoZygote);
+ command_line->AppendSwitch(switches::kNoSandbox);
+ }
+ }
+
+ // Override the system fontconfig configuration with a test configuration so
+ // that the tested font fallback will work the same across systems.
+ void SetUpFontConfigForTest() {
+ gfx::SetUpFontconfig();
+ for (size_t i = 0; i < gfx::kNumSystemFontsForFontconfig; ++i) {
+ gfx::LoadFontIntoFontconfig(
+ base::FilePath(gfx::kSystemFontsForFontconfig[i]));
+ }
+ }
+
+ void OnFontOpen(int id) override { opened_fonts.insert(font_names[id]); };
+
+ void OnGetFallbackFontForChar(UChar32 c, std::string name, int id) override {
+ fallback_fonts[c] = name;
+ font_names[id] = name;
+ }
+
+ std::map<UChar32, std::string> fallback_fonts;
+ std::map<int, std::string> font_names;
+ std::set<std::string> opened_fonts;
+
+ DISALLOW_COPY_AND_ASSIGN(LinuxIPCBrowserTest);
+};
+
+// Tests that Linux IPC font fallback code runs round-trip when Zygote is
+// disabled. It doesn't care what font is chosen, just that the IPC messages are
+// flowing. This test assumes that U+65E5 (CJK "Sun" character) will trigger the
+// font fallback codepath.
+IN_PROC_BROWSER_TEST_P(LinuxIPCBrowserTest, FontFallbackIPCWorks) {
+ GURL test_url = GetTestUrl("font", "font_fallback.html");
+ EXPECT_TRUE(NavigateToURL(shell(), test_url));
+ EXPECT_THAT(fallback_fonts[U'\U000065E5'], testing::Ne(""));
+ EXPECT_THAT(opened_fonts, testing::Contains(fallback_fonts[U'\U000065E5']));
+}
+
+INSTANTIATE_TEST_CASE_P(LinuxIPCBrowserTest,
+ LinuxIPCBrowserTest,
+ ::testing::Values("zygote", "no-zygote"));
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698