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 #include "content/public/test/browser_test.h" | 5 #include "content/public/test/browser_test.h" |
6 #include "headless/public/headless_browser.h" | 6 #include "headless/public/headless_browser.h" |
7 #include "headless/public/headless_web_contents.h" | 7 #include "headless/public/headless_web_contents.h" |
8 #include "headless/test/headless_browser_test.h" | 8 #include "headless/test/headless_browser_test.h" |
| 9 #include "net/test/spawned_test_server/spawned_test_server.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/gfx/geometry/size.h" | 11 #include "ui/gfx/geometry/size.h" |
11 | 12 |
12 namespace headless { | 13 namespace headless { |
13 | 14 |
14 IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, CreateAndDestroyWebContents) { | 15 IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, CreateAndDestroyWebContents) { |
15 scoped_ptr<HeadlessWebContents> web_contents = | 16 scoped_ptr<HeadlessWebContents> web_contents = |
16 browser()->CreateWebContents(gfx::Size(800, 600)); | 17 browser()->CreateWebContents(gfx::Size(800, 600)); |
17 EXPECT_TRUE(web_contents); | 18 EXPECT_TRUE(web_contents); |
18 // TODO(skyostil): Verify viewport dimensions once we can. | 19 // TODO(skyostil): Verify viewport dimensions once we can. |
19 web_contents.reset(); | 20 web_contents.reset(); |
20 } | 21 } |
21 | 22 |
| 23 class HeadlessBrowserTestWithProxy : public HeadlessBrowserTest { |
| 24 public: |
| 25 HeadlessBrowserTestWithProxy() |
| 26 : proxy_server_(net::SpawnedTestServer::TYPE_HTTP, |
| 27 net::SpawnedTestServer::kLocalhost, |
| 28 base::FilePath(FILE_PATH_LITERAL("headless/test/data"))) { |
| 29 } |
| 30 |
| 31 void SetUp() override { |
| 32 ASSERT_TRUE(proxy_server_.Start()); |
| 33 HeadlessBrowserTest::SetUp(); |
| 34 } |
| 35 |
| 36 void TearDown() override { |
| 37 proxy_server_.Stop(); |
| 38 HeadlessBrowserTest::TearDown(); |
| 39 } |
| 40 |
| 41 net::SpawnedTestServer* proxy_server() { return &proxy_server_; } |
| 42 |
| 43 private: |
| 44 net::SpawnedTestServer proxy_server_; |
| 45 }; |
| 46 |
| 47 IN_PROC_BROWSER_TEST_F(HeadlessBrowserTestWithProxy, SetProxyServer) { |
| 48 HeadlessBrowser::Options::Builder builder; |
| 49 builder.SetProxyServer(proxy_server()->host_port_pair()); |
| 50 SetBrowserOptions(builder.Build()); |
| 51 |
| 52 scoped_ptr<HeadlessWebContents> web_contents = |
| 53 browser()->CreateWebContents(gfx::Size(800, 600)); |
| 54 |
| 55 // Load a page which doesn't actually exist, but for which the our proxy |
| 56 // returns valid content anyway. |
| 57 EXPECT_TRUE(NavigateAndWaitForLoad( |
| 58 web_contents.get(), GURL("http://not-an-actual-domain.tld/hello.html"))); |
| 59 } |
| 60 |
22 } // namespace headless | 61 } // namespace headless |
OLD | NEW |