1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/message_loop.h"
#include "chrome/browser/chromeos/setting_level_bubble.h"
#include "chrome/browser/chromeos/setting_level_bubble_view.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "views/controls/progress_bar.h"
#include "views/view.h"
class SettingLevelBubbleTest : public InProcessBrowserTest {
public:
SettingLevelBubbleTest() {
up_icon_.setConfig(SkBitmap::kARGB_8888_Config, 10, 10);
down_icon_.setConfig(SkBitmap::kARGB_8888_Config, 5, 5);
mute_icon_.setConfig(SkBitmap::kARGB_8888_Config, 1, 1);
}
virtual ~SettingLevelBubbleTest() {}
protected:
SkBitmap up_icon_;
SkBitmap down_icon_;
SkBitmap mute_icon_;
private:
DISALLOW_COPY_AND_ASSIGN(SettingLevelBubbleTest);
};
namespace chromeos {
IN_PROC_BROWSER_TEST_F(SettingLevelBubbleTest, CreateAndUpdate) {
SettingLevelBubble bubble(&up_icon_,
&down_icon_,
&mute_icon_);
EXPECT_EQ(NULL, bubble.view_);
EXPECT_EQ(&up_icon_, bubble.increase_icon_);
EXPECT_EQ(&down_icon_, bubble.decrease_icon_);
EXPECT_EQ(&mute_icon_, bubble.disabled_icon_);
// Update setting:
// Old target is 50, new target is 70, set enable = false.
bubble.ShowBubble(70, false);
EXPECT_TRUE(bubble.view_->GetWidget()->IsVisible());
EXPECT_EQ(&mute_icon_, bubble.view_->icon_);
EXPECT_FALSE(bubble.view_->progress_bar_->IsEnabled());
// Old target is 70, new target is 30, set enable = true.
bubble.ShowBubble(30, true);
EXPECT_EQ(&down_icon_, bubble.view_->icon_);
EXPECT_TRUE(bubble.view_->progress_bar_->IsEnabled());
// Old target is 30, new target is 40, set enable = true.
bubble.ShowBubble(30, true);
EXPECT_EQ(&up_icon_, bubble.view_->icon_);
EXPECT_TRUE(bubble.view_->progress_bar_->IsEnabled());
// Old target is 30, new target is 0, set enable = true.
bubble.ShowBubble(0, true);
EXPECT_EQ(&mute_icon_, bubble.view_->icon_);
EXPECT_TRUE(bubble.view_->progress_bar_->IsEnabled());
bubble.HideBubble();
MessageLoop::current()->RunAllPending();
}
IN_PROC_BROWSER_TEST_F(SettingLevelBubbleTest, ShowBubble) {
// Create setting at 30 percent, enabled.
SettingLevelBubble bubble(&up_icon_,
&down_icon_,
&mute_icon_);
bubble.UpdateWithoutShowingBubble(30, false);
EXPECT_EQ(NULL, bubble.view_);
EXPECT_EQ(30, bubble.current_percent_);
// Show bubble at 40 percent, enabled.
bubble.ShowBubble(40, true);
EXPECT_TRUE(bubble.view_ != NULL);
EXPECT_TRUE(bubble.view_->GetWidget()->IsVisible());
// Update to 0 percent and close.
bubble.UpdateWithoutShowingBubble(0, true);
bubble.OnWidgetClosing(bubble.view_->GetWidget());
EXPECT_EQ(0, bubble.current_percent_);
}
} // namespace chromeos
|