| Index: chrome/browser/ui/views/content_setting_bubble_contents_unittest.cc
|
| diff --git a/chrome/browser/ui/views/content_setting_bubble_contents_unittest.cc b/chrome/browser/ui/views/content_setting_bubble_contents_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..913bc43b098e90bd3a102d203853f7e005ac98e2
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/views/content_setting_bubble_contents_unittest.cc
|
| @@ -0,0 +1,136 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/ui/views/content_setting_bubble_contents.h"
|
| +
|
| +#include <memory>
|
| +
|
| +#include "base/macros.h"
|
| +#include "base/memory/ptr_util.h"
|
| +#include "base/strings/string_piece.h"
|
| +#include "base/strings/utf_string_conversions.h"
|
| +#include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
|
| +#include "chrome/browser/ui/content_settings/content_setting_bubble_model_delegate.h"
|
| +#include "chrome/browser/ui/views/harmony/chrome_layout_provider.h"
|
| +#include "chrome/test/base/testing_profile.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "ui/events/test/event_generator.h"
|
| +#include "ui/gfx/native_widget_types.h"
|
| +#include "ui/views/bubble/bubble_dialog_delegate.h"
|
| +#include "ui/views/test/test_views_delegate.h"
|
| +#include "ui/views/test/views_test_base.h"
|
| +#include "ui/views/view.h"
|
| +#include "ui/views/widget/widget.h"
|
| +#include "ui/views/window/dialog_client_view.h"
|
| +
|
| +// Bubble model with a checkbox to manage behavior. When the checkbox is toggled
|
| +// the done button's text is changed.
|
| +class TestContentSettingBubbleModel : public ContentSettingBubbleModel {
|
| + public:
|
| + TestContentSettingBubbleModel(ContentSettingBubbleModel::Delegate* delegate,
|
| + base::string16 done_button_text)
|
| + : ContentSettingBubbleModel(delegate, nullptr, nullptr),
|
| + done_button_text_(done_button_text) {
|
| + SetTitle();
|
| + SetManageText();
|
| + }
|
| +
|
| + ~TestContentSettingBubbleModel() override {}
|
| +
|
| + void SetTitle() override { set_title(base::UTF8ToUTF16("Title")); }
|
| + void SetManageText() override {
|
| + set_manage_text(base::UTF8ToUTF16("test"));
|
| + set_show_manage_text_as_checkbox(true);
|
| + }
|
| +
|
| + void OnManageCheckboxChecked(bool is_checked) override {
|
| + set_done_button_text(done_button_text_);
|
| + }
|
| +
|
| + private:
|
| + base::string16 done_button_text_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(TestContentSettingBubbleModel);
|
| +};
|
| +
|
| +class TestContentSettingBubbleModelDelegate
|
| + : public ContentSettingBubbleModelDelegate {
|
| + public:
|
| + TestContentSettingBubbleModelDelegate() {}
|
| +
|
| + private:
|
| + // ContentSettingBubbleModelDelegate:
|
| + void ShowCollectedCookiesDialog(content::WebContents* web_contents) override {
|
| + }
|
| + void ShowContentSettingsPage(ContentSettingsType type) override {}
|
| + void ShowMediaSettingsPage() override {}
|
| + void ShowLearnMorePage(ContentSettingsType type) override {}
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(TestContentSettingBubbleModelDelegate);
|
| +};
|
| +
|
| +class ContentSettingBubbleContentsTest : public views::ViewsTestBase {
|
| + public:
|
| + ContentSettingBubbleContentsTest() {}
|
| + ~ContentSettingBubbleContentsTest() override {}
|
| +
|
| + void SetUp() override {
|
| + views::ViewsTestBase::SetUp();
|
| + test_views_delegate()->set_layout_provider(
|
| + ChromeLayoutProvider::CreateLayoutProvider());
|
| + }
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(ContentSettingBubbleContentsTest);
|
| +};
|
| +
|
| +// Tests that clicking the checkbox successfully changes the text within the
|
| +// done button, and that the size is properly updated.
|
| +TEST_F(ContentSettingBubbleContentsTest, CheckboxClicked_ResizesDoneButton) {
|
| + // Set up the root widget, needed to show the bubble.
|
| + views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
|
| + nullptr, GetContext(), gfx::Rect(350, 0, 100, 100));
|
| + widget->Show();
|
| +
|
| + base::string16 done_button_text = base::UTF8ToUTF16("01234567890123456789");
|
| +
|
| + auto bubble_model_delegate =
|
| + base::MakeUnique<TestContentSettingBubbleModelDelegate>();
|
| + TestContentSettingBubbleModel* bubble_model =
|
| + new TestContentSettingBubbleModel(bubble_model_delegate.get(),
|
| + done_button_text);
|
| + ContentSettingBubbleContents* bubble_view = new ContentSettingBubbleContents(
|
| + bubble_model, nullptr, widget->GetContentsView(),
|
| + views::BubbleBorder::TOP_RIGHT);
|
| + views::BubbleDialogDelegateView::CreateBubble(bubble_view)->Show();
|
| +
|
| + views::LabelButton* button = bubble_view->GetDialogClientView()->ok_button();
|
| + EXPECT_NE(done_button_text, button->GetText());
|
| + int before_width = button->width();
|
| +
|
| + // Check the checkbox. This entails finding it in the view hierarchy via some
|
| + // iteration.
|
| + auto children = bubble_view->GetChildrenInZOrder();
|
| + for (auto* child : children) {
|
| + if (base::StringPiece(child->GetClassName()) == "Checkbox") {
|
| + views::Checkbox* checkbox = static_cast<views::Checkbox*>(child);
|
| + EXPECT_FALSE(checkbox->checked());
|
| +
|
| + ui::test::EventGenerator event_generator(
|
| + bubble_view->GetWidget()->GetNativeWindow());
|
| + event_generator.MoveMouseToInHost(
|
| + checkbox->GetBoundsInScreen().CenterPoint());
|
| + event_generator.ClickLeftButton();
|
| +
|
| + EXPECT_TRUE(checkbox->checked());
|
| + break;
|
| + }
|
| + }
|
| +
|
| + // The done button's text and size should change.
|
| + EXPECT_EQ(done_button_text, button->GetText());
|
| + EXPECT_GT(button->width(), before_width);
|
| +
|
| + widget->Close();
|
| +}
|
|
|