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 22 matching lines...) Expand all Loading... | |
| 33 ExtensionApiTest::SetUpOnMainThread(); | 33 ExtensionApiTest::SetUpOnMainThread(); |
| 34 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 34 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 35 } | 35 } |
| 36 | 36 |
| 37 | 37 |
| 38 virtual void TearDownOnMainThread() override { | 38 virtual void TearDownOnMainThread() override { |
| 39 ASSERT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete()); | 39 ASSERT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete()); |
| 40 ExtensionApiTest::TearDownOnMainThread(); | 40 ExtensionApiTest::TearDownOnMainThread(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void RunTestsInFile(std::string filename) { | 43 void RunTestsInFile(std::string filename, |
| 44 std::string pdf_filename) { | |
|
raymes
2015/01/23 00:34:51
Will this all fit on a single line?
Alexandre Carlton
2015/01/23 01:46:20
Yes, I'll change it.
| |
| 44 base::FilePath pdf_path; | 45 base::FilePath pdf_path; |
| 45 ASSERT_TRUE(PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path)); | 46 ASSERT_TRUE(PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path)); |
| 46 ASSERT_TRUE( | 47 ASSERT_TRUE( |
| 47 content::PluginService::GetInstance()->GetRegisteredPpapiPluginInfo( | 48 content::PluginService::GetInstance()->GetRegisteredPpapiPluginInfo( |
| 48 pdf_path)); | 49 pdf_path)); |
| 49 ExtensionService* service = extensions::ExtensionSystem::Get( | 50 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 50 profile())->extension_service(); | 51 profile())->extension_service(); |
| 51 service->component_loader()->Add(IDR_PDF_MANIFEST, | 52 service->component_loader()->Add(IDR_PDF_MANIFEST, |
| 52 base::FilePath(FILE_PATH_LITERAL("pdf"))); | 53 base::FilePath(FILE_PATH_LITERAL("pdf"))); |
| 53 const extensions::Extension* extension = | 54 const extensions::Extension* extension = |
| 54 extensions::ExtensionRegistry::Get(profile()) | 55 extensions::ExtensionRegistry::Get(profile()) |
| 55 ->enabled_extensions() | 56 ->enabled_extensions() |
| 56 .GetByID("mhjfbmdgcfjbbpaeojofohoefgiehjai"); | 57 .GetByID("mhjfbmdgcfjbbpaeojofohoefgiehjai"); |
| 57 ASSERT_TRUE(extension); | 58 ASSERT_TRUE(extension); |
| 58 ASSERT_TRUE(MimeTypesHandler::GetHandler( | 59 ASSERT_TRUE(MimeTypesHandler::GetHandler( |
| 59 extension)->CanHandleMIMEType("application/pdf")); | 60 extension)->CanHandleMIMEType("application/pdf")); |
| 60 | 61 |
| 61 extensions::ResultCatcher catcher; | 62 extensions::ResultCatcher catcher; |
| 62 | 63 |
| 63 GURL url(embedded_test_server()->GetURL("/pdf/test.pdf")); | 64 GURL url(embedded_test_server()->GetURL("/pdf/" + pdf_filename)); |
| 64 GURL extension_url( | 65 GURL extension_url( |
| 65 "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html?" + | 66 "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.html?" + |
| 66 url.spec()); | 67 url.spec()); |
| 67 ui_test_utils::NavigateToURL(browser(), extension_url); | 68 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 68 content::WebContents* contents = | 69 content::WebContents* contents = |
| 69 browser()->tab_strip_model()->GetActiveWebContents(); | 70 browser()->tab_strip_model()->GetActiveWebContents(); |
| 70 content::WaitForLoadStop(contents); | 71 content::WaitForLoadStop(contents); |
| 71 | 72 |
| 72 base::FilePath test_data_dir; | 73 base::FilePath test_data_dir; |
| 73 PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir); | 74 PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir); |
| 74 test_data_dir = test_data_dir.Append( | 75 test_data_dir = test_data_dir.Append( |
| 75 FILE_PATH_LITERAL("chrome/test/data/pdf")); | 76 FILE_PATH_LITERAL("chrome/test/data/pdf")); |
| 76 test_data_dir = test_data_dir.AppendASCII(filename); | 77 test_data_dir = test_data_dir.AppendASCII(filename); |
| 77 | 78 |
| 78 std::string test_js; | 79 std::string test_js; |
| 79 ASSERT_TRUE(base::ReadFileToString(test_data_dir, &test_js)); | 80 ASSERT_TRUE(base::ReadFileToString(test_data_dir, &test_js)); |
| 80 ASSERT_TRUE(content::ExecuteScript(contents, test_js)); | 81 ASSERT_TRUE(content::ExecuteScript(contents, test_js)); |
| 81 | 82 |
| 82 if (!catcher.GetNextResult()) | 83 if (!catcher.GetNextResult()) |
| 83 FAIL() << catcher.message(); | 84 FAIL() << catcher.message(); |
| 84 } | 85 } |
| 85 }; | 86 }; |
| 86 | 87 |
| 87 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Basic) { | 88 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Basic) { |
| 88 RunTestsInFile("basic_test.js"); | 89 RunTestsInFile("basic_test.js", "test.pdf"); |
| 89 } | 90 } |
| 90 | 91 |
| 91 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, BasicPlugin) { | 92 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, BasicPlugin) { |
| 92 RunTestsInFile("basic_plugin_test.js"); | 93 RunTestsInFile("basic_plugin_test.js", "test.pdf"); |
| 93 } | 94 } |
| 94 | 95 |
| 95 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Viewport) { | 96 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Viewport) { |
| 96 RunTestsInFile("viewport_test.js"); | 97 RunTestsInFile("viewport_test.js", "test.pdf"); |
| 97 } | 98 } |
| 99 | |
| 100 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Bookmark) { | |
| 101 RunTestsInFile("bookmarks_test.js", "test-bookmarks.pdf"); | |
| 102 } | |
| OLD | NEW |