Chromium Code Reviews| 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/callback.h" | |
| 8 #include "base/macros.h" | |
| 9 #include "build/build_config.h" | |
|
Yusuke Sato
2016/07/19 10:23:58
nit: what is this for?
djacobo_
2016/07/20 21:18:31
My bad, forgot to delete it from previous versions
| |
| 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/navigation_handle.h" | |
|
Yusuke Sato
2016/07/19 10:23:58
Is this necessary?
djacobo_
2016/07/20 21:18:31
A previous version was using it, removed. Done
| |
| 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/resources/grit/views_resources.h" | |
|
Yusuke Sato
2016/07/19 10:23:58
same
djacobo_
2016/07/20 21:18:31
My understanding is that this is for the IDR_CLOSE
| |
| 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() {} | |
|
Yusuke Sato
2016/07/19 10:23:58
= default;
djacobo_
2016/07/20 21:18:31
I will need a different constructor since I am usi
| |
| 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_custom_icons) { | |
|
Yusuke Sato
2016/07/19 10:23:58
use_icons might be better? I wasn't sure what 'cus
djacobo_
2016/07/20 21:18:31
Done.
| |
| 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_custom_icons) | |
| 44 FillAppListWithDummyIcons(); | |
| 45 | |
| 46 GURL url("http://www.google.com"); | |
| 47 WebContents* web_contents = browser()->OpenURL(OpenURLParams( | |
|
Yusuke Sato
2016/07/19 10:23:58
Why is it necessary to open a page here? Can you a
djacobo_
2016/07/20 21:18:31
The bubble class need it since the bubble's lifeti
| |
| 48 url, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); | |
| 49 | |
| 50 // This callback should never be used, his only purpose is to serve as a | |
| 51 // dummy callback so the changes are minimal for IntentPickerBubbleView. | |
| 52 base::Callback<void(size_t, arc::ArcNavigationThrottle::CloseReason)> | |
| 53 dummy_arc_navigation_throttle_cb; | |
| 54 bubble_.reset(new IntentPickerBubbleView( | |
| 55 app_info_, dummy_arc_navigation_throttle_cb, web_contents, true)); | |
|
Yusuke Sato
2016/07/19 10:23:58
true /* was_callback_run */
djacobo_
2016/07/20 21:18:31
Done.
| |
| 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 std::unique_ptr<IntentPickerBubbleView> bubble_; | |
| 67 std::vector<NameAndIcon> app_info_; | |
| 68 | |
| 69 private: | |
| 70 DISALLOW_COPY_AND_ASSIGN(IntentPickerBubbleViewTest); | |
| 71 }; | |
| 72 | |
| 73 // Verifies that we didn't set up an image for any LabelButton. | |
| 74 TEST_F(IntentPickerBubbleViewTest, NullIcons) { | |
| 75 CreateBubbleView(false); | |
| 76 bubble_->Init(); | |
| 77 for (auto app : bubble_->app_label_ptr_) { | |
|
Yusuke Sato
2016/07/19 10:23:58
s/app/label/ probably?
djacobo_
2016/07/20 21:18:31
Changing this part, now we retrieve View* with Get
| |
| 78 EXPECT_TRUE( | |
| 79 app->GetImage(views::Button::ButtonState::STATE_NORMAL).isNull()); | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 // Verifies that all the icons contain a non-null icon. | |
| 84 TEST_F(IntentPickerBubbleViewTest, NonNullIcons) { | |
| 85 CreateBubbleView(true); | |
| 86 bubble_->Init(); | |
| 87 for (auto app : bubble_->app_label_ptr_) { | |
|
Yusuke Sato
2016/07/19 10:23:58
same
djacobo_
2016/07/20 21:18:31
Done.
| |
| 88 EXPECT_FALSE( | |
| 89 app->GetImage(views::Button::ButtonState::STATE_NORMAL).isNull()); | |
| 90 } | |
| 91 } | |
| 92 | |
| 93 // Verifies that the bubble contains as many rows as the input. Populated the | |
| 94 // bubble with an arbitrary image in every row. | |
| 95 TEST_F(IntentPickerBubbleViewTest, LabelsPtrVectorSize) { | |
| 96 CreateBubbleView(true); | |
| 97 bubble_->Init(); | |
| 98 EXPECT_TRUE(app_info_.size() == bubble_->app_label_ptr_.size()); | |
|
Yusuke Sato
2016/07/19 10:23:58
EXPECT_EQ(app_info_.size(), bubble_->app_label_ptr
djacobo_
2016/07/20 21:18:31
Done.
| |
| 99 } | |
| OLD | NEW |