Index: headless/lib/headless_web_contents_browsertest.cc |
diff --git a/headless/lib/headless_web_contents_browsertest.cc b/headless/lib/headless_web_contents_browsertest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5cca855b5bafd4e73b10d2c151c180f5640ccf8d |
--- /dev/null |
+++ b/headless/lib/headless_web_contents_browsertest.cc |
@@ -0,0 +1,61 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/run_loop.h" |
+#include "content/public/test/browser_test.h" |
+#include "headless/public/headless_browser.h" |
+#include "headless/public/headless_web_contents.h" |
+#include "headless/test/headless_browser_test.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "ui/gfx/geometry/size.h" |
+#include "url/gurl.h" |
+ |
+namespace headless { |
+ |
+class HeadlessWebContentsTest : public HeadlessBrowserTest {}; |
+ |
+class WaitForNavigationObserver : public HeadlessWebContents::Observer { |
+ public: |
+ WaitForNavigationObserver(base::RunLoop* run_loop, |
+ HeadlessWebContents* web_contents) |
+ : HeadlessWebContents::Observer(web_contents), run_loop_(run_loop) {} |
+ |
+ void DocumentOnLoadCompletedInMainFrame() override { run_loop_->Quit(); } |
+ |
+ void DidNavigateMainFrame() override {} |
+ void OnLoadProgressChanged(double progress) override {} |
+ void AddMessageToConsole(const std::string& message) override {} |
+ bool ShouldSuppressDialogs(HeadlessWebContents* source) override { |
+ return false; |
+ } |
+ void OnModalAlertDialog(const std::string& message) override {} |
+ bool OnModalConfirmDialog(const std::string& message) override { |
+ return false; |
+ } |
+ std::string OnModalPromptDialog(const std::string& message, |
+ const std::string& default_value) override { |
+ return std::string(); |
+ } |
+ |
+ private: |
+ base::RunLoop* run_loop_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(WaitForNavigationObserver); |
+}; |
+ |
+IN_PROC_BROWSER_TEST_F(HeadlessWebContentsTest, Navigation) { |
+ ASSERT_TRUE(embedded_test_server()->Start()); |
+ scoped_ptr<HeadlessWebContents> web_contents = |
+ browser()->CreateWebContents({800, 600}); |
+ |
+ base::RunLoop run_loop; |
+ base::MessageLoop::ScopedNestableTaskAllower nestable_allower( |
+ base::MessageLoop::current()); |
+ WaitForNavigationObserver observer(&run_loop, web_contents.get()); |
+ |
+ web_contents->OpenURL(embedded_test_server()->GetURL("/hello.html")); |
+ run_loop.Run(); |
+} |
+ |
+} // namespace headless |