blob: 0246afe5d6fe1d66cee14ee62c70e27575786e73 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
// Copyright (c) 2011 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 "content/browser/webui/web_ui_handler_browsertest.h"
#include "base/utf_string_conversions.h"
#include "chrome/test/ui_test_utils.h"
#include "content/browser/renderer_host/render_view_host.h"
bool WebUIHandlerBrowserTest::Execute(const std::string& js_test) {
web_ui_->GetRenderViewHost()->ExecuteJavascriptInWebFrame(
string16(), UTF8ToUTF16(js_test));
return WaitForResult();
}
void WebUIHandlerBrowserTest::HandlePass(const ListValue* args) {
test_succeeded_ = true;
if (is_waiting_)
MessageLoopForUI::current()->Quit();
}
void WebUIHandlerBrowserTest::HandleFail(const ListValue* args) {
test_succeeded_ = false;
if (is_waiting_)
MessageLoopForUI::current()->Quit();
}
void WebUIHandlerBrowserTest::RegisterMessages() {
web_ui_->RegisterMessageCallback("Pass",
NewCallback(this, &WebUIHandlerBrowserTest::HandlePass));
web_ui_->RegisterMessageCallback("Fail",
NewCallback(this, &WebUIHandlerBrowserTest::HandleFail));
}
bool WebUIHandlerBrowserTest::WaitForResult() {
is_waiting_ = true;
ui_test_utils::RunMessageLoop();
is_waiting_ = false;
return test_succeeded_;
}
|