Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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_BROWSER_SITE_PER_PROCESS_BROWSERTEST_H_ | 5 #ifndef CONTENT_BROWSER_SITE_PER_PROCESS_BROWSERTEST_H_ |
| 6 #define CONTENT_BROWSER_SITE_PER_PROCESS_BROWSERTEST_H_ | 6 #define CONTENT_BROWSER_SITE_PER_PROCESS_BROWSERTEST_H_ |
| 7 | 7 |
| 8 #include <map> | |
| 8 #include <string> | 9 #include <string> |
| 10 #include <vector> | |
| 9 | 11 |
| 12 #include "base/callback.h" | |
| 13 #include "base/macros.h" | |
| 10 #include "content/browser/web_contents/web_contents_impl.h" | 14 #include "content/browser/web_contents/web_contents_impl.h" |
| 11 #include "content/public/test/content_browser_test.h" | 15 #include "content/public/test/content_browser_test.h" |
| 12 #include "content/shell/browser/shell.h" | 16 #include "content/shell/browser/shell.h" |
| 13 #include "content/test/content_browser_test_utils_internal.h" | 17 #include "content/test/content_browser_test_utils_internal.h" |
| 18 #include "net/test/embedded_test_server/http_response.h" | |
| 14 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 15 | 20 |
| 21 namespace net { | |
| 22 namespace test_server { | |
| 23 struct HttpRequest; | |
| 24 } | |
| 25 } | |
| 26 | |
| 16 namespace content { | 27 namespace content { |
| 17 | 28 |
| 18 class FrameTreeNode; | 29 class FrameTreeNode; |
| 19 | 30 |
| 20 class SitePerProcessBrowserTest : public ContentBrowserTest { | 31 class SitePerProcessBrowserTest : public ContentBrowserTest { |
| 21 public: | 32 public: |
| 22 SitePerProcessBrowserTest(); | 33 SitePerProcessBrowserTest(); |
| 34 ~SitePerProcessBrowserTest() override; | |
| 35 | |
| 36 void AddDelayedResponse(const net::test_server::SendBytesCallback& send, | |
| 37 const net::test_server::SendCompleteCallback& done); | |
| 23 | 38 |
| 24 protected: | 39 protected: |
| 25 std::string DepictFrameTree(FrameTreeNode* node); | 40 std::string DepictFrameTree(FrameTreeNode* node); |
| 26 | 41 |
| 27 void SetUpCommandLine(base::CommandLine* command_line) override; | 42 void SetUpCommandLine(base::CommandLine* command_line) override; |
| 28 void SetUpOnMainThread() override; | 43 void SetUpOnMainThread() override; |
| 29 | 44 |
| 30 WebContentsImpl* web_contents() const { | 45 WebContentsImpl* web_contents() const { |
| 31 return static_cast<WebContentsImpl*>(shell()->web_contents()); | 46 return static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 32 } | 47 } |
| 33 | 48 |
| 49 // Note: must be called on the UI thread before any requests are made for a | |
| 50 // test. | |
| 51 void SetDelayedRequestsForPath(std::string path, int num_delayed); | |
| 52 | |
| 34 private: | 53 private: |
| 54 // Custom embedded test server handler. Looks for requests matching | |
| 55 // delayed_requests_for_path_, and delays them if necessary. As soon as a | |
| 56 // single request comes in and: | |
| 57 // 1) It matches a delayed path | |
| 58 // 2) No path has any more requests to delay | |
| 59 // Then we release the barrier and finish all delayed requests. | |
| 60 std::unique_ptr<net::test_server::HttpResponse> HandleMockResource( | |
| 61 const net::test_server::HttpRequest& request); | |
| 62 | |
| 63 // If there are no more requests to delay, post a series of tasks finishing | |
| 64 // all the delayed tasks. | |
| 65 void MaybeStartRequests(); | |
| 66 | |
| 67 // Set of closures to call which will complete delayed requests. | |
| 68 std::vector<base::Closure> send_response_closures_; | |
| 69 | |
| 70 // Map from URL paths to the number of requests to delay for that particular | |
| 71 // path. Initialized on the UI thread but modified and read on the IO thread | |
| 72 // once requests start being made. | |
| 73 std::map<std::string, int> delayed_requests_for_path_; | |
|
nasko
2017/01/31 15:50:34
All of these changes don't seem appropriate to add
Charlie Harrison
2017/01/31 20:19:32
Done. Subclass'd
| |
| 74 | |
| 35 FrameTreeVisualizer visualizer_; | 75 FrameTreeVisualizer visualizer_; |
| 76 | |
| 77 DISALLOW_COPY_AND_ASSIGN(SitePerProcessBrowserTest); | |
| 36 }; | 78 }; |
| 37 | 79 |
| 38 } // namespace content | 80 } // namespace content |
| 39 | 81 |
| 40 #endif // CONTENT_BROWSER_SITE_PER_PROCESS_BROWSERTEST_H_ | 82 #endif // CONTENT_BROWSER_SITE_PER_PROCESS_BROWSERTEST_H_ |
| OLD | NEW |