| OLD | NEW |
| (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/bind_helpers.h" |
| 9 #include "base/callback.h" |
| 10 #include "base/macros.h" |
| 11 #include "chrome/browser/chromeos/arc/arc_navigation_throttle.h" |
| 12 #include "chrome/test/base/browser_with_test_window_test.h" |
| 13 #include "content/public/browser/web_contents.h" |
| 14 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/gfx/image/image.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" |
| 19 #include "ui/views/resources/grit/views_resources.h" |
| 20 #include "url/gurl.h" |
| 21 |
| 22 using NameAndIcon = arc::ArcNavigationThrottle::NameAndIcon; |
| 23 using content::WebContents; |
| 24 using content::OpenURLParams; |
| 25 using content::Referrer; |
| 26 |
| 27 class IntentPickerBubbleViewTest : public BrowserWithTestWindowTest { |
| 28 public: |
| 29 IntentPickerBubbleViewTest() = default; |
| 30 |
| 31 void TearDown() override { |
| 32 // Make sure the bubble is destroyed before the profile to avoid a crash. |
| 33 bubble_.reset(); |
| 34 |
| 35 BrowserWithTestWindowTest::TearDown(); |
| 36 } |
| 37 |
| 38 protected: |
| 39 void CreateBubbleView(bool use_icons) { |
| 40 // 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()); |
| 42 app_info_.emplace_back("dank app 2", gfx::Image()); |
| 43 |
| 44 if (use_icons) |
| 45 FillAppListWithDummyIcons(); |
| 46 |
| 47 // We create |web_contents| since the Bubble UI has an Observer that |
| 48 // depends on this, otherwise it wouldn't work. |
| 49 GURL url("http://www.google.com"); |
| 50 WebContents* web_contents = browser()->OpenURL(OpenURLParams( |
| 51 url, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); |
| 52 |
| 53 bubble_ = IntentPickerBubbleView::CreateBubbleView( |
| 54 app_info_, base::Bind(&IntentPickerBubbleViewTest::OnBubbleClosed, |
| 55 base::Unretained(this)), |
| 56 web_contents); |
| 57 } |
| 58 |
| 59 void FillAppListWithDummyIcons() { |
| 60 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 61 gfx::Image dummy_icon = rb.GetImageNamed(IDR_CLOSE); |
| 62 for (auto& app : app_info_) |
| 63 app.second = dummy_icon; |
| 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) {} |
| 69 |
| 70 std::unique_ptr<IntentPickerBubbleView> bubble_; |
| 71 std::vector<NameAndIcon> app_info_; |
| 72 |
| 73 private: |
| 74 DISALLOW_COPY_AND_ASSIGN(IntentPickerBubbleViewTest); |
| 75 }; |
| 76 |
| 77 // Verifies that we didn't set up an image for any LabelButton. |
| 78 TEST_F(IntentPickerBubbleViewTest, NullIcons) { |
| 79 CreateBubbleView(false); |
| 80 size_t size = bubble_->app_info_.size(); |
| 81 for (size_t i = 0; i < size; ++i) { |
| 82 views::LabelButton* app = bubble_->GetLabelButtonAt(i); |
| 83 EXPECT_TRUE( |
| 84 app->GetImage(views::Button::ButtonState::STATE_NORMAL).isNull()) << i; |
| 85 } |
| 86 } |
| 87 |
| 88 // Verifies that all the icons contain a non-null icon. |
| 89 TEST_F(IntentPickerBubbleViewTest, NonNullIcons) { |
| 90 CreateBubbleView(true); |
| 91 size_t size = bubble_->app_info_.size(); |
| 92 for (size_t i = 0; i < size; ++i) { |
| 93 views::LabelButton* app = bubble_->GetLabelButtonAt(i); |
| 94 EXPECT_FALSE( |
| 95 app->GetImage(views::Button::ButtonState::STATE_NORMAL).isNull()) << i; |
| 96 } |
| 97 } |
| 98 |
| 99 // Verifies that the bubble contains as many rows as the input. Populated the |
| 100 // bubble with an arbitrary image in every row. |
| 101 TEST_F(IntentPickerBubbleViewTest, LabelsPtrVectorSize) { |
| 102 CreateBubbleView(true); |
| 103 EXPECT_EQ(app_info_.size(), bubble_->app_info_.size()); |
| 104 } |
| OLD | NEW |