OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "base/base_paths.h" | 5 #include "base/base_paths.h" |
6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "chrome/browser/extensions/component_loader.h" | 8 #include "chrome/browser/extensions/component_loader.h" |
9 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 ExtensionApiTest::SetUpOnMainThread(); | 31 ExtensionApiTest::SetUpOnMainThread(); |
32 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 32 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
33 } | 33 } |
34 | 34 |
35 | 35 |
36 virtual void TearDownOnMainThread() override { | 36 virtual void TearDownOnMainThread() override { |
37 ASSERT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete()); | 37 ASSERT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete()); |
38 ExtensionApiTest::TearDownOnMainThread(); | 38 ExtensionApiTest::TearDownOnMainThread(); |
39 } | 39 } |
40 | 40 |
41 void RunTestsInFile(std::string filename, bool requiresPlugin) { | 41 void RunTestsInFile(std::string filename, std::string filepath, |
raymes
2015/01/13 07:25:12
nit: each param on a separate line
Alexandre Carlton
2015/01/15 05:01:42
Done.
| |
42 bool requiresPlugin) { | |
42 base::FilePath pdf_plugin_src; | 43 base::FilePath pdf_plugin_src; |
43 PathService::Get(base::DIR_SOURCE_ROOT, &pdf_plugin_src); | 44 PathService::Get(base::DIR_SOURCE_ROOT, &pdf_plugin_src); |
44 pdf_plugin_src = pdf_plugin_src.AppendASCII("pdf"); | 45 pdf_plugin_src = pdf_plugin_src.AppendASCII("pdf"); |
45 if (requiresPlugin && !base::DirectoryExists(pdf_plugin_src)) { | 46 if (requiresPlugin && !base::DirectoryExists(pdf_plugin_src)) { |
46 LOG(WARNING) << "Not running " << filename << | 47 LOG(WARNING) << "Not running " << filename << |
47 " because it requires the PDF plugin which is not available."; | 48 " because it requires the PDF plugin which is not available."; |
48 return; | 49 return; |
49 } | 50 } |
50 ExtensionService* service = extensions::ExtensionSystem::Get( | 51 ExtensionService* service = extensions::ExtensionSystem::Get( |
51 profile())->extension_service(); | 52 profile())->extension_service(); |
52 service->component_loader()->Add(IDR_PDF_MANIFEST, | 53 service->component_loader()->Add(IDR_PDF_MANIFEST, |
53 base::FilePath(FILE_PATH_LITERAL("pdf"))); | 54 base::FilePath(FILE_PATH_LITERAL("pdf"))); |
54 const extensions::Extension* extension = | 55 const extensions::Extension* extension = |
55 extensions::ExtensionRegistry::Get(profile()) | 56 extensions::ExtensionRegistry::Get(profile()) |
56 ->enabled_extensions() | 57 ->enabled_extensions() |
57 .GetByID("mhjfbmdgcfjbbpaeojofohoefgiehjai"); | 58 .GetByID("mhjfbmdgcfjbbpaeojofohoefgiehjai"); |
58 ASSERT_TRUE(extension); | 59 ASSERT_TRUE(extension); |
59 ASSERT_TRUE(MimeTypesHandler::GetHandler( | 60 ASSERT_TRUE(MimeTypesHandler::GetHandler( |
60 extension)->CanHandleMIMEType("application/pdf")); | 61 extension)->CanHandleMIMEType("application/pdf")); |
61 | 62 |
62 extensions::ResultCatcher catcher; | 63 extensions::ResultCatcher catcher; |
63 | 64 |
64 GURL url(embedded_test_server()->GetURL("/pdf/test.pdf")); | 65 GURL url(embedded_test_server()->GetURL(filepath)); |
65 GURL extension_url( | 66 GURL extension_url( |
66 "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html?" + | 67 "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html?" + |
67 url.spec()); | 68 url.spec()); |
68 ui_test_utils::NavigateToURL(browser(), extension_url); | 69 ui_test_utils::NavigateToURL(browser(), extension_url); |
69 content::WebContents* contents = | 70 content::WebContents* contents = |
70 browser()->tab_strip_model()->GetActiveWebContents(); | 71 browser()->tab_strip_model()->GetActiveWebContents(); |
71 content::WaitForLoadStop(contents); | 72 content::WaitForLoadStop(contents); |
72 | 73 |
73 base::FilePath test_data_dir; | 74 base::FilePath test_data_dir; |
74 PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir); | 75 PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir); |
75 test_data_dir = test_data_dir.Append( | 76 test_data_dir = test_data_dir.Append( |
76 FILE_PATH_LITERAL("chrome/test/data/pdf")); | 77 FILE_PATH_LITERAL("chrome/test/data/pdf")); |
77 test_data_dir = test_data_dir.AppendASCII(filename); | 78 test_data_dir = test_data_dir.AppendASCII(filename); |
78 | 79 |
79 std::string test_js; | 80 std::string test_js; |
80 ASSERT_TRUE(base::ReadFileToString(test_data_dir, &test_js)); | 81 ASSERT_TRUE(base::ReadFileToString(test_data_dir, &test_js)); |
81 ASSERT_TRUE(content::ExecuteScript(contents, test_js)); | 82 ASSERT_TRUE(content::ExecuteScript(contents, test_js)); |
82 | 83 |
83 if (!catcher.GetNextResult()) | 84 if (!catcher.GetNextResult()) |
84 FAIL() << catcher.message(); | 85 FAIL() << catcher.message(); |
85 } | 86 } |
86 }; | 87 }; |
87 | 88 |
88 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Basic) { | 89 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Basic) { |
89 RunTestsInFile("basic_test.js", false); | 90 RunTestsInFile("basic_test.js", "/pdf/test.pdf", false); |
raymes
2015/01/06 05:52:29
can we just specify the test filename here (e.g. t
Alexandre Carlton
2015/01/15 05:01:42
Done.
| |
90 } | 91 } |
91 | 92 |
92 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, BasicPlugin) { | 93 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, BasicPlugin) { |
93 RunTestsInFile("basic_plugin_test.js", true); | 94 RunTestsInFile("basic_plugin_test.js", "/pdf/test.pdf", true); |
94 } | 95 } |
95 | 96 |
96 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Viewport) { | 97 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Viewport) { |
97 RunTestsInFile("viewport_test.js", false); | 98 RunTestsInFile("viewport_test.js", "/pdf/test.pdf", false); |
98 } | 99 } |
100 | |
101 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Bookmark) { | |
102 RunTestsInFile("bookmarks_test.js", "/pdf/test-bookmarks.pdf", false); | |
103 } | |
OLD | NEW |