Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: headless/lib/headless_web_contents_browsertest.cc

Issue 2043603004: headless: Introduce a browser context (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nits Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « headless/lib/headless_browser_browsertest.cc ('k') | headless/public/headless_browser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 HeadlessWebContents* web_contents = browser()->CreateWebContents( 26 HeadlessWebContents* web_contents =
27 embedded_test_server()->GetURL("/hello.html"), gfx::Size(800, 600)); 27 browser()
28 ->CreateWebContentsBuilder()
29 .SetInitialURL(embedded_test_server()->GetURL("/hello.html"))
30 .Build();
28 EXPECT_TRUE(WaitForLoad(web_contents)); 31 EXPECT_TRUE(WaitForLoad(web_contents));
29 32
30 std::vector<HeadlessWebContents*> all_web_contents = 33 std::vector<HeadlessWebContents*> all_web_contents =
31 browser()->GetAllWebContents(); 34 browser()->GetAllWebContents();
32 35
33 EXPECT_EQ(static_cast<size_t>(1), all_web_contents.size()); 36 EXPECT_EQ(static_cast<size_t>(1), all_web_contents.size());
34 EXPECT_EQ(web_contents, all_web_contents[0]); 37 EXPECT_EQ(web_contents, all_web_contents[0]);
35 } 38 }
36 39
37 IN_PROC_BROWSER_TEST_F(HeadlessWebContentsTest, WindowOpen) { 40 IN_PROC_BROWSER_TEST_F(HeadlessWebContentsTest, WindowOpen) {
38 EXPECT_TRUE(embedded_test_server()->Start()); 41 EXPECT_TRUE(embedded_test_server()->Start());
39 42
40 HeadlessWebContents* web_contents = browser()->CreateWebContents( 43 HeadlessWebContents* web_contents =
41 embedded_test_server()->GetURL("/window_open.html"), gfx::Size(800, 600)); 44 browser()
45 ->CreateWebContentsBuilder()
46 .SetInitialURL(embedded_test_server()->GetURL("/window_open.html"))
47 .Build();
42 EXPECT_TRUE(WaitForLoad(web_contents)); 48 EXPECT_TRUE(WaitForLoad(web_contents));
43 49
44 std::vector<HeadlessWebContents*> all_web_contents = 50 std::vector<HeadlessWebContents*> all_web_contents =
45 browser()->GetAllWebContents(); 51 browser()->GetAllWebContents();
46 52
47 EXPECT_EQ(static_cast<size_t>(2), all_web_contents.size()); 53 EXPECT_EQ(static_cast<size_t>(2), all_web_contents.size());
48 } 54 }
49 55
50 class HeadlessWebContentsScreenshotTest 56 class HeadlessWebContentsScreenshotTest
51 : public HeadlessAsyncDevTooledBrowserTest { 57 : public HeadlessAsyncDevTooledBrowserTest {
52 public: 58 public:
53 void RunDevTooledTest() override { 59 void RunDevTooledTest() override {
54 devtools_client_->GetPage()->GetExperimental()->CaptureScreenshot( 60 devtools_client_->GetPage()->GetExperimental()->CaptureScreenshot(
55 page::CaptureScreenshotParams::Builder().Build(), 61 page::CaptureScreenshotParams::Builder().Build(),
56 base::Bind(&HeadlessWebContentsScreenshotTest::OnScreenshotCaptured, 62 base::Bind(&HeadlessWebContentsScreenshotTest::OnScreenshotCaptured,
57 base::Unretained(this))); 63 base::Unretained(this)));
58 } 64 }
59 65
60 void OnScreenshotCaptured( 66 void OnScreenshotCaptured(
61 std::unique_ptr<page::CaptureScreenshotResult> result) { 67 std::unique_ptr<page::CaptureScreenshotResult> result) {
62 EXPECT_LT(0U, result->GetData().length()); 68 EXPECT_LT(0U, result->GetData().length());
63 FinishAsynchronousTest(); 69 FinishAsynchronousTest();
64 } 70 }
65 }; 71 };
66 72
67 HEADLESS_ASYNC_DEVTOOLED_TEST_F(HeadlessWebContentsScreenshotTest); 73 HEADLESS_ASYNC_DEVTOOLED_TEST_F(HeadlessWebContentsScreenshotTest);
68 74
69 } // namespace headless 75 } // namespace headless
OLDNEW
« no previous file with comments | « headless/lib/headless_browser_browsertest.cc ('k') | headless/public/headless_browser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698