Chromium Code Reviews| Index: chrome/test/plugin/pdf_browsertest.cc |
| =================================================================== |
| --- chrome/test/plugin/pdf_browsertest.cc (revision 66372) |
| +++ chrome/test/plugin/pdf_browsertest.cc (working copy) |
| @@ -7,6 +7,7 @@ |
| #include "base/file_util.h" |
| #include "base/path_service.h" |
| #include "base/string_number_conversions.h" |
| +#include "base/string_util.h" |
| #include "base/utf_string_conversions.h" |
| #include "chrome/browser/browser_window.h" |
| #include "chrome/browser/renderer_host/render_view_host.h" |
| @@ -31,24 +32,26 @@ |
| public NotificationObserver { |
| public: |
| PDFBrowserTest() |
| - : have_plugin_(false), |
| - snapshot_different_(true), |
| + : snapshot_different_(true), |
| next_dummy_search_value_(0) { |
| + EnableDOMAutomation(); |
| } |
| protected: |
| - bool have_plugin() const { return have_plugin_; } |
| - |
| virtual void SetUp() { |
| FilePath pdf_path; |
| PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); |
| - have_plugin_ = file_util::PathExists(pdf_path); |
| InProcessBrowserTest::SetUp(); |
| } |
| + FilePath GetPDFTestDir() { |
| + return FilePath(FilePath::kCurrentDirectory).AppendASCII("plugin"). |
| + AppendASCII("pdf"); |
| + } |
| + |
| void Load() { |
| GURL url(ui_test_utils::GetTestUrl( |
| - FilePath(FilePath::kCurrentDirectory), |
| + GetPDFTestDir(), |
| FilePath(FILE_PATH_LITERAL("pdf_browsertest.pdf")))); |
| ui_test_utils::NavigateToURL(browser(), url); |
| gfx::Rect bounds(gfx::Rect(0, 0, kBrowserWidth, kBrowserHeight)); |
| @@ -105,7 +108,7 @@ |
| if (type == NotificationType::TAB_SNAPSHOT_TAKEN) { |
| MessageLoopForUI::current()->Quit(); |
| FilePath reference = ui_test_utils::GetTestFilePath( |
| - FilePath(FilePath::kCurrentDirectory), |
| + GetPDFTestDir(), |
| FilePath().AppendASCII(expected_filename_)); |
| base::PlatformFileInfo info; |
| ASSERT_TRUE(file_util::GetFileInfo(reference, &info)); |
| @@ -168,10 +171,6 @@ |
| } |
| } |
| - // True if we found the pdf plugin. Needed since only official builders have |
| - // the pdf plugin, so for the rest, and for other devs, we don't want the test |
| - // to fail. |
| - bool have_plugin_; |
| // True if the snapshot differed from the expected value. |
| bool snapshot_different_; |
| // Internal variable used to synchronize to the renderer. |
| @@ -192,8 +191,6 @@ |
| // Tests basic PDF rendering. This can be broken depending on bad merges with |
| // the vendor, so it's important that we have basic sanity checking. |
| IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_Basic) { |
| - if (!have_plugin()) |
| - return; |
| ASSERT_NO_FATAL_FAILURE(Load()); |
| ASSERT_NO_FATAL_FAILURE(WaitForResponse()); |
| @@ -209,9 +206,6 @@ |
| // Tests that scrolling works. |
| IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_Scroll) { |
| - if (!have_plugin()) |
| - return; |
| - |
| ASSERT_NO_FATAL_FAILURE(Load()); |
| // We use wheel mouse event since that's the only one we can easily push to |
| @@ -235,9 +229,6 @@ |
| #endif |
| IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_FindAndCopy) { |
| - if (!have_plugin()) |
| - return; |
| - |
| ASSERT_NO_FATAL_FAILURE(Load()); |
| // Verifies that find in page works. |
| ASSERT_EQ(3, ui_test_utils::FindInPage( |
| @@ -261,4 +252,45 @@ |
| ASSERT_EQ("adipiscing", text); |
| } |
| +// Tests that loading async pdfs works correctly (i.e. document fully loads). |
| +// This also loads all documents that used to crash, to ensure we don't have |
| +// regressions. |
| +IN_PROC_BROWSER_TEST_F(PDFBrowserTest, Loading) { |
| + ASSERT_TRUE(test_server()->Start()); |
| + |
| + std::string base_url = std::string("files/plugin/pdf/"); |
| + |
| + file_util::FileEnumerator file_enumerator( |
| + ui_test_utils::GetTestFilePath(GetPDFTestDir(), FilePath()), |
| + false, |
| + file_util::FileEnumerator::FILES, |
| + FILE_PATH_LITERAL("*.pdf")); |
| + for (FilePath file_path = file_enumerator.Next(); |
| + !file_path.empty(); |
| + file_path = file_enumerator.Next()) { |
| + std::string filename = WideToASCII(file_path.BaseName().ToWStringHack()); |
| + LOG(WARNING) << "PDFBrowserTest.Loading: " << filename; |
|
cbentzel
2010/11/17 03:02:01
Local debugging?
jam
2010/11/17 04:10:10
no, i wanted it to show which pdf it's starting, s
|
| + |
| + GURL url = test_server()->GetURL(base_url + filename); |
| + ui_test_utils::NavigateToURL(browser(), url); |
| + |
| + bool complete = false; |
| + while (true) { |
| + // We might get extraneous NotificationType::LOAD_STOP notifications when |
| + // doing async loading. This happens when the first loader is cancelled |
| + // and before creating a byte-range request loader. |
| + ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| + browser()->GetSelectedTabContents()->render_view_host(), |
| + std::wstring(), |
| + L"window.domAutomationController.send(plugin.documentLoadComplete())", |
| + &complete)); |
| + if (complete) |
| + break; |
| + |
| + ui_test_utils::WaitForLoadStop( |
| + &(browser()->GetSelectedTabContents()->controller())); |
| + } |
| + } |
| +} |
| + |
| } // namespace |