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

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

Issue 1781193004: headless: Make it possible to configure an HTTP proxy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments. Created 4 years, 9 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 "base/run_loop.h"
6 #include "content/public/test/browser_test.h" 5 #include "content/public/test/browser_test.h"
7 #include "headless/public/headless_browser.h" 6 #include "headless/public/headless_browser.h"
8 #include "headless/public/headless_web_contents.h" 7 #include "headless/public/headless_web_contents.h"
9 #include "headless/test/headless_browser_test.h" 8 #include "headless/test/headless_browser_test.h"
10 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/gfx/geometry/size.h" 10 #include "ui/gfx/geometry/size.h"
12 #include "url/gurl.h" 11 #include "url/gurl.h"
13 12
14 namespace headless { 13 namespace headless {
15 14
16 class HeadlessWebContentsTest : public HeadlessBrowserTest {}; 15 class HeadlessWebContentsTest : public HeadlessBrowserTest {};
17 16
18 class WaitForNavigationObserver : public HeadlessWebContents::Observer {
19 public:
20 WaitForNavigationObserver(base::RunLoop* run_loop,
21 HeadlessWebContents* web_contents)
22 : run_loop_(run_loop), web_contents_(web_contents) {
23 web_contents_->AddObserver(this);
24 }
25
26 ~WaitForNavigationObserver() override { web_contents_->RemoveObserver(this); }
27
28 void DocumentOnLoadCompletedInMainFrame() override { run_loop_->Quit(); }
29
30 private:
31 base::RunLoop* run_loop_; // Not owned.
32 HeadlessWebContents* web_contents_; // Not owned.
33
34 DISALLOW_COPY_AND_ASSIGN(WaitForNavigationObserver);
35 };
36
37 IN_PROC_BROWSER_TEST_F(HeadlessWebContentsTest, Navigation) { 17 IN_PROC_BROWSER_TEST_F(HeadlessWebContentsTest, Navigation) {
38 EXPECT_TRUE(embedded_test_server()->Start()); 18 EXPECT_TRUE(embedded_test_server()->Start());
39 scoped_ptr<HeadlessWebContents> web_contents = 19 scoped_ptr<HeadlessWebContents> web_contents =
40 browser()->CreateWebContents(gfx::Size(800, 600)); 20 browser()->CreateWebContents(gfx::Size(800, 600));
41 21 EXPECT_TRUE(NavigateAndWaitForLoad(
42 base::RunLoop run_loop; 22 web_contents.get(), embedded_test_server()->GetURL("/hello.html")));
43 base::MessageLoop::ScopedNestableTaskAllower nestable_allower(
44 base::MessageLoop::current());
45 WaitForNavigationObserver observer(&run_loop, web_contents.get());
46
47 web_contents->OpenURL(embedded_test_server()->GetURL("/hello.html"));
48 run_loop.Run();
49 } 23 }
50 24
51 IN_PROC_BROWSER_TEST_F(HeadlessWebContentsTest, NavigationWithBadURL) { 25 IN_PROC_BROWSER_TEST_F(HeadlessWebContentsTest, NavigationWithBadURL) {
52 scoped_ptr<HeadlessWebContents> web_contents = 26 scoped_ptr<HeadlessWebContents> web_contents =
53 browser()->CreateWebContents(gfx::Size(800, 600)); 27 browser()->CreateWebContents(gfx::Size(800, 600));
54 GURL bad_url("not_valid"); 28 GURL bad_url("not_valid");
55 EXPECT_FALSE(web_contents->OpenURL(bad_url)); 29 EXPECT_FALSE(web_contents->OpenURL(bad_url));
56 } 30 }
57 31
58 } // namespace headless 32 } // 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