Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / toolbar / test_toolbar_actions_bar_bubble_delegate.cc
blob79465e582a79085b1808b86d430cf85c3051e221
1 // Copyright 2015 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.
5 #include "chrome/browser/ui/toolbar/test_toolbar_actions_bar_bubble_delegate.h"
7 #include "base/logging.h"
9 class TestToolbarActionsBarBubbleDelegate::DelegateImpl
10 : public ToolbarActionsBarBubbleDelegate {
11 public:
12 explicit DelegateImpl(TestToolbarActionsBarBubbleDelegate* parent)
13 : parent_(parent) {}
14 ~DelegateImpl() override {}
16 private:
17 base::string16 GetHeadingText() override { return parent_->heading_; }
18 base::string16 GetBodyText() override { return parent_->body_; }
19 base::string16 GetItemListText() override { return parent_->item_list_; }
20 base::string16 GetActionButtonText() override { return parent_->action_; }
21 base::string16 GetDismissButtonText() override { return parent_->dismiss_; }
22 base::string16 GetLearnMoreButtonText() override {
23 return parent_->learn_more_;
25 void OnBubbleShown() override {
26 CHECK(!parent_->shown_);
27 parent_->shown_ = true;
29 void OnBubbleClosed(CloseAction action) override {
30 CHECK(!parent_->close_action_);
31 parent_->close_action_.reset(new CloseAction(action));
34 TestToolbarActionsBarBubbleDelegate* parent_;
36 DISALLOW_COPY_AND_ASSIGN(DelegateImpl);
39 TestToolbarActionsBarBubbleDelegate::TestToolbarActionsBarBubbleDelegate(
40 const base::string16& heading,
41 const base::string16& body,
42 const base::string16& action)
43 : shown_(false),
44 heading_(heading),
45 body_(body),
46 action_(action) {
49 TestToolbarActionsBarBubbleDelegate::~TestToolbarActionsBarBubbleDelegate() {
50 // If the bubble didn't close, it means that it still owns the DelegateImpl,
51 // which has a weak ptr to this object. Make sure that this class always
52 // outlives the bubble.
53 CHECK(close_action_);
56 scoped_ptr<ToolbarActionsBarBubbleDelegate>
57 TestToolbarActionsBarBubbleDelegate::GetDelegate() {
58 return scoped_ptr<ToolbarActionsBarBubbleDelegate>(new DelegateImpl(this));