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 "content/public/test/browser_test_utils.h" | 5 #include "content/public/test/browser_test_utils.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <tuple> | 8 #include <tuple> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... | |
34 #include "content/browser/frame_host/render_frame_host_impl.h" | 34 #include "content/browser/frame_host/render_frame_host_impl.h" |
35 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" | 35 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
36 #include "content/browser/renderer_host/render_widget_host_impl.h" | 36 #include "content/browser/renderer_host/render_widget_host_impl.h" |
37 #include "content/browser/web_contents/web_contents_impl.h" | 37 #include "content/browser/web_contents/web_contents_impl.h" |
38 #include "content/browser/web_contents/web_contents_view.h" | 38 #include "content/browser/web_contents/web_contents_view.h" |
39 #include "content/common/input/synthetic_web_input_event_builders.h" | 39 #include "content/common/input/synthetic_web_input_event_builders.h" |
40 #include "content/common/input_messages.h" | 40 #include "content/common/input_messages.h" |
41 #include "content/common/view_messages.h" | 41 #include "content/common/view_messages.h" |
42 #include "content/public/browser/browser_context.h" | 42 #include "content/public/browser/browser_context.h" |
43 #include "content/public/browser/browser_plugin_guest_manager.h" | 43 #include "content/public/browser/browser_plugin_guest_manager.h" |
44 #include "content/public/browser/browser_thread.h" | |
44 #include "content/public/browser/histogram_fetcher.h" | 45 #include "content/public/browser/histogram_fetcher.h" |
45 #include "content/public/browser/navigation_entry.h" | 46 #include "content/public/browser/navigation_entry.h" |
46 #include "content/public/browser/notification_service.h" | 47 #include "content/public/browser/notification_service.h" |
47 #include "content/public/browser/notification_types.h" | 48 #include "content/public/browser/notification_types.h" |
48 #include "content/public/browser/render_frame_host.h" | 49 #include "content/public/browser/render_frame_host.h" |
49 #include "content/public/browser/render_process_host.h" | 50 #include "content/public/browser/render_process_host.h" |
50 #include "content/public/browser/render_view_host.h" | 51 #include "content/public/browser/render_view_host.h" |
51 #include "content/public/browser/storage_partition.h" | 52 #include "content/public/browser/storage_partition.h" |
52 #include "content/public/browser/web_contents.h" | 53 #include "content/public/browser/web_contents.h" |
53 #include "content/public/test/test_navigation_observer.h" | 54 #include "content/public/test/test_navigation_observer.h" |
54 #include "content/public/test/test_utils.h" | 55 #include "content/public/test/test_utils.h" |
55 #include "content/test/accessibility_browser_test_utils.h" | 56 #include "content/test/accessibility_browser_test_utils.h" |
56 #include "net/base/filename_util.h" | 57 #include "net/base/filename_util.h" |
57 #include "net/cookies/cookie_store.h" | 58 #include "net/cookies/cookie_store.h" |
58 #include "net/test/embedded_test_server/embedded_test_server.h" | 59 #include "net/test/embedded_test_server/embedded_test_server.h" |
59 #include "net/test/embedded_test_server/http_request.h" | 60 #include "net/test/embedded_test_server/http_request.h" |
60 #include "net/test/embedded_test_server/http_response.h" | 61 #include "net/test/embedded_test_server/http_response.h" |
61 #include "net/test/python_utils.h" | 62 #include "net/test/python_utils.h" |
62 #include "net/url_request/url_request_context.h" | 63 #include "net/url_request/url_request_context.h" |
63 #include "net/url_request/url_request_context_getter.h" | 64 #include "net/url_request/url_request_context_getter.h" |
64 #include "testing/gtest/include/gtest/gtest.h" | 65 #include "testing/gtest/include/gtest/gtest.h" |
66 #include "ui/base/clipboard/clipboard.h" | |
67 #include "ui/base/clipboard/scoped_clipboard_writer.h" | |
65 #include "ui/base/resource/resource_bundle.h" | 68 #include "ui/base/resource/resource_bundle.h" |
69 #include "ui/base/test/test_clipboard.h" | |
66 #include "ui/compositor/test/draw_waiter_for_test.h" | 70 #include "ui/compositor/test/draw_waiter_for_test.h" |
67 #include "ui/events/gesture_detection/gesture_configuration.h" | 71 #include "ui/events/gesture_detection/gesture_configuration.h" |
68 #include "ui/events/keycodes/dom/dom_code.h" | 72 #include "ui/events/keycodes/dom/dom_code.h" |
69 #include "ui/events/keycodes/dom/keycode_converter.h" | 73 #include "ui/events/keycodes/dom/keycode_converter.h" |
70 #include "ui/events/latency_info.h" | 74 #include "ui/events/latency_info.h" |
71 #include "ui/resources/grit/webui_resources.h" | 75 #include "ui/resources/grit/webui_resources.h" |
72 | 76 |
73 #if defined(USE_AURA) | 77 #if defined(USE_AURA) |
74 #include "content/browser/renderer_host/render_widget_host_view_aura.h" | 78 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
75 #include "ui/aura/test/window_event_dispatcher_test_api.h" | 79 #include "ui/aura/test/window_event_dispatcher_test_api.h" |
(...skipping 1348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1424 uint32_t InputMsgWatcher::WaitForAck() { | 1428 uint32_t InputMsgWatcher::WaitForAck() { |
1425 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1429 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1426 if (ack_result_ != INPUT_EVENT_ACK_STATE_UNKNOWN) | 1430 if (ack_result_ != INPUT_EVENT_ACK_STATE_UNKNOWN) |
1427 return ack_result_; | 1431 return ack_result_; |
1428 base::RunLoop run_loop; | 1432 base::RunLoop run_loop; |
1429 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure()); | 1433 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure()); |
1430 run_loop.Run(); | 1434 run_loop.Run(); |
1431 return ack_result_; | 1435 return ack_result_; |
1432 } | 1436 } |
1433 | 1437 |
1438 BrowserTestClipboard::BrowserTestClipboard() : is_installed_(false) {} | |
dcheng
2016/07/20 07:02:17
Nit: let's just merge SetUp and TearDown into the
| |
1439 | |
1440 BrowserTestClipboard::~BrowserTestClipboard() { | |
1441 DCHECK(!is_installed_); | |
1442 } | |
1443 | |
1444 void BrowserTestClipboard::SetUp() { | |
1445 DCHECK(!is_installed_); | |
1446 #if defined(OS_WIN) | |
1447 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | |
1448 RunTaskOnIOThreadAndWait( | |
1449 base::Bind(&BrowserTestClipboard::SetUp, base::Unretained(this))); | |
1450 is_installed_ = true; | |
1451 return; | |
1452 } | |
1453 #endif | |
1454 ui::TestClipboard::CreateForCurrentThread(); | |
1455 #if !defined(OS_WIN) | |
1456 is_installed_ = true; | |
1457 #endif | |
1458 } | |
1459 | |
1460 void BrowserTestClipboard::TearDown() { | |
1461 DCHECK(is_installed_); | |
1462 #if defined(OS_WIN) | |
1463 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | |
1464 RunTaskOnIOThreadAndWait( | |
1465 base::Bind(&BrowserTestClipboard::TearDown, base::Unretained(this))); | |
1466 is_installed_ = false; | |
1467 return; | |
1468 } | |
1469 #endif | |
1470 ui::Clipboard::DestroyClipboardForCurrentThread(); | |
1471 #if !defined(OS_WIN) | |
1472 is_installed_ = false; | |
1473 #endif | |
1474 } | |
1475 | |
1476 void BrowserTestClipboard::SetRtf(const std::string& rtf) { | |
1477 DCHECK(is_installed_); | |
1478 #if defined(OS_WIN) | |
1479 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | |
1480 RunTaskOnIOThreadAndWait(base::Bind(&BrowserTestClipboard::SetRtf, | |
1481 base::Unretained(this), rtf)); | |
1482 return; | |
1483 } | |
1484 #endif | |
1485 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_COPY_PASTE); | |
1486 clipboard_writer.WriteRTF(rtf); | |
1487 } | |
1488 | |
1489 void BrowserTestClipboard::SetText(const std::string& text) { | |
1490 DCHECK(is_installed_); | |
1491 #if defined(OS_WIN) | |
1492 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | |
1493 RunTaskOnIOThreadAndWait(base::Bind(&BrowserTestClipboard::SetText, | |
1494 base::Unretained(this), text)); | |
dcheng
2016/07/20 07:02:17
Hmm... what a mess. I guess I need to clean up the
| |
1495 return; | |
1496 } | |
1497 #endif | |
1498 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_COPY_PASTE); | |
1499 clipboard_writer.WriteText(base::ASCIIToUTF16(text)); | |
1500 } | |
1501 | |
1502 void BrowserTestClipboard::RunTaskOnIOThreadAndWait(const base::Closure& task) { | |
1503 base::WaitableEvent completion( | |
1504 base::WaitableEvent::ResetPolicy::AUTOMATIC, | |
1505 base::WaitableEvent::InitialState::NOT_SIGNALED); | |
1506 BrowserThread::PostTask( | |
1507 BrowserThread::IO, FROM_HERE, | |
1508 base::Bind(&BrowserTestClipboard::RunTask, base::Unretained(this), | |
1509 task, &completion)); | |
1510 completion.Wait(); | |
1511 } | |
1512 | |
1513 void BrowserTestClipboard::RunTask(const base::Closure& task, | |
1514 base::WaitableEvent* completion) { | |
1515 task.Run(); | |
1516 completion->Signal(); | |
1517 } | |
1518 | |
1434 } // namespace content | 1519 } // namespace content |
OLD | NEW |