Chromium Code Reviews| 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_PROMPT_FACTORY_H_ |
| 6 #define CHROME_BROWSER_UI_WEBSITE_SETTINGS_MOCK_PERMISSION_BUBBLE_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 PermissionBubbleView; | 14 class PermissionPrompt; |
| 15 class MockPermissionBubbleView; | 15 class MockPermissionPrompt; |
| 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 MockPermissionBubbleFactory { | 22 class MockPermissionPromptFactory { |
| 23 public: | 23 public: |
| 24 explicit MockPermissionBubbleFactory(PermissionRequestManager* manager); | 24 explicit MockPermissionPromptFactory(PermissionRequestManager* manager); |
| 25 ~MockPermissionBubbleFactory(); | 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<PermissionBubbleView> Create(Browser* browser); | 28 std::unique_ptr<PermissionPrompt> Create(Browser* browser); |
| 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 MockPermissionBubbleView; | 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<PermissionBubbleView> DoNotCreate(Browser* browser); | 56 static std::unique_ptr<PermissionPrompt> DoNotCreate( |
| 57 Browser* browser); | |
| 57 | 58 |
| 58 void UpdateResponseType(); | 59 void UpdateResponseType(); |
| 59 void ShowView(MockPermissionBubbleView* view); | 60 void ShowView(MockPermissionPrompt* view); |
| 60 void HideView(MockPermissionBubbleView* 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<MockPermissionBubbleView*> views_; | 67 std::vector<MockPermissionPrompt*> views_; |
|
raymes
2016/08/01 00:58:13
prompts_?
tsergeant
2016/08/01 23:41:12
Done.
| |
| 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(MockPermissionBubbleFactory); | 75 DISALLOW_COPY_AND_ASSIGN(MockPermissionPromptFactory); |
| 75 }; | 76 }; |
| 76 | 77 |
| 77 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_MOCK_PERMISSION_BUBBLE_FACTORY_H_ | 78 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_MOCK_PERMISSION_PROMPT_FACTORY_H_ |
| OLD | NEW |