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

Unified Diff: headless/test/headless_browser_test.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « headless/test/headless_browser_test.h ('k') | headless/test/headless_test_launcher.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: headless/test/headless_browser_test.cc
diff --git a/headless/test/headless_browser_test.cc b/headless/test/headless_browser_test.cc
index 555616a8af7072dfb5795203b9a7766f92a81b48..61d4551e5944fdda4320caf7de632d00e4f92bf7 100644
--- a/headless/test/headless_browser_test.cc
+++ b/headless/test/headless_browser_test.cc
@@ -6,12 +6,45 @@
#include "base/files/file_path.h"
#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
#include "headless/lib/browser/headless_browser_impl.h"
#include "headless/lib/headless_content_main_delegate.h"
+#include "headless/public/headless_web_contents.h"
namespace headless {
+namespace {
+
+class WaitForNavigationObserver : public HeadlessWebContents::Observer {
+ public:
+ WaitForNavigationObserver(base::RunLoop* run_loop,
+ HeadlessWebContents* web_contents)
+ : run_loop_(run_loop),
+ web_contents_(web_contents),
+ navigation_succeeded_(false) {
+ web_contents_->AddObserver(this);
+ }
+
+ ~WaitForNavigationObserver() override { web_contents_->RemoveObserver(this); }
+
+ void DocumentOnLoadCompletedInMainFrame() override { run_loop_->Quit(); }
+ void DidFinishNavigation(bool success) override {
+ navigation_succeeded_ = success;
+ }
+
+ bool navigation_succeeded() const { return navigation_succeeded_; }
+
+ private:
+ base::RunLoop* run_loop_; // Not owned.
+ HeadlessWebContents* web_contents_; // Not owned.
+
+ bool navigation_succeeded_;
+
+ DISALLOW_COPY_AND_ASSIGN(WaitForNavigationObserver);
+};
+
+} // namespace
HeadlessBrowserTest::HeadlessBrowserTest() {
base::FilePath headless_test_data(FILE_PATH_LITERAL("headless/test/data"));
@@ -43,8 +76,28 @@ void HeadlessBrowserTest::RunTestOnMainThreadLoop() {
}
}
+void HeadlessBrowserTest::SetBrowserOptions(
+ const HeadlessBrowser::Options& options) {
+ HeadlessContentMainDelegate::GetInstance()->browser()->SetOptionsForTesting(
+ options);
+}
+
HeadlessBrowser* HeadlessBrowserTest::browser() const {
return HeadlessContentMainDelegate::GetInstance()->browser();
}
+bool HeadlessBrowserTest::NavigateAndWaitForLoad(
+ HeadlessWebContents* web_contents,
+ const GURL& url) {
+ base::RunLoop run_loop;
+ base::MessageLoop::ScopedNestableTaskAllower nestable_allower(
+ base::MessageLoop::current());
+ WaitForNavigationObserver observer(&run_loop, web_contents);
+
+ if (!web_contents->OpenURL(url))
+ return false;
+ run_loop.Run();
+ return observer.navigation_succeeded();
+}
+
} // namespace headless
« no previous file with comments | « headless/test/headless_browser_test.h ('k') | headless/test/headless_test_launcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698