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 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "content/public/test/browser_test.h" | 9 #include "content/public/test/browser_test.h" |
10 #include "headless/public/domains/page.h" | 10 #include "headless/public/domains/page.h" |
11 #include "headless/public/headless_browser.h" | 11 #include "headless/public/headless_browser.h" |
12 #include "headless/public/headless_devtools_client.h" | 12 #include "headless/public/headless_devtools_client.h" |
13 #include "headless/public/headless_web_contents.h" | 13 #include "headless/public/headless_web_contents.h" |
14 #include "headless/test/headless_browser_test.h" | 14 #include "headless/test/headless_browser_test.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
17 #include "url/gurl.h" | 17 #include "url/gurl.h" |
18 | 18 |
19 namespace headless { | 19 namespace headless { |
20 | 20 |
21 class HeadlessWebContentsTest : public HeadlessBrowserTest {}; | 21 class HeadlessWebContentsTest : public HeadlessBrowserTest {}; |
22 | 22 |
23 IN_PROC_BROWSER_TEST_F(HeadlessWebContentsTest, Navigation) { | 23 IN_PROC_BROWSER_TEST_F(HeadlessWebContentsTest, Navigation) { |
24 EXPECT_TRUE(embedded_test_server()->Start()); | 24 EXPECT_TRUE(embedded_test_server()->Start()); |
25 | 25 |
| 26 std::unique_ptr<HeadlessBrowserContext> browser_context = |
| 27 browser()->CreateBrowserContextBuilder().Build(); |
| 28 |
26 HeadlessWebContents* web_contents = | 29 HeadlessWebContents* web_contents = |
27 browser() | 30 browser_context->CreateWebContentsBuilder() |
28 ->CreateWebContentsBuilder() | |
29 .SetInitialURL(embedded_test_server()->GetURL("/hello.html")) | 31 .SetInitialURL(embedded_test_server()->GetURL("/hello.html")) |
30 .Build(); | 32 .Build(); |
31 EXPECT_TRUE(WaitForLoad(web_contents)); | 33 EXPECT_TRUE(WaitForLoad(web_contents)); |
32 | 34 |
33 std::vector<HeadlessWebContents*> all_web_contents = | 35 std::vector<HeadlessWebContents*> all_web_contents = |
34 browser()->GetAllWebContents(); | 36 browser()->GetAllWebContents(); |
35 | 37 |
36 EXPECT_EQ(static_cast<size_t>(1), all_web_contents.size()); | 38 EXPECT_EQ(static_cast<size_t>(1), all_web_contents.size()); |
37 EXPECT_EQ(web_contents, all_web_contents[0]); | 39 EXPECT_EQ(web_contents, all_web_contents[0]); |
38 } | 40 } |
39 | 41 |
40 IN_PROC_BROWSER_TEST_F(HeadlessWebContentsTest, WindowOpen) { | 42 IN_PROC_BROWSER_TEST_F(HeadlessWebContentsTest, WindowOpen) { |
41 EXPECT_TRUE(embedded_test_server()->Start()); | 43 EXPECT_TRUE(embedded_test_server()->Start()); |
42 | 44 |
| 45 std::unique_ptr<HeadlessBrowserContext> browser_context = |
| 46 browser()->CreateBrowserContextBuilder().Build(); |
| 47 |
43 HeadlessWebContents* web_contents = | 48 HeadlessWebContents* web_contents = |
44 browser() | 49 browser_context->CreateWebContentsBuilder() |
45 ->CreateWebContentsBuilder() | |
46 .SetInitialURL(embedded_test_server()->GetURL("/window_open.html")) | 50 .SetInitialURL(embedded_test_server()->GetURL("/window_open.html")) |
47 .Build(); | 51 .Build(); |
48 EXPECT_TRUE(WaitForLoad(web_contents)); | 52 EXPECT_TRUE(WaitForLoad(web_contents)); |
49 | 53 |
50 std::vector<HeadlessWebContents*> all_web_contents = | 54 std::vector<HeadlessWebContents*> all_web_contents = |
51 browser()->GetAllWebContents(); | 55 browser()->GetAllWebContents(); |
52 | 56 |
53 EXPECT_EQ(static_cast<size_t>(2), all_web_contents.size()); | 57 EXPECT_EQ(static_cast<size_t>(2), all_web_contents.size()); |
54 } | 58 } |
55 | 59 |
(...skipping 10 matching lines...) Expand all Loading... |
66 void OnScreenshotCaptured( | 70 void OnScreenshotCaptured( |
67 std::unique_ptr<page::CaptureScreenshotResult> result) { | 71 std::unique_ptr<page::CaptureScreenshotResult> result) { |
68 EXPECT_LT(0U, result->GetData().length()); | 72 EXPECT_LT(0U, result->GetData().length()); |
69 FinishAsynchronousTest(); | 73 FinishAsynchronousTest(); |
70 } | 74 } |
71 }; | 75 }; |
72 | 76 |
73 HEADLESS_ASYNC_DEVTOOLED_TEST_F(HeadlessWebContentsScreenshotTest); | 77 HEADLESS_ASYNC_DEVTOOLED_TEST_F(HeadlessWebContentsScreenshotTest); |
74 | 78 |
75 } // namespace headless | 79 } // namespace headless |
OLD | NEW |