Allow determining when JS has finished loading in ClientWebView.

* src/client/components/client-web-view.vala (ClientWebView): Add
  is_content_loaded property and content_loaded signal, update and fire
  when getting a contentLoaded message from the WebProcess.

* ui/client-web-view.js: Fire the contentLoaded message when loading is
  complete. Add ClientPageStateTest test case to ensure it is working
  fine.

* test/client/components/client-web-view-test-case.vala
  (ClientWebViewTestCase::load_body_fixture): Use is_content_loaded
  rather than is_loading as the test for loading having finished, since
  we're actually interested in when the JS has finished loaded, not the
  resources.
This commit is contained in:
Michael James Gratton 2017-11-16 12:44:57 +11:00
parent 7ad97fb5d9
commit f1e92feae2
6 changed files with 93 additions and 3 deletions

View file

@ -0,0 +1,54 @@
/*
* Copyright 2017 Michael Gratton <mike@vee.net>
*
* This software is licensed under the GNU Lesser General Public License
* (version 2.1 or later). See the COPYING file in this distribution.
*/
class ClientPageStateTest : ClientWebViewTestCase<ClientWebView> {
public ClientPageStateTest() {
base("ClientPageStateTest");
add_test("content_loaded", content_loaded);
try {
ClientWebView.load_scripts();
} catch (Error err) {
assert_not_reached();
}
}
public void content_loaded() {
bool content_loaded_triggered = false;
this.test_view.content_loaded.connect(() => {
content_loaded_triggered = true;
});
assert(!this.test_view.is_content_loaded);
// XXX sketchy - this call will never return if the thing we
// are testing does not work
load_body_fixture("OHHAI");
assert(this.test_view.is_content_loaded);
assert(content_loaded_triggered);
}
protected override ClientWebView set_up_test_view() {
WebKit.UserScript test_script;
test_script = new WebKit.UserScript(
"var geary = new PageState()",
WebKit.UserContentInjectedFrames.TOP_FRAME,
WebKit.UserScriptInjectionTime.START,
null,
null
);
ClientWebView view = new ClientWebView(this.config);
view.get_user_content_manager().add_script(test_script);
return view;
}
}