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

Side by Side Diff: chrome/browser/ui/views/intent_picker_bubble_view_unittest.cc

Issue 2433733002: Revert "Reusing Ok/Cancel buttons for intent picker" (Closed)
Patch Set: Created 4 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
« no previous file with comments | « chrome/browser/ui/views/intent_picker_bubble_view.cc ('k') | ui/views/controls/scroll_view.h » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/ui/views/intent_picker_bubble_view.h" 5 #include "chrome/browser/ui/views/intent_picker_bubble_view.h"
6 6
7 #include <string>
8
9 #include "base/bind.h" 7 #include "base/bind.h"
10 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
11 #include "base/callback.h" 9 #include "base/callback.h"
12 #include "base/macros.h" 10 #include "base/macros.h"
13 #include "chrome/browser/chromeos/arc/arc_navigation_throttle.h" 11 #include "chrome/browser/chromeos/arc/arc_navigation_throttle.h"
14 #include "chrome/test/base/browser_with_test_window_test.h" 12 #include "chrome/test/base/browser_with_test_window_test.h"
15 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
16 #include "ui/base/resource/resource_bundle.h" 14 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/gfx/image/image.h" 15 #include "ui/gfx/image/image.h"
18 #include "ui/views/controls/button/button.h" 16 #include "ui/views/controls/button/button.h"
17 #include "ui/views/controls/button/label_button.h"
19 #include "ui/views/controls/scroll_view.h" 18 #include "ui/views/controls/scroll_view.h"
20 #include "ui/views/resources/grit/views_resources.h" 19 #include "ui/views/resources/grit/views_resources.h"
21 #include "url/gurl.h" 20 #include "url/gurl.h"
22 21
23 using AppInfo = arc::ArcNavigationThrottle::AppInfo; 22 using NameAndIcon = arc::ArcNavigationThrottle::NameAndIcon;
24 using content::WebContents; 23 using content::WebContents;
25 using content::OpenURLParams; 24 using content::OpenURLParams;
26 using content::Referrer; 25 using content::Referrer;
27 26
28 class MousePressedEvent : public ui::Event {
29 public:
30 MousePressedEvent() : Event(ui::ET_MOUSE_PRESSED, base::TimeTicks(), 0) {}
31 ~MousePressedEvent() override {}
32 };
33
34 class IntentPickerBubbleViewTest : public BrowserWithTestWindowTest { 27 class IntentPickerBubbleViewTest : public BrowserWithTestWindowTest {
35 public: 28 public:
36 IntentPickerBubbleViewTest() = default; 29 IntentPickerBubbleViewTest() = default;
37 30
38 void TearDown() override { 31 void TearDown() override {
39 // Make sure the bubble is destroyed before the profile to avoid a crash. 32 // Make sure the bubble is destroyed before the profile to avoid a crash.
40 bubble_.reset(); 33 bubble_.reset();
41 34
42 BrowserWithTestWindowTest::TearDown(); 35 BrowserWithTestWindowTest::TearDown();
43 } 36 }
44 37
45 protected: 38 protected:
46 void CreateBubbleView(bool use_icons) { 39 void CreateBubbleView(bool use_icons) {
47 // Pushing a couple of fake apps just to check they are created on the UI. 40 // Pushing a couple of fake apps just to check they are created on the UI.
48 app_info_.emplace_back(AppInfo(gfx::Image(), "package_1", "dank app 1")); 41 app_info_.emplace_back("dank app 1", gfx::Image());
49 app_info_.emplace_back(AppInfo(gfx::Image(), "package_2", "dank_app_2")); 42 app_info_.emplace_back("dank app 2", gfx::Image());
50 43
51 if (use_icons) 44 if (use_icons)
52 FillAppListWithDummyIcons(); 45 FillAppListWithDummyIcons();
53 46
54 // We create |web_contents| since the Bubble UI has an Observer that 47 // We create |web_contents| since the Bubble UI has an Observer that
55 // depends on this, otherwise it wouldn't work. 48 // depends on this, otherwise it wouldn't work.
56 GURL url("http://www.google.com"); 49 GURL url("http://www.google.com");
57 WebContents* web_contents = browser()->OpenURL( 50 WebContents* web_contents = browser()->OpenURL(
58 OpenURLParams(url, Referrer(), WindowOpenDisposition::CURRENT_TAB, 51 OpenURLParams(url, Referrer(), WindowOpenDisposition::CURRENT_TAB,
59 ui::PAGE_TRANSITION_TYPED, false)); 52 ui::PAGE_TRANSITION_TYPED, false));
60 53
61 bubble_ = IntentPickerBubbleView::CreateBubbleView( 54 bubble_ = IntentPickerBubbleView::CreateBubbleView(
62 app_info_, base::Bind(&IntentPickerBubbleViewTest::OnBubbleClosed, 55 app_info_, base::Bind(&IntentPickerBubbleViewTest::OnBubbleClosed,
63 base::Unretained(this)), 56 base::Unretained(this)),
64 web_contents); 57 web_contents);
65 } 58 }
66 59
67 void FillAppListWithDummyIcons() { 60 void FillAppListWithDummyIcons() {
68 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 61 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
69 gfx::Image dummy_icon = rb.GetImageNamed(IDR_CLOSE); 62 gfx::Image dummy_icon = rb.GetImageNamed(IDR_CLOSE);
70 for (auto& app : app_info_) 63 for (auto& app : app_info_)
71 app.icon = dummy_icon; 64 app.second = dummy_icon;
72 } 65 }
73 66
74 // Dummy method to be called upon bubble closing. 67 // Dummy method to be called upon bubble closing.
75 void OnBubbleClosed(std::string selected_app_package, 68 void OnBubbleClosed(size_t selected_app_tag,
76 arc::ArcNavigationThrottle::CloseReason close_reason) {} 69 arc::ArcNavigationThrottle::CloseReason close_reason) {}
77 70
78 std::unique_ptr<IntentPickerBubbleView> bubble_; 71 std::unique_ptr<IntentPickerBubbleView> bubble_;
79 std::vector<AppInfo> app_info_; 72 std::vector<NameAndIcon> app_info_;
80 73
81 private: 74 private:
82 DISALLOW_COPY_AND_ASSIGN(IntentPickerBubbleViewTest); 75 DISALLOW_COPY_AND_ASSIGN(IntentPickerBubbleViewTest);
83 }; 76 };
84 77
85 // Verifies that we didn't set up an image for any LabelButton. 78 // Verifies that we didn't set up an image for any LabelButton.
86 TEST_F(IntentPickerBubbleViewTest, NullIcons) { 79 TEST_F(IntentPickerBubbleViewTest, NullIcons) {
87 CreateBubbleView(false); 80 CreateBubbleView(false);
88 size_t size = bubble_->app_info_.size(); 81 size_t size = bubble_->app_info_.size();
89 for (size_t i = 0; i < size; ++i) { 82 for (size_t i = 0; i < size; ++i) {
90 gfx::ImageSkia image = bubble_->GetAppImageForTesting(i); 83 views::LabelButton* app = bubble_->GetLabelButtonAt(i);
91 EXPECT_TRUE(image.isNull()) << i; 84 EXPECT_TRUE(
85 app->GetImage(views::Button::ButtonState::STATE_NORMAL).isNull()) << i;
92 } 86 }
93 } 87 }
94 88
95 // Verifies that all the icons contain a non-null icon. 89 // Verifies that all the icons contain a non-null icon.
96 TEST_F(IntentPickerBubbleViewTest, NonNullIcons) { 90 TEST_F(IntentPickerBubbleViewTest, NonNullIcons) {
97 CreateBubbleView(true); 91 CreateBubbleView(true);
98 size_t size = bubble_->app_info_.size(); 92 size_t size = bubble_->app_info_.size();
99 for (size_t i = 0; i < size; ++i) { 93 for (size_t i = 0; i < size; ++i) {
100 gfx::ImageSkia image = bubble_->GetAppImageForTesting(i); 94 views::LabelButton* app = bubble_->GetLabelButtonAt(i);
101 EXPECT_FALSE(image.isNull()) << i; 95 EXPECT_FALSE(
96 app->GetImage(views::Button::ButtonState::STATE_NORMAL).isNull()) << i;
102 } 97 }
103 } 98 }
104 99
105 // Verifies that the bubble contains as many rows as the input. Populated the 100 // Verifies that the bubble contains as many rows as the input. Populated the
106 // bubble with an arbitrary image in every row. 101 // bubble with an arbitrary image in every row.
107 TEST_F(IntentPickerBubbleViewTest, LabelsPtrVectorSize) { 102 TEST_F(IntentPickerBubbleViewTest, LabelsPtrVectorSize) {
108 CreateBubbleView(true); 103 CreateBubbleView(true);
109 EXPECT_EQ(app_info_.size(), bubble_->app_info_.size()); 104 EXPECT_EQ(app_info_.size(), bubble_->app_info_.size());
110 } 105 }
111
112 // Verifies the InkDrop state when creating a new bubble.
113 TEST_F(IntentPickerBubbleViewTest, VerifyStartingInkDrop) {
114 CreateBubbleView(true);
115 size_t size = bubble_->app_info_.size();
116 for (size_t i = 0; i < size; ++i) {
117 EXPECT_EQ(bubble_->GetInkDropStateForTesting(i),
118 views::InkDropState::HIDDEN);
119 }
120 }
121
122 // Press each button at a time and make sure it goes to ACTIVATED state,
123 // followed by HIDDEN state after selecting other button.
124 TEST_F(IntentPickerBubbleViewTest, InkDropStateTransition) {
125 CreateBubbleView(true);
126 size_t size = bubble_->app_info_.size();
127 for (size_t i = 0; i < size; ++i) {
128 bubble_->PressButtonForTesting((i + 1) % size, MousePressedEvent());
129 EXPECT_EQ(bubble_->GetInkDropStateForTesting(i),
130 views::InkDropState::HIDDEN);
131 EXPECT_EQ(bubble_->GetInkDropStateForTesting((i + 1) % size),
132 views::InkDropState::ACTIVATED);
133 }
134 }
135
136 // Arbitrary press the first button twice, check that the InkDropState remains
137 // the same.
138 TEST_F(IntentPickerBubbleViewTest, PressButtonTwice) {
139 CreateBubbleView(true);
140 EXPECT_EQ(bubble_->GetInkDropStateForTesting(0), views::InkDropState::HIDDEN);
141 bubble_->PressButtonForTesting(0, MousePressedEvent());
142 EXPECT_EQ(bubble_->GetInkDropStateForTesting(0),
143 views::InkDropState::ACTIVATED);
144 bubble_->PressButtonForTesting(0, MousePressedEvent());
145 EXPECT_EQ(bubble_->GetInkDropStateForTesting(0),
146 views::InkDropState::ACTIVATED);
147 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/intent_picker_bubble_view.cc ('k') | ui/views/controls/scroll_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698