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 // 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/permissions/permission_request_manager_unittest.cc | 21 // chrome/browser/permissions/permission_request_manager_unittest.cc |
22 class MockPermissionPromptFactory { | 22 class MockPermissionPromptFactory { |
23 public: | 23 public: |
24 explicit MockPermissionPromptFactory(PermissionRequestManager* manager); | 24 explicit MockPermissionPromptFactory(PermissionRequestManager* manager); |
25 ~MockPermissionPromptFactory(); | 25 ~MockPermissionPromptFactory(); |
26 | 26 |
27 // Create method called by the PBM to show a bubble. | 27 // Create method called by the PBM to show a bubble. |
28 std::unique_ptr<PermissionPrompt> Create(Browser* browser); | 28 std::unique_ptr<PermissionPrompt> Create(content::WebContents* web_contents); |
raymes
2016/09/15 02:06:46
nit: forward declare WebContents
lshang
2016/09/15 09:45:06
Done.
| |
29 | 29 |
30 void SetCanUpdateUi(bool can_update_ui); | 30 void SetCanUpdateUi(bool can_update_ui); |
31 | 31 |
32 void ResetCounts(); | 32 void ResetCounts(); |
33 | 33 |
34 void DocumentOnLoadCompletedInMainFrame(); | 34 void DocumentOnLoadCompletedInMainFrame(); |
35 | 35 |
36 void set_response_type(PermissionRequestManager::AutoResponseType type) { | 36 void set_response_type(PermissionRequestManager::AutoResponseType type) { |
37 response_type_ = type; | 37 response_type_ = type; |
38 } | 38 } |
39 | 39 |
40 // If the current view is visible. | 40 // If the current view is visible. |
41 bool is_visible(); | 41 bool is_visible(); |
42 // Number of times |Show| was called on any bubble. | 42 // Number of times |Show| was called on any bubble. |
43 int show_count() { return show_count_; } | 43 int show_count() { return show_count_; } |
44 // Number of requests seen by the last |Show|. | 44 // Number of requests seen by the last |Show|. |
45 int request_count() { return requests_count_; } | 45 int request_count() { return requests_count_; } |
46 // Number of requests seen. | 46 // Number of requests seen. |
47 int total_request_count() { return total_requests_count_; } | 47 int total_request_count() { return total_requests_count_; } |
48 | 48 |
49 void WaitForPermissionBubble(); | 49 void WaitForPermissionBubble(); |
50 | 50 |
51 private: | 51 private: |
52 friend class MockPermissionPrompt; | 52 friend class MockPermissionPrompt; |
53 | 53 |
54 // This shouldn't be called. Is here to fail tests that try to create a bubble | 54 // This shouldn't be called. Is here to fail tests that try to create a bubble |
55 // after the factory has been destroyed. | 55 // after the factory has been destroyed. |
56 static std::unique_ptr<PermissionPrompt> DoNotCreate(Browser* browser); | 56 static std::unique_ptr<PermissionPrompt> DoNotCreate( |
57 content::WebContents* web_contents); | |
57 | 58 |
58 void UpdateResponseType(); | 59 void UpdateResponseType(); |
59 void ShowView(MockPermissionPrompt* view); | 60 void ShowView(MockPermissionPrompt* view); |
60 void HideView(MockPermissionPrompt* view); | 61 void HideView(MockPermissionPrompt* view); |
61 | 62 |
62 bool can_update_ui_; | 63 bool can_update_ui_; |
63 int show_count_; | 64 int show_count_; |
64 int requests_count_; | 65 int requests_count_; |
65 int total_requests_count_; | 66 int total_requests_count_; |
66 std::vector<MockPermissionPrompt*> prompts_; | 67 std::vector<MockPermissionPrompt*> prompts_; |
67 PermissionRequestManager::AutoResponseType response_type_; | 68 PermissionRequestManager::AutoResponseType response_type_; |
68 | 69 |
69 base::Closure show_bubble_quit_closure_; | 70 base::Closure show_bubble_quit_closure_; |
70 | 71 |
71 // The bubble manager that will be associated with this factory. | 72 // The bubble manager that will be associated with this factory. |
72 PermissionRequestManager* manager_; | 73 PermissionRequestManager* manager_; |
73 | 74 |
74 DISALLOW_COPY_AND_ASSIGN(MockPermissionPromptFactory); | 75 DISALLOW_COPY_AND_ASSIGN(MockPermissionPromptFactory); |
75 }; | 76 }; |
76 | 77 |
77 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_MOCK_PERMISSION_PROMPT_FACTORY_H_ | 78 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_MOCK_PERMISSION_PROMPT_FACTORY_H_ |
OLD | NEW |