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" |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 bool navigation_succeeded() const { return navigation_succeeded_; } | 33 bool navigation_succeeded() const { return navigation_succeeded_; } |
34 | 34 |
35 private: | 35 private: |
36 HeadlessWebContentsTest* browser_test_; // Not owned. | 36 HeadlessWebContentsTest* browser_test_; // Not owned. |
37 bool navigation_succeeded_; | 37 bool navigation_succeeded_; |
38 }; | 38 }; |
39 | 39 |
40 IN_PROC_BROWSER_TEST_F(HeadlessWebContentsTest, Navigation) { | 40 IN_PROC_BROWSER_TEST_F(HeadlessWebContentsTest, Navigation) { |
41 EXPECT_TRUE(embedded_test_server()->Start()); | 41 EXPECT_TRUE(embedded_test_server()->Start()); |
42 std::unique_ptr<HeadlessWebContents> web_contents = | 42 HeadlessWebContents* web_contents = browser()->CreateWebContents( |
43 browser()->CreateWebContents( | 43 embedded_test_server()->GetURL("/hello.html"), gfx::Size(800, 600)); |
44 embedded_test_server()->GetURL("/hello.html"), gfx::Size(800, 600)); | |
45 NavigationObserver observer(this); | 44 NavigationObserver observer(this); |
46 web_contents->AddObserver(&observer); | 45 web_contents->AddObserver(&observer); |
47 | 46 |
48 RunAsynchronousTest(); | 47 RunAsynchronousTest(); |
49 | 48 |
50 EXPECT_TRUE(observer.navigation_succeeded()); | 49 EXPECT_TRUE(observer.navigation_succeeded()); |
51 web_contents->RemoveObserver(&observer); | 50 web_contents->RemoveObserver(&observer); |
| 51 |
| 52 std::vector<HeadlessWebContents*> all_web_contents = |
| 53 browser()->GetAllWebContents(); |
| 54 |
| 55 EXPECT_EQ(all_web_contents.size(), static_cast<size_t>(1)); |
| 56 EXPECT_EQ(all_web_contents[0], web_contents); |
| 57 EXPECT_TRUE(web_contents->IsDirectlyCreated()); |
| 58 } |
| 59 |
| 60 IN_PROC_BROWSER_TEST_F(HeadlessWebContentsTest, WindowOpen) { |
| 61 EXPECT_TRUE(embedded_test_server()->Start()); |
| 62 |
| 63 HeadlessWebContents* web_contents = browser()->CreateWebContents( |
| 64 embedded_test_server()->GetURL("/window_open.html"), gfx::Size(800, 600)); |
| 65 NavigationObserver observer(this); |
| 66 web_contents->AddObserver(&observer); |
| 67 |
| 68 RunAsynchronousTest(); |
| 69 |
| 70 EXPECT_TRUE(observer.navigation_succeeded()); |
| 71 web_contents->RemoveObserver(&observer); |
| 72 |
| 73 std::vector<HeadlessWebContents*> all_web_contents = |
| 74 browser()->GetAllWebContents(); |
| 75 |
| 76 EXPECT_EQ(all_web_contents.size(), static_cast<size_t>(2)); |
| 77 |
| 78 // Check that one WebContents was directly created, while other wasn't. |
| 79 EXPECT_TRUE(all_web_contents[0]->IsDirectlyCreated() != |
| 80 all_web_contents[1]->IsDirectlyCreated()); |
52 } | 81 } |
53 | 82 |
54 } // namespace headless | 83 } // namespace headless |
OLD | NEW |