2013-04-01 19:57:28 +02:00
|
|
|
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/window_test.h"
|
2013-04-01 19:57:28 +02:00
|
|
|
|
|
|
|
#include <algorithm>
|
2014-01-28 00:31:03 +01:00
|
|
|
#include <sstream>
|
2013-04-01 19:57:28 +02:00
|
|
|
#include <string>
|
2014-01-28 00:31:03 +01:00
|
|
|
#include <vector>
|
2013-04-01 19:57:28 +02:00
|
|
|
|
2021-06-17 22:08:01 +02:00
|
|
|
#include "include/base/cef_callback.h"
|
2013-04-01 19:57:28 +02:00
|
|
|
#include "include/wrapper/cef_stream_resource_handler.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/main_context.h"
|
2017-11-09 20:00:47 +01:00
|
|
|
#include "tests/cefclient/browser/test_runner.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/window_test_runner.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
#if defined(OS_WIN) || defined(OS_LINUX)
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/window_test_runner_views.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/window_test_runner_win.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
#elif defined(OS_LINUX)
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/window_test_runner_gtk.h"
|
2020-08-29 00:39:23 +02:00
|
|
|
#elif defined(OS_MAC)
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/window_test_runner_mac.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
#endif
|
2013-04-01 19:57:28 +02:00
|
|
|
|
2015-01-22 21:21:21 +01:00
|
|
|
namespace client {
|
2013-04-01 19:57:28 +02:00
|
|
|
namespace window_test {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2017-11-09 20:00:47 +01:00
|
|
|
const char kTestUrlPath[] = "/window";
|
2014-01-28 00:31:03 +01:00
|
|
|
const char kMessagePositionName[] = "WindowTest.Position";
|
|
|
|
const char kMessageMinimizeName[] = "WindowTest.Minimize";
|
|
|
|
const char kMessageMaximizeName[] = "WindowTest.Maximize";
|
|
|
|
const char kMessageRestoreName[] = "WindowTest.Restore";
|
2013-04-01 19:57:28 +02:00
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// Create the appropriate platform test runner object.
|
2021-06-17 22:08:01 +02:00
|
|
|
std::unique_ptr<WindowTestRunner> CreateWindowTestRunner() {
|
2016-01-19 21:09:01 +01:00
|
|
|
#if defined(OS_WIN) || defined(OS_LINUX)
|
|
|
|
if (MainContext::Get()->UseViews())
|
2021-06-17 22:08:01 +02:00
|
|
|
return std::make_unique<WindowTestRunnerViews>();
|
2016-01-19 21:09:01 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
2021-06-17 22:08:01 +02:00
|
|
|
return std::make_unique<WindowTestRunnerWin>();
|
2016-01-19 21:09:01 +01:00
|
|
|
#elif defined(OS_LINUX)
|
2021-06-17 22:08:01 +02:00
|
|
|
return std::make_unique<WindowTestRunnerGtk>();
|
2020-08-29 00:39:23 +02:00
|
|
|
#elif defined(OS_MAC)
|
2021-06-17 22:08:01 +02:00
|
|
|
return std::make_unique<WindowTestRunnerMac>();
|
2016-01-19 21:09:01 +01:00
|
|
|
#else
|
|
|
|
#error "No implementation available for your platform."
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-04-01 19:57:28 +02:00
|
|
|
// Handle messages in the browser process.
|
2014-01-28 00:31:03 +01:00
|
|
|
class Handler : public CefMessageRouterBrowserSide::Handler {
|
2013-04-01 19:57:28 +02:00
|
|
|
public:
|
2017-05-17 11:29:28 +02:00
|
|
|
Handler() : runner_(CreateWindowTestRunner()) {}
|
2014-01-28 00:31:03 +01:00
|
|
|
|
|
|
|
// Called due to cefBroadcast execution in window.html.
|
|
|
|
virtual bool OnQuery(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int64 query_id,
|
|
|
|
const CefString& request,
|
|
|
|
bool persistent,
|
2021-06-17 21:43:06 +02:00
|
|
|
CefRefPtr<Callback> callback) override {
|
2014-01-28 00:31:03 +01:00
|
|
|
// Only handle messages from the test URL.
|
|
|
|
const std::string& url = frame->GetURL();
|
2017-11-09 20:00:47 +01:00
|
|
|
if (!test_runner::IsTestURL(url, kTestUrlPath))
|
2014-01-28 00:31:03 +01:00
|
|
|
return false;
|
2013-04-01 19:57:28 +02:00
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
const std::string& message_name = request;
|
|
|
|
if (message_name.find(kMessagePositionName) == 0) {
|
|
|
|
// Parse the comma-delimited list of integer values.
|
|
|
|
std::vector<int> vec;
|
|
|
|
const std::string& vals =
|
|
|
|
message_name.substr(sizeof(kMessagePositionName));
|
|
|
|
std::stringstream ss(vals);
|
|
|
|
int i;
|
|
|
|
while (ss >> i) {
|
|
|
|
vec.push_back(i);
|
|
|
|
if (ss.peek() == ',')
|
|
|
|
ss.ignore();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vec.size() == 4) {
|
2015-01-22 21:21:21 +01:00
|
|
|
// Execute SetPos() on the main thread.
|
2016-01-19 21:09:01 +01:00
|
|
|
runner_->SetPos(browser, vec[0], vec[1], vec[2], vec[3]);
|
2013-04-01 19:57:28 +02:00
|
|
|
}
|
|
|
|
} else if (message_name == kMessageMinimizeName) {
|
2015-01-22 21:21:21 +01:00
|
|
|
// Execute Minimize() on the main thread.
|
2016-01-19 21:09:01 +01:00
|
|
|
runner_->Minimize(browser);
|
2013-04-01 19:57:28 +02:00
|
|
|
} else if (message_name == kMessageMaximizeName) {
|
2015-01-22 21:21:21 +01:00
|
|
|
// Execute Maximize() on the main thread.
|
2016-01-19 21:09:01 +01:00
|
|
|
runner_->Maximize(browser);
|
2013-04-01 19:57:28 +02:00
|
|
|
} else if (message_name == kMessageRestoreName) {
|
2015-01-22 21:21:21 +01:00
|
|
|
// Execute Restore() on the main thread.
|
2016-01-19 21:09:01 +01:00
|
|
|
runner_->Restore(browser);
|
2014-01-28 00:31:03 +01:00
|
|
|
} else {
|
2014-07-11 22:10:05 +02:00
|
|
|
NOTREACHED();
|
2013-04-01 19:57:28 +02:00
|
|
|
}
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
callback->Success("");
|
|
|
|
return true;
|
2013-04-01 19:57:28 +02:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
private:
|
2021-06-17 22:08:01 +02:00
|
|
|
std::unique_ptr<WindowTestRunner> runner_;
|
2013-04-01 19:57:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2015-01-22 21:21:21 +01:00
|
|
|
void CreateMessageHandlers(test_runner::MessageHandlerSet& handlers) {
|
|
|
|
handlers.insert(new Handler());
|
|
|
|
}
|
|
|
|
|
2013-04-01 19:57:28 +02:00
|
|
|
} // namespace window_test
|
2015-01-22 21:21:21 +01:00
|
|
|
} // namespace client
|