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 "base/path_service.h" | 5 #include "base/path_service.h" |
6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
9 #include "chrome/browser/apps/app_browsertest_util.h" | 9 #include "chrome/browser/apps/app_browsertest_util.h" |
10 #include "chrome/browser/chrome_content_browser_client.h" | 10 #include "chrome/browser/chrome_content_browser_client.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 123 |
124 bool hidden_observed() { return hidden_observed_; } | 124 bool hidden_observed() { return hidden_observed_; } |
125 | 125 |
126 private: | 126 private: |
127 base::Closure hidden_callback_; | 127 base::Closure hidden_callback_; |
128 bool hidden_observed_; | 128 bool hidden_observed_; |
129 | 129 |
130 DISALLOW_COPY_AND_ASSIGN(WebContentsHiddenObserver); | 130 DISALLOW_COPY_AND_ASSIGN(WebContentsHiddenObserver); |
131 }; | 131 }; |
132 | 132 |
| 133 // Watches for context menu to be shown, records count of how many times |
| 134 // context menu was shown. |
| 135 class ContextMenuCallCountObserver { |
| 136 public: |
| 137 ContextMenuCallCountObserver () |
| 138 : num_times_shown_(0), |
| 139 menu_observer_(chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN, |
| 140 base::Bind(&ContextMenuCallCountObserver::OnMenuShown, |
| 141 base::Unretained(this))) { |
| 142 } |
| 143 ~ContextMenuCallCountObserver() {} |
| 144 |
| 145 bool OnMenuShown(const content::NotificationSource& source, |
| 146 const content::NotificationDetails& details) { |
| 147 ++num_times_shown_; |
| 148 auto context_menu = content::Source<RenderViewContextMenu>(source).ptr(); |
| 149 base::MessageLoop::current()->PostTask( |
| 150 FROM_HERE, base::Bind(&RenderViewContextMenuBase::Cancel, |
| 151 base::Unretained(context_menu))); |
| 152 return true; |
| 153 } |
| 154 |
| 155 void Wait() { menu_observer_.Wait(); } |
| 156 |
| 157 int num_times_shown() { return num_times_shown_; } |
| 158 |
| 159 private: |
| 160 int num_times_shown_; |
| 161 content::WindowedNotificationObserver menu_observer_; |
| 162 |
| 163 DISALLOW_COPY_AND_ASSIGN(ContextMenuCallCountObserver); |
| 164 }; |
| 165 |
133 class EmbedderWebContentsObserver : public content::WebContentsObserver { | 166 class EmbedderWebContentsObserver : public content::WebContentsObserver { |
134 public: | 167 public: |
135 explicit EmbedderWebContentsObserver(content::WebContents* web_contents) | 168 explicit EmbedderWebContentsObserver(content::WebContents* web_contents) |
136 : WebContentsObserver(web_contents), terminated_(false) {} | 169 : WebContentsObserver(web_contents), terminated_(false) {} |
137 | 170 |
138 // WebContentsObserver. | 171 // WebContentsObserver. |
139 void RenderProcessGone(base::TerminationStatus status) override { | 172 void RenderProcessGone(base::TerminationStatus status) override { |
140 terminated_ = true; | 173 terminated_ = true; |
141 if (message_loop_runner_.get()) | 174 if (message_loop_runner_.get()) |
142 message_loop_runner_->Quit(); | 175 message_loop_runner_->Quit(); |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 EXPECT_TRUE( | 725 EXPECT_TRUE( |
693 content::ExecuteScript( | 726 content::ExecuteScript( |
694 GetGuestWebContents(), | 727 GetGuestWebContents(), |
695 base::StringPrintf("onAppCommand('%s');", message.c_str()))); | 728 base::StringPrintf("onAppCommand('%s');", message.c_str()))); |
696 | 729 |
697 if (listener) { | 730 if (listener) { |
698 ASSERT_TRUE(listener->WaitUntilSatisfied()); | 731 ASSERT_TRUE(listener->WaitUntilSatisfied()); |
699 } | 732 } |
700 } | 733 } |
701 | 734 |
| 735 void OpenContextMenu(content::WebContents* web_contents) { |
| 736 blink::WebMouseEvent mouse_event; |
| 737 mouse_event.type = blink::WebInputEvent::MouseDown; |
| 738 mouse_event.button = blink::WebMouseEvent::ButtonRight; |
| 739 mouse_event.x = 1; |
| 740 mouse_event.y = 1; |
| 741 web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
| 742 mouse_event.type = blink::WebInputEvent::MouseUp; |
| 743 web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
| 744 } |
| 745 |
702 content::WebContents* GetGuestWebContents() { | 746 content::WebContents* GetGuestWebContents() { |
703 return guest_web_contents_; | 747 return guest_web_contents_; |
704 } | 748 } |
705 | 749 |
706 content::WebContents* GetEmbedderWebContents() { | 750 content::WebContents* GetEmbedderWebContents() { |
707 if (!embedder_web_contents_) { | 751 if (!embedder_web_contents_) { |
708 embedder_web_contents_ = GetFirstAppWindowWebContents(); | 752 embedder_web_contents_ = GetFirstAppWindowWebContents(); |
709 } | 753 } |
710 return embedder_web_contents_; | 754 return embedder_web_contents_; |
711 } | 755 } |
(...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1966 static bool ContextMenuNotificationCallback( | 2010 static bool ContextMenuNotificationCallback( |
1967 const content::NotificationSource& source, | 2011 const content::NotificationSource& source, |
1968 const content::NotificationDetails& details) { | 2012 const content::NotificationDetails& details) { |
1969 auto context_menu = content::Source<RenderViewContextMenu>(source).ptr(); | 2013 auto context_menu = content::Source<RenderViewContextMenu>(source).ptr(); |
1970 base::MessageLoop::current()->PostTask( | 2014 base::MessageLoop::current()->PostTask( |
1971 FROM_HERE, base::Bind(&RenderViewContextMenuBase::Cancel, | 2015 FROM_HERE, base::Bind(&RenderViewContextMenuBase::Cancel, |
1972 base::Unretained(context_menu))); | 2016 base::Unretained(context_menu))); |
1973 return true; | 2017 return true; |
1974 } | 2018 } |
1975 | 2019 |
| 2020 IN_PROC_BROWSER_TEST_F(WebViewTest, ContextMenusAPI_PreventDefault) { |
| 2021 LoadAppWithGuest("web_view/context_menus/basic"); |
| 2022 |
| 2023 content::WebContents* guest_web_contents = GetGuestWebContents(); |
| 2024 content::WebContents* embedder = GetEmbedderWebContents(); |
| 2025 ASSERT_TRUE(embedder); |
| 2026 |
| 2027 // Add a preventDefault() call on context menu event so context menu |
| 2028 // does not show up. |
| 2029 ExtensionTestMessageListener prevent_default_listener( |
| 2030 "WebViewTest.CONTEXT_MENU_DEFAULT_PREVENTED", false); |
| 2031 EXPECT_TRUE(content::ExecuteScript(embedder, "registerPreventDefault()")); |
| 2032 ContextMenuCallCountObserver context_menu_shown_observer; |
| 2033 |
| 2034 OpenContextMenu(guest_web_contents); |
| 2035 |
| 2036 EXPECT_TRUE(prevent_default_listener.WaitUntilSatisfied()); |
| 2037 // Expect the menu to not show up. |
| 2038 EXPECT_EQ(0, context_menu_shown_observer.num_times_shown()); |
| 2039 |
| 2040 // Now remove the preventDefault() and expect context menu to be shown. |
| 2041 ExecuteScriptWaitForTitle( |
| 2042 embedder, "removePreventDefault()", "PREVENT_DEFAULT_LISTENER_REMOVED"); |
| 2043 OpenContextMenu(guest_web_contents); |
| 2044 |
| 2045 // We expect to see a context menu for the second call to |OpenContextMenu|. |
| 2046 context_menu_shown_observer.Wait(); |
| 2047 EXPECT_EQ(1, context_menu_shown_observer.num_times_shown()); |
| 2048 } |
| 2049 |
1976 // Tests that a context menu is created when right-clicking in the webview. This | 2050 // Tests that a context menu is created when right-clicking in the webview. This |
1977 // also tests that the 'contextmenu' event is handled correctly. | 2051 // also tests that the 'contextmenu' event is handled correctly. |
1978 IN_PROC_BROWSER_TEST_F(WebViewTest, TestContextMenu) { | 2052 IN_PROC_BROWSER_TEST_F(WebViewTest, TestContextMenu) { |
1979 LoadAppWithGuest("web_view/context_menus/basic"); | 2053 LoadAppWithGuest("web_view/context_menus/basic"); |
1980 content::WebContents* guest_web_contents = GetGuestWebContents(); | 2054 content::WebContents* guest_web_contents = GetGuestWebContents(); |
1981 | 2055 |
1982 // Register an observer for the context menu. | 2056 // Register an observer for the context menu. |
1983 content::WindowedNotificationObserver menu_observer( | 2057 content::WindowedNotificationObserver menu_observer( |
1984 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN, | 2058 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN, |
1985 base::Bind(ContextMenuNotificationCallback)); | 2059 base::Bind(ContextMenuNotificationCallback)); |
1986 | 2060 |
1987 // Open a context menu. | 2061 OpenContextMenu(guest_web_contents); |
1988 blink::WebMouseEvent mouse_event; | |
1989 mouse_event.type = blink::WebInputEvent::MouseDown; | |
1990 mouse_event.button = blink::WebMouseEvent::ButtonRight; | |
1991 mouse_event.x = 1; | |
1992 mouse_event.y = 1; | |
1993 guest_web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event); | |
1994 mouse_event.type = blink::WebInputEvent::MouseUp; | |
1995 guest_web_contents->GetRenderViewHost()->ForwardMouseEvent(mouse_event); | |
1996 | 2062 |
1997 // Wait for the context menu to be visible. | 2063 // Wait for the context menu to be visible. |
1998 menu_observer.Wait(); | 2064 menu_observer.Wait(); |
1999 } | 2065 } |
2000 | 2066 |
2001 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllow) { | 2067 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllow) { |
2002 MediaAccessAPIAllowTestHelper("testAllow"); | 2068 MediaAccessAPIAllowTestHelper("testAllow"); |
2003 } | 2069 } |
2004 | 2070 |
2005 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllowAndThenDeny) { | 2071 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow_TestAllowAndThenDeny) { |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2594 // http://crbug.com/403325 | 2660 // http://crbug.com/403325 |
2595 #define MAYBE_WebViewInBackgroundPage \ | 2661 #define MAYBE_WebViewInBackgroundPage \ |
2596 DISABLED_WebViewInBackgroundPage | 2662 DISABLED_WebViewInBackgroundPage |
2597 #else | 2663 #else |
2598 #define MAYBE_WebViewInBackgroundPage WebViewInBackgroundPage | 2664 #define MAYBE_WebViewInBackgroundPage WebViewInBackgroundPage |
2599 #endif | 2665 #endif |
2600 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_WebViewInBackgroundPage) { | 2666 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_WebViewInBackgroundPage) { |
2601 ASSERT_TRUE(RunExtensionTest("platform_apps/web_view/background")) | 2667 ASSERT_TRUE(RunExtensionTest("platform_apps/web_view/background")) |
2602 << message_; | 2668 << message_; |
2603 } | 2669 } |
OLD | NEW |