| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/files/file.h" | 6 #include "base/files/file.h" |
| 7 #include "base/files/file_enumerator.h" | 7 #include "base/files/file_enumerator.h" |
| 8 #include "base/hash.h" | 8 #include "base/hash.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 } | 88 } |
| 89 | 89 |
| 90 bool VerifySnapshot(const std::string& expected_filename) { | 90 bool VerifySnapshot(const std::string& expected_filename) { |
| 91 snapshot_different_ = true; | 91 snapshot_different_ = true; |
| 92 expected_filename_ = expected_filename; | 92 expected_filename_ = expected_filename; |
| 93 WebContents* web_contents = | 93 WebContents* web_contents = |
| 94 browser()->tab_strip_model()->GetActiveWebContents(); | 94 browser()->tab_strip_model()->GetActiveWebContents(); |
| 95 DCHECK(web_contents); | 95 DCHECK(web_contents); |
| 96 | 96 |
| 97 content::RenderWidgetHost* rwh = web_contents->GetRenderViewHost(); | 97 content::RenderWidgetHost* rwh = web_contents->GetRenderViewHost(); |
| 98 rwh->GetSnapshotFromRenderer(gfx::Rect(), base::Bind( | 98 rwh->CopyFromBackingStore( |
| 99 &PDFBrowserTest::GetSnapshotFromRendererCallback, this)); | 99 gfx::Rect(), |
| 100 gfx::Size(), |
| 101 base::Bind(&PDFBrowserTest::CopyFromBackingStoreCallback, this), |
| 102 SkBitmap::kARGB_8888_Config); |
| 100 | 103 |
| 101 content::RunMessageLoop(); | 104 content::RunMessageLoop(); |
| 102 | 105 |
| 103 if (snapshot_different_) { | 106 if (snapshot_different_) { |
| 104 LOG(INFO) << "Rendering didn't match, see result " << | 107 LOG(INFO) << "Rendering didn't match, see result " << |
| 105 snapshot_filename_.value().c_str(); | 108 snapshot_filename_.value().c_str(); |
| 106 } | 109 } |
| 107 return !snapshot_different_; | 110 return !snapshot_different_; |
| 108 } | 111 } |
| 109 | 112 |
| 110 void WaitForResponse() { | 113 void WaitForResponse() { |
| 111 // Even if the plugin has loaded the data or scrolled, because of how | 114 // Even if the plugin has loaded the data or scrolled, because of how |
| 112 // pepper painting works, we might not have the data. One way to force this | 115 // pepper painting works, we might not have the data. One way to force this |
| 113 // to be flushed is to do a find operation, since on this two-page test | 116 // to be flushed is to do a find operation, since on this two-page test |
| 114 // document, it'll wait for us to flush the renderer message loop twice and | 117 // document, it'll wait for us to flush the renderer message loop twice and |
| 115 // also the browser's once, at which point we're guaranteed to have updated | 118 // also the browser's once, at which point we're guaranteed to have updated |
| 116 // the backingstore. Hacky, but it works. | 119 // the backingstore. Hacky, but it works. |
| 117 // Note that we need to change the text each time, because if we don't the | 120 // Note that we need to change the text each time, because if we don't the |
| 118 // renderer code will think the second message is to go to next result, but | 121 // renderer code will think the second message is to go to next result, but |
| 119 // there are none so the plugin will assert. | 122 // there are none so the plugin will assert. |
| 120 | 123 |
| 121 base::string16 query = base::UTF8ToUTF16( | 124 base::string16 query = base::UTF8ToUTF16( |
| 122 std::string("xyzxyz" + base::IntToString(next_dummy_search_value_++))); | 125 std::string("xyzxyz" + base::IntToString(next_dummy_search_value_++))); |
| 123 ASSERT_EQ(0, ui_test_utils::FindInPage( | 126 ASSERT_EQ(0, ui_test_utils::FindInPage( |
| 124 browser()->tab_strip_model()->GetActiveWebContents(), | 127 browser()->tab_strip_model()->GetActiveWebContents(), |
| 125 query, true, false, NULL, NULL)); | 128 query, true, false, NULL, NULL)); |
| 126 } | 129 } |
| 127 | 130 |
| 128 private: | 131 private: |
| 129 void GetSnapshotFromRendererCallback(bool success, | 132 void CopyFromBackingStoreCallback(bool success, const SkBitmap& bitmap) { |
| 130 const SkBitmap& bitmap) { | |
| 131 base::MessageLoopForUI::current()->Quit(); | 133 base::MessageLoopForUI::current()->Quit(); |
| 132 ASSERT_EQ(success, true); | 134 ASSERT_EQ(success, true); |
| 133 base::FilePath reference = ui_test_utils::GetTestFilePath( | 135 base::FilePath reference = ui_test_utils::GetTestFilePath( |
| 134 GetPDFTestDir(), | 136 GetPDFTestDir(), |
| 135 base::FilePath().AppendASCII(expected_filename_)); | 137 base::FilePath().AppendASCII(expected_filename_)); |
| 136 base::File::Info info; | 138 base::File::Info info; |
| 137 ASSERT_TRUE(base::GetFileInfo(reference, &info)); | 139 ASSERT_TRUE(base::GetFileInfo(reference, &info)); |
| 138 int size = static_cast<size_t>(info.size); | 140 int size = static_cast<size_t>(info.size); |
| 139 scoped_ptr<char[]> data(new char[size]); | 141 scoped_ptr<char[]> data(new char[size]); |
| 140 ASSERT_EQ(size, base::ReadFile(reference, data.get(), size)); | 142 ASSERT_EQ(size, base::ReadFile(reference, data.get(), size)); |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 browser()->tab_strip_model()->GetActiveWebContents(), | 421 browser()->tab_strip_model()->GetActiveWebContents(), |
| 420 "reloadPDF();")); | 422 "reloadPDF();")); |
| 421 observer.Wait(); | 423 observer.Wait(); |
| 422 | 424 |
| 423 ASSERT_EQ("success", | 425 ASSERT_EQ("success", |
| 424 browser()->tab_strip_model()->GetActiveWebContents()-> | 426 browser()->tab_strip_model()->GetActiveWebContents()-> |
| 425 GetURL().query()); | 427 GetURL().query()); |
| 426 } | 428 } |
| 427 | 429 |
| 428 } // namespace | 430 } // namespace |
| OLD | NEW |