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

Unified Diff: content/renderer/render_view_browsertest.cc

Issue 1496243005: Use Window coordinates for IME composition bounds, auto resize (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 | content/renderer/render_view_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/render_view_browsertest.cc
diff --git a/content/renderer/render_view_browsertest.cc b/content/renderer/render_view_browsertest.cc
index 3e3c3364bbdba28be0679267643ce10a18569725..0cd8cd3bcc3ba6abfa4e684fa951c4f27520a614 100644
--- a/content/renderer/render_view_browsertest.cc
+++ b/content/renderer/render_view_browsertest.cc
@@ -388,15 +388,17 @@ class RenderViewImplScaleFactorTest : public RenderViewImplBlinkSettingsTest {
public:
void DoSetUp() override {
RenderViewImplBlinkSettingsTest::DoSetUp();
+ }
Avi (use Gerrit) 2015/12/10 15:28:54 This override just to call the superclass version
oshima 2015/12/10 18:45:36 oops, thanks for the catch. done.
+ void SetDeviceScaleFactor(float dsf) {
ViewMsg_Resize_Params params;
- params.screen_info.deviceScaleFactor = 2.f;
+ params.screen_info.deviceScaleFactor = dsf;
params.new_size = gfx::Size(100, 100);
params.physical_backing_size = gfx::Size(200, 200);
params.visible_viewport_size = params.new_size;
params.needs_resize_ack = false;
view()->OnResize(params);
- ASSERT_EQ(2.f, view()->device_scale_factor_);
+ ASSERT_EQ(dsf, view()->device_scale_factor_);
}
};
@@ -1828,6 +1830,7 @@ TEST_F(RenderViewImplTest, GetCompositionCharacterBoundsTest) {
view()->OnImeSetComposition(ascii_composition, empty_underline, 0, 0);
view()->GetCompositionCharacterBounds(&bounds);
ASSERT_EQ(ascii_composition.size(), bounds.size());
+
for (size_t i = 0; i < bounds.size(); ++i)
EXPECT_LT(0, bounds[i].width());
view()->OnImeConfirmComposition(
@@ -2491,6 +2494,7 @@ TEST_F(RenderViewImplBlinkSettingsTest, Negative) {
TEST_F(RenderViewImplScaleFactorTest, ConverViewportToWindowWithoutZoomForDSF) {
DoSetUp();
+ SetDeviceScaleFactor(2.f);
blink::WebRect rect(20, 10, 200, 100);
view()->convertViewportToWindow(&rect);
EXPECT_EQ(20, rect.x);
@@ -2503,13 +2507,108 @@ TEST_F(RenderViewImplScaleFactorTest, ConverViewportToWindowWithZoomForDSF) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableUseZoomForDSF);
DoSetUp();
+ SetDeviceScaleFactor(1.f);
+ {
+ blink::WebRect rect(20, 10, 200, 100);
+ view()->convertViewportToWindow(&rect);
+ EXPECT_EQ(20, rect.x);
+ EXPECT_EQ(10, rect.y);
+ EXPECT_EQ(200, rect.width);
+ EXPECT_EQ(100, rect.height);
+ }
- blink::WebRect rect(20, 10, 200, 100);
- view()->convertViewportToWindow(&rect);
- EXPECT_EQ(10, rect.x);
- EXPECT_EQ(5, rect.y);
- EXPECT_EQ(100, rect.width);
- EXPECT_EQ(50, rect.height);
+ SetDeviceScaleFactor(2.f);
+ {
+ blink::WebRect rect(20, 10, 200, 100);
+ view()->convertViewportToWindow(&rect);
+ EXPECT_EQ(10, rect.x);
+ EXPECT_EQ(5, rect.y);
+ EXPECT_EQ(100, rect.width);
+ EXPECT_EQ(50, rect.height);
+ }
+}
+
+#if defined(OS_MACOSX) || defined(USE_AURA)
+TEST_F(RenderViewImplScaleFactorTest, GetCompositionCharacterBoundsTest) {
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kEnableUseZoomForDSF);
+ DoSetUp();
+ SetDeviceScaleFactor(1.f);
+#if defined(OS_WIN)
+ // http://crbug.com/508747
+ if (base::win::GetVersion() >= base::win::VERSION_WIN10)
+ return;
+#endif
+
+ LoadHTML("<textarea id=\"test\"></textarea>");
+ ExecuteJavaScriptForTests("document.getElementById('test').focus();");
+
+ const base::string16 empty_string;
+ const std::vector<blink::WebCompositionUnderline> empty_underline;
+ std::vector<gfx::Rect> bounds_at_1x;
+ view()->OnSetFocus(true);
+
+ // ASCII composition
+ const base::string16 ascii_composition = base::UTF8ToUTF16("aiueo");
+ view()->OnImeSetComposition(ascii_composition, empty_underline, 0, 0);
+ view()->GetCompositionCharacterBounds(&bounds_at_1x);
+ ASSERT_EQ(ascii_composition.size(), bounds_at_1x.size());
+
+ SetDeviceScaleFactor(2.f);
+ std::vector<gfx::Rect> bounds_at_2x;
+ view()->GetCompositionCharacterBounds(&bounds_at_2x);
+ ASSERT_EQ(bounds_at_1x.size(), bounds_at_2x.size());
+ for (size_t i = 0; i < bounds_at_1x.size(); i++) {
+ const gfx::Rect& b1 = bounds_at_1x[i];
+ const gfx::Rect& b2 = bounds_at_2x[i];
+ gfx::Vector2d origin_diff = b1.origin() - b2.origin();
+
+ // The bounds are't exactly same because the font metrics are different
+ // at 1x and 2x. Just make sure that the difference is small.
+ EXPECT_NE(b1, b2);
+ EXPECT_LT(origin_diff.x(), 2);
+ EXPECT_LT(origin_diff.y(), 2);
+ EXPECT_LT(std::abs(b1.width() - b2.width()), 2);
+ EXPECT_LT(std::abs(b1.height() - b2.height()), 2);
+ }
+}
+#endif
+
+namespace {
+
+// Don't use text as it text will change the size in DIP at different
+// scale factor.
+const char kAutoResizeTestPage[] =
+ "<div style='width=20px; height=20px'></div>";
+
+} // namespace
+
+TEST_F(RenderViewImplScaleFactorTest, AutoResizeWithZoomForDSF) {
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kEnableUseZoomForDSF);
+ DoSetUp();
+ view()->EnableAutoResizeForTesting(gfx::Size(5, 5), gfx::Size(1000, 1000));
+ LoadHTML(kAutoResizeTestPage);
+ gfx::Size size_at_1x = view()->size();
+ ASSERT_FALSE(size_at_1x.IsEmpty());
+
+ SetDeviceScaleFactor(2.f);
+ LoadHTML(kAutoResizeTestPage);
+ gfx::Size size_at_2x = view()->size();
+ EXPECT_EQ(size_at_1x, size_at_2x);
+}
+
+TEST_F(RenderViewImplScaleFactorTest, AutoResizeWithoutZoomForDSF) {
+ DoSetUp();
+ view()->EnableAutoResizeForTesting(gfx::Size(5, 5), gfx::Size(1000, 1000));
+ LoadHTML(kAutoResizeTestPage);
+ gfx::Size size_at_1x = view()->size();
+ ASSERT_FALSE(size_at_1x.IsEmpty());
+
+ SetDeviceScaleFactor(2.f);
+ LoadHTML(kAutoResizeTestPage);
+ gfx::Size size_at_2x = view()->size();
+ EXPECT_EQ(size_at_1x, size_at_2x);
}
TEST_F(DevToolsAgentTest, DevToolsResumeOnClose) {
« no previous file with comments | « no previous file | content/renderer/render_view_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698