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

Unified Diff: headless/lib/headless_web_contents_browsertest.cc

Issue 1674263002: headless: Initial headless embedder API implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fine, no console logging Mr. Presubmit. Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
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..5771b6957001036c624edc33b4d21a64bfeb4435
--- /dev/null
+++ b/headless/lib/headless_web_contents_browsertest.cc
@@ -0,0 +1,58 @@
+// 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)
+ : run_loop_(run_loop), web_contents_(web_contents) {
+ web_contents_->AddObserver(this);
+ }
+
+ ~WaitForNavigationObserver() override { web_contents_->RemoveObserver(this); }
+
+ void DocumentOnLoadCompletedInMainFrame() override { run_loop_->Quit(); }
+
+ private:
+ base::RunLoop* run_loop_; // Not owned.
+ HeadlessWebContents* web_contents_; // Not owned.
+
+ DISALLOW_COPY_AND_ASSIGN(WaitForNavigationObserver);
+};
+
+IN_PROC_BROWSER_TEST_F(HeadlessWebContentsTest, Navigation) {
+ EXPECT_TRUE(embedded_test_server()->Start());
+ scoped_ptr<HeadlessWebContents> web_contents =
+ browser()->CreateWebContents(gfx::Size(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();
+}
+
+IN_PROC_BROWSER_TEST_F(HeadlessWebContentsTest, NavigationWithBadURL) {
+ scoped_ptr<HeadlessWebContents> web_contents =
+ browser()->CreateWebContents(gfx::Size(800, 600));
+ GURL bad_url("not_valid");
+ EXPECT_FALSE(web_contents->OpenURL(bad_url));
+}
+
+} // namespace headless
« no previous file with comments | « headless/lib/headless_content_main_delegate.cc ('k') | headless/lib/renderer/headless_content_renderer_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698