Changes between Initial Version and Version 1 of EFLWebKitTests


Ignore:
Timestamp:
Jul 13, 2012 5:49:13 AM (9 years ago)
Author:
tmpsantos@gmail.com
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • EFLWebKitTests

    v1 v1  
     1The WebKit project mandates that every new feature needs tests in order get accepted at the main repository. The EFL WebKit port is no different. If you are writing new APIs or modifying the existing ones, make sure that your changes are backed by a unit test.
     2
     3= gtest =
     4
     5EFL WebKit 1 and 2 uses [http://code.google.com/p/googletest/ gtest] as unit test framework. We strongly recommend reading the [http://code.google.com/p/googletest/wiki/Primer introduction] to gtest before starting. This should be enough to cover most of our testing use cases.
     6
     7= Writing new unit tests for WebKit 2 =
     8
     9== Adding a new test file ==
     10
     11Every API should have a respective test file. For adding a test for an hypothetical ewk_foobarnicator.cpp, the bootstrap should be:
     12
     13 * Add your test file at: Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_foobarnicator.cpp (the prefix is test_ewk2 and not test_ewk, this was done to avoid clashes with WK1 tests)
     14 * Edit [source:trunk/Source/WebKit2/PlatformEfl.cmake Source/WebKit2/PlatformEfl.cmake] and add your test to the EWK2UnitTests_BINARIES list. Note that the test name is the same as the file without the .cpp extension.
     15
     16= Writing the new test =
     17
     18 * The EFL WebKit provides a gtest environment and a fixture to help you writing your tests. The fixture will create a webview ready to use.
     19 * The code bellow is a simplified example of how to test a getter of the ewk_foobarnicator API using the convenience loadUrlSync() method to load a page inline:
     20
     21{{{
     22TEST_F(EWK2UnitTestBase, ewk_foobarnicator_bar_get)
     23{
     24    loadUrlSync(environment->defaultTestPageUrl());
     25    EXPECT_STREQ(ewk_foobarnicator_bar_get(webView()), "my expected string");
     26}
     27}}}
     28
     29 * The same test could have be written using the normal main loop asynchronous flow:
     30
     31{{{
     32static void onLoadProgress(void* userData, Evas_Object* webView, void* eventInfo)
     33{
     34    double progress = *static_cast<double*>(eventInfo);
     35    if (progress != 1)
     36        return;
     37
     38    EXPECT_STREQ(ewk_foobarnicator_bar_get(webView), "my expected string");
     39    ecore_main_loop_quit();
     40}
     41
     42TEST_F(EWK2UnitTestBase, ewk_view_uri_get)
     43{
     44    ewk_view_uri_set(webView(), environment->defaultTestPageUrl());
     45    evas_object_smart_callback_add(webView(), "load,progress", onLoadProgress, this);
     46    ecore_main_loop_begin();
     47}
     48}}}
     49 
     50 * It is recommended to write one test entry at the file per function you are testing (but not enforced). The reason is because every new entry gets a new fixture and consecutively, a fresh webview. We can make sure that a bug on the function A will not interfere on the function B.
     51 * The test environment can be extended by per-test basis. But in order to do that, you might need to override the test main().
     52 * Feel free to extend the test fixture and environment if you find a convenience method/function that might be useful for other tests.
     53
     54== Debugging tests ==
     55
     56 * Tests will render by default on a offscreen memory buffer. You can override this by supplying the flag --useX11Window to your test binary to see what is going on.
     57 * You should do a total cleanup of the memory allocated by your tests. The reason is because we might use these tests on a future leak detector bot, running them wrapped in valgrind + memchecker (and because this is what nice developers do).
     58
     59== Questions ==
     60
     61 * Questions regarding WebKit 2 tests can be answered at #webkit-efl at Freenode (you might want to poke tmpsantos) or at webkit-efl mailing list.