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_PROMPT_FACTORY_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBSITE_SETTINGS_MOCK_PERMISSION_PROMPT_FACTORY_H_ |
6 #define CHROME_BROWSER_UI_WEBSITE_SETTINGS_MOCK_PERMISSION_PROMPT_FACTORY_H_ | 6 #define CHROME_BROWSER_UI_WEBSITE_SETTINGS_MOCK_PERMISSION_PROMPT_FACTORY_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "chrome/browser/permissions/permission_request_manager.h" | 11 #include "chrome/browser/permissions/permission_request_manager.h" |
12 | 12 |
13 class Browser; | 13 class Browser; |
14 class MockPermissionPrompt; | 14 class MockPermissionPrompt; |
15 class PermissionPrompt; | 15 class PermissionPrompt; |
16 | 16 |
| 17 namespace content { |
| 18 class WebContents; |
| 19 } |
| 20 |
17 // Provides a skeleton class for both unit and browser testing when trying to | 21 // 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 | 22 // test the bubble manager logic. Should not be used for anything that requires |
19 // actual UI. | 23 // actual UI. |
20 // See example usage in | 24 // See example usage in |
21 // chrome/browser/permissions/permission_request_manager_unittest.cc | 25 // chrome/browser/permissions/permission_request_manager_unittest.cc |
22 class MockPermissionPromptFactory { | 26 class MockPermissionPromptFactory { |
23 public: | 27 public: |
24 explicit MockPermissionPromptFactory(PermissionRequestManager* manager); | 28 explicit MockPermissionPromptFactory(PermissionRequestManager* manager); |
25 ~MockPermissionPromptFactory(); | 29 ~MockPermissionPromptFactory(); |
26 | 30 |
27 // Create method called by the PBM to show a bubble. | 31 // Create method called by the PBM to show a bubble. |
28 std::unique_ptr<PermissionPrompt> Create(Browser* browser); | 32 std::unique_ptr<PermissionPrompt> Create(content::WebContents* web_contents); |
29 | 33 |
30 void SetCanUpdateUi(bool can_update_ui); | 34 void SetCanUpdateUi(bool can_update_ui); |
31 | 35 |
32 void ResetCounts(); | 36 void ResetCounts(); |
33 | 37 |
34 void DocumentOnLoadCompletedInMainFrame(); | 38 void DocumentOnLoadCompletedInMainFrame(); |
35 | 39 |
36 void set_response_type(PermissionRequestManager::AutoResponseType type) { | 40 void set_response_type(PermissionRequestManager::AutoResponseType type) { |
37 response_type_ = type; | 41 response_type_ = type; |
38 } | 42 } |
39 | 43 |
40 // If the current view is visible. | 44 // If the current view is visible. |
41 bool is_visible(); | 45 bool is_visible(); |
42 // Number of times |Show| was called on any bubble. | 46 // Number of times |Show| was called on any bubble. |
43 int show_count() { return show_count_; } | 47 int show_count() { return show_count_; } |
44 // Number of requests seen by the last |Show|. | 48 // Number of requests seen by the last |Show|. |
45 int request_count() { return requests_count_; } | 49 int request_count() { return requests_count_; } |
46 // Number of requests seen. | 50 // Number of requests seen. |
47 int total_request_count() { return total_requests_count_; } | 51 int total_request_count() { return total_requests_count_; } |
48 | 52 |
49 void WaitForPermissionBubble(); | 53 void WaitForPermissionBubble(); |
50 | 54 |
51 private: | 55 private: |
52 friend class MockPermissionPrompt; | 56 friend class MockPermissionPrompt; |
53 | 57 |
54 // This shouldn't be called. Is here to fail tests that try to create a bubble | 58 // This shouldn't be called. Is here to fail tests that try to create a bubble |
55 // after the factory has been destroyed. | 59 // after the factory has been destroyed. |
56 static std::unique_ptr<PermissionPrompt> DoNotCreate(Browser* browser); | 60 static std::unique_ptr<PermissionPrompt> DoNotCreate( |
| 61 content::WebContents* web_contents); |
57 | 62 |
58 void UpdateResponseType(); | 63 void UpdateResponseType(); |
59 void ShowView(MockPermissionPrompt* view); | 64 void ShowView(MockPermissionPrompt* view); |
60 void HideView(MockPermissionPrompt* view); | 65 void HideView(MockPermissionPrompt* view); |
61 | 66 |
62 bool can_update_ui_; | 67 bool can_update_ui_; |
63 int show_count_; | 68 int show_count_; |
64 int requests_count_; | 69 int requests_count_; |
65 int total_requests_count_; | 70 int total_requests_count_; |
66 std::vector<MockPermissionPrompt*> prompts_; | 71 std::vector<MockPermissionPrompt*> prompts_; |
67 PermissionRequestManager::AutoResponseType response_type_; | 72 PermissionRequestManager::AutoResponseType response_type_; |
68 | 73 |
69 base::Closure show_bubble_quit_closure_; | 74 base::Closure show_bubble_quit_closure_; |
70 | 75 |
71 // The bubble manager that will be associated with this factory. | 76 // The bubble manager that will be associated with this factory. |
72 PermissionRequestManager* manager_; | 77 PermissionRequestManager* manager_; |
73 | 78 |
74 DISALLOW_COPY_AND_ASSIGN(MockPermissionPromptFactory); | 79 DISALLOW_COPY_AND_ASSIGN(MockPermissionPromptFactory); |
75 }; | 80 }; |
76 | 81 |
77 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_MOCK_PERMISSION_PROMPT_FACTORY_H_ | 82 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_MOCK_PERMISSION_PROMPT_FACTORY_H_ |
OLD | NEW |