Exemplo n.º 1
0
void TouchActionTest::runShadowDOMTest(std::string file) {
  TouchActionTrackingWebViewClient client;

  WebView* webView = setupTest(file, client);

  TrackExceptionState es;

  // Oilpan: see runTouchActionTest() comment why these are persistent
  // references.
  Persistent<Document> document =
      static_cast<Document*>(webView->mainFrame()->document());
  Persistent<StaticElementList> hostNodes =
      document->querySelectorAll("[shadow-host]", es);
  ASSERT_FALSE(es.hadException());
  ASSERT_GE(hostNodes->length(), 1u);

  for (unsigned index = 0; index < hostNodes->length(); index++) {
    ShadowRoot* shadowRoot = hostNodes->item(index)->openShadowRoot();
    runTestOnTree(shadowRoot, webView, client);
  }

  // Projections show up in the main document.
  runTestOnTree(document.get(), webView, client);

  // Explicitly reset to break dependency on locally scoped client.
  m_webViewHelper.reset();
}
void ImeOnFocusTest::runImeOnFocusTest(std::string fileName, int expectedImeRequestCount, IntPoint tapPoint, const AtomicString& focusElement, std::string frame)
{
    ImeRequestTrackingWebViewClient client;
    registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL), WebString::fromUTF8(fileName));
    WebViewImpl* webView = m_webViewHelper.initialize(true, 0, &client);
    webView->resize(WebSize(800, 1200));
    loadFrame(webView->mainFrame(), m_baseURL + fileName);
    m_document = m_webViewHelper.webViewImpl()->mainFrameImpl()->document().unwrap<Document>();

    if (!focusElement.isNull())
        focus(focusElement);
    EXPECT_EQ(0, client.imeRequestCount());

    if (tapPoint.x() >= 0 && tapPoint.y() >= 0)
        sendGestureTap(webView, tapPoint);

    if (!frame.empty()) {
        registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL), WebString::fromUTF8(frame));
        WebFrame* childFrame = webView->mainFrame()->firstChild();
        loadFrame(childFrame, m_baseURL + frame);
    }

    if (!focusElement.isNull())
        focus(focusElement);
    EXPECT_EQ(expectedImeRequestCount, client.imeRequestCount());

    m_webViewHelper.reset();
}
TEST_F(WebPluginContainerTest, ClippedRectsForIframedElement)
{
    URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("plugin_container.html"));
    URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("plugin_containing_page.html"));

    TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper.
    FrameTestHelpers::WebViewHelper webViewHelper;
    WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "plugin_containing_page.html", true, &pluginWebFrameClient);
    ASSERT(webView);
    webView->settings()->setPluginsEnabled(true);
    webView->resize(WebSize(300, 300));
    webView->updateAllLifecyclePhases();
    runPendingTasks();

    WebElement pluginElement = webView->mainFrame()->firstChild()->document().getElementById("translated-plugin");
    RefPtrWillBeRawPtr<WebPluginContainerImpl> pluginContainerImpl = toWebPluginContainerImpl(pluginElement.pluginContainer());

    ASSERT(pluginContainerImpl.get());
    pluginContainerImpl->setFrameRect(IntRect(0, 0, 300, 300));

    IntRect windowRect, clipRect, unobscuredRect;
    Vector<IntRect> cutOutRects;
    calculateGeometry(pluginContainerImpl.get(), windowRect, clipRect, unobscuredRect, cutOutRects);
    EXPECT_RECT_EQ(IntRect(10, 210, 300, 300), windowRect);
    EXPECT_RECT_EQ(IntRect(0, 0, 240, 90), clipRect);
    EXPECT_RECT_EQ(IntRect(0, 0, 240, 160), unobscuredRect);

    // Cause the plugin's frame to be detached.
    webViewHelper.reset();
}
TEST_F(WebPluginContainerTest, TopmostAfterDetachTest)
{
    static WebRect topmostRect(10, 10, 40, 40);

    // Plugin that checks isRectTopmost in destroy().
    class TopmostPlugin : public FakeWebPlugin {
    public:
        TopmostPlugin(WebFrame* frame, const WebPluginParams& params)
            : FakeWebPlugin(frame, params) {}

        bool isRectTopmost()
        {
            return container()->isRectTopmost(topmostRect);
        }

        void destroy() override
        {
            // In destroy, isRectTopmost is no longer valid.
            EXPECT_FALSE(container()->isRectTopmost(topmostRect));
            FakeWebPlugin::destroy();
        }
    };

    class TopmostPluginWebFrameClient : public FrameTestHelpers::TestWebFrameClient {
        WebPlugin* createPlugin(WebLocalFrame* frame, const WebPluginParams& params) override
        {
            return new TopmostPlugin(frame, params);
        }
    };

    URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("plugin_container.html"));
    TopmostPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper.
    FrameTestHelpers::WebViewHelper webViewHelper;
    WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "plugin_container.html", true, &pluginWebFrameClient);
    ASSERT(webView);
    webView->settings()->setPluginsEnabled(true);
    webView->resize(WebSize(300, 300));
    webView->updateAllLifecyclePhases();
    runPendingTasks();

    RefPtrWillBeRawPtr<WebPluginContainerImpl> pluginContainerImpl =
        toWebPluginContainerImpl(getWebPluginContainer(webView, WebString::fromUTF8("translated-plugin")));
    pluginContainerImpl->setFrameRect(IntRect(0, 0, 300, 300));

    EXPECT_TRUE(pluginContainerImpl->isRectTopmost(topmostRect));

    TopmostPlugin* testPlugin = static_cast<TopmostPlugin*>(pluginContainerImpl->plugin());
    EXPECT_TRUE(testPlugin->isRectTopmost());

    // Cause the plugin's frame to be detached.
    webViewHelper.reset();

    EXPECT_FALSE(pluginContainerImpl->isRectTopmost(topmostRect));
}
Exemplo n.º 5
0
void TouchActionTest::runIFrameTest(std::string file) {
  TouchActionTrackingWebViewClient client;

  WebView* webView = setupTest(file, client);
  WebFrame* curFrame = webView->mainFrame()->firstChild();
  ASSERT_TRUE(curFrame);

  for (; curFrame; curFrame = curFrame->nextSibling()) {
    // Oilpan: see runTouchActionTest() comment why these are persistent
    // references.
    Persistent<Document> contentDoc =
        static_cast<Document*>(curFrame->document());
    runTestOnTree(contentDoc.get(), webView, client);
  }

  // Explicitly reset to break dependency on locally scoped client.
  m_webViewHelper.reset();
}
Exemplo n.º 6
0
void TouchActionTest::runTouchActionTest(std::string file) {
  TouchActionTrackingWebViewClient client;

  // runTouchActionTest() loads a document in a frame, setting up a
  // nested message loop. Should any Oilpan GC happen while it is in
  // effect, the implicit assumption that we're outside any event
  // loop (=> there being no pointers on the stack needing scanning)
  // when that GC strikes will no longer hold.
  //
  // To ensure that the references on the stack are also traced, we
  // turn them into persistent, stack allocated references. This
  // workaround is sufficient to handle this artificial test
  // scenario.
  WebView* webView = setupTest(file, client);

  Persistent<Document> document =
      static_cast<Document*>(webView->mainFrame()->document());
  runTestOnTree(document.get(), webView, client);

  // Explicitly reset to break dependency on locally scoped client.
  m_webViewHelper.reset();
}
// Verify that isRectTopmost returns false when the document is detached.
TEST_F(WebPluginContainerTest, IsRectTopmostTest)
{
    URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("plugin_container.html"));
    TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper.
    FrameTestHelpers::WebViewHelper webViewHelper;
    WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "plugin_container.html", true, &pluginWebFrameClient);
    ASSERT(webView);
    webView->settings()->setPluginsEnabled(true);
    webView->resize(WebSize(300, 300));
    webView->updateAllLifecyclePhases();
    runPendingTasks();

    RefPtrWillBeRawPtr<WebPluginContainerImpl> pluginContainerImpl =
        toWebPluginContainerImpl(getWebPluginContainer(webView, WebString::fromUTF8("translated-plugin")));
    pluginContainerImpl->setFrameRect(IntRect(0, 0, 300, 300));

    WebRect rect = pluginContainerImpl->element().boundsInViewportSpace();
    EXPECT_TRUE(pluginContainerImpl->isRectTopmost(rect));

    // Cause the plugin's frame to be detached.
    webViewHelper.reset();

    EXPECT_FALSE(pluginContainerImpl->isRectTopmost(rect));
}