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
{
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
;
36 bool IsVisible() override
;
37 void UpdateAnchorPosition() override
;
38 gfx::NativeWindow
GetNativeWindow() override
;
40 // Wrappers that update the state of the bubble.
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_
; }
56 explicit MockPermissionBubbleView(bool browser_test
);
60 bool can_accept_updates_
;
63 std::vector
<PermissionBubbleRequest
*> permission_requests_
;
64 std::vector
<bool> permission_states_
;
67 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_MOCK_PERMISSION_BUBBLE_VIEW_H_