Give names to all utility processes.
[chromium-blink-merge.git] / chrome / browser / pdf / pdf_extension_test.cc
blobd89c474cfd53d9a79a80245079d2da02a4733a93
1 // Copyright 2014 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.
5 #include "base/base_paths.h"
6 #include "base/files/file_util.h"
7 #include "base/path_service.h"
8 #include "chrome/browser/extensions/component_loader.h"
9 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/common/chrome_paths.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/test/base/ui_test_utils.h"
15 #include "content/public/browser/plugin_service.h"
16 #include "content/public/test/browser_test_utils.h"
17 #include "extensions/browser/extension_registry.h"
18 #include "extensions/common/manifest_handlers/mime_types_handler.h"
19 #include "extensions/test/result_catcher.h"
20 #include "grit/browser_resources.h"
21 #include "net/test/embedded_test_server/embedded_test_server.h"
23 class PDFExtensionTest : public ExtensionApiTest {
24 public:
25 virtual ~PDFExtensionTest() {}
27 virtual void SetUpCommandLine(base::CommandLine* command_line) override {
28 ExtensionApiTest::SetUpCommandLine(command_line);
29 command_line->AppendSwitch(switches::kEnableOutOfProcessPdf);
32 virtual void SetUpOnMainThread() override {
33 ExtensionApiTest::SetUpOnMainThread();
34 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
38 virtual void TearDownOnMainThread() override {
39 ASSERT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete());
40 ExtensionApiTest::TearDownOnMainThread();
43 void RunTestsInFile(std::string filename, std::string pdf_filename) {
44 ExtensionService* service = extensions::ExtensionSystem::Get(
45 profile())->extension_service();
46 service->component_loader()->Add(IDR_PDF_MANIFEST,
47 base::FilePath(FILE_PATH_LITERAL("pdf")));
48 const extensions::Extension* extension =
49 extensions::ExtensionRegistry::Get(profile())
50 ->enabled_extensions()
51 .GetByID("mhjfbmdgcfjbbpaeojofohoefgiehjai");
52 ASSERT_TRUE(extension);
53 ASSERT_TRUE(MimeTypesHandler::GetHandler(
54 extension)->CanHandleMIMEType("application/pdf"));
56 extensions::ResultCatcher catcher;
58 GURL url(embedded_test_server()->GetURL("/pdf/" + pdf_filename));
59 GURL extension_url(
60 "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html?" +
61 url.spec());
62 ui_test_utils::NavigateToURL(browser(), extension_url);
63 content::WebContents* contents =
64 browser()->tab_strip_model()->GetActiveWebContents();
65 content::WaitForLoadStop(contents);
67 base::FilePath test_data_dir;
68 PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir);
69 test_data_dir = test_data_dir.Append(
70 FILE_PATH_LITERAL("chrome/test/data/pdf"));
71 base::FilePath test_util_path = test_data_dir.AppendASCII("test_util.js");
72 std::string test_util_js;
73 ASSERT_TRUE(base::ReadFileToString(test_util_path, &test_util_js));
75 base::FilePath test_file_path = test_data_dir.AppendASCII(filename);
76 std::string test_js;
77 ASSERT_TRUE(base::ReadFileToString(test_file_path, &test_js));
79 test_util_js.append(test_js);
80 ASSERT_TRUE(content::ExecuteScript(contents, test_util_js));
82 if (!catcher.GetNextResult())
83 FAIL() << catcher.message();
87 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Basic) {
88 RunTestsInFile("basic_test.js", "test.pdf");
91 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, BasicPlugin) {
92 RunTestsInFile("basic_plugin_test.js", "test.pdf");
95 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Viewport) {
96 RunTestsInFile("viewport_test.js", "test.pdf");
99 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Bookmark) {
100 RunTestsInFile("bookmarks_test.js", "test-bookmarks.pdf");
103 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Navigator) {
104 RunTestsInFile("navigator_test.js", "test.pdf");
107 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, ParamsParser) {
108 RunTestsInFile("params_parser_test.js", "test.pdf");