Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / web / tests / WebFrameTest.cpp
index e65f1aa..569619a 100644 (file)
 #include "WebTextCheckingResult.h"
 #include "WebViewClient.h"
 #include "WebViewImpl.h"
-#include "core/dom/Clipboard.h"
+#include "core/clipboard/Clipboard.h"
 #include "core/dom/DocumentMarkerController.h"
-#include "core/events/MouseEvent.h"
 #include "core/dom/Range.h"
 #include "core/editing/Editor.h"
 #include "core/editing/FrameSelection.h"
 #include "core/editing/SpellChecker.h"
 #include "core/editing/VisiblePosition.h"
+#include "core/events/MouseEvent.h"
 #include "core/html/HTMLFormElement.h"
 #include "core/loader/FrameLoadRequest.h"
 #include "core/page/EventHandler.h"
@@ -394,6 +394,7 @@ protected:
     void executeScript(const WebString& code)
     {
         m_frame->executeScript(WebScriptSource(code));
+        m_frame->view()->layout();
         runPendingTasks();
     }
 
@@ -417,6 +418,7 @@ TEST_F(WebFrameCSSCallbackTest, AuthorStyleSheet)
     std::vector<WebString> selectors;
     selectors.push_back(WebString::fromUTF8("div.initial_on"));
     m_frame->document().watchCSSSelectors(WebVector<WebString>(selectors));
+    m_frame->view()->layout();
     runPendingTasks();
     EXPECT_EQ(1, updateCount());
     EXPECT_THAT(matchedSelectors(), testing::ElementsAre("div.initial_on"));
@@ -424,12 +426,14 @@ TEST_F(WebFrameCSSCallbackTest, AuthorStyleSheet)
     // Check that adding a watched selector calls back for already-present nodes.
     selectors.push_back(WebString::fromUTF8("div.initial_off"));
     doc().watchCSSSelectors(WebVector<WebString>(selectors));
+    m_frame->view()->layout();
     runPendingTasks();
     EXPECT_EQ(2, updateCount());
     EXPECT_THAT(matchedSelectors(), testing::ElementsAre("div.initial_off", "div.initial_on"));
 
     // Check that we can turn off callbacks for certain selectors.
     doc().watchCSSSelectors(WebVector<WebString>());
+    m_frame->view()->layout();
     runPendingTasks();
     EXPECT_EQ(3, updateCount());
     EXPECT_THAT(matchedSelectors(), testing::ElementsAre());
@@ -548,6 +552,7 @@ TEST_F(WebFrameCSSCallbackTest, Reparenting)
     std::vector<WebString> selectors;
     selectors.push_back(WebString::fromUTF8("span"));
     doc().watchCSSSelectors(WebVector<WebString>(selectors));
+    m_frame->view()->layout();
     runPendingTasks();
 
     EXPECT_EQ(1, updateCount());
@@ -571,8 +576,9 @@ TEST_F(WebFrameCSSCallbackTest, MultiSelector)
     selectors.push_back(WebString::fromUTF8("span"));
     selectors.push_back(WebString::fromUTF8("span,p"));
     doc().watchCSSSelectors(WebVector<WebString>(selectors));
-
+    m_frame->view()->layout();
     runPendingTasks();
+
     EXPECT_EQ(1, updateCount());
     EXPECT_THAT(matchedSelectors(), testing::ElementsAre("span", "span, p"));
 }
@@ -587,8 +593,9 @@ TEST_F(WebFrameCSSCallbackTest, InvalidSelector)
     selectors.push_back(WebString::fromUTF8("[")); // Invalid.
     selectors.push_back(WebString::fromUTF8("p span")); // Not compound.
     doc().watchCSSSelectors(WebVector<WebString>(selectors));
-
+    m_frame->view()->layout();
     runPendingTasks();
+
     EXPECT_EQ(1, updateCount());
     EXPECT_THAT(matchedSelectors(), testing::ElementsAre("span"))
         << "An invalid selector shouldn't prevent other selectors from matching.";
@@ -852,6 +859,23 @@ TEST_F(WebFrameTest, DisablingFixedLayoutSizeSetsCorrectLayoutSize)
     EXPECT_EQ(980, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->contentsSize().width());
 }
 
