| 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/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/controls/scroll_view.h" |
| 18 #include "ui/views/resources/grit/views_resources.h" |
| 19 #include "url/gurl.h" |
| 20 |
| 21 using NameAndIcon = arc::ArcNavigationThrottle::NameAndIcon; |
| 22 using content::WebContents; |
| 23 using content::OpenURLParams; |
| 24 using content::Referrer; |
| 25 |
| 26 class IntentPickerBubbleViewTest : public BrowserWithTestWindowTest { |
| 27 public: |
| 28 IntentPickerBubbleViewTest() : weak_ptr_factory_(this) {} |
| 29 |
| 30 void TearDown() override { |
| 31 // Make sure the bubble is destroyed before the profile to avoid a crash. |
| 32 bubble_.reset(); |
| 33 |
| 34 BrowserWithTestWindowTest::TearDown(); |
| 35 } |
| 36 |
| 37 protected: |
| 38 void CreateBubbleView(bool use_icons) { |
| 39 // Pushing a couple of fake apps just to check they are created on the UI. |
| 40 app_info_.emplace_back("dank app 1", gfx::Image()); |
| 41 app_info_.emplace_back("dank app 2", gfx::Image()); |
| 42 |
| 43 if (use_icons) |
| 44 FillAppListWithDummyIcons(); |
| 45 |
| 46 // We create |web_contents| since the Bubble UI has an Observer that |
| 47 // depends on this, otherwise it wouldn't work. |
| 48 GURL url("http://www.google.com"); |
| 49 WebContents* web_contents = browser()->OpenURL(OpenURLParams( |
| 50 url, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); |
| 51 |
| 52 auto dummy_arc_navigation_throttle_cb = |
| 53 base::Bind(&IntentPickerBubbleViewTest::OnBubbleClosed, |
| 54 weak_ptr_factory_.GetWeakPtr()); |
| 55 bubble_ = IntentPickerBubbleView::CreateBubbleForTesting( |
| 56 app_info_, dummy_arc_navigation_throttle_cb, 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 |
| 67 // Dummy method to be called upon bubble closing. |
| 68 void OnBubbleClosed(size_t selected_app_tag, |
| 69 arc::ArcNavigationThrottle::CloseReason close_reason) {} |
| 70 |
| 71 std::unique_ptr<IntentPickerBubbleView> bubble_; |
| 72 std::vector<NameAndIcon> app_info_; |
| 73 |
| 74 private: |
| 75 base::WeakPtrFactory<IntentPickerBubbleViewTest> weak_ptr_factory_; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(IntentPickerBubbleViewTest); |
| 78 }; |
| 79 |
| 80 // Verifies that we didn't set up an image for any LabelButton. |
| 81 TEST_F(IntentPickerBubbleViewTest, NullIcons) { |
| 82 CreateBubbleView(false); |
| 83 size_t size = bubble_->GetAppInfoSizeForTesting(); |
| 84 for (size_t i = 0; i < size; ++i) { |
| 85 views::LabelButton* app = bubble_->GetLabelButtonAtForTesting(i); |
| 86 EXPECT_TRUE(app != nullptr); |
| 87 EXPECT_TRUE( |
| 88 app->GetImage(views::Button::ButtonState::STATE_NORMAL).isNull()); |
| 89 } |
| 90 } |
| 91 |
| 92 // Verifies that all the icons contain a non-null icon. |
| 93 TEST_F(IntentPickerBubbleViewTest, NonNullIcons) { |
| 94 CreateBubbleView(true); |
| 95 size_t size = bubble_->GetAppInfoSizeForTesting(); |
| 96 for (size_t i = 0; i < size; ++i) { |
| 97 views::LabelButton* app = bubble_->GetLabelButtonAtForTesting(i); |
| 98 EXPECT_TRUE(app != nullptr); |
| 99 EXPECT_FALSE( |
| 100 app->GetImage(views::Button::ButtonState::STATE_NORMAL).isNull()); |
| 101 } |
| 102 } |
| 103 |
| 104 // Verifies that the bubble contains as many rows as the input. Populated the |
| 105 // bubble with an arbitrary image in every row. |
| 106 TEST_F(IntentPickerBubbleViewTest, LabelsPtrVectorSize) { |
| 107 CreateBubbleView(true); |
| 108 EXPECT_EQ(app_info_.size(), bubble_->GetAppInfoSizeForTesting()); |
| 109 } |
| OLD | NEW |