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

Side by Side Diff: cc/input/top_controls_manager_unittest.cc

Issue 1001833005: Update from https://crrev.com/320343 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Supress Created 5 years, 9 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
« no previous file with comments | « cc/input/top_controls_manager.cc ('k') | cc/layers/delegated_renderer_layer_impl_unittest.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/input/top_controls_manager.h" 5 #include "cc/input/top_controls_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath>
8 9
10 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
10 #include "base/time/time.h" 12 #include "base/time/time.h"
11 #include "cc/input/top_controls_manager_client.h" 13 #include "cc/input/top_controls_manager_client.h"
12 #include "cc/layers/layer_impl.h" 14 #include "cc/layers/layer_impl.h"
13 #include "cc/test/fake_impl_proxy.h" 15 #include "cc/test/fake_impl_proxy.h"
14 #include "cc/test/fake_layer_tree_host_impl.h" 16 #include "cc/test/fake_layer_tree_host_impl.h"
15 #include "cc/test/test_shared_bitmap_manager.h" 17 #include "cc/test/test_shared_bitmap_manager.h"
16 #include "cc/trees/layer_tree_impl.h" 18 #include "cc/trees/layer_tree_impl.h"
17 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
18 #include "ui/gfx/frame_time.h" 20 #include "ui/gfx/frame_time.h"
(...skipping 25 matching lines...) Expand all
44 void DidChangeTopControlsPosition() override { 46 void DidChangeTopControlsPosition() override {
45 redraw_needed_ = true; 47 redraw_needed_ = true;
46 update_draw_properties_needed_ = true; 48 update_draw_properties_needed_ = true;
47 } 49 }
48 50
49 bool HaveRootScrollLayer() const override { return true; } 51 bool HaveRootScrollLayer() const override { return true; }
50 52
51 float TopControlsHeight() const override { return top_controls_height_; } 53 float TopControlsHeight() const override { return top_controls_height_; }
52 54
53 void SetCurrentTopControlsShownRatio(float ratio) override { 55 void SetCurrentTopControlsShownRatio(float ratio) override {
56 ASSERT_FALSE(std::isnan(ratio));
57 ASSERT_FALSE(ratio == std::numeric_limits<float>::infinity());
58 ASSERT_FALSE(ratio == -std::numeric_limits<float>::infinity());
54 ratio = std::max(ratio, 0.f); 59 ratio = std::max(ratio, 0.f);
55 ratio = std::min(ratio, 1.f); 60 ratio = std::min(ratio, 1.f);
56 top_controls_shown_ratio_ = ratio; 61 top_controls_shown_ratio_ = ratio;
57 } 62 }
58 63
59 float CurrentTopControlsShownRatio() const override { 64 float CurrentTopControlsShownRatio() const override {
60 return top_controls_shown_ratio_; 65 return top_controls_shown_ratio_;
61 } 66 }
62 67
63 LayerImpl* rootScrollLayer() { 68 LayerImpl* rootScrollLayer() {
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 EXPECT_FALSE(manager->animation()); 444 EXPECT_FALSE(manager->animation());
440 EXPECT_FLOAT_EQ(-50.f, manager->ControlsTopOffset()); 445 EXPECT_FLOAT_EQ(-50.f, manager->ControlsTopOffset());
441 EXPECT_FLOAT_EQ(0.f, manager->ContentTopOffset()); 446 EXPECT_FLOAT_EQ(0.f, manager->ContentTopOffset());
442 447
443 client.SetTopControlsHeight(0.f); 448 client.SetTopControlsHeight(0.f);
444 EXPECT_FALSE(manager->animation()); 449 EXPECT_FALSE(manager->animation());
445 EXPECT_FLOAT_EQ(0.f, manager->ControlsTopOffset()); 450 EXPECT_FLOAT_EQ(0.f, manager->ControlsTopOffset());
446 EXPECT_FLOAT_EQ(0.f, manager->ContentTopOffset()); 451 EXPECT_FLOAT_EQ(0.f, manager->ContentTopOffset());
447 } 452 }
448 453
449 TEST(TopControlsManagerTest, ZeroTopControlsHeightScrolling) { 454 TEST(TopControlsManagerTest, ScrollByWithZeroHeightControlsIsNoop) {
450 MockTopControlsManagerClient client(0.f, 0.5f, 0.5f); 455 MockTopControlsManagerClient client(0.f, 0.5f, 0.5f);
451 client.SetCurrentTopControlsShownRatio(0.f);
452 TopControlsManager* manager = client.manager(); 456 TopControlsManager* manager = client.manager();
453 manager->UpdateTopControlsState(BOTH, BOTH, false); 457 manager->UpdateTopControlsState(BOTH, BOTH, false);
454 458
455 manager->ScrollBegin(); 459 manager->ScrollBegin();
456 EXPECT_FLOAT_EQ(-10.f, manager->ScrollBy(gfx::Vector2dF(0.f, -10.f)).y()); 460 gfx::Vector2dF pending = manager->ScrollBy(gfx::Vector2dF(0.f, 20.f));
457 EXPECT_FLOAT_EQ(0.f, manager->TopControlsShownRatio()); 461 EXPECT_FLOAT_EQ(20.f, pending.y());
458 462 EXPECT_FLOAT_EQ(0.f, manager->ControlsTopOffset());
459 client.SetTopControlsHeight(20.f); 463 EXPECT_FLOAT_EQ(0.f, manager->ContentTopOffset());
460 EXPECT_FLOAT_EQ(0.f, manager->TopControlsShownRatio()); 464 EXPECT_FLOAT_EQ(1.f, client.CurrentTopControlsShownRatio());
461
462 EXPECT_FLOAT_EQ(0.f, manager->ScrollBy(gfx::Vector2dF(0.f, -15.f)).y());
463 EXPECT_FLOAT_EQ(0.75f, manager->TopControlsShownRatio());
464 client.SetTopControlsHeight(0.f);
465 manager->ScrollEnd(); 465 manager->ScrollEnd();
466
467 EXPECT_FALSE(manager->animation());
468 EXPECT_FLOAT_EQ(1.f, manager->TopControlsShownRatio());
469 } 466 }
470 467
471 TEST(TopControlsManagerTest, ZeroTopControlsHeightAnimating) {
472 MockTopControlsManagerClient client(0.f, 0.5f, 0.5f);
473 client.SetCurrentTopControlsShownRatio(0.f);
474 TopControlsManager* manager = client.manager();
475
476 manager->UpdateTopControlsState(BOTH, HIDDEN, false);
477 EXPECT_FLOAT_EQ(0.f, manager->TopControlsShownRatio());
478 manager->UpdateTopControlsState(BOTH, SHOWN, false);
479 EXPECT_FLOAT_EQ(1.f, manager->TopControlsShownRatio());
480
481 manager->UpdateTopControlsState(BOTH, HIDDEN, true);
482 EXPECT_FLOAT_EQ(0.f, manager->TopControlsShownRatio());
483 EXPECT_FALSE(manager->animation());
484 manager->UpdateTopControlsState(BOTH, SHOWN, true);
485 EXPECT_FLOAT_EQ(1.f, manager->TopControlsShownRatio());
486 EXPECT_FALSE(manager->animation());
487
488 client.SetCurrentTopControlsShownRatio(0.3f);
489 manager->MainThreadHasStoppedFlinging();
490 EXPECT_FALSE(manager->animation());
491 EXPECT_FLOAT_EQ(0.f, manager->TopControlsShownRatio());
492 }
493 468
494 } // namespace 469 } // namespace
495 } // namespace cc 470 } // namespace cc
OLDNEW
« no previous file with comments | « cc/input/top_controls_manager.cc ('k') | cc/layers/delegated_renderer_layer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698