OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_WEBSITE_SETTINGS_MOCK_PERMISSION_BUBBLE_FACTORY_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBSITE_SETTINGS_MOCK_PERMISSION_BUBBLE_FACTORY_H_ |
6 #define CHROME_BROWSER_UI_WEBSITE_SETTINGS_MOCK_PERMISSION_BUBBLE_FACTORY_H_ | 6 #define CHROME_BROWSER_UI_WEBSITE_SETTINGS_MOCK_PERMISSION_BUBBLE_FACTORY_H_ |
7 | 7 |
| 8 #include <memory> |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | 11 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
12 | 12 |
13 class Browser; | 13 class Browser; |
14 class PermissionBubbleView; | 14 class PermissionBubbleView; |
15 class MockPermissionBubbleView; | 15 class MockPermissionBubbleView; |
16 | 16 |
17 // Provides a skeleton class for both unit and browser testing when trying to | 17 // Provides a skeleton class for both unit and browser testing when trying to |
18 // test the bubble manager logic. Should not be used for anything that requires | 18 // test the bubble manager logic. Should not be used for anything that requires |
19 // actual UI. | 19 // actual UI. |
20 // See example usage in | 20 // See example usage in |
21 // chrome/browser/ui/website_settings/permission_bubble_manager_unittest.cc | 21 // chrome/browser/ui/website_settings/permission_bubble_manager_unittest.cc |
22 class MockPermissionBubbleFactory { | 22 class MockPermissionBubbleFactory { |
23 public: | 23 public: |
24 // Set |is_browser_test| if in a browser test in order to interact with the | 24 // Set |is_browser_test| if in a browser test in order to interact with the |
25 // message loop. That shouldn't be done in unit tests. | 25 // message loop. That shouldn't be done in unit tests. |
26 MockPermissionBubbleFactory(bool is_browser_test, | 26 MockPermissionBubbleFactory(bool is_browser_test, |
27 PermissionBubbleManager* manager); | 27 PermissionBubbleManager* manager); |
28 ~MockPermissionBubbleFactory(); | 28 ~MockPermissionBubbleFactory(); |
29 | 29 |
30 // Create method called by the PBM to show a bubble. | 30 // Create method called by the PBM to show a bubble. |
31 scoped_ptr<PermissionBubbleView> Create(Browser* browser); | 31 std::unique_ptr<PermissionBubbleView> Create(Browser* browser); |
32 | 32 |
33 void SetCanUpdateUi(bool can_update_ui); | 33 void SetCanUpdateUi(bool can_update_ui); |
34 | 34 |
35 void ResetCounts(); | 35 void ResetCounts(); |
36 | 36 |
37 void DocumentOnLoadCompletedInMainFrame(); | 37 void DocumentOnLoadCompletedInMainFrame(); |
38 | 38 |
39 void set_response_type(PermissionBubbleManager::AutoResponseType type) { | 39 void set_response_type(PermissionBubbleManager::AutoResponseType type) { |
40 response_type_ = type; | 40 response_type_ = type; |
41 } | 41 } |
42 | 42 |
43 // If the current view is visible. | 43 // If the current view is visible. |
44 bool is_visible(); | 44 bool is_visible(); |
45 // Number of times |Show| was called on any bubble. | 45 // Number of times |Show| was called on any bubble. |
46 int show_count() { return show_count_; } | 46 int show_count() { return show_count_; } |
47 // Number of requests seen by the last |Show|. | 47 // Number of requests seen by the last |Show|. |
48 int request_count() { return requests_count_; } | 48 int request_count() { return requests_count_; } |
49 // Number of requests seen. | 49 // Number of requests seen. |
50 int total_request_count() { return total_requests_count_; } | 50 int total_request_count() { return total_requests_count_; } |
51 | 51 |
52 private: | 52 private: |
53 friend class MockPermissionBubbleView; | 53 friend class MockPermissionBubbleView; |
54 | 54 |
55 // This shouldn't be called. Is here to fail tests that try to create a bubble | 55 // This shouldn't be called. Is here to fail tests that try to create a bubble |
56 // after the factory has been destroyed. | 56 // after the factory has been destroyed. |
57 static scoped_ptr<PermissionBubbleView> DoNotCreate(Browser* browser); | 57 static std::unique_ptr<PermissionBubbleView> DoNotCreate(Browser* browser); |
58 | 58 |
59 void UpdateResponseType(); | 59 void UpdateResponseType(); |
60 void ShowView(MockPermissionBubbleView* view); | 60 void ShowView(MockPermissionBubbleView* view); |
61 void HideView(MockPermissionBubbleView* view); | 61 void HideView(MockPermissionBubbleView* view); |
62 | 62 |
63 bool is_browser_test_; | 63 bool is_browser_test_; |
64 bool can_update_ui_; | 64 bool can_update_ui_; |
65 int show_count_; | 65 int show_count_; |
66 int requests_count_; | 66 int requests_count_; |
67 int total_requests_count_; | 67 int total_requests_count_; |
68 std::vector<MockPermissionBubbleView*> views_; | 68 std::vector<MockPermissionBubbleView*> views_; |
69 PermissionBubbleManager::AutoResponseType response_type_; | 69 PermissionBubbleManager::AutoResponseType response_type_; |
70 | 70 |
71 // The bubble manager that will be associated with this factory. | 71 // The bubble manager that will be associated with this factory. |
72 PermissionBubbleManager* manager_; | 72 PermissionBubbleManager* manager_; |
73 | 73 |
74 DISALLOW_COPY_AND_ASSIGN(MockPermissionBubbleFactory); | 74 DISALLOW_COPY_AND_ASSIGN(MockPermissionBubbleFactory); |
75 }; | 75 }; |
76 | 76 |
77 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_MOCK_PERMISSION_BUBBLE_FACTORY_H_ | 77 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_MOCK_PERMISSION_BUBBLE_FACTORY_H_ |
OLD | NEW |