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

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

Issue 2134293002: Adding a ScrollView for IntentPickerBubbleView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moving from friend to ForTesting() methods Created 4 years, 5 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/intent_picker_bubble_view.h"
6
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "base/macros.h"
10 #include "chrome/browser/chromeos/arc/arc_navigation_throttle.h"
11 #include "chrome/test/base/browser_with_test_window_test.h"
12 #include "content/public/browser/web_contents.h"
13 #include "ui/base/resource/resource_bundle.h"
14 #include "ui/gfx/image/image.h"
15 #include "ui/views/controls/button/button.h"
16 #include "ui/views/controls/button/label_button.h"
17 #include "ui/views/resources/grit/views_resources.h"
18 #include "url/gurl.h"
19
20 using NameAndIcon = arc::ArcNavigationThrottle::NameAndIcon;
21 using content::WebContents;
22 using content::OpenURLParams;
23 using content::Referrer;
24
25 class IntentPickerBubbleViewTest : public BrowserWithTestWindowTest {
26 public:
27 IntentPickerBubbleViewTest() : weak_ptr_factory_(this) {}
28
29 void TearDown() override {
30 // Make sure the bubble is destroyed before the profile to avoid a crash.
31 bubble_.reset();
32
33 BrowserWithTestWindowTest::TearDown();
34 }
35
36 protected:
37 void CreateBubbleView(bool use_icons) {
38 // Pushing a couple of fake apps just to check they are created on the UI.
39 app_info_.emplace_back("dank app 1", gfx::Image());
40 app_info_.emplace_back("dank app 2", gfx::Image());
41
42 if (use_icons)
43 FillAppListWithDummyIcons();
44
45 // We create |web_contents| since the Bubble UI has an Observer that
46 // depends on this, otherwise it wouldn't work.
47 GURL url("http://www.google.com");
48 WebContents* web_contents = browser()->OpenURL(OpenURLParams(
49 url, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false));
50
51 auto dummy_arc_navigation_throttle_cb =
52 base::Bind(&IntentPickerBubbleViewTest::OnBubbleClosed,
53 weak_ptr_factory_.GetWeakPtr());
54 bubble_ = IntentPickerBubbleView::CreateBubbleForTesting(
55 app_info_, dummy_arc_navigation_throttle_cb, web_contents);
56 }
57
58 void FillAppListWithDummyIcons() {
59 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
60 gfx::Image dummy_icon = rb.GetImageNamed(IDR_CLOSE);
61 for (auto& app : app_info_) {
62 app.second = dummy_icon;
63 }
64 }
65
66 // Dummy method to be called upon bubble closing.
67 void OnBubbleClosed(size_t selected_app_tag,
68 arc::ArcNavigationThrottle::CloseReason close_reason) {}
Yusuke Sato 2016/07/20 21:58:57 optional: Is it possible to test whether or not th
djacobo_ 2016/07/21 16:04:11 I believe so, let me defer it while I give it a go
69
70 std::unique_ptr<IntentPickerBubbleView> bubble_;
71 std::vector<NameAndIcon> app_info_;
72
73 private:
74 base::WeakPtrFactory<IntentPickerBubbleViewTest> weak_ptr_factory_;
75
76 DISALLOW_COPY_AND_ASSIGN(IntentPickerBubbleViewTest);
77 };
78
79 // Verifies that we didn't set up an image for any LabelButton.
80 TEST_F(IntentPickerBubbleViewTest, NullIcons) {
81 CreateBubbleView(false);
82 size_t size = bubble_->GetNumberOfAppLabelsForTesting();
83 for (size_t i = 0; i < size; ++i) {
84 views::LabelButton* app =
85 static_cast<views::LabelButton*>(bubble_->GetViewByID(i + 1));
86 EXPECT_TRUE(
87 app->GetImage(views::Button::ButtonState::STATE_NORMAL).isNull());
88 }
89 }
90
91 // Verifies that all the icons contain a non-null icon.
92 TEST_F(IntentPickerBubbleViewTest, NonNullIcons) {
93 CreateBubbleView(true);
94 size_t size = bubble_->GetNumberOfAppLabelsForTesting();
95 for (size_t i = 0; i < size; ++i) {
96 views::LabelButton* app =
97 static_cast<views::LabelButton*>(bubble_->GetViewByID(i + 1));
98 EXPECT_FALSE(
99 app->GetImage(views::Button::ButtonState::STATE_NORMAL).isNull());
100 }
101 }
102
103 // Verifies that the bubble contains as many rows as the input. Populated the
104 // bubble with an arbitrary image in every row.
105 TEST_F(IntentPickerBubbleViewTest, LabelsPtrVectorSize) {
106 CreateBubbleView(true);
107 EXPECT_EQ(app_info_.size(), bubble_->GetNumberOfAppLabelsForTesting());
108 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698