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 <memory> | 5 #include <memory> |
6 | 6 |
7 #include "content/public/test/browser_test.h" | 7 #include "content/public/test/browser_test.h" |
8 #include "headless/public/headless_browser.h" | 8 #include "headless/public/headless_browser.h" |
9 #include "headless/public/headless_web_contents.h" | 9 #include "headless/public/headless_web_contents.h" |
10 #include "headless/test/headless_browser_test.h" | 10 #include "headless/test/headless_browser_test.h" |
11 #include "net/test/spawned_test_server/spawned_test_server.h" | 11 #include "net/test/spawned_test_server/spawned_test_server.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "ui/gfx/geometry/size.h" | 13 #include "ui/gfx/geometry/size.h" |
14 | 14 |
15 namespace headless { | 15 namespace headless { |
16 | 16 |
17 IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, CreateAndDestroyWebContents) { | 17 IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, CreateAndDestroyWebContents) { |
18 std::unique_ptr<HeadlessWebContents> web_contents = | 18 HeadlessWebContents* web_contents = |
19 browser()->CreateWebContents(GURL("about:blank"), gfx::Size(800, 600)); | 19 browser()->CreateWebContents(GURL("about:blank"), gfx::Size(800, 600)); |
20 EXPECT_TRUE(web_contents); | 20 EXPECT_TRUE(web_contents); |
| 21 |
| 22 EXPECT_EQ(static_cast<size_t>(1), browser()->GetAllWebContents().size()); |
| 23 EXPECT_EQ(web_contents, browser()->GetAllWebContents()[0]); |
21 // TODO(skyostil): Verify viewport dimensions once we can. | 24 // TODO(skyostil): Verify viewport dimensions once we can. |
22 web_contents.reset(); | 25 web_contents->Close(); |
| 26 |
| 27 EXPECT_TRUE(browser()->GetAllWebContents().empty()); |
23 } | 28 } |
24 | 29 |
25 IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, CreateWithBadURL) { | 30 IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, CreateWithBadURL) { |
26 GURL bad_url("not_valid"); | 31 GURL bad_url("not_valid"); |
27 std::unique_ptr<HeadlessWebContents> web_contents = | 32 HeadlessWebContents* web_contents = |
28 browser()->CreateWebContents(bad_url, gfx::Size(800, 600)); | 33 browser()->CreateWebContents(bad_url, gfx::Size(800, 600)); |
29 EXPECT_FALSE(web_contents); | 34 EXPECT_FALSE(web_contents); |
| 35 EXPECT_TRUE(browser()->GetAllWebContents().empty()); |
30 } | 36 } |
31 | 37 |
32 class HeadlessBrowserTestWithProxy : public HeadlessBrowserTest { | 38 class HeadlessBrowserTestWithProxy : public HeadlessBrowserTest { |
33 public: | 39 public: |
34 HeadlessBrowserTestWithProxy() | 40 HeadlessBrowserTestWithProxy() |
35 : proxy_server_(net::SpawnedTestServer::TYPE_HTTP, | 41 : proxy_server_(net::SpawnedTestServer::TYPE_HTTP, |
36 net::SpawnedTestServer::kLocalhost, | 42 net::SpawnedTestServer::kLocalhost, |
37 base::FilePath(FILE_PATH_LITERAL("headless/test/data"))) { | 43 base::FilePath(FILE_PATH_LITERAL("headless/test/data"))) { |
38 } | 44 } |
39 | 45 |
(...skipping 13 matching lines...) Expand all Loading... |
53 net::SpawnedTestServer proxy_server_; | 59 net::SpawnedTestServer proxy_server_; |
54 }; | 60 }; |
55 | 61 |
56 IN_PROC_BROWSER_TEST_F(HeadlessBrowserTestWithProxy, SetProxyServer) { | 62 IN_PROC_BROWSER_TEST_F(HeadlessBrowserTestWithProxy, SetProxyServer) { |
57 HeadlessBrowser::Options::Builder builder; | 63 HeadlessBrowser::Options::Builder builder; |
58 builder.SetProxyServer(proxy_server()->host_port_pair()); | 64 builder.SetProxyServer(proxy_server()->host_port_pair()); |
59 SetBrowserOptions(builder.Build()); | 65 SetBrowserOptions(builder.Build()); |
60 | 66 |
61 // Load a page which doesn't actually exist, but for which the our proxy | 67 // Load a page which doesn't actually exist, but for which the our proxy |
62 // returns valid content anyway. | 68 // returns valid content anyway. |
63 std::unique_ptr<HeadlessWebContents> web_contents = | 69 // |
64 browser()->CreateWebContents( | 70 // TODO(altimin): Currently this construction does not serve hello.html |
65 GURL("http://not-an-actual-domain.tld/hello.html"), | 71 // from headless/test/data as expected. We should fix this. |
66 gfx::Size(800, 600)); | 72 HeadlessWebContents* web_contents = browser()->CreateWebContents( |
67 EXPECT_TRUE(WaitForLoad(web_contents.get())); | 73 GURL("http://not-an-actual-domain.tld/hello.html"), gfx::Size(800, 600)); |
| 74 EXPECT_TRUE(WaitForLoad(web_contents)); |
| 75 EXPECT_EQ(static_cast<size_t>(1), browser()->GetAllWebContents().size()); |
| 76 EXPECT_EQ(web_contents, browser()->GetAllWebContents()[0]); |
| 77 web_contents->Close(); |
| 78 EXPECT_TRUE(browser()->GetAllWebContents().empty()); |
68 } | 79 } |
69 | 80 |
70 } // namespace headless | 81 } // namespace headless |
OLD | NEW |