| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_window.h" | 11 #include "chrome/browser/ui/browser_window.h" |
| 12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 13 #include "chrome/browser/ui/window_sizer.h" | 13 #include "chrome/browser/ui/window_sizer.h" |
| 14 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
| 15 #include "chrome/test/in_process_browser_test.h" | 15 #include "chrome/test/in_process_browser_test.h" |
| 16 #include "chrome/test/ui_test_utils.h" | 16 #include "chrome/test/ui_test_utils.h" |
| 17 #include "content/browser/renderer_host/render_view_host.h" | 17 #include "content/browser/renderer_host/render_view_host.h" |
| 18 #include "content/browser/tab_contents/tab_contents.h" | 18 #include "content/browser/tab_contents/tab_contents.h" |
| 19 #include "content/common/content_notification_types.h" |
| 19 #include "content/common/notification_observer.h" | 20 #include "content/common/notification_observer.h" |
| 20 #include "content/common/notification_type.h" | |
| 21 #include "net/test/test_server.h" | 21 #include "net/test/test_server.h" |
| 22 #include "ui/base/clipboard/clipboard.h" | 22 #include "ui/base/clipboard/clipboard.h" |
| 23 #include "ui/gfx/codec/png_codec.h" | 23 #include "ui/gfx/codec/png_codec.h" |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 // Include things like browser frame and scrollbar and make sure we're bigger | 27 // Include things like browser frame and scrollbar and make sure we're bigger |
| 28 // than the test pdf document. | 28 // than the test pdf document. |
| 29 static const int kBrowserWidth = 1000; | 29 static const int kBrowserWidth = 1000; |
| 30 static const int kBrowserHeight = 600; | 30 static const int kBrowserHeight = 600; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 FilePath(FILE_PATH_LITERAL("pdf_browsertest.pdf")))); | 74 FilePath(FILE_PATH_LITERAL("pdf_browsertest.pdf")))); |
| 75 ui_test_utils::NavigateToURL(browser(), url); | 75 ui_test_utils::NavigateToURL(browser(), url); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void VerifySnapshot(const std::string& expected_filename) { | 78 void VerifySnapshot(const std::string& expected_filename) { |
| 79 snapshot_different_ = true; | 79 snapshot_different_ = true; |
| 80 expected_filename_ = expected_filename; | 80 expected_filename_ = expected_filename; |
| 81 TabContentsWrapper* wrapper = browser()->GetSelectedTabContentsWrapper(); | 81 TabContentsWrapper* wrapper = browser()->GetSelectedTabContentsWrapper(); |
| 82 wrapper->CaptureSnapshot(); | 82 wrapper->CaptureSnapshot(); |
| 83 ui_test_utils::RegisterAndWait(this, | 83 ui_test_utils::RegisterAndWait(this, |
| 84 NotificationType::TAB_SNAPSHOT_TAKEN, | 84 chrome::TAB_SNAPSHOT_TAKEN, |
| 85 Source<TabContentsWrapper>(wrapper)); | 85 Source<TabContentsWrapper>(wrapper)); |
| 86 ASSERT_FALSE(snapshot_different_) << "Rendering didn't match, see result " | 86 ASSERT_FALSE(snapshot_different_) << "Rendering didn't match, see result " |
| 87 "at " << snapshot_filename_.value().c_str(); | 87 "at " << snapshot_filename_.value().c_str(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void WaitForResponse() { | 90 void WaitForResponse() { |
| 91 // Even if the plugin has loaded the data or scrolled, because of how | 91 // Even if the plugin has loaded the data or scrolled, because of how |
| 92 // pepper painting works, we might not have the data. One way to force this | 92 // pepper painting works, we might not have the data. One way to force this |
| 93 // to be flushed is to do a find operation, since on this two-page test | 93 // to be flushed is to do a find operation, since on this two-page test |
| 94 // document, it'll wait for us to flush the renderer message loop twice and | 94 // document, it'll wait for us to flush the renderer message loop twice and |
| 95 // also the browser's once, at which point we're guaranteed to have updated | 95 // also the browser's once, at which point we're guaranteed to have updated |
| 96 // the backingstore. Hacky, but it works. | 96 // the backingstore. Hacky, but it works. |
| 97 // Note that we need to change the text each time, because if we don't the | 97 // Note that we need to change the text each time, because if we don't the |
| 98 // renderer code will think the second message is to go to next result, but | 98 // renderer code will think the second message is to go to next result, but |
| 99 // there are none so the plugin will assert. | 99 // there are none so the plugin will assert. |
| 100 | 100 |
| 101 string16 query = UTF8ToUTF16( | 101 string16 query = UTF8ToUTF16( |
| 102 std::string("xyzxyz" + base::IntToString(next_dummy_search_value_++))); | 102 std::string("xyzxyz" + base::IntToString(next_dummy_search_value_++))); |
| 103 ASSERT_EQ(0, ui_test_utils::FindInPage( | 103 ASSERT_EQ(0, ui_test_utils::FindInPage( |
| 104 browser()->GetSelectedTabContentsWrapper(), query, true, false, NULL)); | 104 browser()->GetSelectedTabContentsWrapper(), query, true, false, NULL)); |
| 105 } | 105 } |
| 106 | 106 |
| 107 private: | 107 private: |
| 108 // NotificationObserver | 108 // NotificationObserver |
| 109 virtual void Observe(NotificationType type, | 109 virtual void Observe(int type, |
| 110 const NotificationSource& source, | 110 const NotificationSource& source, |
| 111 const NotificationDetails& details) { | 111 const NotificationDetails& details) { |
| 112 if (type == NotificationType::TAB_SNAPSHOT_TAKEN) { | 112 if (type == chrome::TAB_SNAPSHOT_TAKEN) { |
| 113 MessageLoopForUI::current()->Quit(); | 113 MessageLoopForUI::current()->Quit(); |
| 114 FilePath reference = ui_test_utils::GetTestFilePath( | 114 FilePath reference = ui_test_utils::GetTestFilePath( |
| 115 GetPDFTestDir(), | 115 GetPDFTestDir(), |
| 116 FilePath().AppendASCII(expected_filename_)); | 116 FilePath().AppendASCII(expected_filename_)); |
| 117 base::PlatformFileInfo info; | 117 base::PlatformFileInfo info; |
| 118 ASSERT_TRUE(file_util::GetFileInfo(reference, &info)); | 118 ASSERT_TRUE(file_util::GetFileInfo(reference, &info)); |
| 119 int size = static_cast<size_t>(info.size); | 119 int size = static_cast<size_t>(info.size); |
| 120 scoped_array<char> data(new char[size]); | 120 scoped_array<char> data(new char[size]); |
| 121 ASSERT_EQ(size, file_util::ReadFile(reference, data.get(), size)); | 121 ASSERT_EQ(size, file_util::ReadFile(reference, data.get(), size)); |
| 122 | 122 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 } | 165 } |
| 166 | 166 |
| 167 if (snapshot_different_) { | 167 if (snapshot_different_) { |
| 168 std::vector<unsigned char> png_data; | 168 std::vector<unsigned char> png_data; |
| 169 gfx::PNGCodec::EncodeBGRASkBitmap(*bitmap, false, &png_data); | 169 gfx::PNGCodec::EncodeBGRASkBitmap(*bitmap, false, &png_data); |
| 170 if (file_util::CreateTemporaryFile(&snapshot_filename_)) { | 170 if (file_util::CreateTemporaryFile(&snapshot_filename_)) { |
| 171 file_util::WriteFile(snapshot_filename_, | 171 file_util::WriteFile(snapshot_filename_, |
| 172 reinterpret_cast<char*>(&png_data[0]), png_data.size()); | 172 reinterpret_cast<char*>(&png_data[0]), png_data.size()); |
| 173 } | 173 } |
| 174 } | 174 } |
| 175 } else if (type == NotificationType::LOAD_STOP) { | 175 } else if (type == chrome::LOAD_STOP) { |
| 176 load_stop_notification_count_++; | 176 load_stop_notification_count_++; |
| 177 } | 177 } |
| 178 } | 178 } |
| 179 | 179 |
| 180 // True if the snapshot differed from the expected value. | 180 // True if the snapshot differed from the expected value. |
| 181 bool snapshot_different_; | 181 bool snapshot_different_; |
| 182 // Internal variable used to synchronize to the renderer. | 182 // Internal variable used to synchronize to the renderer. |
| 183 int next_dummy_search_value_; | 183 int next_dummy_search_value_; |
| 184 // The filename of the bitmap to compare the snapshot to. | 184 // The filename of the bitmap to compare the snapshot to. |
| 185 std::string expected_filename_; | 185 std::string expected_filename_; |
| 186 // If the snapshot is different, holds the location where it's saved. | 186 // If the snapshot is different, holds the location where it's saved. |
| 187 FilePath snapshot_filename_; | 187 FilePath snapshot_filename_; |
| 188 // How many times we've seen NotificationType::LOAD_STOP. | 188 // How many times we've seen chrome::LOAD_STOP. |
| 189 int load_stop_notification_count_; | 189 int load_stop_notification_count_; |
| 190 | 190 |
| 191 scoped_ptr<net::TestServer> pdf_test_server_; | 191 scoped_ptr<net::TestServer> pdf_test_server_; |
| 192 }; | 192 }; |
| 193 | 193 |
| 194 #if defined(OS_CHROMEOS) | 194 #if defined(OS_CHROMEOS) |
| 195 // TODO(sanjeevr): http://crbug.com/79837 | 195 // TODO(sanjeevr): http://crbug.com/79837 |
| 196 #define MAYBE_Basic DISABLED_Basic | 196 #define MAYBE_Basic DISABLED_Basic |
| 197 #else | 197 #else |
| 198 #define MAYBE_Basic Basic | 198 #define MAYBE_Basic Basic |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 // This also loads all documents that used to crash, to ensure we don't have | 269 // This also loads all documents that used to crash, to ensure we don't have |
| 270 // regressions. | 270 // regressions. |
| 271 // Flaky as per http://crbug.com/74548. | 271 // Flaky as per http://crbug.com/74548. |
| 272 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, FLAKY_SLOW_Loading) { | 272 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, FLAKY_SLOW_Loading) { |
| 273 ASSERT_TRUE(pdf_test_server()->Start()); | 273 ASSERT_TRUE(pdf_test_server()->Start()); |
| 274 | 274 |
| 275 NavigationController* controller = | 275 NavigationController* controller = |
| 276 &(browser()->GetSelectedTabContents()->controller()); | 276 &(browser()->GetSelectedTabContents()->controller()); |
| 277 NotificationRegistrar registrar; | 277 NotificationRegistrar registrar; |
| 278 registrar.Add(this, | 278 registrar.Add(this, |
| 279 NotificationType::LOAD_STOP, | 279 chrome::LOAD_STOP, |
| 280 Source<NavigationController>(controller)); | 280 Source<NavigationController>(controller)); |
| 281 std::string base_url = std::string("files/"); | 281 std::string base_url = std::string("files/"); |
| 282 | 282 |
| 283 file_util::FileEnumerator file_enumerator( | 283 file_util::FileEnumerator file_enumerator( |
| 284 ui_test_utils::GetTestFilePath(GetPDFTestDir(), FilePath()), | 284 ui_test_utils::GetTestFilePath(GetPDFTestDir(), FilePath()), |
| 285 false, | 285 false, |
| 286 file_util::FileEnumerator::FILES, | 286 file_util::FileEnumerator::FILES, |
| 287 FILE_PATH_LITERAL("*.pdf")); | 287 FILE_PATH_LITERAL("*.pdf")); |
| 288 for (FilePath file_path = file_enumerator.Next(); | 288 for (FilePath file_path = file_enumerator.Next(); |
| 289 !file_path.empty(); | 289 !file_path.empty(); |
| 290 file_path = file_enumerator.Next()) { | 290 file_path = file_enumerator.Next()) { |
| 291 std::string filename = file_path.BaseName().MaybeAsASCII(); | 291 std::string filename = file_path.BaseName().MaybeAsASCII(); |
| 292 ASSERT_FALSE(filename.empty()); | 292 ASSERT_FALSE(filename.empty()); |
| 293 | 293 |
| 294 #if defined(OS_POSIX) | 294 #if defined(OS_POSIX) |
| 295 if (filename == "sample.pdf") | 295 if (filename == "sample.pdf") |
| 296 continue; // Crashes on Mac and Linux. http://crbug.com/63549 | 296 continue; // Crashes on Mac and Linux. http://crbug.com/63549 |
| 297 #endif | 297 #endif |
| 298 | 298 |
| 299 LOG(WARNING) << "PDFBrowserTest.Loading: " << filename; | 299 LOG(WARNING) << "PDFBrowserTest.Loading: " << filename; |
| 300 | 300 |
| 301 GURL url = pdf_test_server()->GetURL(base_url + filename); | 301 GURL url = pdf_test_server()->GetURL(base_url + filename); |
| 302 ui_test_utils::NavigateToURL(browser(), url); | 302 ui_test_utils::NavigateToURL(browser(), url); |
| 303 | 303 |
| 304 while (true) { | 304 while (true) { |
| 305 int last_count = load_stop_notification_count(); | 305 int last_count = load_stop_notification_count(); |
| 306 // We might get extraneous NotificationType::LOAD_STOP notifications when | 306 // We might get extraneous chrome::LOAD_STOP notifications when |
| 307 // doing async loading. This happens when the first loader is cancelled | 307 // doing async loading. This happens when the first loader is cancelled |
| 308 // and before creating a byte-range request loader. | 308 // and before creating a byte-range request loader. |
| 309 bool complete = false; | 309 bool complete = false; |
| 310 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 310 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 311 browser()->GetSelectedTabContents()->render_view_host(), | 311 browser()->GetSelectedTabContents()->render_view_host(), |
| 312 std::wstring(), | 312 std::wstring(), |
| 313 L"window.domAutomationController.send(plugin.documentLoadComplete())", | 313 L"window.domAutomationController.send(plugin.documentLoadComplete())", |
| 314 &complete)); | 314 &complete)); |
| 315 if (complete) | 315 if (complete) |
| 316 break; | 316 break; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 339 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( | 339 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( |
| 340 browser()->GetSelectedTabContents()->render_view_host(), | 340 browser()->GetSelectedTabContents()->render_view_host(), |
| 341 std::wstring(), | 341 std::wstring(), |
| 342 L"reloadPDF();")); | 342 L"reloadPDF();")); |
| 343 | 343 |
| 344 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); | 344 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); |
| 345 ASSERT_EQ("success", browser()->GetSelectedTabContents()->GetURL().query()); | 345 ASSERT_EQ("success", browser()->GetSelectedTabContents()->GetURL().query()); |
| 346 } | 346 } |
| 347 | 347 |
| 348 } // namespace | 348 } // namespace |
| OLD | NEW |