Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ | 5 #ifndef CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ |
| 6 #define CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ | 6 #define CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ |
| 7 | 7 |
| 8 #include <queue> | 8 #include <queue> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 RenderFrameHost* render_frame_host() const { return render_frame_host_; } | 185 RenderFrameHost* render_frame_host() const { return render_frame_host_; } |
| 186 | 186 |
| 187 private: | 187 private: |
| 188 RenderFrameHost* render_frame_host_; | 188 RenderFrameHost* render_frame_host_; |
| 189 }; | 189 }; |
| 190 | 190 |
| 191 RenderFrameHost* ConvertToRenderFrameHost(RenderViewHost* render_view_host); | 191 RenderFrameHost* ConvertToRenderFrameHost(RenderViewHost* render_view_host); |
| 192 RenderFrameHost* ConvertToRenderFrameHost(RenderFrameHost* render_view_host); | 192 RenderFrameHost* ConvertToRenderFrameHost(RenderFrameHost* render_view_host); |
| 193 RenderFrameHost* ConvertToRenderFrameHost(WebContents* web_contents); | 193 RenderFrameHost* ConvertToRenderFrameHost(WebContents* web_contents); |
| 194 | 194 |
| 195 class DOMAutomationWaiter : public NotificationObserver, | |
|
ncarter (slow)
2016/11/01 19:50:52
Can we do this as an enhancement to the existing D
Łukasz Anforowicz
2016/11/01 23:43:41
Agreed that DOMAutomationWaiter can be scraped and
| |
| 196 public WebContentsObserver { | |
| 197 public: | |
| 198 // Starts monitoring the |target| for calls to | |
| 199 // window.domAutomationController.send(...). | |
| 200 explicit DOMAutomationWaiter(WebContents* target); | |
| 201 | |
| 202 ~DOMAutomationWaiter() override; | |
| 203 | |
| 204 // Waits until the window.domAutomationController.send(response) is called | |
| 205 // inside the |target| (the one that was passed to the constructor) and | |
| 206 // ShouldStopWaiting returns true for the |response| received from |target|. | |
| 207 // | |
| 208 // If |out_response| is not null, then it will receive the |response| from the | |
| 209 // |target|. It is okay if |out_response| is null. | |
| 210 // | |
| 211 // Returns true if the expected response was received (and false if the wait | |
| 212 // was intrrupted for other reasons - e.g. if a renderer crashed). | |
| 213 bool WaitAndGetResponse(std::unique_ptr<base::Value>* out_response) | |
| 214 WARN_UNUSED_RESULT; | |
| 215 | |
| 216 protected: | |
| 217 // Returns whether to stop waiting for the given |response| value (passed by | |
| 218 // javascript to window.domAutomationController.send). In default | |
| 219 // implementation all |response| values stop waiting. | |
| 220 virtual bool ShouldStopWaiting(const base::Value& response); | |
|
Łukasz Anforowicz
2016/11/01 23:43:41
Yesterday I read an article arguing for minimizing
| |
| 221 | |
| 222 private: | |
| 223 // WebContentsObserver overrides, | |
|
ncarter (slow)
2016/11/01 19:50:52
, -> .
Łukasz Anforowicz
2016/11/01 23:43:41
Acknowledged. (not applicable anymore after remov
| |
| 224 void RenderProcessGone(base::TerminationStatus status) override; | |
| 225 | |
| 226 // NotificationObserver overrides. | |
| 227 void Observe(int type, | |
| 228 const NotificationSource& source, | |
| 229 const NotificationDetails& details) override; | |
| 230 | |
| 231 std::unique_ptr<base::Value> response_; | |
| 232 scoped_refptr<MessageLoopRunner> message_loop_runner_; | |
| 233 NotificationRegistrar registrar_; | |
| 234 | |
| 235 DISALLOW_COPY_AND_ASSIGN(DOMAutomationWaiter); | |
| 236 }; | |
| 237 | |
| 195 // Executes the passed |script| in the specified frame. The |script| should not | 238 // Executes the passed |script| in the specified frame. The |script| should not |
| 196 // invoke domAutomationController.send(); otherwise, your test will hang or be | 239 // invoke domAutomationController.send(); otherwise, your test will hang or be |
| 197 // flaky. If you want to extract a result, use one of the below functions. | 240 // flaky. If you want to extract a result, use one of the below functions. |
| 198 // Returns true on success. | 241 // Returns true on success. |
| 199 bool ExecuteScript(const ToRenderFrameHost& adapter, | 242 bool ExecuteScript(const ToRenderFrameHost& adapter, |
| 200 const std::string& script) WARN_UNUSED_RESULT; | 243 const std::string& script) WARN_UNUSED_RESULT; |
| 201 | 244 |
| 202 // The following methods executes the passed |script| in the specified frame and | 245 // The following methods executes the passed |script| in the specified frame and |
| 203 // sets |result| to the value passed to "window.domAutomationController.send" by | 246 // sets |result| to the value passed to "window.domAutomationController.send" by |
| 204 // the executed script. They return true on success, false if the script | 247 // the executed script. They return true on success, false if the script |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 696 | 739 |
| 697 // The MessageLoopRunner used to spin the message loop. | 740 // The MessageLoopRunner used to spin the message loop. |
| 698 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 741 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 699 | 742 |
| 700 DISALLOW_COPY_AND_ASSIGN(ConsoleObserverDelegate); | 743 DISALLOW_COPY_AND_ASSIGN(ConsoleObserverDelegate); |
| 701 }; | 744 }; |
| 702 | 745 |
| 703 } // namespace content | 746 } // namespace content |
| 704 | 747 |
| 705 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ | 748 #endif // CONTENT_PUBLIC_TEST_BROWSER_TEST_UTILS_H_ |
| OLD | NEW |