forked from chromiumembedded/java-cef
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplayHandlerTest.java
More file actions
81 lines (64 loc) · 2.53 KB
/
DisplayHandlerTest.java
File metadata and controls
81 lines (64 loc) · 2.53 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) 2019 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.
package tests.junittests;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.cef.browser.CefBrowser;
import org.cef.browser.CefFrame;
import org.cef.handler.CefDisplayHandlerAdapter;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
// Test the DisplayHandler implementation.
@ExtendWith(TestSetupExtension.class)
class DisplayHandlerTest {
private final String testUrl_ = "http://test.com/test.html";
private final String testContent_ =
"<html><head><title>Test Title</title></head><body>Test!</body></html>";
private boolean gotCallback_ = false;
@Test
void onTitleChange() {
TestFrame frame = new TestFrame() {
@Override
protected void setupTest() {
client_.addDisplayHandler(new CefDisplayHandlerAdapter() {
@Override
public void onTitleChange(CefBrowser browser, String title) {
assertFalse(gotCallback_);
gotCallback_ = true;
assertEquals("Test Title", title);
terminateTest();
}
});
addResource(testUrl_, testContent_, "text/html");
createBrowser(testUrl_);
super.setupTest();
}
};
frame.awaitCompletion();
assertTrue(gotCallback_);
}
@Test
void onAddressChange() {
TestFrame frame = new TestFrame() {
@Override
protected void setupTest() {
client_.addDisplayHandler(new CefDisplayHandlerAdapter() {
@Override
public void onAddressChange(CefBrowser browser, CefFrame frame, String url) {
assertFalse(gotCallback_);
gotCallback_ = true;
assertEquals(url, testUrl_);
terminateTest();
}
});
addResource(testUrl_, testContent_, "text/html");
createBrowser(testUrl_);
super.setupTest();
}
};
frame.awaitCompletion();
assertTrue(gotCallback_);
}
}