| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_PASSWORD_MANAGER_PASSWORD_MANAGER_TEST_BASE_H_ | 5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_MANAGER_TEST_BASE_H_ |
| 6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_MANAGER_TEST_BASE_H_ | 6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_MANAGER_TEST_BASE_H_ |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "chrome/test/base/in_process_browser_test.h" | 10 #include "chrome/test/base/in_process_browser_test.h" |
| 11 #include "content/public/browser/web_contents_observer.h" | 11 #include "content/public/browser/web_contents_observer.h" |
| 12 #include "content/public/test/test_utils.h" | 12 #include "content/public/test/test_utils.h" |
| 13 | 13 |
| 14 namespace autofill { |
| 15 struct PasswordForm; |
| 16 } |
| 17 |
| 14 class NavigationObserver : public content::WebContentsObserver { | 18 class NavigationObserver : public content::WebContentsObserver { |
| 15 public: | 19 public: |
| 16 explicit NavigationObserver(content::WebContents* web_contents); | 20 explicit NavigationObserver(content::WebContents* web_contents); |
| 17 ~NavigationObserver() override; | 21 ~NavigationObserver() override; |
| 18 | 22 |
| 19 // Normally Wait() will not return until a main frame navigation occurs. | 23 // Normally Wait() will not return until a main frame navigation occurs. |
| 20 // If a path is set, Wait() will return after this path has been seen, | 24 // If a path is set, Wait() will return after this path has been seen, |
| 21 // regardless of the frame that navigated. Useful for multi-frame pages. | 25 // regardless of the frame that navigated. Useful for multi-frame pages. |
| 22 void SetPathToWaitFor(const std::string& path) { wait_for_path_ = path; } | 26 void SetPathToWaitFor(const std::string& path) { wait_for_path_ = path; } |
| 23 | 27 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 48 DISALLOW_COPY_AND_ASSIGN(NavigationObserver); | 52 DISALLOW_COPY_AND_ASSIGN(NavigationObserver); |
| 49 }; | 53 }; |
| 50 | 54 |
| 51 // Observes the save password prompt (bubble or infobar) for a specified | 55 // Observes the save password prompt (bubble or infobar) for a specified |
| 52 // WebContents, keeps track of whether or not it is currently shown, and allows | 56 // WebContents, keeps track of whether or not it is currently shown, and allows |
| 53 // accepting saving passwords through it. | 57 // accepting saving passwords through it. |
| 54 class PromptObserver { | 58 class PromptObserver { |
| 55 public: | 59 public: |
| 56 virtual ~PromptObserver(); | 60 virtual ~PromptObserver(); |
| 57 | 61 |
| 58 // Checks if the prompt is being currently shown. | 62 // Checks if the save prompt is being currently shown. |
| 59 virtual bool IsShowingPrompt() const = 0; | 63 virtual bool IsShowingPrompt() const = 0; |
| 60 | 64 |
| 65 // Checks if the update prompt is being currently shown. |
| 66 virtual bool IsShowingUpdatePrompt() const; |
| 67 |
| 61 // Expecting that the prompt is shown, saves the password. Checks that the | 68 // Expecting that the prompt is shown, saves the password. Checks that the |
| 62 // prompt is no longer visible afterwards. | 69 // prompt is no longer visible afterwards. |
| 63 void Accept() const; | 70 void Accept() const; |
| 64 | 71 |
| 72 // Expecting that the prompt is shown, update |form| with the password from |
| 73 // observed form. Checks that the prompt is no longer visible afterwards. |
| 74 void AcceptUpdatePrompt(const autofill::PasswordForm& form) const; |
| 75 |
| 65 // Chooses the right implementation of PromptObserver and creates an instance | 76 // Chooses the right implementation of PromptObserver and creates an instance |
| 66 // of it. | 77 // of it. |
| 67 static scoped_ptr<PromptObserver> Create(content::WebContents* web_contents); | 78 static scoped_ptr<PromptObserver> Create(content::WebContents* web_contents); |
| 68 | 79 |
| 69 protected: | 80 protected: |
| 70 PromptObserver(); | 81 PromptObserver(); |
| 71 | 82 |
| 72 // Accepts the password. The implementation can assume that the prompt is | 83 // Accepts the password. The implementation can assume that the prompt is |
| 73 // currently shown, but is required to verify that the prompt is eventually | 84 // currently shown, but is required to verify that the prompt is eventually |
| 74 // closed. | 85 // closed. |
| 75 virtual void AcceptImpl() const = 0; | 86 virtual void AcceptImpl() const = 0; |
| 76 | 87 |
| 88 // Accepts the password update. The implementation can assume that the prompt |
| 89 // is currently shown, but is required to verify that the prompt is eventually |
| 90 // closed. |
| 91 // TODO(dvadym): Make this method pure virtual as soon as update UI is |
| 92 // implemented for infobar. http://crbug.com/359315 |
| 93 virtual void AcceptUpdatePromptImpl( |
| 94 const autofill::PasswordForm& form) const {} |
| 95 |
| 77 private: | 96 private: |
| 78 DISALLOW_COPY_AND_ASSIGN(PromptObserver); | 97 DISALLOW_COPY_AND_ASSIGN(PromptObserver); |
| 79 }; | 98 }; |
| 80 | 99 |
| 81 class PasswordManagerBrowserTestBase : public InProcessBrowserTest { | 100 class PasswordManagerBrowserTestBase : public InProcessBrowserTest { |
| 82 public: | 101 public: |
| 83 PasswordManagerBrowserTestBase(); | 102 PasswordManagerBrowserTestBase(); |
| 84 ~PasswordManagerBrowserTestBase() override; | 103 ~PasswordManagerBrowserTestBase() override; |
| 85 | 104 |
| 86 // InProcessBrowserTest: | 105 // InProcessBrowserTest: |
| (...skipping 30 matching lines...) Expand all Loading... |
| 117 | 136 |
| 118 // Accessors | 137 // Accessors |
| 119 content::WebContents* WebContents(); | 138 content::WebContents* WebContents(); |
| 120 content::RenderViewHost* RenderViewHost(); | 139 content::RenderViewHost* RenderViewHost(); |
| 121 | 140 |
| 122 private: | 141 private: |
| 123 DISALLOW_COPY_AND_ASSIGN(PasswordManagerBrowserTestBase); | 142 DISALLOW_COPY_AND_ASSIGN(PasswordManagerBrowserTestBase); |
| 124 }; | 143 }; |
| 125 | 144 |
| 126 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_MANAGER_TEST_BASE_H_ | 145 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_MANAGER_TEST_BASE_H_ |
| OLD | NEW |