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

Unified Diff: content/renderer/render_frame_impl_browsertest.cc

Issue 1273183002: Fix invalid C-style cast in RenderFrameImplTest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: two casts; comments Created 5 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/render_frame_impl_browsertest.cc
diff --git a/content/renderer/render_frame_impl_browsertest.cc b/content/renderer/render_frame_impl_browsertest.cc
index ceb52cd626293343294bbb5938217a221e0e8bba..59850424af051d20f2127895def16483f6bf2b9c 100644
--- a/content/renderer/render_frame_impl_browsertest.cc
+++ b/content/renderer/render_frame_impl_browsertest.cc
@@ -110,7 +110,20 @@ class RenderFrameTestObserver : public RenderFrameObserver {
// RenderWidget.
TEST_F(RenderFrameImplTest, MAYBE_SubframeWidget) {
EXPECT_TRUE(frame_widget());
- EXPECT_NE(frame_widget(), (content::RenderWidget*)view_);
+ // We can't convert to content::RenderWidget* directly,
+ // because it and content::RenderView are two unrelated base classes
nasko 2015/08/06 20:55:20 nit: drop the "content::" prefix, as this code is
krasin 2015/08/06 21:02:22 Done.
+ // of content::RenderViewImpl. If a class has multiple base classes,
+ // each base class pointer will be distinct, and direct casts
+ // between unrelated base classes are undefined, even if they share
+ // a common derived class. The compiler has no way in general of
+ // determining the displacement between the two classes, so these
+ // types of casts cannot be implemented in a type safe way.
+ // So overcome this, we make two legal static casts:
nasko 2015/08/06 20:55:20 nit: s/So/To/
krasin 2015/08/06 21:02:22 Done.
+ // first, downcast from RenderView* to RenderViewImpl*,
+ // then upcast from RenderViewImpl* to RenderWidger*.
nasko 2015/08/06 20:55:20 nit: RenderWidget
krasin 2015/08/06 21:02:22 Done.
+ EXPECT_NE(frame_widget(),
+ static_cast<content::RenderWidget*>(
+ static_cast<content::RenderViewImpl*>((view_))));
}
// Verify a subframe RenderWidget properly processes its viewport being
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698