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

Unified Diff: third_party/WebKit/Source/web/tests/WebFrameTest.cpp

Issue 2783743002: Fix nullptr deref in maybeRenderFallbackContent() (Closed)
Patch Set: Fix tests, handled the non-loading cause in the maybeRenderFallbackContent() if block 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/web/tests/WebFrameTest.cpp
diff --git a/third_party/WebKit/Source/web/tests/WebFrameTest.cpp b/third_party/WebKit/Source/web/tests/WebFrameTest.cpp
index 6499c5330e00aa88c0e7cc019b5ae104eb2573ca..926d33740b7ad84e3b8c4fb0fe0e4065ade3a123 100644
--- a/third_party/WebKit/Source/web/tests/WebFrameTest.cpp
+++ b/third_party/WebKit/Source/web/tests/WebFrameTest.cpp
@@ -11588,4 +11588,66 @@ TEST_F(WebFrameTest, LocalFrameWithRemoteParentIsTransparent) {
view->close();
}
+class TestFallbackWebFrameClient : public FrameTestHelpers::TestWebFrameClient {
+ public:
+ explicit TestFallbackWebFrameClient() : m_childClient(nullptr) {}
+
+ void setChildWebFrameClient(TestFallbackWebFrameClient* client) {
+ m_childClient = client;
+ }
+
+ WebLocalFrame* createChildFrame(
+ WebLocalFrame* parent,
+ WebTreeScopeType scope,
+ const WebString&,
+ const WebString&,
+ WebSandboxFlags,
+ const WebFrameOwnerProperties& frameOwnerProperties) override {
+ DCHECK(m_childClient);
+ WebLocalFrame* frame =
+ WebLocalFrame::create(scope, m_childClient, nullptr, nullptr);
+ parent->appendChild(frame);
+ return frame;
+ }
+
+ WebNavigationPolicy decidePolicyForNavigation(
+ const NavigationPolicyInfo& info) override {
+ if (m_childClient || KURL(info.urlRequest.url()) == blankURL())
+ return WebNavigationPolicyCurrentTab;
+ return WebNavigationPolicyHandledByClient;
+ }
+
+ private:
+ TestFallbackWebFrameClient* m_childClient;
+};
+
+TEST_F(WebFrameTest, FallbackForNonexistentProvisionalNavigation) {
+ registerMockedHttpURLLoad("fallback.html");
+ TestFallbackWebFrameClient mainClient;
+ TestFallbackWebFrameClient childClient;
+ mainClient.setChildWebFrameClient(&childClient);
+
+ FrameTestHelpers::WebViewHelper webViewHelper;
+ webViewHelper.initialize(true, &mainClient);
+
+ WebLocalFrameImpl* mainFrame = webViewHelper.webView()->mainFrameImpl();
+ WebURLRequest request(toKURL(m_baseURL + "fallback.html"));
+ mainFrame->loadRequest(request);
+
+ // Because the child frame will be HandledByClient, the main frame will not
+ // finish loading, so we cant use
+ // FrameTestHelpers::pumpPendingRequestsForFrameToLoad.
+ Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
+
+ // Overwrite the client-handled child frame navigation with about:blank.
+ WebLocalFrame* child = mainFrame->firstChild()->toWebLocalFrame();
+ child->loadRequest(WebURLRequest(blankURL()));
+
+ // Failing the original child frame navigation and trying to render fallback
+ // content shouldn't crash. It should return true as though it showed
+ // fallback. This is so the caller won't attempt to replace the correctly
+ // empty frame with an error page.
+ EXPECT_TRUE(child->maybeRenderFallbackContent(WebURLError()));
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698