OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <queue> | |
6 | |
5 #include "base/location.h" | 7 #include "base/location.h" |
6 #include "base/path_service.h" | 8 #include "base/path_service.h" |
7 #include "base/process/process.h" | 9 #include "base/process/process.h" |
8 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
9 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
10 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
11 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
12 #include "chrome/app/chrome_command_ids.h" | 14 #include "chrome/app/chrome_command_ids.h" |
13 #include "chrome/browser/apps/app_browsertest_util.h" | 15 #include "chrome/browser/apps/app_browsertest_util.h" |
14 #include "chrome/browser/chrome_content_browser_client.h" | 16 #include "chrome/browser/chrome_content_browser_client.h" |
15 #include "chrome/browser/lifetime/application_lifetime.h" | 17 #include "chrome/browser/lifetime/application_lifetime.h" |
16 #include "chrome/browser/prerender/prerender_link_manager.h" | 18 #include "chrome/browser/prerender/prerender_link_manager.h" |
17 #include "chrome/browser/prerender/prerender_link_manager_factory.h" | 19 #include "chrome/browser/prerender/prerender_link_manager_factory.h" |
18 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" | 21 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" |
20 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" | 22 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti l.h" |
21 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" | 23 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" |
22 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
23 #include "chrome/browser/ui/browser_dialogs.h" | 25 #include "chrome/browser/ui/browser_dialogs.h" |
24 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 26 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
25 #include "chrome/test/base/ui_test_utils.h" | 27 #include "chrome/test/base/ui_test_utils.h" |
26 #include "components/content_settings/core/browser/host_content_settings_map.h" | 28 #include "components/content_settings/core/browser/host_content_settings_map.h" |
27 #include "components/guest_view/browser/guest_view_manager.h" | 29 #include "components/guest_view/browser/guest_view_manager.h" |
28 #include "components/guest_view/browser/guest_view_manager_factory.h" | 30 #include "components/guest_view/browser/guest_view_manager_factory.h" |
29 #include "components/guest_view/browser/test_guest_view_manager.h" | 31 #include "components/guest_view/browser/test_guest_view_manager.h" |
32 #include "content/browser/renderer_host/render_widget_host_impl.h" | |
33 #include "content/common/input/synthetic_web_input_event_builders.h" | |
30 #include "content/public/browser/gpu_data_manager.h" | 34 #include "content/public/browser/gpu_data_manager.h" |
31 #include "content/public/browser/interstitial_page.h" | 35 #include "content/public/browser/interstitial_page.h" |
32 #include "content/public/browser/interstitial_page_delegate.h" | 36 #include "content/public/browser/interstitial_page_delegate.h" |
33 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
34 #include "content/public/browser/render_process_host.h" | 38 #include "content/public/browser/render_process_host.h" |
35 #include "content/public/browser/web_contents_delegate.h" | 39 #include "content/public/browser/web_contents_delegate.h" |
36 #include "content/public/common/child_process_host.h" | 40 #include "content/public/common/child_process_host.h" |
37 #include "content/public/common/content_switches.h" | 41 #include "content/public/common/content_switches.h" |
38 #include "content/public/test/browser_test_utils.h" | 42 #include "content/public/test/browser_test_utils.h" |
39 #include "content/public/test/fake_speech_recognition_manager.h" | 43 #include "content/public/test/fake_speech_recognition_manager.h" |
40 #include "content/public/test/test_renderer_host.h" | 44 #include "content/public/test/test_renderer_host.h" |
41 #include "extensions/browser/api/declarative/rules_registry.h" | 45 #include "extensions/browser/api/declarative/rules_registry.h" |
42 #include "extensions/browser/api/declarative/rules_registry_service.h" | 46 #include "extensions/browser/api/declarative/rules_registry_service.h" |
43 #include "extensions/browser/api/declarative/test_rules_registry.h" | 47 #include "extensions/browser/api/declarative/test_rules_registry.h" |
44 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" | 48 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" |
45 #include "extensions/browser/app_window/native_app_window.h" | 49 #include "extensions/browser/app_window/native_app_window.h" |
46 #include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h " | 50 #include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h " |
47 #include "extensions/browser/guest_view/web_view/web_view_guest.h" | 51 #include "extensions/browser/guest_view/web_view/web_view_guest.h" |
48 #include "extensions/common/extension.h" | 52 #include "extensions/common/extension.h" |
49 #include "extensions/common/extensions_client.h" | 53 #include "extensions/common/extensions_client.h" |
50 #include "extensions/test/extension_test_message_listener.h" | 54 #include "extensions/test/extension_test_message_listener.h" |
51 #include "media/base/media_switches.h" | 55 #include "media/base/media_switches.h" |
52 #include "net/test/embedded_test_server/embedded_test_server.h" | 56 #include "net/test/embedded_test_server/embedded_test_server.h" |
53 #include "net/test/embedded_test_server/http_request.h" | 57 #include "net/test/embedded_test_server/http_request.h" |
54 #include "net/test/embedded_test_server/http_response.h" | 58 #include "net/test/embedded_test_server/http_response.h" |
59 #include "ui/aura/window.h" | |
55 #include "ui/gfx/switches.h" | 60 #include "ui/gfx/switches.h" |
56 #include "ui/gl/gl_switches.h" | 61 #include "ui/gl/gl_switches.h" |
62 #include "ui/views/view.h" | |
63 #include "ui/views/widget/widget.h" | |
57 | 64 |
58 #if defined(ENABLE_PLUGINS) | 65 #if defined(ENABLE_PLUGINS) |
59 #include "content/public/browser/plugin_service.h" | 66 #include "content/public/browser/plugin_service.h" |
60 #include "content/public/common/webplugininfo.h" | 67 #include "content/public/common/webplugininfo.h" |
61 #include "content/public/test/ppapi_test_utils.h" | 68 #include "content/public/test/ppapi_test_utils.h" |
62 #endif | 69 #endif |
63 | 70 |
64 #if defined(OS_CHROMEOS) | 71 #if defined(OS_CHROMEOS) |
65 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 72 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
66 #include "chrome/browser/chromeos/accessibility/speech_monitor.h" | 73 #include "chrome/browser/chromeos/accessibility/speech_monitor.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 const char* title) { | 206 const char* title) { |
200 base::string16 expected_title(base::ASCIIToUTF16(title)); | 207 base::string16 expected_title(base::ASCIIToUTF16(title)); |
201 base::string16 error_title(base::ASCIIToUTF16("error")); | 208 base::string16 error_title(base::ASCIIToUTF16("error")); |
202 | 209 |
203 content::TitleWatcher title_watcher(web_contents, expected_title); | 210 content::TitleWatcher title_watcher(web_contents, expected_title); |
204 title_watcher.AlsoWaitForTitle(error_title); | 211 title_watcher.AlsoWaitForTitle(error_title); |
205 EXPECT_TRUE(content::ExecuteScript(web_contents, script)); | 212 EXPECT_TRUE(content::ExecuteScript(web_contents, script)); |
206 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 213 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
207 } | 214 } |
208 | 215 |
216 void GiveItSomeTime(int ms) { | |
217 base::RunLoop run_loop; | |
218 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
219 FROM_HERE, run_loop.QuitClosure(), base::TimeDelta::FromMilliseconds(ms)); | |
220 run_loop.Run(); | |
221 } | |
222 | |
223 views::View* FindWebView(views::View* v) { | |
224 std::queue<views::View*> queue; | |
225 queue.push(v); | |
226 while (!queue.empty()) { | |
227 views::View* current = queue.front(); | |
228 queue.pop(); | |
229 if (std::string(current->GetClassName()).find("WebView") != | |
230 std::string::npos) { | |
231 return current; | |
232 } | |
233 | |
234 for (int i = 0; i < current->child_count(); ++i) | |
235 queue.push(current->child_at(i)); | |
236 } | |
237 return nullptr; | |
238 } | |
239 | |
209 } // namespace | 240 } // namespace |
210 | 241 |
211 // This class intercepts media access request from the embedder. The request | 242 // This class intercepts media access request from the embedder. The request |
212 // should be triggered only if the embedder API (from tests) allows the request | 243 // should be triggered only if the embedder API (from tests) allows the request |
213 // in Javascript. | 244 // in Javascript. |
214 // We do not issue the actual media request; the fact that the request reached | 245 // We do not issue the actual media request; the fact that the request reached |
215 // embedder's WebContents is good enough for our tests. This is also to make | 246 // embedder's WebContents is good enough for our tests. This is also to make |
216 // the test run successfully on trybots. | 247 // the test run successfully on trybots. |
217 class MockWebContentsDelegate : public content::WebContentsDelegate { | 248 class MockWebContentsDelegate : public content::WebContentsDelegate { |
218 public: | 249 public: |
(...skipping 2146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2365 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages. | 2396 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages. |
2366 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/post_message/basic")) | 2397 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/post_message/basic")) |
2367 << message_; | 2398 << message_; |
2368 } | 2399 } |
2369 | 2400 |
2370 // Tests that webviews do get garbage collected. | 2401 // Tests that webviews do get garbage collected. |
2371 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestGarbageCollect) { | 2402 IN_PROC_BROWSER_TEST_F(WebViewTest, Shim_TestGarbageCollect) { |
2372 TestHelper("testGarbageCollect", "web_view/shim", NO_TEST_SERVER); | 2403 TestHelper("testGarbageCollect", "web_view/shim", NO_TEST_SERVER); |
2373 GetGuestViewManager()->WaitForSingleViewGarbageCollected(); | 2404 GetGuestViewManager()->WaitForSingleViewGarbageCollected(); |
2374 } | 2405 } |
2406 | |
2407 typedef WebViewTest WebViewFocusTest; | |
wjmaclean
2015/06/18 18:37:48
I just realized, these needs to be in a
#if defi
| |
2408 | |
2409 // The following test verifies that a views::WebView hosting an embedder | |
2410 // gains focus on touchstart. | |
2411 IN_PROC_BROWSER_TEST_F(WebViewFocusTest, TouchFocusesEmbedder) { | |
2412 LoadAppWithGuest("web_view/accept_touch_events"); | |
2413 | |
2414 content::WebContents* web_contents = GetEmbedderWebContents(); | |
2415 content::RenderViewHost* embedder_rvh = web_contents->GetRenderViewHost(); | |
2416 | |
2417 bool embedder_has_touch_handler = | |
2418 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh); | |
2419 EXPECT_FALSE(embedder_has_touch_handler); | |
2420 | |
2421 SendMessageToGuestAndWait("install-touch-handler", "installed-touch-handler"); | |
2422 | |
2423 // Note that we need to wait for the installed/registered touch handler to | |
2424 // appear in browser process before querying |embedder_rvh|. | |
2425 // In practice, since we do a roundrtip from browser process to guest and | |
2426 // back, this is sufficient. | |
2427 embedder_has_touch_handler = | |
2428 content::RenderViewHostTester::HasTouchEventHandler(embedder_rvh); | |
2429 EXPECT_TRUE(embedder_has_touch_handler); | |
2430 | |
2431 extensions::AppWindow* app_window = GetFirstAppWindowForBrowser(browser()); | |
2432 aura::Window* window = app_window->GetNativeWindow(); | |
2433 EXPECT_TRUE(app_window); | |
2434 EXPECT_TRUE(window); | |
2435 views::Widget* widget = views::Widget::GetWidgetForNativeView(window); | |
2436 EXPECT_TRUE(widget->GetRootView()); | |
2437 // We only expect a single views::webview in the view hierarchy. | |
2438 views::View* aura_webview = FindWebView(widget->GetRootView()); | |
2439 ASSERT_TRUE(aura_webview); | |
2440 gfx::Rect bounds(aura_webview->bounds()); | |
2441 EXPECT_TRUE(aura_webview->IsFocusable()); | |
2442 | |
2443 views::View* padding_view = new views::View(); | |
2444 padding_view->SetBounds(bounds.x() + bounds.width(), 0, 100, 100); | |
2445 padding_view->SetFocusable(true); | |
2446 aura_webview->parent()->AddChildView(padding_view); | |
2447 padding_view->SetPosition(gfx::Point(bounds.x() + bounds.width(), 0)); | |
2448 | |
2449 EXPECT_TRUE(aura_webview->HasFocus()); | |
2450 padding_view->RequestFocus(); | |
2451 EXPECT_TRUE(padding_view->HasFocus()); | |
2452 EXPECT_FALSE(aura_webview->HasFocus()); | |
2453 | |
2454 // We'll give this a fairly long delay, as the cost otherwise is having the | |
2455 // test timeout. | |
2456 GiveItSomeTime(100 /* milliseconds */); | |
wjmaclean
2015/06/18 18:37:48
I'll add a bug number to explain this.
| |
2457 | |
2458 // Generate and send synthetic touch event. | |
2459 content::SyntheticWebTouchEvent touch; | |
2460 // TODO(wjmaclean): This is fragile ... if anyone alters the location/size | |
2461 // of the webview in accept_touch_events then this may miss its target. | |
2462 touch.PressPoint(10, 10); | |
2463 content::RenderWidgetHostImpl* widget_host = | |
2464 content::RenderWidgetHostImpl::From(web_contents->GetRenderViewHost()); | |
2465 widget_host->ForwardTouchEventWithLatencyInfo(touch, ui::LatencyInfo()); | |
2466 | |
2467 // Wait for the TouchStart to propagate and restore focus. Test times out | |
2468 // on failure. | |
2469 while (!aura_webview->HasFocus()) | |
2470 base::MessageLoop::current()->RunUntilIdle(); | |
2471 } | |
OLD | NEW |