Opened 3 years ago

Closed 13 months ago

#4081 closed defect (fixed)

Fix failing MockWebRequestTest test for libadblockplus-android

Reported by: asmirnov Assignee: asmirnov
Priority: P3 Milestone:
Module: Libadblockplus-Android Keywords:
Cc: rjeschke Blocked By: #4031
Blocking: Platform: Unknown / Cross platform
Ready: yes Confidential: no
Tester: Unknown Verified working: no
Review URL(s):

https://codereview.adblockplus.org/29345369/

Description

MockWebRequestTest test similar to https://hg.adblockplus.org/libadblockplus/file/tip/test/WebRequest.cpp.

It is failing with assert exception:

     [exec] junit.framework.ComparisonFailure: expected:<{["Foo":"Bar"]}> but was:<{[]}>
     [exec] 	at org.adblockplus.libadblockplus.tests.MockWebRequestTest.testSuccessfulRequest(MockWebRequestTest.java:118)
     [exec] 	at java.lang.reflect.Method.invokeNative(Native Method)
     [exec] 	at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
     [exec] 	at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
     [exec] 	at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
     [exec] 	at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)

The reason is (most likely) headers are not mapped from java code to c++ code even if mock webrequest impl with headers is used:

private class LocalMockWebRequest extends WebRequest {
        @Override
        public ServerResponse httpGET(String url, List<HeaderEntry> headers) {
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            ServerResponse result = new ServerResponse();
            result.setStatus(ServerResponse.NsStatus.OK);
            result.setResponseStatus(123);
            result.setReponseHeaders(Arrays.asList(new HeaderEntry("Foo", "Bar")));

            result.setResponse(
                url + "\n" +
                headers.get(0).getKey() + "\n" +
                headers.get(0).getValue());
            return result;
        }
    }

and

@Override
    protected void setUp() throws Exception {
        super.setUp();

        jsEngine.setWebRequest(new LocalMockWebRequest());
    }

Change History (7)

comment:1 Changed 3 years ago by asmirnov

  • Component changed from Unknown to Libadblockplus-Android

comment:2 Changed 3 years ago by asmirnov

  • Owner changed from Anton to asmirnov

comment:4 Changed 3 years ago by asmirnov

  • Status changed from new to reviewing

comment:5 Changed 3 years ago by asmirnov

  • Review URL(s) modified (diff)

comment:6 Changed 3 years ago by abpbot

comment:7 Changed 13 months ago by asmirnov

  • Resolution set to fixed
  • Status changed from reviewing to closed
Note: See TracTickets for help on using tickets.