+TEST_F(WebFrameTest, ZeroHeightPositiveWidthNotIgnored)
+{
+    UseMockScrollbarSettings mockScrollbarSettings;
+
+    FixedLayoutTestWebViewClient client;
+    client.m_screenInfo.deviceScaleFactor = 1;
+    int viewportWidth = 1280;
+    int viewportHeight = 0;
+
+    FrameTestHelpers::WebViewHelper webViewHelper;
+    webViewHelper.initialize(true, 0, &client, enableViewportSettings);
+    webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight));
+
+    EXPECT_EQ(viewportWidth, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().width());
+    EXPECT_EQ(viewportHeight, webViewHelper.webViewImpl()->mainFrameImpl()->frameView()->layoutSize().height());
+}
+
 TEST_F(WebFrameTest, DeviceScaleFactorUsesDefaultWithoutViewportTag)
 {
     UseMockScrollbarSettings mockScrollbarSettings;
@@ -2632,7 +2656,7 @@ TEST_F(WebFrameTest, ReloadWhileProvisional)
 
     WebDataSource* dataSource = webViewHelper.webView()->mainFrame()->dataSource();
     ASSERT_TRUE(dataSource);
-    EXPECT_EQ(toKURL("about:blank"), toKURL(dataSource->request().url().spec()));
+    EXPECT_EQ(toKURL(m_baseURL + "fixed_layout.html"), toKURL(dataSource->request().url().spec()));
 }
 
 TEST_F(WebFrameTest, AppendRedirects)
@@ -3054,7 +3078,8 @@ private:
 };
 
 // This fails on Mac https://bugs.webkit.org/show_bug.cgi?id=108574
-#if OS(MACOSX)
+// Also failing on Android: http://crbug.com/341314
+#if OS(MACOSX) || OS(ANDROID)
 TEST_F(WebFrameTest, DISABLED_FindInPageMatchRects)
 #else
 TEST_F(WebFrameTest, FindInPageMatchRects)
@@ -4628,6 +4653,32 @@ TEST_F(WebFrameTest, BackToReload)
     EXPECT_EQ(WebURLRequest::ReloadIgnoringCacheData, frame->dataSource()->request().cachePolicy());
 }
 
