Commit 293783ba authored by asvitkine's avatar asvitkine Committed by Commit bot

[Mac] Fix download item text sometimes being misaligned.

There's two possible stable values for |titleY_|,
kPrimaryTextPosTop - when status message is visible,
kPrimaryTextOnlyPosTop - when status message is not visible.

There was an inconistency how this was being initialized -
as isStatusTextVisible_ was being set to NO but the value
was set to kPrimaryTextPosTop.

The text would then be misaligned if the code would take
the -hideSecondaryTitle in -setStateFromDownload:.

This CL fixes the issue and updates the test to check this.

BUG=484848

Review URL: https://codereview.chromium.org/1130903004

Cr-Commit-Position: refs/heads/master@{#329305}
parent 35024356
...@@ -64,6 +64,7 @@ enum DownloadItemMousePosition { ...@@ -64,6 +64,7 @@ enum DownloadItemMousePosition {
@interface DownloadItemCell(TestingAPI) @interface DownloadItemCell(TestingAPI)
- (BOOL)isStatusTextVisible; - (BOOL)isStatusTextVisible;
- (CGFloat)statusTextAlpha; - (CGFloat)statusTextAlpha;
- (CGFloat)titleY;
- (void)skipVisibilityAnimation; - (void)skipVisibilityAnimation;
- (void)showSecondaryTitle; - (void)showSecondaryTitle;
- (void)hideSecondaryTitle; - (void)hideSecondaryTitle;
......
...@@ -138,7 +138,7 @@ void DummyRTLMirror(gfx::Rect* bounds) { ...@@ -138,7 +138,7 @@ void DummyRTLMirror(gfx::Rect* bounds) {
- (void)setInitialState { - (void)setInitialState {
isStatusTextVisible_ = NO; isStatusTextVisible_ = NO;
titleY_ = kPrimaryTextPosTop; titleY_ = kPrimaryTextOnlyPosTop;
statusAlpha_ = 0.0; statusAlpha_ = 0.0;
indeterminateProgressAngle_ = DownloadShelf::kStartAngleDegrees; indeterminateProgressAngle_ = DownloadShelf::kStartAngleDegrees;
...@@ -727,6 +727,10 @@ void DummyRTLMirror(gfx::Rect* bounds) { ...@@ -727,6 +727,10 @@ void DummyRTLMirror(gfx::Rect* bounds) {
return statusAlpha_; return statusAlpha_;
} }
- (CGFloat)titleY {
return titleY_;
}
- (void)skipVisibilityAnimation { - (void)skipVisibilityAnimation {
[toggleStatusVisibilityAnimation_ setCurrentProgress:1.0]; [toggleStatusVisibilityAnimation_ setCurrentProgress:1.0];
} }
......
...@@ -2,22 +2,19 @@ ...@@ -2,22 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#import "chrome/browser/ui/cocoa/download/download_item_cell.h"
#include "base/mac/scoped_nsobject.h" #include "base/mac/scoped_nsobject.h"
#include "chrome/browser/download/download_item_model.h" #include "chrome/browser/download/download_item_model.h"
#import "chrome/browser/ui/cocoa/cocoa_test_helper.h" #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
#import "chrome/browser/ui/cocoa/download/download_item_cell.h"
#include "content/public/test/mock_download_item.h" #include "content/public/test/mock_download_item.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h" #include "testing/platform_test.h"
using ::testing::Return;
using ::testing::_; using ::testing::_;
using ::testing::Return;
using ::testing::ReturnRefOfCopy; using ::testing::ReturnRefOfCopy;
class DownloadItemCellTest : public CocoaTest { class DownloadItemCellTest : public CocoaTest {
public: public:
DownloadItemCellTest() : CocoaTest() { DownloadItemCellTest() : CocoaTest() {
...@@ -42,16 +39,19 @@ class DownloadItemCellTest : public CocoaTest { ...@@ -42,16 +39,19 @@ class DownloadItemCellTest : public CocoaTest {
TEST_F(DownloadItemCellTest, ToggleStatusText) { TEST_F(DownloadItemCellTest, ToggleStatusText) {
EXPECT_FALSE([cell_ isStatusTextVisible]); EXPECT_FALSE([cell_ isStatusTextVisible]);
EXPECT_FLOAT_EQ(0.0, [cell_ statusTextAlpha]); EXPECT_FLOAT_EQ(0.0, [cell_ statusTextAlpha]);
CGFloat titleYNoStatus = [cell_ titleY];
[cell_ showSecondaryTitle]; [cell_ showSecondaryTitle];
[cell_ skipVisibilityAnimation]; [cell_ skipVisibilityAnimation];
EXPECT_TRUE([cell_ isStatusTextVisible]); EXPECT_TRUE([cell_ isStatusTextVisible]);
EXPECT_FLOAT_EQ(1.0, [cell_ statusTextAlpha]); EXPECT_FLOAT_EQ(1.0, [cell_ statusTextAlpha]);
EXPECT_LT([cell_ titleY], titleYNoStatus);
[cell_ hideSecondaryTitle]; [cell_ hideSecondaryTitle];
[cell_ skipVisibilityAnimation]; [cell_ skipVisibilityAnimation];
EXPECT_FALSE([cell_ isStatusTextVisible]); EXPECT_FALSE([cell_ isStatusTextVisible]);
EXPECT_FLOAT_EQ(0.0, [cell_ statusTextAlpha]); EXPECT_FLOAT_EQ(0.0, [cell_ statusTextAlpha]);
EXPECT_FLOAT_EQ(titleYNoStatus, [cell_ titleY]);
} }
TEST_F(DownloadItemCellTest, IndeterminateProgress) { TEST_F(DownloadItemCellTest, IndeterminateProgress) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment