Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / website_settings / mock_permission_bubble_view.cc
blob7406d132f003be670480a6922a9369a5cf568594
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/website_settings/mock_permission_bubble_view.h"
7 #include "base/bind.h"
8 #include "base/run_loop.h"
9 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
11 MockPermissionBubbleView::~MockPermissionBubbleView() {}
13 // Static
14 scoped_ptr<PermissionBubbleView> MockPermissionBubbleView::CreateBrowserMock(
15 Browser* browser) {
16 return make_scoped_ptr(new MockPermissionBubbleView(true));
19 // Static
20 scoped_ptr<PermissionBubbleView> MockPermissionBubbleView::CreateUnitMock(
21 Browser* browser) {
22 return make_scoped_ptr(new MockPermissionBubbleView(false));
25 // Static
26 MockPermissionBubbleView* MockPermissionBubbleView::GetFrom(
27 PermissionBubbleManager* manager) {
28 return static_cast<MockPermissionBubbleView*>(manager->view_.get());
31 // Static
32 void MockPermissionBubbleView::SetFactory(PermissionBubbleManager* manager,
33 bool is_browser_test) {
34 if (is_browser_test) {
35 manager->view_factory_ =
36 base::Bind(&MockPermissionBubbleView::CreateBrowserMock);
37 } else {
38 manager->view_factory_ =
39 base::Bind(&MockPermissionBubbleView::CreateUnitMock);
41 manager->HideBubble();
44 void MockPermissionBubbleView::SetDelegate(Delegate* delegate) {
45 delegate_ = delegate;
48 void MockPermissionBubbleView::Show(
49 const std::vector<PermissionBubbleRequest*>& requests,
50 const std::vector<bool>& accept_state) {
51 visible_ = true;
52 ++show_count_;
53 requests_count_ += requests.size();
54 permission_requests_ = requests;
55 permission_states_ = accept_state;
56 if (browser_test_)
57 base::MessageLoopForUI::current()->Quit();
60 void MockPermissionBubbleView::Hide() {
61 visible_ = false;
64 bool MockPermissionBubbleView::IsVisible() {
65 return visible_;
68 void MockPermissionBubbleView::UpdateAnchorPosition() {
71 gfx::NativeWindow MockPermissionBubbleView::GetNativeWindow() {
72 return nullptr;
75 bool MockPermissionBubbleView::CanAcceptRequestUpdate() {
76 return can_accept_updates_;
79 void MockPermissionBubbleView::Accept() {
80 delegate_->Accept();
83 void MockPermissionBubbleView::Deny() {
84 delegate_->Deny();
87 void MockPermissionBubbleView::Close() {
88 delegate_->Closing();
91 void MockPermissionBubbleView::Clear() {
92 visible_ = false;
93 can_accept_updates_ = true;
94 delegate_ = nullptr;
95 permission_requests_.clear();
96 permission_states_.clear();
99 void MockPermissionBubbleView::SetBrowserTest(bool browser_test) {
100 browser_test_ = browser_test;
103 MockPermissionBubbleView::MockPermissionBubbleView(bool browser_test)
104 : visible_(false),
105 show_count_(0),
106 requests_count_(0),
107 can_accept_updates_(true),
108 delegate_(nullptr),
109 browser_test_(browser_test) {}