| 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/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/snapshot_tab_helper.h" | 12 #include "chrome/browser/ui/snapshot_tab_helper.h" |
| 13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 13 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 14 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
| 15 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
| 16 #include "chrome/test/base/in_process_browser_test.h" | 16 #include "chrome/test/base/in_process_browser_test.h" |
| 17 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
| 18 #include "content/public/browser/navigation_controller.h" | 18 #include "content/public/browser/navigation_controller.h" |
| 19 #include "content/public/browser/notification_observer.h" | 19 #include "content/public/browser/notification_observer.h" |
| 20 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
| 21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 #include "net/test/test_server.h" | 22 #include "net/test/test_server.h" |
| 23 #include "third_party/skia/include/core/SkBitmap.h" | 23 #include "third_party/skia/include/core/SkBitmap.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 76 |
| 77 GURL url(ui_test_utils::GetTestUrl( | 77 GURL url(ui_test_utils::GetTestUrl( |
| 78 GetPDFTestDir(), | 78 GetPDFTestDir(), |
| 79 FilePath(FILE_PATH_LITERAL("pdf_browsertest.pdf")))); | 79 FilePath(FILE_PATH_LITERAL("pdf_browsertest.pdf")))); |
| 80 ui_test_utils::NavigateToURL(browser(), url); | 80 ui_test_utils::NavigateToURL(browser(), url); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void VerifySnapshot(const std::string& expected_filename) { | 83 void VerifySnapshot(const std::string& expected_filename) { |
| 84 snapshot_different_ = true; | 84 snapshot_different_ = true; |
| 85 expected_filename_ = expected_filename; | 85 expected_filename_ = expected_filename; |
| 86 TabContentsWrapper* wrapper = browser()->GetSelectedTabContentsWrapper(); | 86 TabContents* tab_contents = browser()->GetActiveTabContents(); |
| 87 wrapper->snapshot_tab_helper()->CaptureSnapshot(); | 87 tab_contents->snapshot_tab_helper()->CaptureSnapshot(); |
| 88 ui_test_utils::RegisterAndWait( | 88 ui_test_utils::RegisterAndWait( |
| 89 this, | 89 this, |
| 90 chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN, | 90 chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN, |
| 91 content::Source<WebContents>(wrapper->web_contents())); | 91 content::Source<WebContents>(tab_contents->web_contents())); |
| 92 ASSERT_FALSE(snapshot_different_) << "Rendering didn't match, see result " | 92 ASSERT_FALSE(snapshot_different_) << "Rendering didn't match, see result " |
| 93 "at " << snapshot_filename_.value().c_str(); | 93 "at " << snapshot_filename_.value().c_str(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void WaitForResponse() { | 96 void WaitForResponse() { |
| 97 // Even if the plugin has loaded the data or scrolled, because of how | 97 // Even if the plugin has loaded the data or scrolled, because of how |
| 98 // pepper painting works, we might not have the data. One way to force this | 98 // pepper painting works, we might not have the data. One way to force this |
| 99 // to be flushed is to do a find operation, since on this two-page test | 99 // to be flushed is to do a find operation, since on this two-page test |
| 100 // document, it'll wait for us to flush the renderer message loop twice and | 100 // document, it'll wait for us to flush the renderer message loop twice and |
| 101 // also the browser's once, at which point we're guaranteed to have updated | 101 // also the browser's once, at which point we're guaranteed to have updated |
| 102 // the backingstore. Hacky, but it works. | 102 // the backingstore. Hacky, but it works. |
| 103 // Note that we need to change the text each time, because if we don't the | 103 // Note that we need to change the text each time, because if we don't the |
| 104 // renderer code will think the second message is to go to next result, but | 104 // renderer code will think the second message is to go to next result, but |
| 105 // there are none so the plugin will assert. | 105 // there are none so the plugin will assert. |
| 106 | 106 |
| 107 string16 query = UTF8ToUTF16( | 107 string16 query = UTF8ToUTF16( |
| 108 std::string("xyzxyz" + base::IntToString(next_dummy_search_value_++))); | 108 std::string("xyzxyz" + base::IntToString(next_dummy_search_value_++))); |
| 109 ASSERT_EQ(0, ui_test_utils::FindInPage( | 109 ASSERT_EQ(0, ui_test_utils::FindInPage( |
| 110 browser()->GetSelectedTabContentsWrapper(), query, true, false, NULL)); | 110 browser()->GetActiveTabContents(), query, true, false, NULL)); |
| 111 } | 111 } |
| 112 | 112 |
| 113 private: | 113 private: |
| 114 // content::NotificationObserver | 114 // content::NotificationObserver |
| 115 virtual void Observe(int type, | 115 virtual void Observe(int type, |
| 116 const content::NotificationSource& source, | 116 const content::NotificationSource& source, |
| 117 const content::NotificationDetails& details) { | 117 const content::NotificationDetails& details) { |
| 118 if (type == chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN) { | 118 if (type == chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN) { |
| 119 MessageLoopForUI::current()->Quit(); | 119 MessageLoopForUI::current()->Quit(); |
| 120 FilePath reference = ui_test_utils::GetTestFilePath( | 120 FilePath reference = ui_test_utils::GetTestFilePath( |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_Scroll) { | 230 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_Scroll) { |
| 231 ASSERT_NO_FATAL_FAILURE(Load()); | 231 ASSERT_NO_FATAL_FAILURE(Load()); |
| 232 | 232 |
| 233 // We use wheel mouse event since that's the only one we can easily push to | 233 // We use wheel mouse event since that's the only one we can easily push to |
| 234 // the renderer. There's no way to push a cross-platform keyboard event at | 234 // the renderer. There's no way to push a cross-platform keyboard event at |
| 235 // the moment. | 235 // the moment. |
| 236 WebKit::WebMouseWheelEvent wheel_event; | 236 WebKit::WebMouseWheelEvent wheel_event; |
| 237 wheel_event.type = WebKit::WebInputEvent::MouseWheel; | 237 wheel_event.type = WebKit::WebInputEvent::MouseWheel; |
| 238 wheel_event.deltaY = -200; | 238 wheel_event.deltaY = -200; |
| 239 wheel_event.wheelTicksY = -2; | 239 wheel_event.wheelTicksY = -2; |
| 240 WebContents* web_contents = browser()->GetSelectedWebContents(); | 240 WebContents* web_contents = browser()->GetActiveWebContents(); |
| 241 web_contents->GetRenderViewHost()->ForwardWheelEvent(wheel_event); | 241 web_contents->GetRenderViewHost()->ForwardWheelEvent(wheel_event); |
| 242 ASSERT_NO_FATAL_FAILURE(WaitForResponse()); | 242 ASSERT_NO_FATAL_FAILURE(WaitForResponse()); |
| 243 | 243 |
| 244 int y_offset = 0; | 244 int y_offset = 0; |
| 245 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractInt( | 245 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractInt( |
| 246 browser()->GetSelectedWebContents()->GetRenderViewHost(), | 246 browser()->GetActiveWebContents()->GetRenderViewHost(), |
| 247 std::wstring(), | 247 std::wstring(), |
| 248 L"window.domAutomationController.send(plugin.pageYOffset())", | 248 L"window.domAutomationController.send(plugin.pageYOffset())", |
| 249 &y_offset)); | 249 &y_offset)); |
| 250 ASSERT_GT(y_offset, 0); | 250 ASSERT_GT(y_offset, 0); |
| 251 } | 251 } |
| 252 | 252 |
| 253 #if defined(OS_CHROMEOS) | 253 #if defined(OS_CHROMEOS) |
| 254 // TODO(sanjeevr): http://crbug.com/79837 | 254 // TODO(sanjeevr): http://crbug.com/79837 |
| 255 #define MAYBE_FindAndCopy DISABLED_FindAndCopy | 255 #define MAYBE_FindAndCopy DISABLED_FindAndCopy |
| 256 #else | 256 #else |
| 257 #define MAYBE_FindAndCopy FindAndCopy | 257 #define MAYBE_FindAndCopy FindAndCopy |
| 258 #endif | 258 #endif |
| 259 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_FindAndCopy) { | 259 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_FindAndCopy) { |
| 260 ASSERT_NO_FATAL_FAILURE(Load()); | 260 ASSERT_NO_FATAL_FAILURE(Load()); |
| 261 // Verifies that find in page works. | 261 // Verifies that find in page works. |
| 262 ASSERT_EQ(3, ui_test_utils::FindInPage( | 262 ASSERT_EQ(3, ui_test_utils::FindInPage( |
| 263 browser()->GetSelectedTabContentsWrapper(), UTF8ToUTF16("adipiscing"), | 263 browser()->GetActiveTabContents(), UTF8ToUTF16("adipiscing"), |
| 264 true, false, NULL)); | 264 true, false, NULL)); |
| 265 | 265 |
| 266 // Verify that copying selected text works. | 266 // Verify that copying selected text works. |
| 267 ui::Clipboard clipboard; | 267 ui::Clipboard clipboard; |
| 268 // Reset the clipboard first. | 268 // Reset the clipboard first. |
| 269 ui::Clipboard::ObjectMap objects; | 269 ui::Clipboard::ObjectMap objects; |
| 270 ui::Clipboard::ObjectMapParams params; | 270 ui::Clipboard::ObjectMapParams params; |
| 271 params.push_back(std::vector<char>()); | 271 params.push_back(std::vector<char>()); |
| 272 objects[ui::Clipboard::CBF_TEXT] = params; | 272 objects[ui::Clipboard::CBF_TEXT] = params; |
| 273 clipboard.WriteObjects(ui::Clipboard::BUFFER_STANDARD, objects); | 273 clipboard.WriteObjects(ui::Clipboard::BUFFER_STANDARD, objects); |
| 274 | 274 |
| 275 browser()->GetSelectedWebContents()->GetRenderViewHost()->Copy(); | 275 browser()->GetActiveWebContents()->GetRenderViewHost()->Copy(); |
| 276 ASSERT_NO_FATAL_FAILURE(WaitForResponse()); | 276 ASSERT_NO_FATAL_FAILURE(WaitForResponse()); |
| 277 | 277 |
| 278 std::string text; | 278 std::string text; |
| 279 clipboard.ReadAsciiText(ui::Clipboard::BUFFER_STANDARD, &text); | 279 clipboard.ReadAsciiText(ui::Clipboard::BUFFER_STANDARD, &text); |
| 280 ASSERT_EQ("adipiscing", text); | 280 ASSERT_EQ("adipiscing", text); |
| 281 } | 281 } |
| 282 | 282 |
| 283 // Tests that loading async pdfs works correctly (i.e. document fully loads). | 283 // Tests that loading async pdfs works correctly (i.e. document fully loads). |
| 284 // This also loads all documents that used to crash, to ensure we don't have | 284 // This also loads all documents that used to crash, to ensure we don't have |
| 285 // regressions. | 285 // regressions. |
| 286 // If it flakes, reopen http://crbug.com/74548. | 286 // If it flakes, reopen http://crbug.com/74548. |
| 287 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, SLOW_Loading) { | 287 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, SLOW_Loading) { |
| 288 ASSERT_TRUE(pdf_test_server()->Start()); | 288 ASSERT_TRUE(pdf_test_server()->Start()); |
| 289 | 289 |
| 290 NavigationController* controller = | 290 NavigationController* controller = |
| 291 &(browser()->GetSelectedWebContents()->GetController()); | 291 &(browser()->GetActiveWebContents()->GetController()); |
| 292 content::NotificationRegistrar registrar; | 292 content::NotificationRegistrar registrar; |
| 293 registrar.Add(this, | 293 registrar.Add(this, |
| 294 content::NOTIFICATION_LOAD_STOP, | 294 content::NOTIFICATION_LOAD_STOP, |
| 295 content::Source<NavigationController>(controller)); | 295 content::Source<NavigationController>(controller)); |
| 296 std::string base_url = std::string("files/"); | 296 std::string base_url = std::string("files/"); |
| 297 | 297 |
| 298 file_util::FileEnumerator file_enumerator( | 298 file_util::FileEnumerator file_enumerator( |
| 299 ui_test_utils::GetTestFilePath(GetPDFTestDir(), FilePath()), | 299 ui_test_utils::GetTestFilePath(GetPDFTestDir(), FilePath()), |
| 300 false, | 300 false, |
| 301 file_util::FileEnumerator::FILES, | 301 file_util::FileEnumerator::FILES, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 316 GURL url = pdf_test_server()->GetURL(base_url + filename); | 316 GURL url = pdf_test_server()->GetURL(base_url + filename); |
| 317 ui_test_utils::NavigateToURL(browser(), url); | 317 ui_test_utils::NavigateToURL(browser(), url); |
| 318 | 318 |
| 319 while (true) { | 319 while (true) { |
| 320 int last_count = load_stop_notification_count(); | 320 int last_count = load_stop_notification_count(); |
| 321 // We might get extraneous chrome::LOAD_STOP notifications when | 321 // We might get extraneous chrome::LOAD_STOP notifications when |
| 322 // doing async loading. This happens when the first loader is cancelled | 322 // doing async loading. This happens when the first loader is cancelled |
| 323 // and before creating a byte-range request loader. | 323 // and before creating a byte-range request loader. |
| 324 bool complete = false; | 324 bool complete = false; |
| 325 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 325 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 326 browser()->GetSelectedWebContents()->GetRenderViewHost(), | 326 browser()->GetActiveWebContents()->GetRenderViewHost(), |
| 327 std::wstring(), | 327 std::wstring(), |
| 328 L"window.domAutomationController.send(plugin.documentLoadComplete())", | 328 L"window.domAutomationController.send(plugin.documentLoadComplete())", |
| 329 &complete)); | 329 &complete)); |
| 330 if (complete) | 330 if (complete) |
| 331 break; | 331 break; |
| 332 | 332 |
| 333 // Check if the LOAD_STOP notification could have come while we run a | 333 // Check if the LOAD_STOP notification could have come while we run a |
| 334 // nested message loop for the JS call. | 334 // nested message loop for the JS call. |
| 335 if (last_count != load_stop_notification_count()) | 335 if (last_count != load_stop_notification_count()) |
| 336 continue; | 336 continue; |
| 337 ui_test_utils::WaitForLoadStop(browser()->GetSelectedWebContents()); | 337 ui_test_utils::WaitForLoadStop(browser()->GetActiveWebContents()); |
| 338 } | 338 } |
| 339 } | 339 } |
| 340 } | 340 } |
| 341 | 341 |
| 342 // Flaky as per http://crbug.com/74549. | 342 // Flaky as per http://crbug.com/74549. |
| 343 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, DISABLED_OnLoadAndReload) { | 343 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, DISABLED_OnLoadAndReload) { |
| 344 ASSERT_TRUE(pdf_test_server()->Start()); | 344 ASSERT_TRUE(pdf_test_server()->Start()); |
| 345 | 345 |
| 346 GURL url = pdf_test_server()->GetURL("files/onload_reload.html"); | 346 GURL url = pdf_test_server()->GetURL("files/onload_reload.html"); |
| 347 ui_test_utils::NavigateToURL(browser(), url); | 347 ui_test_utils::NavigateToURL(browser(), url); |
| 348 | 348 |
| 349 ui_test_utils::WindowedNotificationObserver observer( | 349 ui_test_utils::WindowedNotificationObserver observer( |
| 350 content::NOTIFICATION_LOAD_STOP, | 350 content::NOTIFICATION_LOAD_STOP, |
| 351 content::Source<NavigationController>( | 351 content::Source<NavigationController>( |
| 352 &browser()->GetSelectedWebContents()->GetController())); | 352 &browser()->GetActiveWebContents()->GetController())); |
| 353 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( | 353 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( |
| 354 browser()->GetSelectedWebContents()->GetRenderViewHost(), | 354 browser()->GetActiveWebContents()->GetRenderViewHost(), |
| 355 std::wstring(), | 355 std::wstring(), |
| 356 L"reloadPDF();")); | 356 L"reloadPDF();")); |
| 357 observer.Wait(); | 357 observer.Wait(); |
| 358 | 358 |
| 359 ASSERT_EQ("success", browser()->GetSelectedWebContents()->GetURL().query()); | 359 ASSERT_EQ("success", browser()->GetActiveWebContents()->GetURL().query()); |
| 360 } | 360 } |
| 361 | 361 |
| 362 } // namespace | 362 } // namespace |
| OLD | NEW |