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

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

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