Title: [102683] branches/chromium/963/Source/WebKit/chromium
Revision
102683
Author
jap...@chromium.org
Date
2011-12-13 09:13:47 -0800 (Tue, 13 Dec 2011)

Log Message

Revert 96912 - Always call setActive() in WebViewImpl::setFocus(),
not just when enabling focus.
https://bugs.webkit.org/show_bug.cgi?id=65220

Reviewed by Darin Fisher.

* WebKit.gyp:
* WebKit.gypi:
* src/WebViewImpl.cpp:
(WebKit::WebViewImpl::setFocus):
* tests/FrameTestHelpers.cpp: Added, refactored out of WebFrameTest.cpp.
(WebKit::FrameTestHelpers::registerMockedURLLoad):
(WebKit::FrameTestHelpers::loadFrame):
(WebKit::FrameTestHelpers::defaultWebFrameClient):
(WebKit::FrameTestHelpers::defaultWebViewClient):
(WebKit::FrameTestHelpers::createWebViewAndLoad):
* tests/FrameTestHelpers.h: Added, refactored out of WebFrameTest.cpp.
* tests/WebFrameTest.cpp:
* tests/WebViewTest.cpp: Added.


TBR=jap...@chromium.org
Review URL: http://codereview.chromium.org/8895026

Modified Paths

Diff

Modified: branches/chromium/963/Source/WebKit/chromium/WebKit.gyp (102682 => 102683)


--- branches/chromium/963/Source/WebKit/chromium/WebKit.gyp	2011-12-13 16:31:17 UTC (rev 102682)
+++ branches/chromium/963/Source/WebKit/chromium/WebKit.gyp	2011-12-13 17:13:47 UTC (rev 102683)
@@ -729,7 +729,6 @@
                                 'tests/WebFrameTest.cpp',
                                 'tests/WebPageNewSerializerTest.cpp',
                                 'tests/WebPageSerializerTest.cpp',
