OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/run_loop.h" |
| 6 #include "content/public/test/browser_test.h" |
| 7 #include "headless/public/headless_browser.h" |
| 8 #include "headless/public/headless_web_contents.h" |
| 9 #include "headless/test/headless_browser_test.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "ui/gfx/geometry/size.h" |
| 12 #include "url/gurl.h" |
| 13 |
| 14 namespace headless { |
| 15 |
| 16 class HeadlessWebContentsTest : public HeadlessBrowserTest {}; |
| 17 |
| 18 class WaitForNavigationObserver : public HeadlessWebContents::Observer { |
| 19 public: |
| 20 WaitForNavigationObserver(base::RunLoop* run_loop, |
| 21 HeadlessWebContents* web_contents) |
| 22 : HeadlessWebContents::Observer(web_contents), run_loop_(run_loop) {} |
| 23 |
| 24 void DocumentOnLoadCompletedInMainFrame() override { run_loop_->Quit(); } |
| 25 |
| 26 void DidNavigateMainFrame() override {} |
| 27 void OnLoadProgressChanged(double progress) override {} |
| 28 void AddMessageToConsole(const std::string& message) override {} |
| 29 bool ShouldSuppressDialogs(HeadlessWebContents* source) override { |
| 30 return false; |
| 31 } |
| 32 void OnModalAlertDialog(const std::string& message) override {} |
| 33 bool OnModalConfirmDialog(const std::string& message) override { |
| 34 return false; |
| 35 } |
| 36 std::string OnModalPromptDialog(const std::string& message, |
| 37 const std::string& default_value) override { |
| 38 return std::string(); |
| 39 } |
| 40 |
| 41 private: |
| 42 base::RunLoop* run_loop_; |
| 43 |
| 44 DISALLOW_COPY_AND_ASSIGN(WaitForNavigationObserver); |
| 45 }; |
| 46 |
| 47 IN_PROC_BROWSER_TEST_F(HeadlessWebContentsTest, Navigation) { |
| 48 ASSERT_TRUE(embedded_test_server()->Start()); |
| 49 scoped_ptr<HeadlessWebContents> web_contents = |
| 50 browser()->CreateWebContents({800, 600}); |
| 51 |
| 52 base::RunLoop run_loop; |
| 53 base::MessageLoop::ScopedNestableTaskAllower nestable_allower( |
| 54 base::MessageLoop::current()); |
| 55 WaitForNavigationObserver observer(&run_loop, web_contents.get()); |
| 56 |
| 57 web_contents->OpenURL(embedded_test_server()->GetURL("/hello.html")); |
| 58 run_loop.Run(); |
| 59 } |
| 60 |
| 61 } // namespace headless |
OLD | NEW |