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