OLD | NEW |
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 3335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3346 WebString::fromUTF8(m_baseURL.c_str()), | 3346 WebString::fromUTF8(m_baseURL.c_str()), |
3347 WebString::fromUTF8("add_frame_in_unload.html")); | 3347 WebString::fromUTF8("add_frame_in_unload.html")); |
3348 m_webViewHelper.initializeAndLoad( | 3348 m_webViewHelper.initializeAndLoad( |
3349 m_baseURL + "add_frame_in_unload_wrapper.html", true, &frameClient); | 3349 m_baseURL + "add_frame_in_unload_wrapper.html", true, &frameClient); |
3350 FrameTestHelpers::loadFrame(m_webViewHelper.webView()->mainFrame(), | 3350 FrameTestHelpers::loadFrame(m_webViewHelper.webView()->mainFrame(), |
3351 "about:blank"); | 3351 "about:blank"); |
3352 EXPECT_EQ(1, frameClient.count()); | 3352 EXPECT_EQ(1, frameClient.count()); |
3353 m_webViewHelper.reset(); | 3353 m_webViewHelper.reset(); |
3354 } | 3354 } |
3355 | 3355 |
3356 class TouchEventHandlerWebWidgetClient | 3356 class TouchEventHandlerWebViewClient |
3357 : public FrameTestHelpers::TestWebWidgetClient { | 3357 : public FrameTestHelpers::TestWebViewClient { |
3358 public: | 3358 public: |
3359 // WebWidgetClient methods | 3359 // WebWidgetClient methods |
3360 void hasTouchEventHandlers(bool state) override { | 3360 void hasTouchEventHandlers(bool state) override { |
3361 m_hasTouchEventHandlerCount[state]++; | 3361 m_hasTouchEventHandlerCount[state]++; |
3362 } | 3362 } |
3363 | 3363 |
3364 // Local methods | 3364 // Local methods |
3365 TouchEventHandlerWebWidgetClient() : m_hasTouchEventHandlerCount() {} | 3365 TouchEventHandlerWebViewClient() : m_hasTouchEventHandlerCount() {} |
3366 | 3366 |
3367 int getAndResetHasTouchEventHandlerCallCount(bool state) { | 3367 int getAndResetHasTouchEventHandlerCallCount(bool state) { |
3368 int value = m_hasTouchEventHandlerCount[state]; | 3368 int value = m_hasTouchEventHandlerCount[state]; |
3369 m_hasTouchEventHandlerCount[state] = 0; | 3369 m_hasTouchEventHandlerCount[state] = 0; |
3370 return value; | 3370 return value; |
3371 } | 3371 } |
3372 | 3372 |
3373 private: | 3373 private: |
3374 int m_hasTouchEventHandlerCount[2]; | 3374 int m_hasTouchEventHandlerCount[2]; |
3375 }; | 3375 }; |
3376 | 3376 |
3377 // This test verifies that WebWidgetClient::hasTouchEventHandlers is called | 3377 // This test verifies that WebWidgetClient::hasTouchEventHandlers is called |
3378 // accordingly for various calls to EventHandlerRegistry::did{Add|Remove| | 3378 // accordingly for various calls to EventHandlerRegistry::did{Add|Remove| |
3379 // RemoveAll}EventHandler(..., TouchEvent). Verifying that those calls are made | 3379 // RemoveAll}EventHandler(..., TouchEvent). Verifying that those calls are made |
3380 // correctly is the job of LayoutTests/fast/events/event-handler-count.html. | 3380 // correctly is the job of LayoutTests/fast/events/event-handler-count.html. |
3381 TEST_P(WebViewTest, HasTouchEventHandlers) { | 3381 TEST_P(WebViewTest, HasTouchEventHandlers) { |
3382 TouchEventHandlerWebWidgetClient client; | 3382 TouchEventHandlerWebViewClient client; |
3383 // We need to create a LayerTreeView for the client before loading the page, | |
3384 // otherwise ChromeClient will default to assuming there are touch handlers. | |
3385 WebLayerTreeView* layerTreeView = client.initializeLayerTreeView(); | |
3386 std::string url = m_baseURL + "has_touch_event_handlers.html"; | 3383 std::string url = m_baseURL + "has_touch_event_handlers.html"; |
3387 URLTestHelpers::registerMockedURLLoad(toKURL(url), | 3384 URLTestHelpers::registerMockedURLLoad(toKURL(url), |
3388 "has_touch_event_handlers.html"); | 3385 "has_touch_event_handlers.html"); |
3389 WebViewImpl* webViewImpl = | 3386 WebViewImpl* webViewImpl = |
3390 m_webViewHelper.initializeAndLoad(url, true, 0, 0, &client); | 3387 m_webViewHelper.initializeAndLoad(url, true, 0, &client); |
3391 ASSERT_TRUE(layerTreeView); | |
3392 const EventHandlerRegistry::EventHandlerClass touchEvent = | 3388 const EventHandlerRegistry::EventHandlerClass touchEvent = |
3393 EventHandlerRegistry::TouchStartOrMoveEventBlocking; | 3389 EventHandlerRegistry::TouchStartOrMoveEventBlocking; |
3394 | 3390 |
3395 // The page is initialized with at least one no-handlers call. | 3391 // The page is initialized with at least one no-handlers call. |
3396 // In practice we get two such calls because WebViewHelper::initializeAndLoad | 3392 // In practice we get two such calls because WebViewHelper::initializeAndLoad |
3397 // first initializes an empty frame, and then loads a document into it, so | 3393 // first initializes and empty frame, and then loads a document into it, so |
3398 // there are two FrameLoader::commitProvisionalLoad calls. | 3394 // there are two FrameLoader::commitProvisionalLoad calls. |
3399 EXPECT_LT(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 3395 EXPECT_GE(client.getAndResetHasTouchEventHandlerCallCount(false), 1); |
3400 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); | 3396 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(true)); |
3401 | 3397 |
3402 // Adding the first document handler results in a has-handlers call. | 3398 // Adding the first document handler results in a has-handlers call. |
3403 Document* document = webViewImpl->mainFrameImpl()->frame()->document(); | 3399 Document* document = webViewImpl->mainFrameImpl()->frame()->document(); |
3404 EventHandlerRegistry* registry = | 3400 EventHandlerRegistry* registry = |
3405 &document->frameHost()->eventHandlerRegistry(); | 3401 &document->frameHost()->eventHandlerRegistry(); |
3406 registry->didAddEventHandler(*document, touchEvent); | 3402 registry->didAddEventHandler(*document, touchEvent); |
3407 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); | 3403 EXPECT_EQ(0, client.getAndResetHasTouchEventHandlerCallCount(false)); |
3408 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); | 3404 EXPECT_EQ(1, client.getAndResetHasTouchEventHandlerCallCount(true)); |
3409 | 3405 |
(...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4379 EXPECT_EQ(expectedWidth, vwElement->offsetWidth()); | 4375 EXPECT_EQ(expectedWidth, vwElement->offsetWidth()); |
4380 EXPECT_EQ(expectedHeight, vwElement->offsetHeight()); | 4376 EXPECT_EQ(expectedHeight, vwElement->offsetHeight()); |
4381 | 4377 |
4382 webView->resize(WebSize(800, 600)); | 4378 webView->resize(WebSize(800, 600)); |
4383 frame->printEnd(); | 4379 frame->printEnd(); |
4384 | 4380 |
4385 EXPECT_EQ(800, vwElement->offsetWidth()); | 4381 EXPECT_EQ(800, vwElement->offsetWidth()); |
4386 } | 4382 } |
4387 | 4383 |
4388 } // namespace blink | 4384 } // namespace blink |
OLD | NEW |