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

Side by Side Diff: cc/trees/layer_tree_host_impl_unittest.cc

Issue 23533051: [android_webview] Use a fraction to calculate scroll offset. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revert changes from previous patch set as they break AwSettings tests Created 7 years, 2 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/layers/layer_impl_unittest.cc ('k') | cc/trees/layer_tree_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/trees/layer_tree_host_impl.h" 5 #include "cc/trees/layer_tree_host_impl.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 2307 matching lines...) Expand 10 before | Expand all | Expand 10 after
2318 2318
2319 // The scale should not have been applied to the scroll delta. 2319 // The scale should not have been applied to the scroll delta.
2320 scroll_info = host_impl_->ProcessScrollDeltas(); 2320 scroll_info = host_impl_->ProcessScrollDeltas();
2321 ExpectContains(*scroll_info.get(), 2321 ExpectContains(*scroll_info.get(),
2322 scroll_layer->id(), 2322 scroll_layer->id(),
2323 wheel_scroll_delta); 2323 wheel_scroll_delta);
2324 } 2324 }
2325 2325
2326 class TestScrollOffsetDelegate : public LayerScrollOffsetDelegate { 2326 class TestScrollOffsetDelegate : public LayerScrollOffsetDelegate {
2327 public: 2327 public:
2328 TestScrollOffsetDelegate() {} 2328 TestScrollOffsetDelegate() : page_scale_factor_(0.f) {}
2329
2329 virtual ~TestScrollOffsetDelegate() {} 2330 virtual ~TestScrollOffsetDelegate() {}
2330 2331
2332 virtual void SetMaxScrollOffset(gfx::Vector2dF max_scroll_offset) OVERRIDE {
2333 max_scroll_offset_ = max_scroll_offset;
2334 }
2335
2331 virtual void SetTotalScrollOffset(gfx::Vector2dF new_value) OVERRIDE { 2336 virtual void SetTotalScrollOffset(gfx::Vector2dF new_value) OVERRIDE {
2332 last_set_scroll_offset_ = new_value; 2337 last_set_scroll_offset_ = new_value;
2333 } 2338 }
2334 2339
2335 virtual gfx::Vector2dF GetTotalScrollOffset() OVERRIDE { 2340 virtual gfx::Vector2dF GetTotalScrollOffset() OVERRIDE {
2336 return getter_return_value_; 2341 return getter_return_value_;
2337 } 2342 }
2338 2343
2344 virtual void SetPageScaleFactor(float page_scale_factor) OVERRIDE {
2345 page_scale_factor_ = page_scale_factor;
2346 }
2347
2348 virtual void SetScrollableSize(gfx::SizeF scrollable_size) OVERRIDE {
2349 scrollable_size_ = scrollable_size;
2350 }
2351
2339 gfx::Vector2dF last_set_scroll_offset() { 2352 gfx::Vector2dF last_set_scroll_offset() {
2340 return last_set_scroll_offset_; 2353 return last_set_scroll_offset_;
2341 } 2354 }
2342 2355
2343 void set_getter_return_value(gfx::Vector2dF value) { 2356 void set_getter_return_value(gfx::Vector2dF value) {
2344 getter_return_value_ = value; 2357 getter_return_value_ = value;
2345 } 2358 }
2346 2359
2360 gfx::Vector2dF max_scroll_offset() const {
2361 return max_scroll_offset_;
2362 }
2363
2364 gfx::SizeF scrollable_size() const {
2365 return scrollable_size_;
2366 }
2367
2368 float page_scale_factor() const {
2369 return page_scale_factor_;
2370 }
2371
2347 private: 2372 private:
2348 gfx::Vector2dF last_set_scroll_offset_; 2373 gfx::Vector2dF last_set_scroll_offset_;
2349 gfx::Vector2dF getter_return_value_; 2374 gfx::Vector2dF getter_return_value_;
2375 gfx::Vector2dF max_scroll_offset_;
2376 gfx::SizeF scrollable_size_;
2377 float page_scale_factor_;
2350 }; 2378 };
2351 2379
2352 TEST_F(LayerTreeHostImplTest, RootLayerScrollOffsetDelegation) { 2380 TEST_F(LayerTreeHostImplTest, RootLayerScrollOffsetDelegation) {
2353 TestScrollOffsetDelegate scroll_delegate; 2381 TestScrollOffsetDelegate scroll_delegate;
2382 host_impl_->SetViewportSize(gfx::Size(10, 20));
2354 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); 2383 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100));
2355 2384
2356 // Setting the delegate results in the current scroll offset being set. 2385 // Setting the delegate results in the current scroll offset being set.
2357 gfx::Vector2dF initial_scroll_delta(10.f, 10.f); 2386 gfx::Vector2dF initial_scroll_delta(10.f, 10.f);
2358 scroll_layer->SetScrollOffset(gfx::Vector2d()); 2387 scroll_layer->SetScrollOffset(gfx::Vector2d());
2359 scroll_layer->SetScrollDelta(initial_scroll_delta); 2388 scroll_layer->SetScrollDelta(initial_scroll_delta);
2360 host_impl_->SetRootLayerScrollOffsetDelegate(&scroll_delegate); 2389 host_impl_->SetRootLayerScrollOffsetDelegate(&scroll_delegate);
2361 EXPECT_EQ(initial_scroll_delta.ToString(), 2390 EXPECT_EQ(initial_scroll_delta.ToString(),
2362 scroll_delegate.last_set_scroll_offset().ToString()); 2391 scroll_delegate.last_set_scroll_offset().ToString());
2363 2392
2393 // Setting the delegate results in the scrollable_size, max_scroll_offset and
2394 // page_scale being set.
2395 EXPECT_EQ(gfx::SizeF(100, 100), scroll_delegate.scrollable_size());
2396 EXPECT_EQ(gfx::Vector2dF(90, 80), scroll_delegate.max_scroll_offset());
2397 EXPECT_EQ(1.f, scroll_delegate.page_scale_factor());
2398
2399 // Updating page scale immediately updates the delegate.
2400 host_impl_->active_tree()->SetPageScaleFactorAndLimits(2.f, 0.5f, 4.f);
2401 EXPECT_EQ(2.f, scroll_delegate.page_scale_factor());
2402 host_impl_->active_tree()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f);
2403 EXPECT_EQ(1.f, scroll_delegate.page_scale_factor());
2404
2364 // Scrolling should be relative to the offset as returned by the delegate. 2405 // Scrolling should be relative to the offset as returned by the delegate.
2365 gfx::Vector2dF scroll_delta(0.f, 10.f); 2406 gfx::Vector2dF scroll_delta(0.f, 10.f);
2366 gfx::Vector2dF current_offset(7.f, 8.f); 2407 gfx::Vector2dF current_offset(7.f, 8.f);
2367 2408
2368 scroll_delegate.set_getter_return_value(current_offset); 2409 scroll_delegate.set_getter_return_value(current_offset);
2369 EXPECT_EQ(InputHandler::ScrollStarted, 2410 EXPECT_EQ(InputHandler::ScrollStarted,
2370 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture)); 2411 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture));
2371 2412
2372 host_impl_->ScrollBy(gfx::Point(), scroll_delta); 2413 host_impl_->ScrollBy(gfx::Point(), scroll_delta);
2373 EXPECT_EQ(current_offset + scroll_delta, 2414 EXPECT_EQ(current_offset + scroll_delta,
(...skipping 4250 matching lines...) Expand 10 before | Expand all | Expand 10 after
6624 host_impl_.reset(); 6665 host_impl_.reset();
6625 6666
6626 // The CopyOutputResult's callback was cancelled, the CopyOutputResult 6667 // The CopyOutputResult's callback was cancelled, the CopyOutputResult
6627 // released, and the texture deleted. 6668 // released, and the texture deleted.
6628 EXPECT_TRUE(context_provider->HasOneRef()); 6669 EXPECT_TRUE(context_provider->HasOneRef());
6629 EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures()); 6670 EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures());
6630 } 6671 }
6631 6672
6632 } // namespace 6673 } // namespace
6633 } // namespace cc 6674 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/layer_impl_unittest.cc ('k') | cc/trees/layer_tree_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698