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

Side by Side Diff: third_party/WebKit/Source/web/tests/WebViewTest.cpp

Issue 2790893004: Delete Android content detectors. (Closed)
Patch Set: Rebase Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 1930 matching lines...) Expand 10 before | Expand all | Expand 10 after
1941 1941
1942 // Disable navigation on drag-and-drop. 1942 // Disable navigation on drag-and-drop.
1943 webView->settingsImpl()->setNavigateOnDragDrop(false); 1943 webView->settingsImpl()->setNavigateOnDragDrop(false);
1944 1944
1945 // Attempt to drag and drop to barUrl and verify that no navigation has 1945 // Attempt to drag and drop to barUrl and verify that no navigation has
1946 // occurred. 1946 // occurred.
1947 DragAndDropURL(webView, barUrl); 1947 DragAndDropURL(webView, barUrl);
1948 EXPECT_EQ(fooUrl, webView->mainFrame()->document().url().string().utf8()); 1948 EXPECT_EQ(fooUrl, webView->mainFrame()->document().url().string().utf8());
1949 } 1949 }
1950 1950
1951 class ContentDetectorClient : public FrameTestHelpers::TestWebViewClient {
1952 public:
1953 ContentDetectorClient() { reset(); }
1954
1955 WebURL detectContentIntentAt(const WebHitTestResult& hitTest) override {
1956 m_contentDetectionRequested = true;
1957 return m_contentDetectionResult;
1958 }
1959
1960 void scheduleContentIntent(const WebURL& url, bool isMainFrame) override {
1961 m_scheduledIntentURL = url;
1962 m_wasInMainFrame = isMainFrame;
1963 }
1964
1965 void cancelScheduledContentIntents() override {
1966 m_pendingIntentsCancelled = true;
1967 }
1968
1969 void reset() {
1970 m_contentDetectionRequested = false;
1971 m_pendingIntentsCancelled = false;
1972 m_scheduledIntentURL = WebURL();
1973 m_wasInMainFrame = false;
1974 m_contentDetectionResult = WebURL();
1975 }
1976
1977 bool contentDetectionRequested() const { return m_contentDetectionRequested; }
1978 bool pendingIntentsCancelled() const { return m_pendingIntentsCancelled; }
1979 const WebURL& scheduledIntentURL() const { return m_scheduledIntentURL; }
1980 bool wasInMainFrame() const { return m_wasInMainFrame; }
1981 void setContentDetectionResult(const WebURL& result) {
1982 m_contentDetectionResult = result;
1983 }
1984
1985 private:
1986 bool m_contentDetectionRequested;
1987 bool m_pendingIntentsCancelled;
1988 WebURL m_scheduledIntentURL;
1989 bool m_wasInMainFrame;
1990 WebURL m_contentDetectionResult;
1991 };
1992
1993 bool WebViewTest::tapElement(WebInputEvent::Type type, Element* element) { 1951 bool WebViewTest::tapElement(WebInputEvent::Type type, Element* element) {
1994 if (!element || !element->layoutObject()) 1952 if (!element || !element->layoutObject())
1995 return false; 1953 return false;
1996 1954
1997 DCHECK(m_webViewHelper.webView()); 1955 DCHECK(m_webViewHelper.webView());
1998 element->scrollIntoViewIfNeeded(); 1956 element->scrollIntoViewIfNeeded();
1999 1957
2000 // TODO(bokan): Technically incorrect, event positions should be in viewport 1958 // TODO(bokan): Technically incorrect, event positions should be in viewport
2001 // space. crbug.com/371902. 1959 // space. crbug.com/371902.
2002 IntPoint center = 1960 IntPoint center =
(...skipping 30 matching lines...) Expand all
2033 1991
2034 // The expected layout size comes from the calculation done in 1992 // The expected layout size comes from the calculation done in
2035 // resizePageRectsKeepingRatio which is used from PrintContext::begin to 1993 // resizePageRectsKeepingRatio which is used from PrintContext::begin to
2036 // scale the page size. 1994 // scale the page size.
2037 const float ratio = pageSize.height() / (float)pageSize.width(); 1995 const float ratio = pageSize.height() / (float)pageSize.width();
2038 const int icbWidth = floor(pageSize.width() * minimumShrinkFactor); 1996 const int icbWidth = floor(pageSize.width() * minimumShrinkFactor);
2039 const int icbHeight = floor(icbWidth * ratio); 1997 const int icbHeight = floor(icbWidth * ratio);
2040 return IntSize(icbWidth, icbHeight); 1998 return IntSize(icbWidth, icbHeight);
2041 } 1999 }
2042 2000
2043 TEST_P(WebViewTest, DetectContentAroundPosition) {
2044 registerMockedHttpURLLoad("content_listeners.html");
2045
2046 ContentDetectorClient client;
2047 WebView* webView = m_webViewHelper.initializeAndLoad(
2048 m_baseURL + "content_listeners.html", true, 0, &client);
2049 webView->resize(WebSize(500, 300));
2050 webView->updateAllLifecyclePhases();
2051 runPendingTasks();
2052
2053 WebString clickListener = WebString::fromUTF8("clickListener");
2054 WebString touchstartListener = WebString::fromUTF8("touchstartListener");
2055 WebString mousedownListener = WebString::fromUTF8("mousedownListener");
2056 WebString noListener = WebString::fromUTF8("noListener");
2057 WebString link = WebString::fromUTF8("link");
2058
2059 // Ensure content detection is not requested for nodes listening to click,
2060 // mouse or touch events when we do simple taps.
2061 EXPECT_TRUE(tapElementById(WebInputEvent::GestureTap, clickListener));
2062 EXPECT_FALSE(client.contentDetectionRequested());
2063 client.reset();
2064
2065 EXPECT_TRUE(tapElementById(WebInputEvent::GestureTap, touchstartListener));
2066 EXPECT_FALSE(client.contentDetectionRequested());
2067 client.reset();
2068
2069 EXPECT_TRUE(tapElementById(WebInputEvent::GestureTap, mousedownListener));
2070 EXPECT_FALSE(client.contentDetectionRequested());
2071 client.reset();
2072
2073 // Content detection should work normally without these event listeners.
2074 // The click listener in the body should be ignored as a special case.
2075 EXPECT_TRUE(tapElementById(WebInputEvent::GestureTap, noListener));
2076 EXPECT_TRUE(client.contentDetectionRequested());
2077 EXPECT_FALSE(client.scheduledIntentURL().isValid());
2078
2079 WebURL intentURL = toKURL(m_baseURL);
2080 client.setContentDetectionResult(intentURL);
2081 EXPECT_TRUE(tapElementById(WebInputEvent::GestureTap, noListener));
2082 EXPECT_TRUE(client.scheduledIntentURL() == intentURL);
2083 EXPECT_TRUE(client.wasInMainFrame());
2084
2085 // Tapping elsewhere should cancel the scheduled intent.
2086 WebGestureEvent event(WebInputEvent::GestureTap, WebInputEvent::NoModifiers,
2087 WebInputEvent::TimeStampForTesting);
2088 event.sourceDevice = WebGestureDeviceTouchscreen;
2089 webView->handleInputEvent(WebCoalescedInputEvent(event));
2090 runPendingTasks();
2091 EXPECT_TRUE(client.pendingIntentsCancelled());
2092
2093 // Explicitly reset to break dependency on locally scoped client.
2094 m_webViewHelper.reset();
2095 }
2096
2097 TEST_P(WebViewTest, ContentDetectionInIframe) {
2098 registerMockedHttpURLLoad("content_listeners_iframe.html");
2099
2100 ContentDetectorClient client;
2101 WebView* webView = m_webViewHelper.initializeAndLoad(
2102 m_baseURL + "content_listeners_iframe.html", true, 0, &client);
2103 webView->resize(WebSize(500, 300));
2104 webView->updateAllLifecyclePhases();
2105 runPendingTasks();
2106
2107 WebString noListener = WebString::fromUTF8("noListener");
2108 WebString frameName = WebString::fromUTF8("innerFrame");
2109
2110 WebURL intentURL = toKURL(m_baseURL);
2111 client.setContentDetectionResult(intentURL);
2112 Element* element = static_cast<Element*>(
2113 webView->findFrameByName(frameName)->document().getElementById(
2114 noListener));
2115 EXPECT_TRUE(tapElement(WebInputEvent::GestureTap, element));
2116 EXPECT_TRUE(client.scheduledIntentURL() == intentURL);
2117 EXPECT_FALSE(client.wasInMainFrame());
2118
2119 // Explicitly reset to break dependency on locally scoped client.
2120 m_webViewHelper.reset();
2121 }
2122
2123 TEST_P(WebViewTest, ClientTapHandling) { 2001 TEST_P(WebViewTest, ClientTapHandling) {
2124 TapHandlingWebViewClient client; 2002 TapHandlingWebViewClient client;
2125 client.reset(); 2003 client.reset();
2126 WebView* webView = 2004 WebView* webView =
2127 m_webViewHelper.initializeAndLoad("about:blank", true, 0, &client); 2005 m_webViewHelper.initializeAndLoad("about:blank", true, 0, &client);
2128 WebGestureEvent event(WebInputEvent::GestureTap, WebInputEvent::NoModifiers, 2006 WebGestureEvent event(WebInputEvent::GestureTap, WebInputEvent::NoModifiers,
2129 WebInputEvent::TimeStampForTesting); 2007 WebInputEvent::TimeStampForTesting);
2130 event.sourceDevice = WebGestureDeviceTouchscreen; 2008 event.sourceDevice = WebGestureDeviceTouchscreen;
2131 event.x = 3; 2009 event.x = 3;
2132 event.y = 8; 2010 event.y = 8;
(...skipping 2308 matching lines...) Expand 10 before | Expand all | Expand 10 after
4441 EXPECT_FALSE(frameView->visualViewportSuppliesScrollbars()); 4319 EXPECT_FALSE(frameView->visualViewportSuppliesScrollbars());
4442 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { 4320 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) {
4443 EXPECT_NE(nullptr, 4321 EXPECT_NE(nullptr,
4444 frameView->layoutViewportScrollableArea()->verticalScrollbar()); 4322 frameView->layoutViewportScrollableArea()->verticalScrollbar());
4445 } else { 4323 } else {
4446 EXPECT_NE(nullptr, frameView->verticalScrollbar()); 4324 EXPECT_NE(nullptr, frameView->verticalScrollbar());
4447 } 4325 }
4448 } 4326 }
4449 4327
4450 } // namespace blink 4328 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebViewImpl.cpp ('k') | third_party/WebKit/Source/web/tests/data/content_listeners.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698