Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 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/confirm_bubble_views.h" | |
| 6 | |
| 7 #include "base/utf_string_conversions.h" | |
| 8 #include "chrome/browser/ui/confirm_bubble.h" | |
| 9 #include "chrome/browser/ui/confirm_bubble_model.h" | |
| 10 #include "grit/theme_resources.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 #include "ui/base/resource/resource_bundle.h" | |
| 13 #include "ui/views/test/views_test_base.h" | |
| 14 #include "ui/views/widget/widget.h" | |
| 15 | |
| 16 using views::Widget; | |
| 17 | |
| 18 class TestConfirmBubbleModel : public ConfirmBubbleModel { | |
| 19 public: | |
| 20 TestConfirmBubbleModel() {} | |
| 21 virtual ~TestConfirmBubbleModel() {} | |
| 22 | |
| 23 virtual string16 GetTitle() const OVERRIDE; | |
| 24 virtual string16 GetMessageText() const OVERRIDE; | |
| 25 virtual gfx::Image* GetIcon() const OVERRIDE; | |
| 26 virtual int GetButtons() const OVERRIDE; | |
| 27 virtual string16 GetButtonLabel(BubbleButton button) const OVERRIDE; | |
| 28 virtual void Accept() OVERRIDE {} | |
| 29 virtual void Cancel() OVERRIDE {} | |
| 30 virtual string16 GetLinkText() const OVERRIDE; | |
| 31 virtual void LinkClicked() OVERRIDE {} | |
| 32 | |
| 33 private: | |
| 34 DISALLOW_COPY_AND_ASSIGN(TestConfirmBubbleModel); | |
| 35 }; | |
| 36 | |
| 37 string16 TestConfirmBubbleModel::GetTitle() const { | |
| 38 return ASCIIToUTF16("Title"); | |
| 39 } | |
| 40 | |
| 41 string16 TestConfirmBubbleModel::GetMessageText() const { | |
| 42 return ASCIIToUTF16("Message"); | |
| 43 } | |
| 44 | |
| 45 gfx::Image* TestConfirmBubbleModel::GetIcon() const { | |
| 46 return &ResourceBundle::GetSharedInstance().GetImageNamed( | |
| 47 IDR_PRODUCT_LOGO_16); | |
| 48 } | |
| 49 | |
| 50 int TestConfirmBubbleModel::GetButtons() const { | |
| 51 return BUTTON_OK | BUTTON_CANCEL; | |
| 52 } | |
| 53 | |
| 54 string16 TestConfirmBubbleModel::GetButtonLabel(BubbleButton button) const { | |
| 55 return button == BUTTON_OK ? ASCIIToUTF16("OK") : ASCIIToUTF16("Cancel"); | |
| 56 } | |
| 57 | |
| 58 string16 TestConfirmBubbleModel::GetLinkText() const { | |
| 59 return ASCIIToUTF16("Link"); | |
| 60 } | |
| 61 | |
| 62 /////////////////////////////////////////////////////////////////////////////// | |
| 63 | |
| 64 typedef views::ViewsTestBase ConfirmBubbleViewsTest; | |
| 65 | |
| 66 TEST_F(ConfirmBubbleViewsTest, CreateAndClose) { | |
|
Elliot Glaysher
2013/01/24 23:16:58
Thank you.
| |
| 67 // Create parent widget, as confirm bubble must have an owner. | |
| 68 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); | |
| 69 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 70 scoped_ptr<views::Widget> parent_widget(new Widget); | |
| 71 parent_widget->Init(params); | |
| 72 parent_widget->Show(); | |
| 73 | |
| 74 // Bubble owns the model. | |
| 75 ConfirmBubbleViews* bubble = | |
| 76 new ConfirmBubbleViews(parent_widget->GetNativeView(), | |
| 77 gfx::Point(12, 34), | |
| 78 new TestConfirmBubbleModel); | |
| 79 views::BubbleDelegateView::CreateBubble(bubble); | |
| 80 bubble->Show(); | |
| 81 | |
| 82 // We're anchored to a point, not a specific view or widget. | |
| 83 EXPECT_EQ("12,34", bubble->anchor_point().ToString()); | |
| 84 EXPECT_FALSE(bubble->anchor_view()); | |
| 85 EXPECT_FALSE(bubble->anchor_widget()); | |
| 86 | |
| 87 // Clean up. | |
| 88 bubble->GetWidget()->CloseNow(); | |
| 89 parent_widget->CloseNow(); | |
| 90 } | |
| OLD | NEW |