Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(732)

Unified Diff: chrome/browser/apps/guest_view/web_view_browsertest.cc

Issue 1254883006: Bubble scroll events from WebView guest to embedder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Complete test. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/test/data/extensions/platform_apps/web_view/scrollable_embedder_and_guest/guest.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/apps/guest_view/web_view_browsertest.cc
diff --git a/chrome/browser/apps/guest_view/web_view_browsertest.cc b/chrome/browser/apps/guest_view/web_view_browsertest.cc
index 1f58684567b1fc1d851a184255cc270a3736f272..addfce6709a5dff85422fe05e97abfea6bf01ce0 100644
--- a/chrome/browser/apps/guest_view/web_view_browsertest.cc
+++ b/chrome/browser/apps/guest_view/web_view_browsertest.cc
@@ -35,6 +35,7 @@
#include "content/public/browser/interstitial_page_delegate.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/common/child_process_host.h"
#include "content/public/common/content_switches.h"
@@ -59,6 +60,8 @@
#include "ui/compositor/compositor.h"
#include "ui/compositor/compositor_observer.h"
#include "ui/events/event_switches.h"
+#include "ui/events/gesture_detection/gesture_provider_config_helper.h"
+#include "ui/events/test/event_generator.h"
#include "ui/gfx/switches.h"
#include "ui/gl/gl_switches.h"
#include "ui/views/view.h"
@@ -2505,6 +2508,98 @@ IN_PROC_BROWSER_TEST_F(WebViewTest,
"web_view/shim", NEEDS_TEST_SERVER);
}
+class WebViewTouchTest : public WebViewTest {
+ protected:
+ void SetUpCommandLine(base::CommandLine* command_line) override {
+ command_line->AppendSwitchASCII(switches::kTouchEvents,
+ switches::kTouchEventsEnabled);
+
+ WebViewTest::SetUpCommandLine(command_line);
+ }
+};
+
+namespace {
+
+class ScrollWaiter {
+ public:
+ explicit ScrollWaiter(content::RenderWidgetHostView* host_view)
+ : host_view_(host_view),
+ current_offset_(host_view_->GetLastScrollOffset()) {}
+ ~ScrollWaiter() {}
+
+ void WaitForScrollChange() {
+ while (current_offset_ == host_view_->GetLastScrollOffset())
+ base::MessageLoop::current()->RunUntilIdle();
+ }
+
+ private:
+ content::RenderWidgetHostView* host_view_;
+ gfx::Vector2dF current_offset_;
+};
+
+} // namespace
+
+// Tests that scrolls bubble from guest to embedder.
+IN_PROC_BROWSER_TEST_F(WebViewTouchTest, TestGuestScrollsBubble) {
+ LoadAppWithGuest("web_view/scrollable_embedder_and_guest");
+
+ content::WebContents* embedder_contents = GetEmbedderWebContents();
+
+ std::vector<content::WebContents*> guest_web_contents_list;
+ GetGuestViewManager()->WaitForNumGuestsCreated(1u);
+ GetGuestViewManager()->GetGuestWebContentsList(&guest_web_contents_list);
+ ASSERT_EQ(1u, guest_web_contents_list.size());
+
+ content::WebContents* guest_contents = guest_web_contents_list[0];
+
+ // Send scroll gesture to embedder & verify.
+ content::RenderWidgetHostView* embedder_host_view =
+ embedder_contents->GetRenderWidgetHostView();
+ EXPECT_EQ(gfx::Vector2dF(), embedder_host_view->GetLastScrollOffset());
+
+ float touch_slop = ui::GetGestureProviderConfig(
+ ui::GestureProviderConfigType::CURRENT_PLATFORM)
+ .gesture_detector_config.touch_slop;
+ float scroll_magnitude = 15.f;
+ float gesture_distance = scroll_magnitude + touch_slop;
+
+ {
+ gfx::Point embedder_scroll_start(200, 40 + gesture_distance);
+ gfx::Point embedder_scroll_end(200, 40);
+ gfx::Vector2dF expected_offset(0.f, scroll_magnitude);
+
+ ScrollWaiter waiter(embedder_host_view);
+
+ ui::test::EventGenerator generator(
+ embedder_contents->GetTopLevelNativeWindow(), embedder_scroll_start);
+ generator.GestureScrollSequence(embedder_scroll_start, embedder_scroll_end,
+ base::TimeDelta::FromMilliseconds(100), 1);
+ waiter.WaitForScrollChange();
+ EXPECT_EQ(expected_offset, embedder_host_view->GetLastScrollOffset());
+ }
+
+ content::RenderWidgetHostView* guest_host_view =
+ guest_contents->GetRenderWidgetHostView();
+ EXPECT_EQ(gfx::Vector2dF(), guest_host_view->GetLastScrollOffset());
+
+ // Send scroll gesture to guest and verify embedder scrolls.
+ // Perform a scroll gesture of the same magnitude, but in the opposite
+ // direction and centered over the GuestView this time.
+ {
+ gfx::Point guest_scroll_start(200, 120);
+ gfx::Point guest_scroll_end(200, 120 + gesture_distance);
+ ScrollWaiter waiter(embedder_host_view);
+
+ ui::test::EventGenerator generator(
+ embedder_contents->GetTopLevelNativeWindow(), guest_scroll_start);
+ generator.GestureScrollSequence(guest_scroll_start, guest_scroll_end,
+ base::TimeDelta::FromMilliseconds(100), 1);
+
+ waiter.WaitForScrollChange();
+ EXPECT_EQ(gfx::Vector2dF(), embedder_host_view->GetLastScrollOffset());
+ }
+}
+
#if defined(USE_AURA)
// TODO(wjmaclean): when WebViewTest is re-enabled on the site-isolation
// bots, then re-enable this test class as well.
« no previous file with comments | « no previous file | chrome/test/data/extensions/platform_apps/web_view/scrollable_embedder_and_guest/guest.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698