-                                'tests/WebViewTest.cpp',
                             ],
                             'conditions': [
                                 ['OS=="win" or OS=="mac"', {

Modified: branches/chromium/963/Source/WebKit/chromium/WebKit.gypi (102682 => 102683)


--- branches/chromium/963/Source/WebKit/chromium/WebKit.gypi	2011-12-13 16:31:17 UTC (rev 102682)
+++ branches/chromium/963/Source/WebKit/chromium/WebKit.gypi	2011-12-13 17:13:47 UTC (rev 102683)
@@ -70,8 +70,6 @@
             'tests/CCSchedulerTestCommon.h',
             'tests/CCThreadTaskTest.cpp',
             'tests/FloatQuadTest.cpp',
-            'tests/FrameTestHelpers.cpp',
-            'tests/FrameTestHelpers.h',
             'tests/IDBBindingUtilitiesTest.cpp',
             'tests/IDBKeyPathTest.cpp',
             'tests/IDBLevelDBCodingTest.cpp',
@@ -96,7 +94,6 @@
             'tests/WebPageNewSerializerTest.cpp',
             'tests/WebPageSerializerTest.cpp',
             'tests/WebURLRequestTest.cpp',
-            'tests/WebViewTest.cpp',
         ],
 
         'conditions': [

Modified: branches/chromium/963/Source/WebKit/chromium/src/WebViewImpl.cpp (102682 => 102683)


--- branches/chromium/963/Source/WebKit/chromium/src/WebViewImpl.cpp	2011-12-13 16:31:17 UTC (rev 102682)
+++ branches/chromium/963/Source/WebKit/chromium/src/WebViewImpl.cpp	2011-12-13 17:13:47 UTC (rev 102683)
@@ -1423,8 +1423,10 @@
 void WebViewImpl::setFocus(bool enable)
 {
     m_page->focusController()->setFocused(enable);
-    m_page->focusController()->setActive(enable);
     if (enable) {
+        // Note that we don't call setActive() when disabled as this cause extra
+        // focus/blur events to be dispatched.
+        m_page->focusController()->setActive(true);
         RefPtr<Frame> focusedFrame = m_page->focusController()->focusedFrame();
         if (focusedFrame) {
             Node* focusedNode = focusedFrame->document()->focusedNode();

Modified: branches/chromium/963/Source/WebKit/chromium/tests/WebFrameTest.cpp (102682 => 102683)


--- branches/chromium/963/Source/WebKit/chromium/tests/WebFrameTest.cpp	2011-12-13 16:31:17 UTC (rev 102682)
+++ branches/chromium/963/Source/WebKit/chromium/tests/WebFrameTest.cpp	2011-12-13 17:13:47 UTC (rev 102683)
@@ -30,7 +30,6 @@
 
 #include "config.h"
 
-#include "FrameTestHelpers.h"
 #include "ResourceError.h"
 #include "WebDocument.h"
 #include "WebFormElement.h"
@@ -40,8 +39,14 @@
 #include "WebSearchableFormData.h"
 #include "WebSecurityPolicy.h"
 #include "WebSettings.h"
+#include "WebString.h"
+#include "WebURL.h"
+#include "WebURLRequest.h"
+#include "WebURLResponse.h"
+#include "WebViewClient.h"
 #include "WebViewImpl.h"
 #include "v8.h"
+#include <googleurl/src/gurl.h>
 #include <gtest/gtest.h>
 #include <webkit/support/webkit_support.h>
 
@@ -52,8 +57,8 @@
 class WebFrameTest : public testing::Test {
 public:
     WebFrameTest()
-        : m_baseURL("http://www.test.com/"),
-          m_chromeURL("chrome://")
+        : baseURL("http://www.test.com/"),
+          chromeURL("chrome://")
     {
     }
 
@@ -64,19 +69,61 @@
 
     void registerMockedHttpURLLoad(const std::string& fileName)
     {
-        FrameTestHelpers::registerMockedURLLoad(m_baseURL, fileName);
+        registerMockedURLLoad(baseURL, fileName);
     }
 
     void registerMockedChromeURLLoad(const std::string& fileName)
     {
-        FrameTestHelpers::registerMockedURLLoad(m_chromeURL, fileName);
+        registerMockedURLLoad(chromeURL, fileName);
     }
 
+    void serveRequests()
+    {
+        webkit_support::ServeAsynchronousMockedRequests();
+    }
+
+    void loadHttpFrame(WebFrame* frame, const std::string& fileName)
+    {
+        loadFrame(frame, baseURL, fileName);
+    }
+
+    void loadChromeFrame(WebFrame* frame, const std::string& fileName)
+    {
+        loadFrame(frame, chromeURL, fileName);
+    }
+
+    void registerMockedURLLoad(const std::string& base, const std::string& fileName)
+    {
+        WebURLResponse response;
+        response.initialize();
+        response.setMIMEType("text/html");
+
+        std::string filePath = webkit_support::GetWebKitRootDir().utf8();
+        filePath += "/Source/WebKit/chromium/tests/data/";
+        filePath += fileName;
+
+        webkit_support::RegisterMockedURL(WebURL(GURL(base + fileName)), response, WebString::fromUTF8(filePath));
+    }
+
+    void loadFrame(WebFrame* frame, const std::string& base, const std::string& fileName)
+    {
+        WebURLRequest urlRequest;
+        urlRequest.initialize();
+        urlRequest.setURL(WebURL(GURL(base + fileName)));
+        frame->loadRequest(urlRequest);
+    }
+
 protected:
-    std::string m_baseURL;
-    std::string m_chromeURL;
+    std::string baseURL;
+    std::string chromeURL;
 };
 
+class TestWebFrameClient : public WebFrameClient {
+};
+
+class TestWebViewClient : public WebViewClient {
+};
+
 TEST_F(WebFrameTest, ContentText)
 {
     registerMockedHttpURLLoad("iframes_test.html");
@@ -84,8 +131,14 @@
     registerMockedHttpURLLoad("invisible_iframe.html");
     registerMockedHttpURLLoad("zero_sized_iframe.html");
 
-    WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "iframes_test.html");
+    // Create and initialize the WebView.
+    TestWebFrameClient webFrameClient;
+    WebView* webView = WebView::create(0);
+    webView->initializeMainFrame(&webFrameClient);
 
+    loadHttpFrame(webView->mainFrame(), "iframes_test.html");
+    serveRequests();
+
     // Now retrieve the frames text and test it only includes visible elements.
     std::string content = webView->mainFrame()->contentAsText(1024).utf8();
     EXPECT_NE(std::string::npos, content.find(" visible paragraph"));
@@ -104,8 +157,15 @@
     registerMockedHttpURLLoad("invisible_iframe.html");
     registerMockedHttpURLLoad("zero_sized_iframe.html");
 
-    WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "iframes_test.html", true);
+    // Create and initialize the WebView.
+    TestWebFrameClient webFrameClient;
+    WebView* webView = WebView::create(0);
+    webView->settings()->setJavaScriptEnabled(true);
+    webView->initializeMainFrame(&webFrameClient);
 
+    loadHttpFrame(webView->mainFrame(), "iframes_test.html");
+    serveRequests();
+
     v8::HandleScope scope;
     EXPECT_EQ(webView->mainFrame(),
               WebFrame::frameForContext(
@@ -121,8 +181,13 @@
 {
     registerMockedHttpURLLoad("form.html");
 
-    WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "form.html");
+    TestWebFrameClient webFrameClient;
+    WebView* webView = WebView::create(0);
+    webView->initializeMainFrame(&webFrameClient);
 
+    loadHttpFrame(webView->mainFrame(), "form.html");
+    serveRequests();
+
     WebVector<WebFormElement> forms;
     webView->mainFrame()->document().forms(forms);
     webView->close();
@@ -137,11 +202,18 @@
 {
     registerMockedChromeURLLoad("history.html");
 
-    WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_chromeURL + "history.html", true);
+    // Create and initialize the WebView.
+    TestWebFrameClient webFrameClient;
+    WebView* webView = WebView::create(0);
+    webView->settings()->setJavaScriptEnabled(true);
+    webView->initializeMainFrame(&webFrameClient);
 
+    loadChromeFrame(webView->mainFrame(), "history.html");
+    serveRequests();
+
     // Try to run JS against the chrome-style URL.
     WebSecurityPolicy::registerURLSchemeAsNotAllowingJavascriptURLs("chrome");
-    FrameTestHelpers::loadFrame(webView->mainFrame(), "_javascript_:document.body.appendChild(document.createTextNode('Clobbered'))");
+    loadFrame(webView->mainFrame(), "_javascript_:", "document.body.appendChild(document.createTextNode('Clobbered'))");
 
     // Now retrieve the frames text and see if it was clobbered.
     std::string content = webView->mainFrame()->contentAsText(1024).utf8();
@@ -175,12 +247,17 @@
     registerMockedHttpURLLoad("form.html");
 
     TestReloadDoesntRedirectWebFrameClient webFrameClient;
-    WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "form.html", false, &webFrameClient);
+    WebView* webView = WebView::create(0);
+    webView->initializeMainFrame(&webFrameClient);
 
+    loadHttpFrame(webView->mainFrame(), "form.html");
+    serveRequests();
+    // Frame is loaded.
+
     webView->mainFrame()->reload(true);
     // start reload before request is delivered.
     webView->mainFrame()->reload(true);
-    webkit_support::ServeAsynchronousMockedRequests();
+    serveRequests();
 }
 
 TEST_F(WebFrameTest, ClearFocusedNodeTest)
@@ -188,8 +265,16 @@
     registerMockedHttpURLLoad("iframe_clear_focused_node_test.html");
     registerMockedHttpURLLoad("autofocus_input_field_iframe.html");
 
-    WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(FrameTestHelpers::createWebViewAndLoad(m_baseURL + "iframe_clear_focused_node_test.html", true));
+    // Create and initialize the WebView.
+    TestWebFrameClient webFrameClient;
+    TestWebViewClient webviewClient;
+    WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(WebView::create(&webviewClient));
+    webViewImpl->settings()->setJavaScriptEnabled(true);
+    webViewImpl->initializeMainFrame(&webFrameClient);
 
+    loadHttpFrame(webViewImpl->mainFrame(), "iframe_clear_focused_node_test.html");
+    serveRequests();
+
     // Clear the focused node.
     webViewImpl->clearFocusedNode();
 
@@ -268,7 +353,11 @@
 
     // Load a frame with an iframe, make sure we get the right create notifications.
     ContextLifetimeTestWebFrameClient webFrameClient;
-    WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "context_notifications_test.html", true, &webFrameClient);
+    WebView* webView = WebView::create(0);
+    webView->settings()->setJavaScriptEnabled(true);
+    webView->initializeMainFrame(&webFrameClient);
+    loadHttpFrame(webView->mainFrame(), "context_notifications_test.html");
+    serveRequests();
 
     WebFrame* mainFrame = webView->mainFrame();
     WebFrame* childFrame = mainFrame->firstChild();
@@ -306,11 +395,15 @@
     registerMockedHttpURLLoad("context_notifications_test_frame.html");
 
     ContextLifetimeTestWebFrameClient webFrameClient;
-    WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "context_notifications_test.html", true, &webFrameClient);
+    WebView* webView = WebView::create(0);
+    webView->settings()->setJavaScriptEnabled(true);
+    webView->initializeMainFrame(&webFrameClient);
+    loadHttpFrame(webView->mainFrame(), "context_notifications_test.html");
+    serveRequests();
 
     // Refresh, we should get two release notifications and two more create notifications.
     webView->mainFrame()->reload(false);
-    webkit_support::ServeAsynchronousMockedRequests();
+    serveRequests();
     ASSERT_EQ(4u, webFrameClient.createNotifications.size());
     ASSERT_EQ(2u, webFrameClient.releaseNotifications.size());
 
@@ -345,7 +438,11 @@
     registerMockedHttpURLLoad("context_notifications_test_frame.html");
 
     ContextLifetimeTestWebFrameClient webFrameClient;
-    WebView* webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "context_notifications_test.html", true, &webFrameClient);
+    WebView* webView = WebView::create(0);
+    webView->settings()->setJavaScriptEnabled(true);
+    webView->initializeMainFrame(&webFrameClient);
+    loadHttpFrame(webView->mainFrame(), "context_notifications_test.html");
+    serveRequests();
 
     // Add an isolated world.
     webFrameClient.reset();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to