#include "base/bind.h"
#include "base/command_line.h"
#include "base/json/json_reader.h"
-#include "base/path_service.h"
#include "base/process/kill.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "content/public/test/test_utils.h"
#include "net/base/filename_util.h"
#include "net/cookies/cookie_store.h"
+#include "net/test/embedded_test_server/embedded_test_server.h"
+#include "net/test/embedded_test_server/http_request.h"
+#include "net/test/embedded_test_server/http_response.h"
#include "net/test/python_utils.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/compositor/test/draw_waiter_for_test.h"
-#include "ui/events/gestures/gesture_configuration.h"
+#include "ui/events/gesture_detection/gesture_configuration.h"
#include "ui/events/keycodes/dom4/keycode_converter.h"
#include "ui/resources/grit/webui_resources.h"
message_loop_runner_ = new MessageLoopRunner;
}
- virtual void Observe(int type,
- const NotificationSource& source,
- const NotificationDetails& details) OVERRIDE {
+ void Observe(int type,
+ const NotificationSource& source,
+ const NotificationDetails& details) override {
DCHECK(type == NOTIFICATION_DOM_OPERATION_RESPONSE);
Details<DomOperationNotificationDetails> dom_op_details(details);
response_ = dom_op_details->json;
}
// Overridden from WebContentsObserver:
- virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE {
+ void RenderProcessGone(base::TerminationStatus status) override {
message_loop_runner_->Quit();
}
DISALLOW_COPY_AND_ASSIGN(DOMOperationObserver);
};
+class InterstitialObserver : public content::WebContentsObserver {
+ public:
+ InterstitialObserver(content::WebContents* web_contents,
+ const base::Closure& attach_callback,
+ const base::Closure& detach_callback)
+ : WebContentsObserver(web_contents),
+ attach_callback_(attach_callback),
+ detach_callback_(detach_callback) {
+ }
+ ~InterstitialObserver() override {}
+
+ // WebContentsObserver methods:
+ void DidAttachInterstitialPage() override { attach_callback_.Run(); }
+ void DidDetachInterstitialPage() override { detach_callback_.Run(); }
+
+ private:
+ base::Closure attach_callback_;
+ base::Closure detach_callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(InterstitialObserver);
+};
+
// Specifying a prototype so that we can add the WARN_UNUSED_RESULT attribute.
bool ExecuteScriptHelper(
RenderFrameHost* render_frame_host,
base::Bind(&SetCookieCallback, result, event));
}
+scoped_ptr<net::test_server::HttpResponse> CrossSiteRedirectResponseHandler(
+ const GURL& server_base_url,
+ const net::test_server::HttpRequest& request) {
+ std::string prefix("/cross-site/");
+ if (!StartsWithASCII(request.relative_url, prefix, true))
+ return scoped_ptr<net::test_server::HttpResponse>();
+
+ std::string params = request.relative_url.substr(prefix.length());
+
+ // A hostname to redirect to must be included in the URL, therefore at least
+ // one '/' character is expected.
+ size_t slash = params.find('/');
+ if (slash == std::string::npos)
+ return scoped_ptr<net::test_server::HttpResponse>();
+
+ // Replace the host of the URL with the one passed in the URL.
+ std::string host = params.substr(0, slash);
+ GURL::Replacements replace_host;
+ replace_host.SetHostStr(host);
+ GURL redirect_server = server_base_url.ReplaceComponents(replace_host);
+
+ // Append the real part of the path to the new URL.
+ std::string path = params.substr(slash + 1);
+ GURL redirect_target(redirect_server.Resolve(path));
+ DCHECK(redirect_target.is_valid());
+
+ scoped_ptr<net::test_server::BasicHttpResponse> http_response(
+ new net::test_server::BasicHttpResponse);
+ http_response->set_code(net::HTTP_MOVED_PERMANENTLY);
+ http_response->AddCustomHeader("Location", redirect_target.spec());
+ return http_response.Pass();
+}
+
} // namespace
runner->Run();
}
+void SetupCrossSiteRedirector(
+ net::test_server::EmbeddedTestServer* embedded_test_server) {
+ embedded_test_server->RegisterRequestHandler(
+ base::Bind(&CrossSiteRedirectResponseHandler,
+ embedded_test_server->base_url()));
+}
+
+void WaitForInterstitialAttach(content::WebContents* web_contents) {
+ if (web_contents->ShowingInterstitialPage())
+ return;
+ scoped_refptr<content::MessageLoopRunner> loop_runner(
+ new content::MessageLoopRunner);
+ InterstitialObserver observer(web_contents,
+ loop_runner->QuitClosure(),
+ base::Closure());
+ loop_runner->Run();
+}
+
+void WaitForInterstitialDetach(content::WebContents* web_contents) {
+ RunTaskAndWaitForInterstitialDetach(web_contents, base::Closure());
+}
+
+void RunTaskAndWaitForInterstitialDetach(content::WebContents* web_contents,
+ const base::Closure& task) {
+ if (!web_contents || !web_contents->ShowingInterstitialPage())
+ return;
+ scoped_refptr<content::MessageLoopRunner> loop_runner(
+ new content::MessageLoopRunner);
+ InterstitialObserver observer(web_contents,
+ base::Closure(),
+ loop_runner->QuitClosure());
+ if (!task.is_null())
+ task.Run();
+ // At this point, web_contents may have been deleted.
+ loop_runner->Run();
+}
+
TitleWatcher::TitleWatcher(WebContents* web_contents,
const base::string16& expected_title)
: WebContentsObserver(web_contents),
void RenderProcessHostWatcher::RenderProcessExited(
RenderProcessHost* host,
- base::ProcessHandle handle,
base::TerminationStatus status,
int exit_code) {
if (type_ == WATCH_FOR_PROCESS_EXIT)