Chromium Code Reviews| 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, |
| 42 std::string pdf_filename, | |
| 43 bool requiresPlugin) { | |
|
raymes
2015/01/15 05:40:19
nit: can you please remove the requiresPlugin para
Alexandre Carlton
2015/01/16 02:39:07
Done.
| |
| 42 base::FilePath pdf_plugin_src; | 44 base::FilePath pdf_plugin_src; |
| 43 PathService::Get(base::DIR_SOURCE_ROOT, &pdf_plugin_src); | 45 PathService::Get(base::DIR_SOURCE_ROOT, &pdf_plugin_src); |
| 44 pdf_plugin_src = pdf_plugin_src.AppendASCII("pdf"); | 46 pdf_plugin_src = pdf_plugin_src.AppendASCII("pdf"); |
| 45 if (requiresPlugin && !base::DirectoryExists(pdf_plugin_src)) { | 47 if (requiresPlugin && !base::DirectoryExists(pdf_plugin_src)) { |
| 46 LOG(WARNING) << "Not running " << filename << | 48 LOG(WARNING) << "Not running " << filename << |
| 47 " because it requires the PDF plugin which is not available."; | 49 " because it requires the PDF plugin which is not available."; |
| 48 return; | 50 return; |
| 49 } | 51 } |
| 50 ExtensionService* service = extensions::ExtensionSystem::Get( | 52 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 51 profile())->extension_service(); | 53 profile())->extension_service(); |
| 52 service->component_loader()->Add(IDR_PDF_MANIFEST, | 54 service->component_loader()->Add(IDR_PDF_MANIFEST, |
| 53 base::FilePath(FILE_PATH_LITERAL("pdf"))); | 55 base::FilePath(FILE_PATH_LITERAL("pdf"))); |
| 54 const extensions::Extension* extension = | 56 const extensions::Extension* extension = |
| 55 extensions::ExtensionRegistry::Get(profile()) | 57 extensions::ExtensionRegistry::Get(profile()) |
| 56 ->enabled_extensions() | 58 ->enabled_extensions() |
| 57 .GetByID("mhjfbmdgcfjbbpaeojofohoefgiehjai"); | 59 .GetByID("mhjfbmdgcfjbbpaeojofohoefgiehjai"); |
| 58 ASSERT_TRUE(extension); | 60 ASSERT_TRUE(extension); |
| 59 ASSERT_TRUE(MimeTypesHandler::GetHandler( | 61 ASSERT_TRUE(MimeTypesHandler::GetHandler( |
| 60 extension)->CanHandleMIMEType("application/pdf")); | 62 extension)->CanHandleMIMEType("application/pdf")); |
| 61 | 63 |
| 62 extensions::ResultCatcher catcher; | 64 extensions::ResultCatcher catcher; |
| 63 | 65 |
| 64 GURL url(embedded_test_server()->GetURL("/pdf/test.pdf")); | 66 GURL url(embedded_test_server()->GetURL("/pdf/" + pdf_filename)); |
| 65 GURL extension_url( | 67 GURL extension_url( |
| 66 "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html?" + | 68 "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html?" + |
| 67 url.spec()); | 69 url.spec()); |
| 68 ui_test_utils::NavigateToURL(browser(), extension_url); | 70 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 69 content::WebContents* contents = | 71 content::WebContents* contents = |
| 70 browser()->tab_strip_model()->GetActiveWebContents(); | 72 browser()->tab_strip_model()->GetActiveWebContents(); |
| 71 content::WaitForLoadStop(contents); | 73 content::WaitForLoadStop(contents); |
| 72 | 74 |
| 73 base::FilePath test_data_dir; | 75 base::FilePath test_data_dir; |
| 74 PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir); | 76 PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir); |
| 75 test_data_dir = test_data_dir.Append( | 77 test_data_dir = test_data_dir.Append( |
| 76 FILE_PATH_LITERAL("chrome/test/data/pdf")); | 78 FILE_PATH_LITERAL("chrome/test/data/pdf")); |
| 77 test_data_dir = test_data_dir.AppendASCII(filename); | 79 test_data_dir = test_data_dir.AppendASCII(filename); |
| 78 | 80 |
| 79 std::string test_js; | 81 std::string test_js; |
| 80 ASSERT_TRUE(base::ReadFileToString(test_data_dir, &test_js)); | 82 ASSERT_TRUE(base::ReadFileToString(test_data_dir, &test_js)); |
| 81 ASSERT_TRUE(content::ExecuteScript(contents, test_js)); | 83 ASSERT_TRUE(content::ExecuteScript(contents, test_js)); |
| 82 | 84 |
| 83 if (!catcher.GetNextResult()) | 85 if (!catcher.GetNextResult()) |
| 84 FAIL() << catcher.message(); | 86 FAIL() << catcher.message(); |
| 85 } | 87 } |
| 86 }; | 88 }; |
| 87 | 89 |
| 88 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Basic) { | 90 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Basic) { |
| 89 RunTestsInFile("basic_test.js", false); | 91 RunTestsInFile("basic_test.js", "test.pdf", false); |
| 90 } | 92 } |
| 91 | 93 |
| 92 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, BasicPlugin) { | 94 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, BasicPlugin) { |
| 93 RunTestsInFile("basic_plugin_test.js", true); | 95 RunTestsInFile("basic_plugin_test.js", "test.pdf", true); |
| 94 } | 96 } |
| 95 | 97 |
| 96 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Viewport) { | 98 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Viewport) { |
| 97 RunTestsInFile("viewport_test.js", false); | 99 RunTestsInFile("viewport_test.js", "test.pdf", false); |
| 98 } | 100 } |
| 101 | |
| 102 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Bookmark) { | |
| 103 RunTestsInFile("bookmarks_test.js", "test-bookmarks.pdf", false); | |
| 104 } | |
| OLD | NEW |