+TEST_F(WebFrameTest, BackDuringChildFrameReload)
+{
+    registerMockedHttpURLLoad("page_with_blank_iframe.html");
+    FrameTestHelpers::WebViewHelper webViewHelper;
+    webViewHelper.initializeAndLoad(m_baseURL + "page_with_blank_iframe.html", true);
+    WebFrame* mainFrame = webViewHelper.webView()->mainFrame();
+    WebFrame* childFrame = mainFrame->firstChild();
+    ASSERT_TRUE(childFrame);
+
+    // Start a history navigation, then have a different frame commit a navigation.
+    // In this case, reload an about:blank frame, which will commit synchronously.
+    // After the history navigation completes, both the appropriate document url and
+    // the current history item should reflect the history navigation.
+    registerMockedHttpURLLoad("white-1x1.png");
+    WebHistoryItem item;
+    item.initialize();
+    WebURL historyURL(toKURL(m_baseURL + "white-1x1.png"));
+    item.setURLString(historyURL.string());
+    mainFrame->loadHistoryItem(item);
+
+    childFrame->reload();
+    Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
+    EXPECT_EQ(item.urlString(), mainFrame->document().url().string());
+    EXPECT_EQ(item.urlString(), mainFrame->currentHistoryItem().urlString());
+}
+
 TEST_F(WebFrameTest, ReloadPost)
 {
     registerMockedHttpURLLoad("reload_post.html");
@@ -4685,13 +4736,22 @@ public:
     int willSendRequestCallCount() const { return m_willSendRequestCallCount; }
     int childFrameCreationCount() const { return m_childFrameCreationCount; }
 
-    virtual WebFrame* createChildFrame(WebFrame*, const WebString&)
+    virtual WebFrame* createChildFrame(WebFrame* parent, const WebString&)
     {
         m_childFrameCreationCount++;
-        return WebFrame::create(m_client);
+        WebFrame* frame = WebFrame::create(m_client);
+        parent->appendChild(frame);
+        return frame;
+    }
+
+    virtual void frameDetached(WebFrame* frame) OVERRIDE
+    {
+        if (frame->parent())
+            frame->parent()->removeChild(frame);
+        frame->close();
     }
 
-    virtual void willSendRequest(WebFrame* frame, unsigned, WebURLRequest& request, const WebURLResponse&)
+    virtual void willSendRequest(WebFrame* frame, unsigned, WebURLRequest& request, const WebURLResponse&) OVERRIDE
     {
         m_policy = request.cachePolicy();
         m_willSendRequestCallCount++;
@@ -4716,7 +4776,7 @@ TEST_F(WebFrameTest, ReloadIframe)
     webViewHelper.initializeAndLoad(m_baseURL + "iframe_reload.html", true, &mainClient);
 
     WebFrameImpl* mainFrame = webViewHelper.webViewImpl()->mainFrameImpl();
-    WebFrameImpl* childFrame = toWebFrameImpl(mainFrame->firstChild());
+    RefPtr<WebFrameImpl> childFrame = toWebFrameImpl(mainFrame->firstChild());
     ASSERT_EQ(childFrame->client(), &childClient);
     EXPECT_EQ(mainClient.childFrameCreationCount(), 1);
     EXPECT_EQ(childClient.willSendRequestCallCount(), 1);
@@ -4726,7 +4786,7 @@ TEST_F(WebFrameTest, ReloadIframe)
     Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
 
     // A new WebFrame should have been created, but the child WebFrameClient should be reused.
-    ASSERT_FALSE(childFrame == toWebFrameImpl(mainFrame->firstChild()));
+    ASSERT_NE(childFrame, toWebFrameImpl(mainFrame->firstChild()));
     ASSERT_EQ(toWebFrameImpl(mainFrame->firstChild())->client(), &childClient);
 
     EXPECT_EQ(mainClient.childFrameCreationCount(), 2);
@@ -4747,7 +4807,7 @@ TEST_F(WebFrameTest, ExportHistoryItemFromChildFrame)
 
     WebFrame* childFrame = webViewHelper.webViewImpl()->mainFrameImpl()->firstChild();
     WebHistoryItem item = childFrame->currentHistoryItem();
-    EXPECT_EQ(item.urlString(), WebString::fromUTF8(m_baseURL + "iframe_reload.html"));
+    EXPECT_EQ(item.urlString().utf8(), m_baseURL + "iframe_reload.html");
 }
 
 class TestSameDocumentWebFrameClient : public WebFrameClient {
@@ -5047,4 +5107,54 @@ TEST_F(WebFrameTest, CreateChildFrameFailure)
     EXPECT_EQ(1, client.callCount());
 }
 
+TEST_F(WebFrameTest, fixedPositionInFixedViewport)
+{
+    UseMockScrollbarSettings mockScrollbarSettings;
+    registerMockedHttpURLLoad("fixed-position-in-fixed-viewport.html");
+    FrameTestHelpers::WebViewHelper webViewHelper;
+    webViewHelper.initializeAndLoad(m_baseURL + "fixed-position-in-fixed-viewport.html", true, 0, 0, enableViewportSettings);
+
+    WebView* webView = webViewHelper.webView();
+    webView->resize(WebSize(100, 100));
+    webView->layout();
+
+    Document* document = toWebFrameImpl(webView->mainFrame())->frame()->document();
+    Element* bottomFixed = document->getElementById("bottom-fixed");
+    Element* topBottomFixed = document->getElementById("top-bottom-fixed");
+    Element* rightFixed = document->getElementById("right-fixed");
+    Element* leftRightFixed = document->getElementById("left-right-fixed");
+
+    webView->resize(WebSize(100, 200));
+    webView->layout();
+    EXPECT_EQ(200, bottomFixed->offsetTop() + bottomFixed->offsetHeight());
+    EXPECT_EQ(200, topBottomFixed->offsetHeight());
+
+    webView->settings()->setMainFrameResizesAreOrientationChanges(false);
+    webView->resize(WebSize(200, 200));
+    webView->layout();
+    EXPECT_EQ(200, rightFixed->offsetLeft() + rightFixed->offsetWidth());
+    EXPECT_EQ(200, leftRightFixed->offsetWidth());
+
+    webView->settings()->setMainFrameResizesAreOrientationChanges(true);
+    // Will scale the page by 1.5.
+    webView->resize(WebSize(300, 330));
+    webView->layout();
+    EXPECT_EQ(220, bottomFixed->offsetTop() + bottomFixed->offsetHeight());
+    EXPECT_EQ(220, topBottomFixed->offsetHeight());
+    EXPECT_EQ(200, rightFixed->offsetLeft() + rightFixed->offsetWidth());
+    EXPECT_EQ(200, leftRightFixed->offsetWidth());
+}
+
+TEST_F(WebFrameTest, FrameViewSetFrameRect)
+{
+    FrameTestHelpers::WebViewHelper webViewHelper;
+    webViewHelper.initializeAndLoad("about:blank");
+
+    WebCore::FrameView* frameView = webViewHelper.webViewImpl()->mainFrameImpl()->frameView();
+    frameView->setFrameRect(WebCore::IntRect(0, 0, 200, 200));
+    EXPECT_EQ_RECT(WebCore::IntRect(0, 0, 200, 200), frameView->frameRect());
+    frameView->setFrameRect(WebCore::IntRect(100, 100, 200, 200));
+    EXPECT_EQ_RECT(WebCore::IntRect(100, 100, 200, 200), frameView->frameRect());
+}
+
 } // namespace