Fix crash when ALT+Clicking invalid protocol link (issue #2306)

This commit is contained in:
Marshall Greenblatt
2017-12-22 16:05:32 -05:00
parent f052e282dd
commit 54a015f785
6 changed files with 326 additions and 104 deletions

View File

@@ -8,8 +8,10 @@
#include "include/cef_process_message.h"
#include "include/cef_request.h"
#include "include/cef_request_context.h"
#include "include/cef_response.h"
#include "include/cef_values.h"
#include "tests/ceftests/test_suite.h"
// Test that CefRequest::HeaderMap objects are equal
// If |allowExtras| is true then additional header fields will be allowed in
@@ -62,4 +64,116 @@ void TestProcessMessageEqual(CefRefPtr<CefProcessMessage> val1,
void TestStringVectorEqual(const std::vector<CefString>& val1,
const std::vector<CefString>& val2);
enum TestRequestContextMode {
TEST_RC_MODE_NONE,
TEST_RC_MODE_GLOBAL,
TEST_RC_MODE_GLOBAL_WITH_HANDLER,
TEST_RC_MODE_CUSTOM,
TEST_RC_MODE_CUSTOM_WITH_HANDLER,
};
inline bool IsTestRequestContextModeCustom(TestRequestContextMode mode) {
return mode == TEST_RC_MODE_CUSTOM ||
mode == TEST_RC_MODE_CUSTOM_WITH_HANDLER;
}
// Return a RequestContext object matching the specified |mode|.
// |cache_path| may be specified for CUSTOM modes.
// Use the RC_TEST_GROUP_BASE macro to test all valid combinations.
CefRefPtr<CefRequestContext> CreateTestRequestContext(
TestRequestContextMode mode,
const std::string& cache_path);
// Helper macro for testing a single RequestContextMode value.
// See RC_TEST_GROUP_ALL documentation for example usage.
#define RC_TEST_BASE(test_case_name, test_name, test_class, test_mode, \
rc_mode, with_cache_path) \
TEST(test_case_name, test_name) { \
CefScopedTempDir scoped_temp_dir; \
std::string cache_path; \
if (with_cache_path) { \
EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); \
cache_path = scoped_temp_dir.GetPath(); \
} \
CefRefPtr<test_class> handler = \
new test_class(test_class::test_mode, rc_mode, cache_path); \
handler->ExecuteTest(); \
ReleaseAndWaitForDestructor(handler); \
if (!scoped_temp_dir.IsEmpty()) { \
CefTestSuite::GetInstance()->RegisterTempDirectory( \
scoped_temp_dir.Take()); \
} \
}
// RequestContextModes that operate in memory.
#define RC_TEST_GROUP_IN_MEMORY(test_case_name, test_name, test_class, \
test_mode) \
RC_TEST_BASE(test_case_name, test_name##RCNone, test_class, test_mode, \
TEST_RC_MODE_NONE, false); \
RC_TEST_BASE(test_case_name, test_name##RCGlobal, test_class, test_mode, \
TEST_RC_MODE_GLOBAL, false); \
RC_TEST_BASE(test_case_name, test_name##RCGlobalWithHandler, test_class, \
test_mode, TEST_RC_MODE_GLOBAL_WITH_HANDLER, false); \
RC_TEST_BASE(test_case_name, test_name##RCCustomInMemory, test_class, \
test_mode, TEST_RC_MODE_CUSTOM, false); \
RC_TEST_BASE(test_case_name, test_name##RCCustomInMemoryWithHandler, \
test_class, test_mode, TEST_RC_MODE_CUSTOM_WITH_HANDLER, \
false);
// RequestContextModes that operate on disk.
#define RC_TEST_GROUP_ON_DISK(test_case_name, test_name, test_class, \
test_mode) \
RC_TEST_BASE(test_case_name, test_name##RCCustomOnDisk, test_class, \
test_mode, TEST_RC_MODE_CUSTOM, true); \
RC_TEST_BASE(test_case_name, test_name##RCCustomOnDiskWithHandler, \
test_class, test_mode, TEST_RC_MODE_CUSTOM_WITH_HANDLER, true);
// Helper macro for testing all valid combinations of RequestContextMode values.
// For example:
//
// // Test handler implementation.
// class MyTestHandler : public TestHandler {
// public:
// // Test modes supported by MyTestHandler.
// enum TestMode {
// FIRST,
// SECOND,
// };
//
// // Constructor always accepts three arguments.
// MyTestHandler(TestMode test_mode,
// TestRequestContextMode rc_mode,
// const std::string& rc_cache_path)
// : test_mode_(test_mode), rc_mode_(rc_mode),
// rc_cache_path_(rc_cache_path) {}
//
// void RunTest() override {
// // Create a RequestContext with the specified attributes.
// CefRefPtr<CefRequestContext> request_context =
// CreateTestRequestContext(rc_mode_, rc_cache_path_);
//
// // Do something with |test_mode_| and |request_context|...
// }
//
// private:
// const TestMode test_mode_;
// const TestRequestContextMode rc_mode_;
// const std::string rc_cache_path_;
//
// IMPLEMENT_REFCOUNTING(MyTestHandler);
// };
//
// // Helper macro for defining tests using MyTestHandler.
// #define MY_TEST_GROUP(test_name, test_mode) \
// RC_TEST_GROUP_ALL(MyTest, test_name, MyTestHandler, test_mode)
//
// // Implementation for MyTest.First* tests.
// MY_TEST_GROUP(First, FIRST);
// // Implementation for MyTest.Second* tests.
// MY_TEST_GROUP(Second, SECOND);
//
#define RC_TEST_GROUP_ALL(test_case_name, test_name, test_class, test_mode) \
RC_TEST_GROUP_IN_MEMORY(test_case_name, test_name, test_class, test_mode) \
RC_TEST_GROUP_ON_DISK(test_case_name, test_name, test_class, test_mode)
#endif // CEF_TESTS_UNITTESTS_TEST_UTIL_H_