Elim cr-checkbox
[chromium-blink-merge.git] / chrome / browser / ui / website_settings / mock_permission_bubble_view.h
blob47008449cc44f462ec143ff6ac1c93fa4bf5f07b
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 #ifndef CHROME_BROWSER_UI_WEBSITE_SETTINGS_MOCK_PERMISSION_BUBBLE_VIEW_H_
6 #define CHROME_BROWSER_UI_WEBSITE_SETTINGS_MOCK_PERMISSION_BUBBLE_VIEW_H_
8 #include "chrome/browser/ui/website_settings/permission_bubble_request.h"
9 #include "chrome/browser/ui/website_settings/permission_bubble_view.h"
11 class PermissionBubbleManager;
13 // Provides a skeleton class for unit testing, when trying to test the bubble
14 // manager logic. Should not be used for anything that requires actual UI.
15 // See example usage in
16 // chrome/browser/geolocation/geolocation_permission_context_unittest.cc.
17 class MockPermissionBubbleView : public PermissionBubbleView {
18 public:
19 ~MockPermissionBubbleView() override;
21 // Create a MPBV that has |browser_test_| set to true.
22 static scoped_ptr<PermissionBubbleView> CreateBrowserMock(Browser* browser);
23 // Create a MPBV that has |browser_test_| set to false.
24 static scoped_ptr<PermissionBubbleView> CreateUnitMock(Browser* browser);
26 static MockPermissionBubbleView* GetFrom(PermissionBubbleManager* manager);
27 static void SetFactory(PermissionBubbleManager* manager,
28 bool is_browser_test);
30 // PermissionBubbleView:
31 void SetDelegate(Delegate* delegate) override;
32 void Show(const std::vector<PermissionBubbleRequest*>& requests,
33 const std::vector<bool>& accept_state) override;
34 bool CanAcceptRequestUpdate() override;
35 void Hide() override;
36 bool IsVisible() override;
37 void UpdateAnchorPosition() override;
38 gfx::NativeWindow GetNativeWindow() override;
40 // Wrappers that update the state of the bubble.
41 void Accept();
42 void Deny();
43 void Close();
44 void Clear();
46 // If we're in a browser test, we need to interact with the message loop.
47 // But that shouldn't be done in unit tests.
48 void SetBrowserTest(bool browser_test);
50 // Number of times |Show| was called.
51 int show_count() const { return show_count_; }
52 // Number of requests seen by |Show|.
53 int requests_count() const { return requests_count_; }
55 private:
56 explicit MockPermissionBubbleView(bool browser_test);
57 bool visible_;
58 int show_count_;
59 int requests_count_;
60 bool can_accept_updates_;
61 Delegate* delegate_;
62 bool browser_test_;
63 std::vector<PermissionBubbleRequest*> permission_requests_;
64 std::vector<bool> permission_states_;
67 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_MOCK_PERMISSION_BUBBLE_VIEW_H_