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

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

Issue 2229943003: Reusing Ok/Cancel buttons for intent picker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: For testing we don't create a widget to contain the class, so DialogButtons are not in place, this … Created 4 years, 3 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
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "chrome/browser/chromeos/arc/arc_navigation_throttle.h" 11 #include "chrome/browser/chromeos/arc/arc_navigation_throttle.h"
12 #include "chrome/test/base/browser_with_test_window_test.h" 12 #include "chrome/test/base/browser_with_test_window_test.h"
13 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
14 #include "ui/base/resource/resource_bundle.h" 14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/gfx/image/image.h" 15 #include "ui/gfx/image/image.h"
16 #include "ui/views/controls/button/button.h" 16 #include "ui/views/controls/button/button.h"
17 #include "ui/views/controls/button/label_button.h"
18 #include "ui/views/controls/scroll_view.h" 17 #include "ui/views/controls/scroll_view.h"
19 #include "ui/views/resources/grit/views_resources.h" 18 #include "ui/views/resources/grit/views_resources.h"
20 #include "url/gurl.h" 19 #include "url/gurl.h"
21 20
22 using NameAndIcon = arc::ArcNavigationThrottle::NameAndIcon; 21 using NameAndIcon = arc::ArcNavigationThrottle::NameAndIcon;
23 using content::WebContents; 22 using content::WebContents;
24 using content::OpenURLParams; 23 using content::OpenURLParams;
25 using content::Referrer; 24 using content::Referrer;
26 25
26 class MousePressedEvent : public ui::Event {
27 public:
28 MousePressedEvent() : Event(ui::ET_MOUSE_PRESSED, base::TimeTicks(), 0) {}
29 ~MousePressedEvent() override {}
30 };
31
27 class IntentPickerBubbleViewTest : public BrowserWithTestWindowTest { 32 class IntentPickerBubbleViewTest : public BrowserWithTestWindowTest {
28 public: 33 public:
29 IntentPickerBubbleViewTest() = default; 34 IntentPickerBubbleViewTest() = default;
30 35
31 void TearDown() override { 36 void TearDown() override {
32 // Make sure the bubble is destroyed before the profile to avoid a crash. 37 // Make sure the bubble is destroyed before the profile to avoid a crash.
33 bubble_.reset(); 38 bubble_.reset();
34 39
35 BrowserWithTestWindowTest::TearDown(); 40 BrowserWithTestWindowTest::TearDown();
36 } 41 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 78
74 private: 79 private:
75 DISALLOW_COPY_AND_ASSIGN(IntentPickerBubbleViewTest); 80 DISALLOW_COPY_AND_ASSIGN(IntentPickerBubbleViewTest);
76 }; 81 };
77 82
78 // Verifies that we didn't set up an image for any LabelButton. 83 // Verifies that we didn't set up an image for any LabelButton.
79 TEST_F(IntentPickerBubbleViewTest, NullIcons) { 84 TEST_F(IntentPickerBubbleViewTest, NullIcons) {
80 CreateBubbleView(false); 85 CreateBubbleView(false);
81 size_t size = bubble_->app_info_.size(); 86 size_t size = bubble_->app_info_.size();
82 for (size_t i = 0; i < size; ++i) { 87 for (size_t i = 0; i < size; ++i) {
83 views::LabelButton* app = bubble_->GetLabelButtonAt(i); 88 gfx::ImageSkia image = bubble_->GetAppImageForTesting(i);
84 EXPECT_TRUE( 89 EXPECT_TRUE(image.isNull()) << i;
85 app->GetImage(views::Button::ButtonState::STATE_NORMAL).isNull()) << i;
86 } 90 }
87 } 91 }
88 92
89 // Verifies that all the icons contain a non-null icon. 93 // Verifies that all the icons contain a non-null icon.
90 TEST_F(IntentPickerBubbleViewTest, NonNullIcons) { 94 TEST_F(IntentPickerBubbleViewTest, NonNullIcons) {
91 CreateBubbleView(true); 95 CreateBubbleView(true);
92 size_t size = bubble_->app_info_.size(); 96 size_t size = bubble_->app_info_.size();
93 for (size_t i = 0; i < size; ++i) { 97 for (size_t i = 0; i < size; ++i) {
94 views::LabelButton* app = bubble_->GetLabelButtonAt(i); 98 gfx::ImageSkia image = bubble_->GetAppImageForTesting(i);
95 EXPECT_FALSE( 99 EXPECT_FALSE(image.isNull()) << i;
96 app->GetImage(views::Button::ButtonState::STATE_NORMAL).isNull()) << i;
97 } 100 }
98 } 101 }
99 102
100 // Verifies that the bubble contains as many rows as the input. Populated the 103 // Verifies that the bubble contains as many rows as the input. Populated the
101 // bubble with an arbitrary image in every row. 104 // bubble with an arbitrary image in every row.
102 TEST_F(IntentPickerBubbleViewTest, LabelsPtrVectorSize) { 105 TEST_F(IntentPickerBubbleViewTest, LabelsPtrVectorSize) {
103 CreateBubbleView(true); 106 CreateBubbleView(true);
104 EXPECT_EQ(app_info_.size(), bubble_->app_info_.size()); 107 EXPECT_EQ(app_info_.size(), bubble_->app_info_.size());
105 } 108 }
109
110 // Verifies the InkDrop state when creating a new bubble.
111 TEST_F(IntentPickerBubbleViewTest, VerifyStartingInkDrop) {
112 CreateBubbleView(true);
113 size_t size = bubble_->app_info_.size();
114 for (size_t i = 0; i < size; ++i) {
115 EXPECT_EQ(bubble_->GetInkDropStateForTesting(i),
116 views::InkDropState::HIDDEN);
117 }
118 }
119
120 // Press each button at a time and make sure it goes to ACTIVATED state,
121 // followed by HIDDEN state after selecting other button.
122 TEST_F(IntentPickerBubbleViewTest, InkDropStateTransition) {
123 CreateBubbleView(true);
124 size_t size = bubble_->app_info_.size();
125 for (size_t i = 0; i < size; ++i) {
126 bubble_->PressButtonForTesting((i + 1) % size, MousePressedEvent());
127 EXPECT_EQ(bubble_->GetInkDropStateForTesting(i),
128 views::InkDropState::HIDDEN);
129 EXPECT_EQ(bubble_->GetInkDropStateForTesting((i + 1) % size),
130 views::InkDropState::ACTIVATED);
131 }
132 }
bruthig 2016/09/08 15:13:12 nit: It might be worth a test that clicks the same
djacobo_ 2016/09/08 21:27:06 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698