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