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, std::string pdf_filename) { | 43 void RunTestsInFile(std::string filename, |
| 44 std::string pdf_filename, | |
| 45 std::string commonfile) { | |
|
raymes
2015/01/28 01:33:45
Let's not pass this as a param. Instead let's just
Deepak
2015/01/28 05:57:23
Done.
Deepak
2015/01/28 05:57:24
Done.
| |
| 44 base::FilePath pdf_path; | 46 base::FilePath pdf_path; |
| 45 ASSERT_TRUE(PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path)); | 47 ASSERT_TRUE(PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path)); |
| 46 ASSERT_TRUE( | 48 ASSERT_TRUE( |
| 47 content::PluginService::GetInstance()->GetRegisteredPpapiPluginInfo( | 49 content::PluginService::GetInstance()->GetRegisteredPpapiPluginInfo( |
| 48 pdf_path)); | 50 pdf_path)); |
| 49 ExtensionService* service = extensions::ExtensionSystem::Get( | 51 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 50 profile())->extension_service(); | 52 profile())->extension_service(); |
| 51 service->component_loader()->Add(IDR_PDF_MANIFEST, | 53 service->component_loader()->Add(IDR_PDF_MANIFEST, |
| 52 base::FilePath(FILE_PATH_LITERAL("pdf"))); | 54 base::FilePath(FILE_PATH_LITERAL("pdf"))); |
| 53 const extensions::Extension* extension = | 55 const extensions::Extension* extension = |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 66 url.spec()); | 68 url.spec()); |
| 67 ui_test_utils::NavigateToURL(browser(), extension_url); | 69 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 68 content::WebContents* contents = | 70 content::WebContents* contents = |
| 69 browser()->tab_strip_model()->GetActiveWebContents(); | 71 browser()->tab_strip_model()->GetActiveWebContents(); |
| 70 content::WaitForLoadStop(contents); | 72 content::WaitForLoadStop(contents); |
| 71 | 73 |
| 72 base::FilePath test_data_dir; | 74 base::FilePath test_data_dir; |
| 73 PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir); | 75 PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir); |
| 74 test_data_dir = test_data_dir.Append( | 76 test_data_dir = test_data_dir.Append( |
| 75 FILE_PATH_LITERAL("chrome/test/data/pdf")); | 77 FILE_PATH_LITERAL("chrome/test/data/pdf")); |
| 76 test_data_dir = test_data_dir.AppendASCII(filename); | 78 |
| 79 base::FilePath file_test_data_dir = test_data_dir.AppendASCII(filename); | |
| 77 | 80 |
| 78 std::string test_js; | 81 std::string test_js; |
| 79 ASSERT_TRUE(base::ReadFileToString(test_data_dir, &test_js)); | 82 ASSERT_TRUE(base::ReadFileToString(file_test_data_dir, &test_js)); |
| 83 | |
| 84 if (!commonfile.empty()) { | |
| 85 std::string test_common_js; | |
| 86 test_data_dir = test_data_dir.AppendASCII(commonfile); | |
| 87 ASSERT_TRUE(base::ReadFileToString(test_data_dir, &test_common_js)); | |
| 88 test_js.append(test_common_js); | |
| 89 } | |
| 90 | |
| 80 ASSERT_TRUE(content::ExecuteScript(contents, test_js)); | 91 ASSERT_TRUE(content::ExecuteScript(contents, test_js)); |
| 81 | 92 |
| 82 if (!catcher.GetNextResult()) | 93 if (!catcher.GetNextResult()) |
| 83 FAIL() << catcher.message(); | 94 FAIL() << catcher.message(); |
| 84 } | 95 } |
| 85 }; | 96 }; |
| 86 | 97 |
| 87 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Basic) { | 98 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Basic) { |
| 88 RunTestsInFile("basic_test.js", "test.pdf"); | 99 RunTestsInFile("basic_test.js", "test.pdf", ""); |
| 89 } | 100 } |
| 90 | 101 |
| 91 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, BasicPlugin) { | 102 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, BasicPlugin) { |
| 92 RunTestsInFile("basic_plugin_test.js", "test.pdf"); | 103 RunTestsInFile("basic_plugin_test.js", "test.pdf", ""); |
| 93 } | 104 } |
| 94 | 105 |
| 95 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Viewport) { | 106 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Viewport) { |
| 96 RunTestsInFile("viewport_test.js", "test.pdf"); | 107 RunTestsInFile("viewport_test.js", "test.pdf", "common_file.js"); |
| 97 } | 108 } |
| 98 | 109 |
| 99 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Bookmark) { | 110 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, Bookmark) { |
| 100 RunTestsInFile("bookmarks_test.js", "test-bookmarks.pdf"); | 111 RunTestsInFile("bookmarks_test.js", "test-bookmarks.pdf", ""); |
| 101 } | 112 } |
| 113 | |
| 114 IN_PROC_BROWSER_TEST_F(PDFExtensionTest, NamedDestionations) { | |
| 115 RunTestsInFile("nameddestinations_test.js", "test.pdf", "common_file.js"); | |
| 116 } | |
| OLD | NEW |